Make -b a multi-option for backends

symbol_search
Tyler Goodlet 2021-05-18 08:38:13 -04:00
parent 59377da0ad
commit fd8dc4f1a3
5 changed files with 30 additions and 19 deletions

View File

@ -50,7 +50,7 @@ def api(config, meth, kwargs, keys):
"""Make a broker-client API method call """Make a broker-client API method call
""" """
# global opts # global opts
broker = config['broker'] broker = config['brokers'][0]
_kwargs = {} _kwargs = {}
for kwarg in kwargs: for kwarg in kwargs:
@ -87,7 +87,7 @@ def quote(config, tickers, df_output):
"""Print symbol quotes to the console """Print symbol quotes to the console
""" """
# global opts # global opts
brokermod = config['brokermod'] brokermod = config['brokermods'][0]
quotes = trio.run(partial(core.stocks_quote, brokermod, tickers)) quotes = trio.run(partial(core.stocks_quote, brokermod, tickers))
if not quotes: if not quotes:
@ -123,7 +123,7 @@ def bars(config, symbol, count, df_output):
"""Retreive 1m bars for symbol and print on the console """Retreive 1m bars for symbol and print on the console
""" """
# global opts # global opts
brokermod = config['brokermod'] brokermod = config['brokermods'][0]
# broker backend should return at the least a # broker backend should return at the least a
# list of candle dictionaries # list of candle dictionaries
@ -159,7 +159,7 @@ def record(config, rate, name, dhost, filename):
"""Record client side quotes to a file on disk """Record client side quotes to a file on disk
""" """
# global opts # global opts
brokermod = config['brokermod'] brokermod = config['brokermods'][0]
loglevel = config['loglevel'] loglevel = config['loglevel']
log = config['log'] log = config['log']
@ -222,7 +222,7 @@ def optsquote(config, symbol, df_output, date):
"""Retreive symbol option quotes on the console """Retreive symbol option quotes on the console
""" """
# global opts # global opts
brokermod = config['brokermod'] brokermod = config['brokermods'][0]
quotes = trio.run( quotes = trio.run(
partial( partial(
@ -250,7 +250,7 @@ def symbol_info(config, tickers):
"""Print symbol quotes to the console """Print symbol quotes to the console
""" """
# global opts # global opts
brokermod = config['brokermod'] brokermod = config['brokermods'][0]
quotes = trio.run(partial(core.symbol_info, brokermod, tickers)) quotes = trio.run(partial(core.symbol_info, brokermod, tickers))
if not quotes: if not quotes:
@ -273,7 +273,7 @@ def search(config, pattern):
"""Search for symbols from broker backend(s). """Search for symbols from broker backend(s).
""" """
# global opts # global opts
brokermod = config['brokermod'] brokermod = config['brokermods'][0]
quotes = tractor.run( quotes = tractor.run(
partial(core.symbol_search, brokermod, pattern), partial(core.symbol_search, brokermod, pattern),

View File

@ -57,21 +57,31 @@ def pikerd(loglevel, host, tl, pdb):
@click.group(context_settings=_context_defaults) @click.group(context_settings=_context_defaults)
@click.option('--broker', '-b', default=DEFAULT_BROKER, @click.option(
help='Broker backend to use') '--brokers', '-b',
default=[DEFAULT_BROKER],
multiple=True,
help='Broker backend to use'
)
@click.option('--loglevel', '-l', default='warning', help='Logging level') @click.option('--loglevel', '-l', default='warning', help='Logging level')
@click.option('--tl', is_flag=True, help='Enable tractor logging') @click.option('--tl', is_flag=True, help='Enable tractor logging')
@click.option('--configdir', '-c', help='Configuration directory') @click.option('--configdir', '-c', help='Configuration directory')
@click.pass_context @click.pass_context
def cli(ctx, broker, loglevel, tl, configdir): def cli(ctx, brokers, loglevel, tl, configdir):
if configdir is not None: if configdir is not None:
assert os.path.isdir(configdir), f"`{configdir}` is not a valid path" assert os.path.isdir(configdir), f"`{configdir}` is not a valid path"
config._override_config_dir(configdir) config._override_config_dir(configdir)
ctx.ensure_object(dict) 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({ ctx.obj.update({
'broker': broker, 'brokers': brokers,
'brokermod': get_brokermod(broker), 'brokermods': brokermods,
'loglevel': loglevel, 'loglevel': loglevel,
'tractorloglevel': None, 'tractorloglevel': None,
'log': get_console_log(loglevel), 'log': get_console_log(loglevel),

View File

@ -1563,7 +1563,7 @@ async def _async_main(
widgets: Dict[str, Any], widgets: Dict[str, Any],
sym: str, sym: str,
brokername: str, brokernames: str,
loglevel: str, loglevel: str,
) -> None: ) -> None:
@ -1617,7 +1617,7 @@ async def _async_main(
chart_app.search = search chart_app.search = search
# this internally starts a ``chart_symbol()`` task above # 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( async with _search.register_symbol_search(
@ -1645,7 +1645,7 @@ async def _async_main(
def _main( def _main(
sym: str, sym: str,
brokername: str, brokernames: [str],
piker_loglevel: str, piker_loglevel: str,
tractor_kwargs, tractor_kwargs,
) -> None: ) -> None:
@ -1655,7 +1655,7 @@ def _main(
# Qt entry point # Qt entry point
run_qtractor( run_qtractor(
func=_async_main, func=_async_main,
args=(sym, brokername, piker_loglevel), args=(sym, brokernames, piker_loglevel),
main_widget=ChartSpace, main_widget=ChartSpace,
tractor_kwargs=tractor_kwargs, tractor_kwargs=tractor_kwargs,
) )

View File

@ -38,6 +38,7 @@ from PyQt5.QtCore import (
QCoreApplication, QCoreApplication,
) )
import qdarkstyle import qdarkstyle
# import qdarkgraystyle
import trio import trio
import tractor import tractor
from outcome import Error from outcome import Error

View File

@ -49,7 +49,7 @@ def monitor(config, rate, name, dhost, test, tl):
"""Start a real-time watchlist UI """Start a real-time watchlist UI
""" """
# global opts # global opts
brokermod = config['brokermod'] brokermod = config['brokermods'][0]
loglevel = config['loglevel'] loglevel = config['loglevel']
log = config['log'] log = config['log']
@ -142,13 +142,13 @@ def chart(config, symbol, profile, pdb):
_profile._pg_profile = profile _profile._pg_profile = profile
# global opts # global opts
brokername = config['broker'] brokernames = config['brokers']
tractorloglevel = config['tractorloglevel'] tractorloglevel = config['tractorloglevel']
pikerloglevel = config['loglevel'] pikerloglevel = config['loglevel']
_main( _main(
sym=symbol, sym=symbol,
brokername=brokername, brokernames=brokernames,
piker_loglevel=pikerloglevel, piker_loglevel=pikerloglevel,
tractor_kwargs={ tractor_kwargs={
'debug_mode': pdb, 'debug_mode': pdb,