Add symbol-info command
parent
dcb0a30ad6
commit
934108a024
|
@ -226,3 +226,26 @@ def optsquote(config, symbol, df_output, date):
|
||||||
click.echo(df)
|
click.echo(df)
|
||||||
else:
|
else:
|
||||||
click.echo(colorize_json(quotes))
|
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))
|
||||||
|
|
|
@ -22,7 +22,7 @@ async def api(brokername: str, methname: str, **kwargs) -> dict:
|
||||||
async with brokermod.get_client() as client:
|
async with brokermod.get_client() as client:
|
||||||
meth = getattr(client, methname, None)
|
meth = getattr(client, methname, None)
|
||||||
if meth is None:
|
if meth is None:
|
||||||
log.warning(
|
log.debug(
|
||||||
f"Couldn't find API method {methname} looking up on client")
|
f"Couldn't find API method {methname} looking up on client")
|
||||||
meth = getattr(client.api, methname, None)
|
meth = getattr(client.api, methname, None)
|
||||||
|
|
||||||
|
@ -108,15 +108,3 @@ async def symbol_info(
|
||||||
"""
|
"""
|
||||||
async with brokermod.get_client() as client:
|
async with brokermod.get_client() as client:
|
||||||
return await client.symbol_info(symbol, **kwargs)
|
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)
|
|
||||||
|
|
|
@ -408,7 +408,7 @@ class Client:
|
||||||
|
|
||||||
return symbols2ids
|
return symbols2ids
|
||||||
|
|
||||||
async def symbol_data(self, tickers: List[str]):
|
async def symbol_info(self, tickers: List[str]):
|
||||||
"""Return symbol data for ``tickers``.
|
"""Return symbol data for ``tickers``.
|
||||||
"""
|
"""
|
||||||
t2ids = await self.tickers2ids(tickers)
|
t2ids = await self.tickers2ids(tickers)
|
||||||
|
@ -419,6 +419,9 @@ class Client:
|
||||||
|
|
||||||
return symbols
|
return symbols
|
||||||
|
|
||||||
|
# TODO: deprecate
|
||||||
|
symbol_data = symbol_info
|
||||||
|
|
||||||
async def quote(self, tickers: [str]):
|
async def quote(self, tickers: [str]):
|
||||||
"""Return stock quotes for each ticker in ``tickers``.
|
"""Return stock quotes for each ticker in ``tickers``.
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue