From 61294c6c44ab773054595d0bb0b9d5d3c5fa5827 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 1 Dec 2018 16:09:41 -0500 Subject: [PATCH] Adhere to the same non-found-symbol behaviour as QT --- piker/brokers/robinhood.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/piker/brokers/robinhood.py b/piker/brokers/robinhood.py index 63cd8af7..ff1e22d4 100644 --- a/piker/brokers/robinhood.py +++ b/piker/brokers/robinhood.py @@ -2,6 +2,7 @@ Robinhood API backend. """ from functools import partial +from typing import List from async_generator import asynccontextmanager # TODO: move to urllib3/requests once supported @@ -44,7 +45,7 @@ class Client: self._sess.base_location = _service_ep self.api = _API(self._sess) - def _zip_in_order(self, symbols: [str], results_dict: dict): + def _zip_in_order(self, symbols: [str], quotes: List[dict]): return {quote.get('symbol', sym) if quote else sym: quote for sym, quote in zip(symbols, results_dict)} @@ -52,11 +53,16 @@ class Client: """Retrieve quotes for a list of ``symbols``. """ try: - resp = await self.api.quotes(','.join(symbols)) + quotes = (await self.api.quotes(','.join(symbols)))['results'] except BrokerError: - resp = {'results': [None] * len(symbols)} + quotes = [None] * len(symbols) - return self._zip_in_order(symbols, resp['results']) + for quote in quotes: + # insert our subscription key field + if quote is not None: + quote['key'] = quote['symbol'] + + return list(filter(bool, quotes)) async def symbol_data(self, symbols: [str]): """Retrieve symbol data via the ``fundamentals`` endpoint.