Add symbol-info command
parent
d10f80865e
commit
d102537ca8
|
@ -225,3 +225,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))
|
||||||
|
|
|
@ -28,7 +28,7 @@ async def api(brokername: str, methname: str, **kwargs) -> dict:
|
||||||
|
|
||||||
meth = getattr(client.api, methname, None)
|
meth = getattr(client.api, 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, methname, None)
|
meth = getattr(client, methname, None)
|
||||||
|
|
||||||
|
@ -121,3 +121,14 @@ async def bars(
|
||||||
"""
|
"""
|
||||||
async with brokermod.get_client() as client:
|
async with brokermod.get_client() as client:
|
||||||
return await client.bars(symbol, **kwargs)
|
return await client.bars(symbol, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
async def symbol_info(
|
||||||
|
brokermod: ModuleType,
|
||||||
|
symbol: str,
|
||||||
|
**kwargs,
|
||||||
|
) -> Dict[str, Dict[str, Dict[str, Any]]]:
|
||||||
|
"""Return symbol info from broker.
|
||||||
|
"""
|
||||||
|
async with brokermod.get_client() as client:
|
||||||
|
return await client.symbol_info(symbol, **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