3

I'm trying to make a simple GUI that collects a few sets of historical stock data from Alpha Vantage. I'm getting this error:

  File "d:\GIT\StockAI\main.py", line 34, in run
    data = ts.get_daily(symbol=stock, outputsize='full')
  File "C:\Users\benlu\Anaconda3\lib\site-packages\alpha_vantage\alphavantage.py", line 178, in _format_wrapper
    data = call_response[data_key]
KeyError: 'Time Series (Daily)'

I'm not entirely sure what that means, and I'm having some trouble googling the issue. I assume it's something rather simple that I'm missing. Additionally, the output format is set to pandas, if that's important. Here's (hopefully) all the relevant code:

stockList = ["AAPL", "AMZN", "GOOG", "GOOGL", "MSFT", "JPM", "JNJ", "BA"]

for stock in stockList:
    data = ts.get_daily(symbol=stock, outputsize='full')
    data[0].to_csv(stock + '.csv')

It seems to work rather randomly; it'll collect a few .csv files and then just seemingly randomly it will stop... anyone have any help to send my way? I'd greatly appreciate it!

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Ben L
  • 63
  • 3
  • 10

1 Answers1

2

From my experience this happens when the free tier limit is exceeded. You can only call the API 5 times per minute. The error is very misleading, but it is related to the free tier.

To solve this problem you can simply add a timeout after 5 calls, or get the premium API.

Info from the website support page:

Are there usage/frequency limits for the API service?

We are proud to provide free API service for our global community of users and recommend that you make API requests sparingly (up to 5 API requests per minute and 500 requests per day) to achieve the best server-side performance. If you would like to target a larger API call volume, please visit premium membership.

Note: If you are a student or educator, chances are that your school already has a data partnership with Alpha Vantage. If not, please ask your school/library administrator to contact partnerships@alphavantage.co for a special partnership plan for educational institutions.

klaus
  • 1,187
  • 2
  • 9
  • 19