0

Hi I'm trying to get the current WTI (West Texas Intermediate) price but GoogleFinance doesn't recognize it. Has anybody had luck with this?

Mitchell Bivens
  • 97
  • 2
  • 12

3 Answers3

1

Ok. Found a solution. Google Sheets has an add-on and you can add the Yahoo Finance and then run formula =YAHOOFINANCE("ticker") and pick up commodities such as WTI (CL=F).

Mitchell Bivens
  • 97
  • 2
  • 12
0

With Yahoo, you can also get the information by decoding the json cntained in the web page. In A1 for instance =marketPrice("CL=F") and the script :

function marketPrice(code) {
  var url='https://finance.yahoo.com/quote/'+code
  var source = UrlFetchApp.fetch(url).getContentText()
  var jsonString = source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}'
  var data = JSON.parse(jsonString)
  var regularMarketPrice = data.context.dispatcher.stores.StreamDataStore.quoteData.item(code).regularMarketPrice.raw
  return regularMarketPrice
}
Object.prototype.item=function(i){return this[i]};
Mike Steelson
  • 14,650
  • 2
  • 5
  • 20
  • So the script above works great in Apps Script and I can see the price in the Logs but on the Google Sheet there's nothing. I also notice there no assigned cell either so I would assume that is the reason for that. How would I make the code display on google sheets? – Mitchell Bivens May 12 '21 at 07:36
-1

Try

=GOOGLEFINANCE("NYSE:WTI","price")
Mike Steelson
  • 14,650
  • 2
  • 5
  • 20