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
parent
6b2e85e4b3
commit
2e878ca52a
|
@ -58,6 +58,10 @@ async def _setup_persistent_brokerd(
|
||||||
the broker backend as needed.
|
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(
|
log = _util.get_console_log(
|
||||||
loglevel or tractor.current_actor().loglevel,
|
loglevel or tractor.current_actor().loglevel,
|
||||||
name=f'{_util.subsys}.{brokername}',
|
name=f'{_util.subsys}.{brokername}',
|
||||||
|
|
|
@ -21,8 +21,6 @@ Deribit backend.
|
||||||
|
|
||||||
from piker.log import get_logger
|
from piker.log import get_logger
|
||||||
|
|
||||||
log = get_logger(__name__)
|
|
||||||
|
|
||||||
from .api import (
|
from .api import (
|
||||||
get_client,
|
get_client,
|
||||||
)
|
)
|
||||||
|
@ -30,13 +28,15 @@ from .feed import (
|
||||||
open_history_client,
|
open_history_client,
|
||||||
open_symbol_search,
|
open_symbol_search,
|
||||||
stream_quotes,
|
stream_quotes,
|
||||||
backfill_bars
|
# backfill_bars,
|
||||||
)
|
)
|
||||||
# from .broker import (
|
# from .broker import (
|
||||||
# trades_dialogue,
|
# open_trade_dialog,
|
||||||
# norm_trade_records,
|
# norm_trade_records,
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
log = get_logger(__name__)
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'get_client',
|
'get_client',
|
||||||
# 'trades_dialogue',
|
# 'trades_dialogue',
|
||||||
|
|
|
@ -64,7 +64,6 @@ from piker.accounting import (
|
||||||
open_pps,
|
open_pps,
|
||||||
PpTable,
|
PpTable,
|
||||||
)
|
)
|
||||||
from .._util import get_console_log
|
|
||||||
from piker.clearing._messages import (
|
from piker.clearing._messages import (
|
||||||
Order,
|
Order,
|
||||||
Status,
|
Status,
|
||||||
|
@ -217,7 +216,7 @@ async def recv_trade_updates(
|
||||||
client.inline_errors(to_trio)
|
client.inline_errors(to_trio)
|
||||||
|
|
||||||
# sync with trio task
|
# sync with trio task
|
||||||
to_trio.send_nowait(None)
|
to_trio.send_nowait(client.ib)
|
||||||
|
|
||||||
def push_tradesies(
|
def push_tradesies(
|
||||||
eventkit_obj,
|
eventkit_obj,
|
||||||
|
@ -513,8 +512,9 @@ async def open_trade_event_stream(
|
||||||
async with tractor.to_asyncio.open_channel_from(
|
async with tractor.to_asyncio.open_channel_from(
|
||||||
recv_trade_updates,
|
recv_trade_updates,
|
||||||
client=client,
|
client=client,
|
||||||
) as (first, trade_event_stream):
|
) as (ibclient, trade_event_stream):
|
||||||
|
|
||||||
|
assert ibclient is client.ib
|
||||||
task_status.started(trade_event_stream)
|
task_status.started(trade_event_stream)
|
||||||
await trio.sleep_forever()
|
await trio.sleep_forever()
|
||||||
|
|
||||||
|
@ -523,13 +523,10 @@ async def open_trade_event_stream(
|
||||||
async def trades_dialogue(
|
async def trades_dialogue(
|
||||||
|
|
||||||
ctx: tractor.Context,
|
ctx: tractor.Context,
|
||||||
loglevel: str = None,
|
# loglevel: str = None,
|
||||||
|
|
||||||
) -> AsyncIterator[dict[str, Any]]:
|
) -> 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'])
|
accounts_def = config.load_accounts(['ib'])
|
||||||
|
|
||||||
global _client_cache
|
global _client_cache
|
||||||
|
|
|
@ -422,7 +422,6 @@ def trades2pps(
|
||||||
@tractor.context
|
@tractor.context
|
||||||
async def trades_dialogue(
|
async def trades_dialogue(
|
||||||
ctx: tractor.Context,
|
ctx: tractor.Context,
|
||||||
loglevel: str = None,
|
|
||||||
|
|
||||||
) -> AsyncIterator[dict[str, Any]]:
|
) -> AsyncIterator[dict[str, Any]]:
|
||||||
|
|
||||||
|
|
|
@ -373,8 +373,8 @@ async def open_brokerd_dialog(
|
||||||
# TODO: ideally choose only one of these ep names..
|
# TODO: ideally choose only one of these ep names..
|
||||||
trades_endpoint: Callable
|
trades_endpoint: Callable
|
||||||
for ep_name in [
|
for ep_name in [
|
||||||
'trades_dialogue',
|
'trades_dialogue', # legacy
|
||||||
'open_trade_dialog',
|
'open_trade_dialog', # probably final name?
|
||||||
]:
|
]:
|
||||||
trades_endpoint = getattr(
|
trades_endpoint = getattr(
|
||||||
brokermod,
|
brokermod,
|
||||||
|
@ -390,7 +390,6 @@ async def open_brokerd_dialog(
|
||||||
# open live brokerd trades endpoint
|
# open live brokerd trades endpoint
|
||||||
open_trades_endpoint = portal.open_context(
|
open_trades_endpoint = portal.open_context(
|
||||||
trades_endpoint,
|
trades_endpoint,
|
||||||
loglevel=loglevel,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -527,7 +527,7 @@ _sells: defaultdict[
|
||||||
|
|
||||||
|
|
||||||
@tractor.context
|
@tractor.context
|
||||||
async def trades_dialogue(
|
async def open_trade_dialog(
|
||||||
|
|
||||||
ctx: tractor.Context,
|
ctx: tractor.Context,
|
||||||
broker: str,
|
broker: str,
|
||||||
|
@ -695,21 +695,21 @@ async def open_paperboi(
|
||||||
|
|
||||||
async with (
|
async with (
|
||||||
tractor.find_actor(service_name) as portal,
|
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
|
# NOTE: only spawn if no paperboi already is up since we likely
|
||||||
# don't need more then one actor for simulated order clearing
|
# don't need more then one actor for simulated order clearing
|
||||||
# per broker-backend.
|
# per broker-backend.
|
||||||
if portal is None:
|
if portal is None:
|
||||||
log.info('Starting new paper-engine actor')
|
log.info('Starting new paper-engine actor')
|
||||||
portal = await tn.start_actor(
|
portal = await an.start_actor(
|
||||||
service_name,
|
service_name,
|
||||||
enable_modules=[__name__]
|
enable_modules=[__name__]
|
||||||
)
|
)
|
||||||
we_spawned = True
|
we_spawned = True
|
||||||
|
|
||||||
async with portal.open_context(
|
async with portal.open_context(
|
||||||
trades_dialogue,
|
open_trade_dialog,
|
||||||
broker=broker,
|
broker=broker,
|
||||||
fqme=fqme,
|
fqme=fqme,
|
||||||
loglevel=loglevel,
|
loglevel=loglevel,
|
||||||
|
|
Loading…
Reference in New Issue