Change `Client.symbols()` to `symbol_data()`
Make `symbol_data()` a common backend API method for looking up auxiliary ticker/symbol data from brokers. It seems most have such a call/endpoint.kivy_mainline_and_py3.8
parent
8fc74c5085
commit
8544c22cdc
|
@ -17,7 +17,7 @@ from ..log import get_logger, colorize_json
|
|||
import asks
|
||||
asks.init('trio')
|
||||
|
||||
log = get_logger('questrade')
|
||||
log = get_logger(__name__)
|
||||
|
||||
_refresh_token_ep = 'https://login.questrade.com/oauth2/'
|
||||
_version = 'v1'
|
||||
|
@ -165,8 +165,8 @@ class Client:
|
|||
|
||||
return quotes
|
||||
|
||||
async def symbols(self, tickers):
|
||||
"""Return quotes for each ticker in ``tickers``.
|
||||
async def symbol_data(self, tickers: [str]):
|
||||
"""Return symbol data for ``tickers``.
|
||||
"""
|
||||
t2ids = await self.tickers2ids(tickers)
|
||||
ids = ','.join(map(str, t2ids.values()))
|
||||
|
|
|
@ -4,14 +4,15 @@ Robinhood API backend.
|
|||
from functools import partial
|
||||
|
||||
from async_generator import asynccontextmanager
|
||||
# TODO: move to urllib3/requests once supported
|
||||
import asks
|
||||
|
||||
from ..log import get_logger
|
||||
from ._util import resproc
|
||||
from ..calc import percent_change
|
||||
|
||||
log = get_logger('robinhood')
|
||||
|
||||
asks.init('trio')
|
||||
log = get_logger(__name__)
|
||||
_service_ep = 'https://api.robinhood.com'
|
||||
|
||||
|
||||
|
@ -43,15 +44,25 @@ class Client:
|
|||
self._sess.base_location = _service_ep
|
||||
self.api = _API(self._sess)
|
||||
|
||||
async def quote(self, symbols: [str]):
|
||||
results = (await self.api.quotes(','.join(symbols)))['results']
|
||||
return {quote['symbol'] if quote else sym: quote
|
||||
for sym, quote in zip(symbols, results)}
|
||||
def _zip_in_order(self, symbols: [str], results_dict: dict):
|
||||
return {quote.get('symbol', sym) if quote else sym: quote
|
||||
for sym, quote in zip(symbols, results_dict)}
|
||||
|
||||
async def symbols(self, tickers: [str]):
|
||||
"""Placeholder for the watchlist calling code...
|
||||
async def quote(self, symbols: [str]):
|
||||
"""Retrieve quotes for a list of ``symbols``.
|
||||
"""
|
||||
return {}
|
||||
return self._zip_in_order(
|
||||
symbols,
|
||||
(await self.api.quotes(','.join(symbols)))['results']
|
||||
)
|
||||
|
||||
async def symbol_data(self, symbols: [str]):
|
||||
"""Retrieve symbol data via the ``fundmentals`` endpoint.
|
||||
"""
|
||||
return self._zip_in_order(
|
||||
symbols,
|
||||
(await self.api.fundamentals(','.join(symbols)))['results']
|
||||
)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
|
|
Loading…
Reference in New Issue