Skip to content

Instantly share code, notes, and snippets.

@icy
Forked from mikaelz/YahooFinance.js
Created January 27, 2022 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icy/2c1455a07b56ec0fe9eb434976f41e3f to your computer and use it in GitHub Desktop.
Save icy/2c1455a07b56ec0fe9eb434976f41e3f to your computer and use it in GitHub Desktop.
Google script to fetch stock quote data from Yahoo Finance
*
Author: Ky-Anh Huynh
Original script: https://gist.github.com/mikaelz/11b956c3d2e078105a19dd9df70dbf27
Usage:
ticker : Your ticker name, eg. ETH-EUR
token : A random string otherwise yahoo output may be a bit messy
You should have random token on each call!
*/
function MyYahooTicker(ticker,token) {
var ticker = ticker || "SXR8.DE";
var token = token || "secure-random-string";
ticker = encodeURI(ticker);
var response = UrlFetchApp.fetch("https://query2.finance.yahoo.com/v10/finance/quoteSummary/" + ticker + "?modules=price,summaryDetail&hello=" + token);
var chain = JSON.parse(response.getContentText());
return parseFloat(chain.quoteSummary.result[0].price.regularMarketPrice.raw);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment