首页 > 解决方案 > 通过 GOOGLEFINANCE 检索 CVE-WT 的价格

问题描述

TSX 上 CVE 的价格可以=GOOGLEFINANCE("TSE:CVE", "price")在 Google 表格中检索。如何使用 GOOGLEFINANCE 获得 CVE-WT 的价格?

标签: google-finance

解决方案


我在 googlefinance 上找不到。您可以通过 yahoo 检索:

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[code].regularMarketPrice.raw
  return regularMarketPrice
}
function test() {Logger.log(marketPrice('CVE-WT'))}

推荐阅读