Handle brokerd errors even when no client-side-status found

even_moar_kraken_order_fixes
Tyler Goodlet 2022-10-27 10:51:14 -04:00
parent c43f7eb656
commit 8a61211c8c
1 changed files with 22 additions and 7 deletions

View File

@ -581,6 +581,7 @@ class Router(Struct):
notify_on_headless: bool = True,
) -> bool:
# print(f'SUBSCRIBERS: {self.subscribers}')
to_remove: set[tractor.MsgStream] = set()
if sub_key == 'all':
@ -611,7 +612,8 @@ class Router(Struct):
and notify_on_headless
):
log.info(
'No clients attached, firing notification for {sub_key} msg:\n'
'No clients attached, '
f'firing notification for {sub_key} msg:\n'
f'{msg}'
)
await notify_from_ems_status_msg(
@ -763,8 +765,8 @@ async def translate_and_relay_brokerd_events(
'oid': oid, # ems order-dialog id
'reqid': reqid, # brokerd generated order-request id
'symbol': sym,
} if status_msg := book._active.get(oid):
}:
status_msg = book._active.get(oid)
msg = BrokerdError(**brokerd_msg)
log.error(fmsg) # XXX make one when it's blank?
@ -776,11 +778,21 @@ async def translate_and_relay_brokerd_events(
# about. In most default situations, with composed orders
# (ex. brackets), most brokers seem to use a oca policy.
status_msg.resp = 'error'
status_msg.brokerd_msg = msg
book._active[oid] = status_msg
# only relay to client side if we have an active
# ongoing dialog
if status_msg:
status_msg.resp = 'error'
status_msg.brokerd_msg = msg
book._active[oid] = status_msg
await router.client_broadcast(sym, status_msg)
await router.client_broadcast(
status_msg.req.symbol,
status_msg,
)
else:
log.error(f'Error for unknown order flow:\n{msg}')
continue
# BrokerdStatus
case {
@ -1265,6 +1277,9 @@ async def process_client_order_cmds(
status,
)
case _:
log.warning(f'Rx UNHANDLED order request {cmd}')
@acm
async def maybe_open_trade_relays(