diff --git a/piker/clearing/_ems.py b/piker/clearing/_ems.py index f5eeff87..48c8cce3 100644 --- a/piker/clearing/_ems.py +++ b/piker/clearing/_ems.py @@ -201,6 +201,7 @@ async def clear_dark_triggers( msg = BrokerdOrder( action=cmd['action'], oid=oid, + account=cmd['account'], time_ns=time.time_ns(), # this **creates** new order request for the @@ -621,8 +622,11 @@ async def translate_and_relay_brokerd_events( # another stupid ib error to handle # if 10147 in message: cancel + resp = 'broker_errored' + broker_details = msg.dict() + # don't relay message to order requester client - continue + # continue elif name in ( 'status', @@ -741,6 +745,7 @@ async def process_client_order_cmds( oid=oid, reqid=reqid, time_ns=time.time_ns(), + account=live_entry.account, ) # NOTE: cancel response will be relayed back in messages @@ -814,6 +819,7 @@ async def process_client_order_cmds( action=action, price=trigger_price, size=size, + account=msg.account, ) # send request to backend @@ -1016,6 +1022,7 @@ async def _emsd_main( try: _router.clients.add(ems_client_order_stream) + # main entrypoint, run here until cancelled. await process_client_order_cmds( ems_client_order_stream, @@ -1035,7 +1042,7 @@ async def _emsd_main( dialogues = _router.dialogues - for oid, client_stream in dialogues.items(): + for oid, client_stream in dialogues.copy().items(): if client_stream == ems_client_order_stream: diff --git a/piker/ui/order_mode.py b/piker/ui/order_mode.py index 87332ac6..49a6cb99 100644 --- a/piker/ui/order_mode.py +++ b/piker/ui/order_mode.py @@ -103,7 +103,7 @@ class OrderMode: arrows: ArrowEditor multistatus: MultiStatus pp: PositionTracker - allocator: 'Allocator' # noqa + alloc: 'Allocator' # noqa pane: SettingsPane active: bool = False @@ -193,6 +193,7 @@ class OrderMode: order = self._staged_order = Order( action=action, price=price, + account=self.alloc.account_name(), size=0, symbol=symbol, brokers=symbol.brokers, @@ -538,6 +539,8 @@ async def open_order_mode( # load account names from ``brokers.toml`` accounts = bidict(config.load_accounts()) + # process pps back from broker, only present + # account names reported back from ``brokerd``. pp_account = None if pp_msg: @@ -598,7 +601,7 @@ async def open_order_mode( arrows, multistatus, pp_tracker, - allocator=alloc, + alloc=alloc, pane=order_pane, ) @@ -823,10 +826,13 @@ async def process_trades_and_update_ui( elif resp in ( 'broker_cancelled', 'broker_inactive', + 'broker_errored', 'dark_cancelled' ): # delete level line from view mode.on_cancel(oid) + broker_msg = msg['brokerd_msg'] + log.warning(f'Order {oid} failed with:\n{pformat(broker_msg)}') elif resp in ( 'dark_triggered'