Only relay fills if dialog still alive

open_order_loading
Tyler Goodlet 2022-08-16 11:18:49 -04:00
parent be8fd32e7d
commit bafd2cb44f
1 changed files with 17 additions and 24 deletions

View File

@ -249,12 +249,6 @@ async def clear_dark_triggers(
await brokerd_orders_stream.send(brokerd_msg) await brokerd_orders_stream.send(brokerd_msg)
# mark this entry as having sent an order
# request. the entry will be replaced once the
# target broker replies back with
# a ``BrokerdOrderAck`` msg including the
# allocated unique ``BrokerdOrderAck.reqid`` key
# generated by the broker's own systems.
# book._ems_entries[oid] = live_req # book._ems_entries[oid] = live_req
# book._msgflows[oid].maps.insert(0, live_req) # book._msgflows[oid].maps.insert(0, live_req)
@ -279,6 +273,12 @@ async def clear_dark_triggers(
) )
# update actives # update actives
# mark this entry as having sent an order
# request. the entry will be replaced once the
# target broker replies back with
# a ``BrokerdOrderAck`` msg including the
# allocated unique ``BrokerdOrderAck.reqid`` key
# generated by the broker's own systems.
if cmd.action == 'alert': if cmd.action == 'alert':
# don't register the alert status (so it won't # don't register the alert status (so it won't
# be reloaded by clients) since it's now # be reloaded by clients) since it's now
@ -666,7 +666,6 @@ async def translate_and_relay_brokerd_events(
# cancelled by the ems controlling client before we # cancelled by the ems controlling client before we
# received this ack, in which case we relay that cancel # received this ack, in which case we relay that cancel
# signal **asap** to the backend broker # signal **asap** to the backend broker
# status = book._active.get(oid)
status_msg = book._active[oid] status_msg = book._active[oid]
req = status_msg.req req = status_msg.req
if req and req.action == 'cancel': if req and req.action == 'cancel':
@ -747,14 +746,11 @@ async def translate_and_relay_brokerd_events(
if status == 'closed': if status == 'closed':
log.info(f'Execution for {oid} is complete!') log.info(f'Execution for {oid} is complete!')
# only if we already rxed a fill then probably
# this clear is fully complete? (frickin ib..)
if old_resp == 'fill':
status_msg = book._active.pop(oid) status_msg = book._active.pop(oid)
elif status == 'canceled': elif status == 'canceled':
log.cancel(f'Cancellation for {oid} is complete!') log.cancel(f'Cancellation for {oid} is complete!')
status_msg = book._active.pop(oid)
else: # open else: # open
# relayed from backend but probably not handled so # relayed from backend but probably not handled so
@ -775,14 +771,11 @@ async def translate_and_relay_brokerd_events(
ems_client_order_stream = router.dialogues[oid] ems_client_order_stream = router.dialogues[oid]
# wtf a fill can come after 'closed' from ib? # XXX: bleh, a fill can come after 'closed' from `ib`?
status_msg = book._active[oid] # only send a late fill event we haven't already closed
# out the dialog status locally.
# only if we already rxed a 'closed' status_msg = book._active.get(oid)
# this clear is fully complete? (frickin ib..) if status_msg:
# if status_msg.resp == 'closed':
# status_msg = book._active.pop(oid)
status_msg.resp = 'fill' status_msg.resp = 'fill'
status_msg.reqid = reqid status_msg.reqid = reqid
status_msg.brokerd_msg = msg status_msg.brokerd_msg = msg