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
"""
# 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),

View File

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

View File

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

View File

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

View File

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