Add symbol-info command

marketstore_integration
Tyler Goodlet 2020-06-16 11:55:37 -04:00
parent dcb0a30ad6
commit 934108a024
3 changed files with 28 additions and 14 deletions

View File

@ -226,3 +226,26 @@ def optsquote(config, symbol, df_output, date):
click.echo(df)
else:
click.echo(colorize_json(quotes))
@cli.command()
@click.argument('tickers', nargs=-1, required=True)
@click.pass_obj
def symbol_info(config, tickers):
"""Print symbol quotes to the console
"""
# global opts
brokermod = config['brokermod']
quotes = trio.run(partial(core.symbol_info, brokermod, tickers))
if not quotes:
log.error(f"No quotes could be found for {tickers}?")
return
if len(quotes) < len(tickers):
syms = tuple(map(itemgetter('symbol'), quotes))
for ticker in tickers:
if ticker not in syms:
brokermod.log.warn(f"Could not find symbol {ticker}?")
click.echo(colorize_json(quotes))

View File

@ -22,7 +22,7 @@ async def api(brokername: str, methname: str, **kwargs) -> dict:
async with brokermod.get_client() as client:
meth = getattr(client, methname, None)
if meth is None:
log.warning(
log.debug(
f"Couldn't find API method {methname} looking up on client")
meth = getattr(client.api, methname, None)
@ -108,15 +108,3 @@ async def symbol_info(
"""
async with brokermod.get_client() as client:
return await client.symbol_info(symbol, **kwargs)
async def symbol_search(
brokermod: ModuleType,
pattern: str,
**kwargs,
) -> Dict[str, Dict[str, Dict[str, Any]]]:
"""Return symbol info from broker.
"""
async with brokermod.get_client() as client:
# TODO: support multiple asset type concurrent searches.
return await client.search_stocks(pattern=pattern, **kwargs)

View File

@ -408,7 +408,7 @@ class Client:
return symbols2ids
async def symbol_data(self, tickers: List[str]):
async def symbol_info(self, tickers: List[str]):
"""Return symbol data for ``tickers``.
"""
t2ids = await self.tickers2ids(tickers)
@ -419,6 +419,9 @@ class Client:
return symbols
# TODO: deprecate
symbol_data = symbol_info
async def quote(self, tickers: [str]):
"""Return stock quotes for each ticker in ``tickers``.
"""