I am writing an app to track stock data entered into a spreadsheet. I currently have it working by making a call to pandas_datareader.tiingo.TiingoDailyReader for every symbol. The data reader is capable of taking a list of symbols and pulling all the data for those symbols at once. I prefer this because I can make one call then query the dataframe it returns.

The issue I'm running into is when a symbol is delisted or does not exist this causes the entire call to fail resulting in an empty dataframe. I've worked around this a little bit by checking all the symbols against a list of supported symbols for Tiingo. However, this is not perfect as I have run into a instances where a symbol is supported but does not have data for the dates I request.

Is there a way to call all the symbols at once and have the data reader skip these errors or return no data for the problem symbol?

Thanks,

1

There are 1 best solutions below

0
On

I think you should check the symbols and start and end dates before you run the data acquisition. The reference is from the official reference

import urllib.request
import pandas as pd
import io

url = 'https://apimedia.tiingo.com/docs/tiingo/daily/supported_tickers.zip'
zip_tickers = urllib.request.urlopen(url).read()
zip_tick = io.BytesIO(zip_tickers)

with zipfile.ZipFile(zip_tick) as myzip:
    csv_data = myzip.extract('supported_tickers.csv')  

df = pd.read_csv(csv_data, sep=',')

df
    ticker  exchange    assetType   priceCurrency   startDate   endDate
0   000001  SHE Stock   CNY 2007-08-30  2020-09-11
1   000002  SHE Stock   CNY 2000-01-04  2020-09-11
2   000003  SHE Stock   CNY NaN NaN
3   000004  SHE Stock   CNY 2007-08-31  2020-09-11
4   000005  SHE Stock   CNY 2001-01-02  2020-09-11
... ... ... ... ... ... ...
87303   ZZK NYSE ARCA   Stock   USD 2020-07-22  2020-09-11
87304   ZZLL    OTCBB   Stock   USD 2017-09-26  2020-09-11
87305   ZZLLD   OTCBB   Stock   USD 2017-10-06  2017-10-30
87306   ZZZ NYSE ARCA   Stock   USD 2014-10-31  2020-09-11
87307   ZZZOF   PINK    Stock   USD 2017-09-22  2020-09-11
87308 rows × 6 columns