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