From 934108a02477c5de431d997d6cf245665d54d76b Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 16 Jun 2020 11:55:37 -0400 Subject: [PATCH] Add symbol-info command --- piker/brokers/cli.py | 23 +++++++++++++++++++++++ piker/brokers/core.py | 14 +------------- piker/brokers/questrade.py | 5 ++++- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/piker/brokers/cli.py b/piker/brokers/cli.py index cbdd87b9..f904e221 100644 --- a/piker/brokers/cli.py +++ b/piker/brokers/cli.py @@ -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)) diff --git a/piker/brokers/core.py b/piker/brokers/core.py index 6162b4e5..e65fcb40 100644 --- a/piker/brokers/core.py +++ b/piker/brokers/core.py @@ -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) diff --git a/piker/brokers/questrade.py b/piker/brokers/questrade.py index d12d3e64..73ad2984 100644 --- a/piker/brokers/questrade.py +++ b/piker/brokers/questrade.py @@ -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``. """