ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
13.25k stars 2.34k forks source link

Problem catching/handling ValueError #76

Closed teeling closed 5 years ago

teeling commented 5 years ago

Hi, thanks for a great piece of software. I have a small problem, I have a (fairly large) list of tickers that I'm feeding in to yf.download(). Some times Yahoo doesn't have a lot of data for all the tickers I ask for (for example, very small stocks on the Stockholm exchange sometimes shows no history at all) and when this happens yfinance throws an error:

ValueError: ('FEEL.ST', 'No data found for this date range, symbol may be delisted')

I'd like to catch this error, so I can try to get the data from somewhere else, but trying to do so opens up two separate problems:

If I run yf.download threaded, as per default, I can't catch the error at all. The upside is that it keeps downloading all the rest of the data, so I get most of what I need. I just don't know exactly what I'm missing.

If i run yf.download with threads=False I can catch the error, but at the same time it stops downloading the rest of the data.

I guess in the first case I could examine the data downloaded and look for NaN's, and in the second case I could manually skip the error-generating ticker and proceed with the rest, but I'd just like to see if anyone else has run in to the same problem and have an elegant solution?

Thanks!

sidereumcorpus commented 5 years ago

I am also getting this error, except mine is with APPL!

ranaroussi commented 5 years ago

See issue #78: This is an issue on the source: https://finance.yahoo.com/quote/AAPL/history?period1=1562155200&period2=1562241600&interval=1d&filter=history&frequency=1d

Emnolope commented 5 years ago

Can you add an option so it can skip the delisted symbols, it's kinda messing my code with up.