Adjust cli to new backend api

kivy_mainline_and_py3.8
Tyler Goodlet 2018-03-20 13:28:24 -04:00
parent e75f0718a5
commit 42e9296b36
1 changed files with 16 additions and 22 deletions

View File

@ -8,7 +8,10 @@ import click
import trio import trio
import pandas as pd import pandas as pd
from .log import get_console_log, colorize_json from .log import get_console_log, colorize_json, get_logger
from .brokers import core
log = get_logger('cli')
def run(main, loglevel='info'): def run(main, loglevel='info'):
@ -29,7 +32,7 @@ def cli():
@cli.command() @cli.command()
@click.option('--broker', default='questrade', help='Broker backend to use') @click.option('--broker', '-b', default='questrade', 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('--keys', '-k', multiple=True, @click.option('--keys', '-k', multiple=True,
help='Return results only for these keys') help='Return results only for these keys')
@ -49,7 +52,7 @@ def api(meth, kwargs, loglevel, broker, keys):
key, _, value = kwarg.partition('=') key, _, value = kwarg.partition('=')
_kwargs[key] = value _kwargs[key] = value
data = run(partial(brokermod.api, meth, **_kwargs), loglevel=loglevel) data = run(partial(core.api, brokermod, meth, **_kwargs), loglevel=loglevel)
if keys: if keys:
# filter to requested keys # filter to requested keys
@ -66,7 +69,7 @@ def api(meth, kwargs, loglevel, broker, keys):
@cli.command() @cli.command()
@click.option('--broker', default='questrade', help='Broker backend to use') @click.option('--broker', '-b', default='questrade', 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('--df-output', '-df', flag_value=True, @click.option('--df-output', '-df', flag_value=True,
help='Ouput in `pandas.DataFrame` format') help='Ouput in `pandas.DataFrame` format')
@ -75,8 +78,11 @@ def quote(loglevel, broker, tickers, df_output):
"""client for testing broker API methods with pretty printing of output. """client for testing broker API methods with pretty printing of output.
""" """
brokermod = import_module('.' + broker, 'piker.brokers') brokermod = import_module('.' + broker, 'piker.brokers')
quotes = run(partial(brokermod.quote, tickers), loglevel=loglevel) quotes = run(partial(core.quote, brokermod, tickers), loglevel=loglevel)
cols = quotes[0].copy() if not quotes:
log.error(f"No quotes could be found for {tickers}?")
return
cols = quotes[tickers[0]].copy()
cols.pop('symbol') cols.pop('symbol')
if df_output: if df_output:
df = pd.DataFrame( df = pd.DataFrame(
@ -90,22 +96,7 @@ def quote(loglevel, broker, tickers, df_output):
@cli.command() @cli.command()
@click.option('--broker', default='questrade', help='Broker backend to use') @click.option('--broker', '-b', default='questrade', help='Broker backend to use')
@click.option('--loglevel', '-l', default='info', help='Logging level')
@click.argument('tickers', nargs=-1)
def stream(broker, loglevel, tickers, keys):
# import broker module daemon entry point
bm = import_module('.' + broker, 'piker.brokers')
run(
partial(bm.serve_forever, [
partial(bm.poll_tickers, tickers=tickers)
]),
loglevel
)
@cli.command()
@click.option('--broker', default='questrade', help='Broker backend to use')
@click.option('--loglevel', '-l', default='warning', help='Logging level') @click.option('--loglevel', '-l', default='warning', help='Logging level')
@click.argument('name', nargs=1, required=True) @click.argument('name', nargs=1, required=True)
def watch(loglevel, broker, name): def watch(loglevel, broker, name):
@ -130,6 +121,9 @@ def watch(loglevel, broker, name):
'GM', 'TSLA', 'DOL.TO', 'CIM', 'SPY', 'GM', 'TSLA', 'DOL.TO', 'CIM', 'SPY',
'SHOP.TO', 'SHOP.TO',
], ],
'pharma': [
'ATE.VN'
],
} }
# broker_conf_path = os.path.join( # broker_conf_path = os.path.join(
# click.get_app_dir('piker'), 'watchlists.json') # click.get_app_dir('piker'), 'watchlists.json')