From 2e878ca52abc40004d8dbfb5ed529c9ec7013241 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 14 Jun 2023 18:29:40 -0400 Subject: [PATCH] Don't pass loglevel to trade dialog endpoint It's been getting setup in the `brokerd` daemon-actor spawn task for a while now and worker tasks already get a ref to that global log instance so they don't need to care (in data or trading) task spawn endpoints. Also move to the new `open_trade_dialog()` naming for working broker backends B) --- piker/brokers/_daemon.py | 4 ++++ piker/brokers/deribit/__init__.py | 8 ++++---- piker/brokers/ib/broker.py | 11 ++++------- piker/brokers/kraken/broker.py | 1 - piker/clearing/_ems.py | 5 ++--- piker/clearing/_paper_engine.py | 8 ++++---- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/piker/brokers/_daemon.py b/piker/brokers/_daemon.py index 8a81b1d6..34cbfca4 100644 --- a/piker/brokers/_daemon.py +++ b/piker/brokers/_daemon.py @@ -58,6 +58,10 @@ async def _setup_persistent_brokerd( the broker backend as needed. ''' + # NOTE: we only need to setup logging once (and only) here + # since all hosted daemon tasks will reference this same + # log instance's (actor local) state and thus don't require + # any further (level) configuration on their own B) log = _util.get_console_log( loglevel or tractor.current_actor().loglevel, name=f'{_util.subsys}.{brokername}', diff --git a/piker/brokers/deribit/__init__.py b/piker/brokers/deribit/__init__.py index f5c48b58..4c0c1850 100644 --- a/piker/brokers/deribit/__init__.py +++ b/piker/brokers/deribit/__init__.py @@ -21,8 +21,6 @@ Deribit backend. from piker.log import get_logger -log = get_logger(__name__) - from .api import ( get_client, ) @@ -30,13 +28,15 @@ from .feed import ( open_history_client, open_symbol_search, stream_quotes, - backfill_bars + # backfill_bars, ) # from .broker import ( - # trades_dialogue, + # open_trade_dialog, # norm_trade_records, # ) +log = get_logger(__name__) + __all__ = [ 'get_client', # 'trades_dialogue', diff --git a/piker/brokers/ib/broker.py b/piker/brokers/ib/broker.py index 73477c0a..a5c68c36 100644 --- a/piker/brokers/ib/broker.py +++ b/piker/brokers/ib/broker.py @@ -64,7 +64,6 @@ from piker.accounting import ( open_pps, PpTable, ) -from .._util import get_console_log from piker.clearing._messages import ( Order, Status, @@ -217,7 +216,7 @@ async def recv_trade_updates( client.inline_errors(to_trio) # sync with trio task - to_trio.send_nowait(None) + to_trio.send_nowait(client.ib) def push_tradesies( eventkit_obj, @@ -513,8 +512,9 @@ async def open_trade_event_stream( async with tractor.to_asyncio.open_channel_from( recv_trade_updates, client=client, - ) as (first, trade_event_stream): + ) as (ibclient, trade_event_stream): + assert ibclient is client.ib task_status.started(trade_event_stream) await trio.sleep_forever() @@ -523,13 +523,10 @@ async def open_trade_event_stream( async def trades_dialogue( ctx: tractor.Context, - loglevel: str = None, + # loglevel: str = None, ) -> AsyncIterator[dict[str, Any]]: - # XXX: required to propagate ``tractor`` loglevel to piker logging - get_console_log(loglevel or tractor.current_actor().loglevel) - accounts_def = config.load_accounts(['ib']) global _client_cache diff --git a/piker/brokers/kraken/broker.py b/piker/brokers/kraken/broker.py index 96ab77ae..fc2eff62 100644 --- a/piker/brokers/kraken/broker.py +++ b/piker/brokers/kraken/broker.py @@ -422,7 +422,6 @@ def trades2pps( @tractor.context async def trades_dialogue( ctx: tractor.Context, - loglevel: str = None, ) -> AsyncIterator[dict[str, Any]]: diff --git a/piker/clearing/_ems.py b/piker/clearing/_ems.py index 7abd4a61..ffd5882b 100644 --- a/piker/clearing/_ems.py +++ b/piker/clearing/_ems.py @@ -373,8 +373,8 @@ async def open_brokerd_dialog( # TODO: ideally choose only one of these ep names.. trades_endpoint: Callable for ep_name in [ - 'trades_dialogue', - 'open_trade_dialog', + 'trades_dialogue', # legacy + 'open_trade_dialog', # probably final name? ]: trades_endpoint = getattr( brokermod, @@ -390,7 +390,6 @@ async def open_brokerd_dialog( # open live brokerd trades endpoint open_trades_endpoint = portal.open_context( trades_endpoint, - loglevel=loglevel, ) else: diff --git a/piker/clearing/_paper_engine.py b/piker/clearing/_paper_engine.py index fd998e97..4220bf63 100644 --- a/piker/clearing/_paper_engine.py +++ b/piker/clearing/_paper_engine.py @@ -527,7 +527,7 @@ _sells: defaultdict[ @tractor.context -async def trades_dialogue( +async def open_trade_dialog( ctx: tractor.Context, broker: str, @@ -695,21 +695,21 @@ async def open_paperboi( async with ( tractor.find_actor(service_name) as portal, - tractor.open_nursery() as tn, + tractor.open_nursery() as an, ): # NOTE: only spawn if no paperboi already is up since we likely # don't need more then one actor for simulated order clearing # per broker-backend. if portal is None: log.info('Starting new paper-engine actor') - portal = await tn.start_actor( + portal = await an.start_actor( service_name, enable_modules=[__name__] ) we_spawned = True async with portal.open_context( - trades_dialogue, + open_trade_dialog, broker=broker, fqme=fqme, loglevel=loglevel,