By bccoder
I am trying to pull some stock data from Alpha Vantage in my DigitalOcean droplet (Ubuntu with Python pre-installed).
Below is the code snippet:
import requests
import json
r = requests.get('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&key=MYKEY')
print r.json()
I was expecting a JSON object like:
"Meta Data": {
"1. Information": "Daily Time Series with Splits and Dividend Events",
"2. Symbol": "IBM",
"3. Last Refreshed": "2020-10-16",
"4. Output Size": "Compact",
"5. Time Zone": "US/Eastern"
},
"Time Series (Daily)": {
"2020-10-16": {
"1. open": "125.1700",
"2. high": "126.4300",
"3. low": "124.6550",
"4. close": "125.9300",
"5. adjusted close": "125.9300",
"6. volume": "4714320",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0000"
},
"2020-10-15": {
"1. open": "124.0800",
"2. high": "125.2150",
"3. low": "123.8500",
"4. close": "124.8900",
"5. adjusted close": "124.8900",
"6. volume": "3389301",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0000"
},
"2020-10-14": {
"1. open": "125.1300",
"2. high": "126.9400",
"3. low": "125.1300",
"4. close": "125.9400",
"5. adjusted close": "125.9400",
"6. volume": "3730139",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0000"
},
But I got:
{
"Error Message": "the parameter apikey is invalid or missing. Please claim your free API key on (https://www.alphavantage.co/support/#api-key). It should take less than 20 seconds."
}
Having been debugging for hours… Could anyone help me out?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
@bccoder I think the problem is misleading API Docs from AlphaVantage.co
You need to change the name of the parameter from: key to apikey.
So before:
r = requests.get('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&key=MYKEY')
after:
r = requests.get('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&apikey=MYKEY')
Seconding @AHA’s answer, the parameter is “apikey” instead of “key”. Below is a sample code snippet (source: Medium):
import requests
import json
key = 'XXX'
ticker = 'IBM'
url = 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol={}&apikey={}'.format(ticker, key)
response = requests.get(url)
print(response.json())
Best of luck!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.