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)
basic_buy_bot
Tyler Goodlet 2023-06-14 18:29:40 -04:00
parent 6b2e85e4b3
commit 2e878ca52a
6 changed files with 18 additions and 19 deletions

View File

@ -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}',

View File

@ -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',

View File

@ -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

View File

@ -422,7 +422,6 @@ def trades2pps(
@tractor.context
async def trades_dialogue(
ctx: tractor.Context,
loglevel: str = None,
) -> AsyncIterator[dict[str, Any]]:

View File

@ -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:

View File

@ -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,