Always allocate a new `OrderClient` per `open_ems()` call

master
Tyler Goodlet 2023-05-28 14:05:03 -04:00
parent 41aa87f847
commit f6549fcb62
1 changed files with 13 additions and 18 deletions

View File

@ -165,8 +165,6 @@ class OrderClient(Struct):
) )
_client: OrderClient = None
async def relay_orders_from_sync_code( async def relay_orders_from_sync_code(
@ -274,34 +272,31 @@ async def open_ems(
# open 2-way trade command stream # open 2-way trade command stream
ctx.open_stream() as trades_stream, ctx.open_stream() as trades_stream,
): ):
# use any pre-existing actor singleton client. size: int = 100 # what should this be?
global _client
if _client is None:
size = 100
tx, rx = trio.open_memory_channel(size) tx, rx = trio.open_memory_channel(size)
brx = broadcast_receiver(rx, size) brx = broadcast_receiver(rx, size)
# setup local ui event streaming channels for request/resp # setup local ui event streaming channels for request/resp
# streamging with EMS daemon # streamging with EMS daemon
_client = OrderClient( client = OrderClient(
_ems_stream=trades_stream, _ems_stream=trades_stream,
_to_relay_task=tx, _to_relay_task=tx,
_from_sync_order_client=brx, _from_sync_order_client=brx,
) )
_client._ems_stream = trades_stream client._ems_stream = trades_stream
# start sync code order msg delivery task # start sync code order msg delivery task
async with trio.open_nursery() as n: async with trio.open_nursery() as n:
n.start_soon( n.start_soon(
relay_orders_from_sync_code, relay_orders_from_sync_code,
_client, client,
fqme, fqme,
trades_stream trades_stream
) )
yield ( yield (
_client, client,
trades_stream, trades_stream,
positions, positions,
accounts, accounts,