Only require `-b <brokername>` for filtering
Instead of requiring any `-b` try to import all built-in broker backend python modules by default and only load those detected from the input symbol list's fqsn values. In other words the `piker chart` cmd can be run sin `-b` now and that flag is only required if you only want to load a subset of the built-ins or are trying to load a specific not-yet-builtin backend.agg_feedz
parent
c944db5f02
commit
28fd795280
|
@ -36,7 +36,6 @@ from .. import config
|
|||
|
||||
|
||||
log = get_logger('cli')
|
||||
DEFAULT_BROKER = 'questrade'
|
||||
|
||||
|
||||
@click.command()
|
||||
|
@ -118,7 +117,7 @@ def pikerd(
|
|||
@click.group(context_settings=config._context_defaults)
|
||||
@click.option(
|
||||
'--brokers', '-b',
|
||||
default=[DEFAULT_BROKER],
|
||||
default=None,
|
||||
multiple=True,
|
||||
help='Broker backend to use'
|
||||
)
|
||||
|
@ -144,10 +143,13 @@ def cli(
|
|||
|
||||
ctx.ensure_object(dict)
|
||||
|
||||
if len(brokers) == 1:
|
||||
brokermods = [get_brokermod(brokers[0])]
|
||||
else:
|
||||
brokermods = [get_brokermod(broker) for broker in brokers]
|
||||
if not brokers:
|
||||
# (try to) load all (supposedly) supported data/broker backends
|
||||
from piker.brokers import __brokers__
|
||||
brokers = __brokers__
|
||||
|
||||
brokermods = [get_brokermod(broker) for broker in brokers]
|
||||
assert brokermods
|
||||
|
||||
reg_addr: None | tuple[str, int] = None
|
||||
if host or port:
|
||||
|
|
|
@ -19,15 +19,16 @@ Main app startup and run.
|
|||
|
||||
'''
|
||||
from functools import partial
|
||||
from types import ModuleType
|
||||
|
||||
from PyQt5.QtCore import QEvent
|
||||
import trio
|
||||
|
||||
from .._daemon import maybe_spawn_brokerd
|
||||
from ..brokers import get_brokermod
|
||||
from . import _event
|
||||
from ._exec import run_qtractor
|
||||
from ..data.feed import install_brokerd_search
|
||||
from ..data._source import unpack_fqsn
|
||||
from . import _search
|
||||
from ._chart import GodWidget
|
||||
from ..log import get_logger
|
||||
|
@ -36,27 +37,26 @@ log = get_logger(__name__)
|
|||
|
||||
|
||||
async def load_provider_search(
|
||||
|
||||
broker: str,
|
||||
brokermod: str,
|
||||
loglevel: str,
|
||||
|
||||
) -> None:
|
||||
|
||||
log.info(f'loading brokerd for {broker}..')
|
||||
name = brokermod.name
|
||||
log.info(f'loading brokerd for {name}..')
|
||||
|
||||
async with (
|
||||
|
||||
maybe_spawn_brokerd(
|
||||
broker,
|
||||
name,
|
||||
loglevel=loglevel
|
||||
) as portal,
|
||||
|
||||
install_brokerd_search(
|
||||
portal,
|
||||
get_brokermod(broker),
|
||||
brokermod,
|
||||
),
|
||||
):
|
||||
|
||||
# keep search engine stream up until cancelled
|
||||
await trio.sleep_forever()
|
||||
|
||||
|
@ -67,7 +67,7 @@ async def _async_main(
|
|||
main_widget: GodWidget,
|
||||
|
||||
syms: list[str],
|
||||
brokernames: str,
|
||||
brokers: dict[str, ModuleType],
|
||||
loglevel: str,
|
||||
|
||||
) -> None:
|
||||
|
@ -99,6 +99,11 @@ async def _async_main(
|
|||
sbar = godwidget.window.status_bar
|
||||
starting_done = sbar.open_status('starting ze sexy chartz')
|
||||
|
||||
needed_brokermods: dict[str, ModuleType] = {}
|
||||
for fqsn in syms:
|
||||
brokername, *_ = unpack_fqsn(fqsn)
|
||||
needed_brokermods[brokername] = brokers[brokername]
|
||||
|
||||
async with (
|
||||
trio.open_nursery() as root_n,
|
||||
):
|
||||
|
@ -140,8 +145,12 @@ async def _async_main(
|
|||
):
|
||||
# load other providers into search **after**
|
||||
# the chart's select cache
|
||||
for broker in brokernames:
|
||||
root_n.start_soon(load_provider_search, broker, loglevel)
|
||||
for brokername, mod in needed_brokermods.items():
|
||||
root_n.start_soon(
|
||||
load_provider_search,
|
||||
mod,
|
||||
loglevel,
|
||||
)
|
||||
|
||||
await order_mode_ready.wait()
|
||||
|
||||
|
@ -171,7 +180,7 @@ async def _async_main(
|
|||
|
||||
def _main(
|
||||
syms: list[str],
|
||||
brokernames: [str],
|
||||
brokermods: list[ModuleType],
|
||||
piker_loglevel: str,
|
||||
tractor_kwargs,
|
||||
) -> None:
|
||||
|
@ -182,7 +191,11 @@ def _main(
|
|||
'''
|
||||
run_qtractor(
|
||||
func=_async_main,
|
||||
args=(syms, brokernames, piker_loglevel),
|
||||
args=(
|
||||
syms,
|
||||
{mod.name: mod for mod in brokermods},
|
||||
piker_loglevel,
|
||||
),
|
||||
main_widget_type=GodWidget,
|
||||
tractor_kwargs=tractor_kwargs,
|
||||
)
|
||||
|
|
|
@ -166,16 +166,16 @@ def chart(
|
|||
))
|
||||
return
|
||||
|
||||
|
||||
# global opts
|
||||
brokernames = config['brokers']
|
||||
brokermods = config['brokermods']
|
||||
assert brokermods
|
||||
tractorloglevel = config['tractorloglevel']
|
||||
pikerloglevel = config['loglevel']
|
||||
|
||||
|
||||
_main(
|
||||
syms=symbols,
|
||||
brokernames=brokernames,
|
||||
brokermods=brokermods,
|
||||
piker_loglevel=pikerloglevel,
|
||||
tractor_kwargs={
|
||||
'debug_mode': pdb,
|
||||
|
|
Loading…
Reference in New Issue