Last active
April 25, 2020 15:14
-
-
Save rmcxm/00a6014240979f20f48679e732b4a1a2 to your computer and use it in GitHub Desktop.
Bitmex Swagger API samples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client = bitmex.bitmex(test=True, api_key='r72bdD9PDSGTN', api_secret='osCkZ-LosU2-6Wq5FO5U5pGDsTdo_urrX') | |
current price: | |
import requests, json | |
response = requests.get("https://www.bitmex.com/api/v1/orderBook/L2?symbol=eth&depth=1").json() | |
response [{'symbol': 'ETHUSD', 'id': 29699996359, 'side': 'Sell', 'size': 342, 'price': 182.05}, | |
{'symbol': 'ETHUSD', 'id': 29699996360, 'side': 'Buy', 'size': 160102, 'price': 182}] | |
client.OrderBook.OrderBook_getL2(symbol="XBTUSD",depth=2).result() | |
Place Orders: | |
short | |
client.Order.Order_new(symbol='XBTUSD', orderQty=-10, price=10405.0).result() | |
long | |
client.Order.Order_new(symbol='XBTUSD', orderQty=10, price=10505.0).result() | |
place stop loss sell with 'close on trigger' | |
client.Order.Order_new(symbol='XBTUSD', orderQty=-10, stopPx=10505.0, ordType='Stop', execInst='Close').result() | |
place stop loss buy with 'close on trigger' | |
client.Order.Order_new(symbol='XBTUSD', orderQty=10, stopPx=10505.0, ordType='Stop', execInst='Close').result() | |
place limit sell 'reduce only' | |
client.Order.Order_new(symbol='XBTUSD', orderQty=-10, price=10230.0, execInst='ReduceOnly').result() | |
client.Order.Order_new(symbol='ETHUSD', orderQty=1, price=148.65, execInst='ParticipateDoNotInitiate').result() | |
GetOrders: | |
OPEN ORDERS: | |
client.Order.Order_getOrders(symbol='XBTUSD', reverse=True, count=10, filter=json.dumps({"open": True})).result() | |
candle data: | |
getpositions: | |
client.Position.Position_get(filter=json.dumps({"symbol": "XBTUSD"})).result()[0][0]['avgEntryPrice'] | |
candle stick data | |
bucketed trades... | |
client.Trade.Trade_getBucketed(binSize='5m',count=5, symbol='XBTUSD', reverse=True).result() | |
balances-avail | |
client.User.User_getMargin().result()[0]['availableMargin'] | |
filled order | |
client.Order.Order_getOrders(symbol='XBTUSD', filter=json.dumps({"orderID": '59877027-90b5-c089-2c42-ff959ee74b43'})).result() | |
trailing stop: | |
client.Order.Order_new(symbol='XBTUSD', orderQty=-10, pegPriceType='TrailingStopPeg', pegOffsetValue='-10', execInst='Close,LastPrice').result() | |
client.Order.Order_new(symbol='XBTUSD', orderQty=10, pegPriceType='TrailingStopPeg', pegOffsetValue='10', execInst='Close,LastPrice').result() | |
BOT: | |
while True: | |
'your code here' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment