def _yahoo(self, quote, exchange=None):
""" Collects data from Yahoo Finance API """
query = quote + "." + exchange.upper() if exchange else quote
if not hasattr(self, '_session_y'):
self._session_y = requests.Session()
r = self._session_y.get(__class__._Y_API + query)
if r.status_code == 404:
raise LookupError('Ticker symbol not found.')
else:
r.raise_for_status()
jayson = r.json()['optionChain']['result'][0]['quote']
self.ticker = jayson['symbol']
self._price = jayson['regularMarketPrice']
self.currency = jayson['currency']
self.exchange = jayson['exchange']
self.change = jayson['regularMarketChange']
self.cp = jayson['regularMarketChangePercent']
self._last_trade = datetime.utcfromtimestamp(jayson['regularMarketTime'])
self.name = jayson['longName']
self.dy = jayson.get('trailingAnnualDividendYield', 0)
评论列表
文章目录