mcdallas / wallstreet

Real time stock and option data.
MIT License
1.33k stars 201 forks source link

Yahoo Finance update caused Stock.historical() not work #43

Closed qwangln closed 1 year ago

qwangln commented 1 year ago

It seems Yahoo Finance website updated with some encryption in middle of Dec 2022. so the historical() in the Stock didn't work well now.

Python 3.10.8 (main, Nov 24 2022, 14:13:03) [GCC 11.2.0] Type 'copyright', 'credits' or 'license' for more information IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import wallstreet

In [2]: aapl = wallstreet.Stock("AAPL")

In [3]: aapl Out[3]: Stock(ticker=AAPL, price=129.98)

In [4]: aapl.historical(7)

ValueError Traceback (most recent call last) Cell In [4], line 1 ----> 1 aapl.historical(7)

File ~/anaconda3/envs/py3a/lib/python3.10/site-packages/wallstreet/wallstreet.py:208, in Stock.historical(self, days_back, frequency) 207 def historical(self, days_back=30, frequency='d'): --> 208 return YahooFinanceHistory(symbol=self.ticker, days_back=days_back, frequency=frequency).get_quote()

File ~/anaconda3/envs/py3a/lib/python3.10/site-packages/wallstreet/wallstreet.py:97, in YahooFinanceHistory.get_quote(self) 94 raise ImportError('This functionality requires pandas to be installed') 96 if not hasattr(self, 'crumb') or len(self.session.cookies) == 0: ---> 97 self.get_crumb() 98 now = datetime.utcnow() 99 dateto = int(now.timestamp())

File ~/anaconda3/envs/py3a/lib/python3.10/site-packages/wallstreet/wallstreet.py:86, in YahooFinanceHistory.get_crumb(self) 84 match = re.search(self.crumb_regex, response.text) 85 if not match: ---> 86 raise ValueError('Could not get crumb from Yahoo Finance') 87 else: 88 self.crumb = match.group(1)

ValueError: Could not get crumb from Yahoo Finance

In [5]:

mcdallas commented 1 year ago

hey @qwangln thanks for the report, the issue should be fixed now. I've published a new version 0.3.2 with the fix. You can get it with pip install --upgrade wallstreet