ystockquote icon indicating copy to clipboard operation
ystockquote copied to clipboard

get_historical_prices not working

Open ifuchs opened this issue 7 years ago • 10 comments

As of this week, get_historical_prices seems to either timeout or give URL not found responses. I have tried from several platforms with the same results. Can others reproduce the error? Does anyone know the cause or a solution?

pprint(ystockquote.get_historical_prices('GOOGL', '2013-01-03', '2013-01-08')) Traceback (most recent call last): File "", line 1, in File "//anaconda/lib/python2.7/site-packages/ystockquote.py", line 486, in get_historical_prices resp = urlopen(req) File "//anaconda/lib/python2.7/urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "//anaconda/lib/python2.7/urllib2.py", line 431, in open response = self._open(req, data) File "//anaconda/lib/python2.7/urllib2.py", line 449, in _open '_open', req) File "//anaconda/lib/python2.7/urllib2.py", line 409, in _call_chain result = func(*args) File "//anaconda/lib/python2.7/urllib2.py", line 1227, in http_open return self.do_open(httplib.HTTPConnection, req) File "//anaconda/lib/python2.7/urllib2.py", line 1197, in do_open raise URLError(err) urllib2.URLError: <urlopen error [Errno 60] Operation timed out>

ifuchs avatar May 19 '17 20:05 ifuchs

Same thing here @ifuchs When trying the example on the project page, pprint(ystockquote.get_historical_prices('GOOGL', '2013-01-03', '2013-01-08'))

I get error HTTPError: HTTP Error 504: Maximum Transaction Time Exceeded


Seems like Yahoo Finance API has been shut down, read more about it there: https://forums.yahoo.net/t5/Yahoo-Finance-help/Is-Yahoo-Finance-API-broken/td-p/250503 http://stackoverflow.com/questions/44057580/yahoo-finance-api-changes-2017

@cgoldberg any chance you can implement a workaround like this one maybe? would be awesome :) https://github.com/c0redumb/yahoo_quote_download

dejafait avatar May 21 '17 14:05 dejafait

It looks like Yahoo removed the csv API it was pulling data from. I'm looking for alternative data source

cgoldberg avatar May 22 '17 13:05 cgoldberg

Scraping data from the stock quotes page is an option, but their markup is a disaster

cgoldberg avatar May 22 '17 13:05 cgoldberg

If Yahoo historical quotes can't be made to work reliably, this seems to work:

http://trading.cheno.net/wp-content/uploads/2011/12/google.py

ifuchs avatar May 30 '17 16:05 ifuchs

I have an open pull request that parses their data (grabbing json in source). Passes the python 2.7 tests but not the 3.x ones https://github.com/amalek215/ystockquote

amalek215 avatar May 30 '17 17:05 amalek215

There is still yahoo alternative while using url: "https://query1.finance.yahoo.com/v7/finance/download"; Client requires to have enabled cookies and get crumb. Example query looks like:

https://query1.finance.yahoo.com/v7/finance/download/SBUX?period1=1451602800&period2=1496140683&interval=1d&events=history&crumb=.BprRZODzhT

I used this new endpoint but for some request I get NULL data inside, just let you know. Cheers.

pljanot avatar May 30 '17 22:05 pljanot

For the past year I have been developing a backtesting algo using the historical prices provided by Yahoo finance. Having the API shut down I have nowhere to pull data from. I hope some genius can fix this in the near future or provide an alternative.

Cloudberry04 avatar Jun 05 '17 19:06 Cloudberry04

See my comment above. I have used GoogleQuote to replace Yahoo historical quotes.

ifuchs avatar Jun 05 '17 19:06 ifuchs

The link provided by @ifuchs doesn't seem to work. Is a fix coming or has a better solution been found?

simtaxman avatar Sep 07 '17 17:09 simtaxman

I am still seeking a way to get a closing price for a specific date. Does anyone have a working script?

ifuchs avatar Sep 21 '17 22:09 ifuchs