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?
Asked
Active
Viewed 2,431 times
0
-
Could you use importxml from cmegroup or some other site that post commodity prices and changes? – Mitchell Bivens May 11 '21 at 03:36
3 Answers
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
-
-
-
-
So above I said I use the add-on YAHOOFINANCE but the problem I'm running into now is that after about an hour I get an error message in the cell where the price is suppose to be shown. – Mitchell Bivens May 12 '21 at 07:38