Handle pre-existing open orders specifically by checking for null `oid`

kraken_ws_orders
Tyler Goodlet 2022-07-13 12:24:28 -04:00
parent abb6854e74
commit 5b135fad61
1 changed files with 16 additions and 8 deletions

View File

@ -202,7 +202,10 @@ async def handle_order_requests(
async def subscribe( async def subscribe(
ws: wsproto.WSConnection, ws: wsproto.WSConnection,
token: str, token: str,
subs: list[str] = ['ownTrades', 'openOrders'], subs: list[str] = [
'ownTrades',
'openOrders',
],
): ):
''' '''
Setup ws api subscriptions: Setup ws api subscriptions:
@ -603,10 +606,13 @@ async def handle_order_updates(
else: else:
vlm = rest.get('vol_exec', 0) vlm = rest.get('vol_exec', 0)
reqid = reqids2txids.inverse[txid] reqid = reqids2txids.inverse.get(txid)
oid = ids.inverse.get(reqid) oid = ids.inverse.get(reqid)
if not oid:
if (
status == 'open'
and oid is None # a non-ems-active order
):
# TODO: handle these and relay them # TODO: handle these and relay them
# through the EMS to the client / UI # through the EMS to the client / UI
# side! # side!
@ -621,13 +627,11 @@ async def handle_order_updates(
await ws.send_msg({ await ws.send_msg({
'event': 'cancelOrder', 'event': 'cancelOrder',
'token': token, 'token': token,
'reqid': reqid, 'reqid': reqid or 0,
'txid': [txid], 'txid': [txid],
}) })
continue continue
msgs = emsflow[oid]
# send BrokerdStatus messages for all # send BrokerdStatus messages for all
# order state updates # order state updates
resp = BrokerdStatus( resp = BrokerdStatus(
@ -655,7 +659,11 @@ async def handle_order_updates(
{'name': 'kraken'}, **update_msg {'name': 'kraken'}, **update_msg
), ),
) )
msgs.append(resp)
# TODO: use collections.ChainMap here
# msgs = emsflow[oid]
# msgs.append(resp)
await ems_stream.send(resp) await ems_stream.send(resp)
# fill event. # fill event.