Support an account field in clearing system
Each backend broker may support multiple (types) of accounts; this patch lets clients send order requests that pass through an `account` field in certain `emsd` <-> `brokerd` transactions. This allows each provider to read in and conduct logic based on what account value is passed via requests to the `trades_dialogue()` endpoint as well as tie together positioning updates with relevant account keys for display in UIs. This also adds relay support for a `Status` msg with a `'broker_errored'` status which for now will trigger the same logic as cancelled orders on the client side and thus will remove order lines submitted on a chart.fsp_feeds
parent
504040eb59
commit
b01538f183
|
@ -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:
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue