From fd8dc4f1a3389b35e8251e3f5ca1d6045a2da4fc Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 18 May 2021 08:38:13 -0400 Subject: [PATCH] Make -b a multi-option for backends --- piker/brokers/cli.py | 14 +++++++------- piker/cli/__init__.py | 20 +++++++++++++++----- piker/ui/_chart.py | 8 ++++---- piker/ui/_exec.py | 1 + piker/ui/cli.py | 6 +++--- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/piker/brokers/cli.py b/piker/brokers/cli.py index aa3abd24..b0083cfa 100644 --- a/piker/brokers/cli.py +++ b/piker/brokers/cli.py @@ -50,7 +50,7 @@ def api(config, meth, kwargs, keys): """Make a broker-client API method call """ # global opts - broker = config['broker'] + broker = config['brokers'][0] _kwargs = {} for kwarg in kwargs: @@ -87,7 +87,7 @@ def quote(config, tickers, df_output): """Print symbol quotes to the console """ # global opts - brokermod = config['brokermod'] + brokermod = config['brokermods'][0] quotes = trio.run(partial(core.stocks_quote, brokermod, tickers)) if not quotes: @@ -123,7 +123,7 @@ def bars(config, symbol, count, df_output): """Retreive 1m bars for symbol and print on the console """ # global opts - brokermod = config['brokermod'] + brokermod = config['brokermods'][0] # broker backend should return at the least a # list of candle dictionaries @@ -159,7 +159,7 @@ def record(config, rate, name, dhost, filename): """Record client side quotes to a file on disk """ # global opts - brokermod = config['brokermod'] + brokermod = config['brokermods'][0] loglevel = config['loglevel'] log = config['log'] @@ -222,7 +222,7 @@ def optsquote(config, symbol, df_output, date): """Retreive symbol option quotes on the console """ # global opts - brokermod = config['brokermod'] + brokermod = config['brokermods'][0] quotes = trio.run( partial( @@ -250,7 +250,7 @@ def symbol_info(config, tickers): """Print symbol quotes to the console """ # global opts - brokermod = config['brokermod'] + brokermod = config['brokermods'][0] quotes = trio.run(partial(core.symbol_info, brokermod, tickers)) if not quotes: @@ -273,7 +273,7 @@ def search(config, pattern): """Search for symbols from broker backend(s). """ # global opts - brokermod = config['brokermod'] + brokermod = config['brokermods'][0] quotes = tractor.run( partial(core.symbol_search, brokermod, pattern), diff --git a/piker/cli/__init__.py b/piker/cli/__init__.py index 2ca5a1a6..0cc38874 100644 --- a/piker/cli/__init__.py +++ b/piker/cli/__init__.py @@ -57,21 +57,31 @@ def pikerd(loglevel, host, tl, pdb): @click.group(context_settings=_context_defaults) -@click.option('--broker', '-b', default=DEFAULT_BROKER, - help='Broker backend to use') +@click.option( + '--brokers', '-b', + default=[DEFAULT_BROKER], + multiple=True, + help='Broker backend to use' +) @click.option('--loglevel', '-l', default='warning', help='Logging level') @click.option('--tl', is_flag=True, help='Enable tractor logging') @click.option('--configdir', '-c', help='Configuration directory') @click.pass_context -def cli(ctx, broker, loglevel, tl, configdir): +def cli(ctx, brokers, loglevel, tl, configdir): if configdir is not None: assert os.path.isdir(configdir), f"`{configdir}` is not a valid path" config._override_config_dir(configdir) ctx.ensure_object(dict) + + if len(brokers) == 1: + brokermods = [get_brokermod(brokers[0])] + else: + brokermods = [get_brokermod(broker) for broker in brokers] + ctx.obj.update({ - 'broker': broker, - 'brokermod': get_brokermod(broker), + 'brokers': brokers, + 'brokermods': brokermods, 'loglevel': loglevel, 'tractorloglevel': None, 'log': get_console_log(loglevel), diff --git a/piker/ui/_chart.py b/piker/ui/_chart.py index 330d4d14..a0e2628e 100644 --- a/piker/ui/_chart.py +++ b/piker/ui/_chart.py @@ -1563,7 +1563,7 @@ async def _async_main( widgets: Dict[str, Any], sym: str, - brokername: str, + brokernames: str, loglevel: str, ) -> None: @@ -1617,7 +1617,7 @@ async def _async_main( chart_app.search = search # this internally starts a ``chart_symbol()`` task above - chart_app.load_symbol(brokername, sym, loglevel) + chart_app.load_symbol(brokernames[0], sym, loglevel) async with _search.register_symbol_search( @@ -1645,7 +1645,7 @@ async def _async_main( def _main( sym: str, - brokername: str, + brokernames: [str], piker_loglevel: str, tractor_kwargs, ) -> None: @@ -1655,7 +1655,7 @@ def _main( # Qt entry point run_qtractor( func=_async_main, - args=(sym, brokername, piker_loglevel), + args=(sym, brokernames, piker_loglevel), main_widget=ChartSpace, tractor_kwargs=tractor_kwargs, ) diff --git a/piker/ui/_exec.py b/piker/ui/_exec.py index 53de8554..96755fab 100644 --- a/piker/ui/_exec.py +++ b/piker/ui/_exec.py @@ -38,6 +38,7 @@ from PyQt5.QtCore import ( QCoreApplication, ) import qdarkstyle +# import qdarkgraystyle import trio import tractor from outcome import Error diff --git a/piker/ui/cli.py b/piker/ui/cli.py index b40a4c31..b674acfe 100644 --- a/piker/ui/cli.py +++ b/piker/ui/cli.py @@ -49,7 +49,7 @@ def monitor(config, rate, name, dhost, test, tl): """Start a real-time watchlist UI """ # global opts - brokermod = config['brokermod'] + brokermod = config['brokermods'][0] loglevel = config['loglevel'] log = config['log'] @@ -142,13 +142,13 @@ def chart(config, symbol, profile, pdb): _profile._pg_profile = profile # global opts - brokername = config['broker'] + brokernames = config['brokers'] tractorloglevel = config['tractorloglevel'] pikerloglevel = config['loglevel'] _main( sym=symbol, - brokername=brokername, + brokernames=brokernames, piker_loglevel=pikerloglevel, tractor_kwargs={ 'debug_mode': pdb,