Last active
February 2, 2024 21:31
-
-
Save kannaiah/53881607c9eba63099689591ad6e949e to your computer and use it in GitHub Desktop.
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
function getYahooPrice(symbol, datetime) { | |
symbol = symbol || "NSE:PANACEABIO"; | |
// symbol = symbol.replace("NSE:", "") + ".NS"; | |
Utilities.sleep(Math.floor(Math.random() * 5000)) | |
var url = 'https://query1.finance.yahoo.com/v7/finance/download/'+ symbol + '?interval=1d&events=history'; // last one day history | |
Logger.log(url); | |
var response = UrlFetchApp.fetch(url, {muteHttpExceptions: true}); | |
if (response.getResponseCode()) { | |
var textFile = response.getContentText(); | |
if (textFile.indexOf("Date") != -1) { | |
var csv = Utilities.parseCsv(textFile); | |
} else { | |
Logger.log("Some Error"); | |
return "No Data"; | |
} | |
} | |
Logger.log(csv); | |
Logger.log(csv[1][4]); | |
return parseFloat(csv[1][4]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on this, I have created the following: