diff --git a/piker/brokers/core.py b/piker/brokers/core.py index a3e00691..e87b0ded 100644 --- a/piker/brokers/core.py +++ b/piker/brokers/core.py @@ -37,7 +37,12 @@ async def quote(brokermod: ModuleType, tickers: [str]) -> dict: """Return quotes dict for ``tickers``. """ async with brokermod.get_client() as client: - return await client.quote(tickers) + results = await client.quote(tickers) + for key, val in results.items(): + if val is None: + brokermod.log.warn(f"Could not find symbol {key}?") + + return results async def poll_tickers( diff --git a/piker/brokers/questrade.py b/piker/brokers/questrade.py index a4cc3005..021895f1 100644 --- a/piker/brokers/questrade.py +++ b/piker/brokers/questrade.py @@ -152,7 +152,15 @@ class Client: t2ids = await self.tickers2ids(tickers) ids = ','.join(map(str, t2ids.values())) results = (await self.api.quotes(ids=ids))['quotes'] - return {sym: quote for sym, quote in zip(tickers, results)} + quotes = {quote['symbol']: quote for quote in results} + + # set None for all symbols not found + if len(t2ids) < len(tickers): + for ticker in tickers: + if ticker not in quotes: + quotes[ticker] = None + + return quotes async def symbols(self, tickers): """Return quotes for each ticker in ``tickers``. @@ -275,6 +283,8 @@ async def get_client() -> Client: @asynccontextmanager async def quoter(client: Client, tickers: [str]): + """Quoter context. + """ t2ids = await client.tickers2ids(tickers) ids = ','.join(map(str, t2ids.values())) diff --git a/piker/brokers/robinhood.py b/piker/brokers/robinhood.py index 2c626f15..5a6b7de8 100644 --- a/piker/brokers/robinhood.py +++ b/piker/brokers/robinhood.py @@ -1,8 +1,8 @@ """ Robinhood API backend. """ -import asks from async_generator import asynccontextmanager +import asks from ..log import get_logger from ._util import resproc @@ -27,7 +27,8 @@ class _API: return await self._request('quotes/', params={'symbols': symbols}) async def fundamentals(self, symbols: str) -> dict: - return await self._request('fundamentals/', params={'symbols': symbols}) + return await self._request( + 'fundamentals/', params={'symbols': symbols}) class Client: @@ -40,9 +41,9 @@ class Client: self.api = _API(self._sess) async def quote(self, symbols: [str]): - resp = await self.api.quotes(','.join(symbols)) - results = resp['results'] - return {sym: quote for sym, quote in zip(symbols, results)} + results = (await self.api.quotes(','.join(symbols)))['results'] + return {quote['symbol'] if quote else sym: quote + for sym, quote in zip(symbols, results)} @asynccontextmanager