async def get_all_open_positions(test=True): bitmex_client = bitmex( test=test, api_key='x48r7VjMUus3QyYZjPMEKF-V', api_secret='WYnTxTvSIKNou8FBXK-9cJtjFlQhWiaFdmJJN-se4UaCnYQW') bitmex_opens = bitmex_client.Position.Position_get().result() msg = { "jsonrpc": "2.0", "id": 404, "method": "private/get_position", "params": { "instrument_name": "BTC-27DEC19" } } auth_msg = { "jsonrpc": "2.0", "id": 9929, "method": "public/auth", "params": { "grant_type": "client_credentials", "client_id": 'vwfyxeIV', "client_secret": 'RhGoowkhuL5Y-HqEqyzIU0Ss1UmKTg4v5DghS6Ld8iE' } } api_url = 'wss://test.deribit.com/ws/api/v2' if test == False: api_url = 'wss://www.deribit.com/ws/api/v2' async with websockets.connect(api_url) as websocket: await websocket.send(json.dumps(auth_msg)) response1 = await websocket.recv() await websocket.send(json.dumps(msg)) response = await websocket.recv() # do something with the response... deribit_opens = (json.loads(response)) return ({'bitmex_opens': bitmex_opens, 'deribit_opens': deribit_opens})
# updates spread percentiles thresholds once per day if loop_counter > 1440: (open_spread, close_spread) = spread_finder(test=TEST) # gets and prints current open sizes on both markets open_sizes_dict = get_open_sizes(test=TEST) bitmex_open = open_sizes_dict['bm_d27_qty'] deribit_open = open_sizes_dict['db_d27_qty'] print( f"Bitmex Open Qty: {bitmex_open}, Deribit Open Qty: {deribit_open}" ) # this may need to be moved up 1 level to outside 'while True' loop bitmex_client = bitmex( test=TEST, api_key='x48r7VjMUus3QyYZjPMEKF-V', api_secret='WYnTxTvSIKNou8FBXK-9cJtjFlQhWiaFdmJJN-se4UaCnYQW') while ((deribit_open == 0) and (bitmex_open == 0)): print("\nBitmex & Deribit @ 0. Monitoring for OPENING oppurtunity") (bm_ask_d27, bm_bid_d27, db_ask_d27, db_bid_d27) = get_d27_prices(test=TEST) if ( (bm_bid_d27 - db_ask_d27) > open_spread ): #bitmex bid (sell) atleast 0.5% greater than deribit ask (buy) #TODO: implement limit_wait_til_filled() trades bitmex_response = place_bitmex_market( side='Sell', qty=PURCHASE_AMOUNT,
def close_bitmex_positions(test=True, bitmex_public = 'x48r7VjMUus3QyYZjPMEKF-V', bitmex_secret = 'WYnTxTvSIKNou8FBXK-9cJtjFlQhWiaFdmJJN-se4UaCnYQW'): bitmex_client = bitmex(test=test, api_key=bitmex_public, api_secret=bitmex_secret) return(bitmex_client.Order.Order_closePosition(symbol="XBTZ19").result())
def bitmex_test_market(symbol='XBTUSD',qty=1000): bitmex_client = bitmex(test=True, api_key=bitmex_public, api_secret=bitmex_secret) bitmex_client.Order.Order_new(side='Buy', symbol=symbol, orderQty=qty, ordType='Market').result()
def get_bitmex_positions(test=True, bitmex_public = 'x48r7VjMUus3QyYZjPMEKF-V', bitmex_secret = 'WYnTxTvSIKNou8FBXK-9cJtjFlQhWiaFdmJJN-se4UaCnYQW'): bitmex_client = bitmex(test=test, api_key=bitmex_public, api_secret=bitmex_secret) return(bitmex_client.Position.Position_get().result())
def bitmex_cancel(test=True, bitmex_public = 'x48r7VjMUus3QyYZjPMEKF-V', bitmex_secret = 'WYnTxTvSIKNou8FBXK-9cJtjFlQhWiaFdmJJN-se4UaCnYQW'): bitmex_client = bitmex(test=test, api_key=bitmex_public, api_secret=bitmex_secret) return(bitmex_client.Order.Order_cancel().result())
def get_bitmex_opens(test=True, bitmex_public = 'x48r7VjMUus3QyYZjPMEKF-V', bitmex_secret = 'WYnTxTvSIKNou8FBXK-9cJtjFlQhWiaFdmJJN-se4UaCnYQW'): bitmex_client = bitmex(test=test, api_key=bitmex_public, api_secret=bitmex_secret) return(bitmex_client.Order.Order_getOrders(filter='{\"open\": true}').result())
def place_bitmex_limit_and_wait(price, side='Buy', symbol='XBTZ19', qty=1000, test=True, bitmex_public = 'x48r7VjMUus3QyYZjPMEKF-V', bitmex_secret = 'WYnTxTvSIKNou8FBXK-9cJtjFlQhWiaFdmJJN-se4UaCnYQW'): bitmex_client = bitmex(test=test, api_key=bitmex_public, api_secret=bitmex_secret) bitmex_limit = bitmex_client.Order.Order_new(side=side, symbol=symbol, orderQty=qty, ordType='Limit', price=price).result() # , clOrdID='abc123' parameter optional return()
def place_bitmex_market(side='Buy', symbol='XBTZ19',qty=1000, test=True, bitmex_public = 'x48r7VjMUus3QyYZjPMEKF-V', bitmex_secret = 'WYnTxTvSIKNou8FBXK-9cJtjFlQhWiaFdmJJN-se4UaCnYQW'): bitmex_client = bitmex(test=test, api_key=bitmex_public, api_secret=bitmex_secret) return(bitmex_client.Order.Order_new(side=side, symbol=symbol, orderQty=qty, ordType='Market').result())