def _yahoo(self, quote, d, m, y):
""" Collects data from Yahoo Finance API """
epoch = int(round(mktime(date(y, m, d).timetuple())/86400, 0)*86400)
if not hasattr(self, '_session_y'):
self._session_y = requests.Session()
r = self._session_y.get(__class__._Y_API + quote + '?date=' + str(epoch))
if r.status_code == 404:
raise LookupError('Ticker symbol not found.')
else:
r.raise_for_status()
json = r.json()
try:
self.data = json['optionChain']['result'][0]['options'][0]
except IndexError:
raise LookupError('No options listed for this stock.')
self._exp = [datetime.utcfromtimestamp(i).date() for i in json['optionChain']['result'][0]['expirationDates']]
评论列表
文章目录