python-3.xyahoo-financequandl

Get free SP500 historical end of day data through API


Is there any way to get free SP500 historical end-of-day data ideally in API and csv form? Not sure why it seems to be harder than I could imagine.

For example:

Quandl: SPY or SPX symbol not found

rs = requests.get('https://www.quandl.com/api/v3/datasets/WIKI/SPY/data.csv?api_key=<API Keys>')

Is there any API that I could try?

Thank you.


Solution

  • You can retrieve it via API by installing quandl with pip install quandl and then making a request as follows:

    import quandl
    
    quandl.ApiConfig.api_key = 'YOUR_KEY'
    quandl.get('EOD/SPY', start_date='2021-02-26', end_date='2021-02-26')
    

    However, you need to be subscribed to the dataset to be able to access the data this way.