Port clearing engine to new tractor stream api

tractor_open_stream_from
Tyler Goodlet 2021-04-29 08:40:16 -04:00
parent 56db2c812d
commit d3b50b9920
2 changed files with 133 additions and 131 deletions

View File

@ -246,13 +246,14 @@ async def open_ems(
async with maybe_open_emsd(broker) as portal:
trades_stream = await portal.run(
async with portal.open_stream_from(
_emsd_main,
client_actor_name=actor.name,
broker=broker,
symbol=symbol.key,
)
) as trades_stream:
with trio.fail_after(10):
await book._ready_to_receive.wait()

View File

@ -339,9 +339,9 @@ async def process_broker_trades(
"""
broker = feed.mod.name
with trio.fail_after(5):
# TODO: make this a context
# in the paper engine case this is just a mem receive channel
trades_stream = await feed.recv_trades_data()
async with feed.receive_trades_data() as trades_stream:
first = await trades_stream.__anext__()
# startup msg expected as first from broker backend
@ -426,7 +426,8 @@ async def process_broker_trades(
# - PendingSubmit
# - PendingCancel
# - PreSubmitted (simulated orders)
# - ApiCancelled (cancelled by client before submission to routing)
# - ApiCancelled (cancelled by client before submission
# to routing)
# - Cancelled
# - Filled
# - Inactive (reject or cancelled but not by trader)
@ -675,10 +676,10 @@ async def _emsd_main(
# acting as an EMS client and will submit orders) to
# receive requests pushed over a tractor stream
# using (for now) an async generator.
order_stream = await portal.run(
async with portal.open_stream_from(
send_order_cmds,
symbol_key=symbol,
)
) as order_stream:
# start inbound order request processing
await process_order_cmds(