Keep to one EMS daemon if possible
parent
327129db37
commit
a1691cf1c5
|
@ -146,6 +146,31 @@ async def send_order_cmds():
|
||||||
yield cmd
|
yield cmd
|
||||||
|
|
||||||
|
|
||||||
|
@asynccontextmanager
|
||||||
|
async def maybe_open_emsd(
|
||||||
|
) -> 'StreamReceiveChannel': # noqa
|
||||||
|
|
||||||
|
async with tractor.find_actor('emsd') as portal:
|
||||||
|
if portal is not None:
|
||||||
|
yield portal
|
||||||
|
|
||||||
|
else:
|
||||||
|
# we gotta spawn it
|
||||||
|
log.info("Spawning EMS daemon")
|
||||||
|
|
||||||
|
# TODO: add ``maybe_spawn_emsd()`` for this
|
||||||
|
async with tractor.open_nursery() as n:
|
||||||
|
|
||||||
|
portal = await n.start_actor(
|
||||||
|
'emsd',
|
||||||
|
enable_modules=[
|
||||||
|
'piker.exchange._ems',
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
yield portal
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def open_ems(
|
async def open_ems(
|
||||||
broker: str,
|
broker: str,
|
||||||
|
@ -182,18 +207,16 @@ async def open_ems(
|
||||||
- 'dark_cancelled', 'broker_cancelled'
|
- 'dark_cancelled', 'broker_cancelled'
|
||||||
- 'dark_executed', 'broker_executed'
|
- 'dark_executed', 'broker_executed'
|
||||||
- 'broker_filled'
|
- 'broker_filled'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
actor = tractor.current_actor()
|
actor = tractor.current_actor()
|
||||||
|
|
||||||
# TODO: add ``maybe_spawn_emsd()`` for this
|
# wait for service to connect back to us signalling
|
||||||
async with tractor.open_nursery() as n:
|
# ready for order commands
|
||||||
|
book = get_orders()
|
||||||
|
|
||||||
|
async with maybe_open_emsd() as portal:
|
||||||
|
|
||||||
portal = await n.start_actor(
|
|
||||||
'emsd',
|
|
||||||
enable_modules=[
|
|
||||||
'piker.exchange._ems',
|
|
||||||
],
|
|
||||||
)
|
|
||||||
trades_stream = await portal.run(
|
trades_stream = await portal.run(
|
||||||
_ems_main,
|
_ems_main,
|
||||||
client_actor_name=actor.name,
|
client_actor_name=actor.name,
|
||||||
|
@ -201,11 +224,6 @@ async def open_ems(
|
||||||
symbol=symbol.key,
|
symbol=symbol.key,
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# wait for service to connect back to us signalling
|
|
||||||
# ready for order commands
|
|
||||||
book = get_orders()
|
|
||||||
|
|
||||||
with trio.fail_after(10):
|
with trio.fail_after(10):
|
||||||
await book._ready_to_receive.wait()
|
await book._ready_to_receive.wait()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue