Last active
April 16, 2019 06:40
-
-
Save kpooooooooooo/45fcf8eb4ed5f074c249965f9e43bbb8 to your computer and use it in GitHub Desktop.
KPO Alpha Vantage Guide
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
api_key = 'PASTE_YOUR_API_KEY_HERE' | |
url = 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=' | |
function getAlphaVantage(symbol) { | |
var response = UrlFetchApp.fetch(url + symbol + "&apikey=" + api_key).getContentText(); | |
var data = JSON.parse(response); | |
var timeSeries = data["Time Series (Daily)"]; | |
var value = 0.0; | |
for (var dates in timeSeries) { | |
value = timeSeries[dates]["4. close"]; | |
Logger.log("Within getAlphaVantage(symbol) function:" + value) | |
if (value > 0.0) { | |
break; | |
} | |
} | |
return parseFloat(value); | |
} | |
function getAlphaVantageSlowly(symbol, seconds) { | |
// Cannot sleep too long - A custom function call must return within 30 seconds | |
// https://developers.google.com/apps-script/guides/sheets/functions | |
temp = seconds % 30 | |
Utilities.sleep(temp * 1000) // function is in milliseconds | |
var response = UrlFetchApp.fetch(url + symbol + "&apikey=" + api_key).getContentText(); | |
var data = JSON.parse(response); | |
var timeSeries = data["Time Series (Daily)"]; | |
var value = 0.0; | |
for (var dates in timeSeries) { | |
value = timeSeries[dates]["4. close"]; | |
Logger.log("Within getAlphaVantage(symbol) function:" + value) | |
if (value > 0.0) { | |
break; | |
} | |
} | |
return parseFloat(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment