Fill failed symbol lookup df row with NaNs

kivy_mainline_and_py3.8
Tyler Goodlet 2018-03-20 21:02:59 -04:00
parent 48fe280e0c
commit 6c0f1fbdfc
1 changed files with 12 additions and 7 deletions

View File

@ -32,7 +32,8 @@ def cli():
@cli.command() @cli.command()
@click.option('--broker', '-b', 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')
@ -52,7 +53,8 @@ def api(meth, kwargs, loglevel, broker, keys):
key, _, value = kwarg.partition('=') key, _, value = kwarg.partition('=')
_kwargs[key] = value _kwargs[key] = value
data = run(partial(core.api, brokermod, 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
@ -69,7 +71,8 @@ def api(meth, kwargs, loglevel, broker, keys):
@cli.command() @cli.command()
@click.option('--broker', '-b', 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')
@ -82,12 +85,13 @@ def quote(loglevel, broker, tickers, df_output):
if not quotes: if not quotes:
log.error(f"No quotes could be found for {tickers}?") log.error(f"No quotes could be found for {tickers}?")
return return
cols = quotes[tickers[0]].copy()
cols = next(filter(bool, quotes.values())).copy()
cols.pop('symbol') cols.pop('symbol')
if df_output: if df_output:
df = pd.DataFrame( df = pd.DataFrame(
quotes, (quote or {} for quote in quotes.values()),
index=[item['symbol'] for item in quotes], index=quotes.keys(),
columns=cols, columns=cols,
) )
click.echo(df) click.echo(df)
@ -96,7 +100,8 @@ def quote(loglevel, broker, tickers, df_output):
@cli.command() @cli.command()
@click.option('--broker', '-b', 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.argument('name', nargs=1, required=True) @click.argument('name', nargs=1, required=True)
def watch(loglevel, broker, name): def watch(loglevel, broker, name):