apilayer / marketstack

Free Real-Time, Intraday & Historical Stock Market Data API
https://marketstack.com
68 stars 14 forks source link

eod API to get historical info missing historical info for ETFs #26

Open ryanmark1867 opened 3 years ago

ryanmark1867 commented 3 years ago

Hi - I have been using the MarketStack eod API to get historical information about a series of tickers. The data seems to be OK for basic company tickers, but I am getting unexpected results for tickers for ETFs and other aggregates. In particular, for the following ETF tickers, when I call the MarketStack API I only get a subset of the ticker's history. See the list below for the history that should be available and what I actually get back from MarketStack. Below that list is the Python function that I use to call the MarketStack API. Please let me know if there is something wrong with the way I am calling the API to get the entire history for these ETF tickers.

SPY

ETF available since Feb/1993 (MarketStack API only returns daily data back to June 2, 2020). https://www.google.com/finance/quote/SPY:NYSEARCA?window=MAX IVV

ETF available since May/2000 (MarketStack API only returns daily data back to July 18, 2005). https://www.google.com/finance/quote/IVV:NYSEARCA?window=MAX VOO

ETF available since Sept/2010 (MarketStack API only returns daily data back to June 2, 2020). https://www.google.com/finance/quote/VOO:NYSEARCA?window=MAX URTH

ETF available since Jan/2012 (MarketStack API only returns daily data back to June 2, 2020). https://www.google.com/finance/quote/URTH:NYSEARCA?window=MAX

Here is the Python function that I am using to invoke the MarketStack API to get historical information about tickers.

def get_close_data(symbol='AAPL.US', api_token='OeAFFmMliFG5orCUuwAKQ8l4WWFQ67YX', from_date = '2021-07-01', to_date = '2021-07-08'): session = requests.Session() print("symbol is ",symbol) print("from_date ",from_date) print("to_date ", to_date)

base_url = 'http://api.marketstack.com/v1/tickers/'+symbol+'/eod'

base_url = 'http://api.marketstack.com/v1/eod'

url = 'https://eodhistoricaldata.com/api/div/%s' % symbol

params = {'access_key': api_token,'symbols':symbol,'limit':10000,'date_from':from_date,'date_to':to_date} r = session.get(base_url, params=params)

ticker_dict = json.loads(r.text)["data"]

print("ticker_dict is ", ticker_dict)

if r.status_code == requests.codes.ok:

print("status OK ")

df = pd.DataFrame.from_dict(ticker_dict, orient='columns')

df = pd.read_csv(StringIO(r.text), skipfooter=0, parse_dates=[0], index_col=0, engine='python')

return(True, df) else: print("status code",str(r.status_code)) print("reason code",str(r.reason)) return(False,"null")

raise Exception(r.status_code, r.reason, url)