[英]Alternatives to google finance stock prices
I'm trying to make a Stock portfolio tracker for my investments.我正在尝试为我的投资制作股票投资组合跟踪器。 I already understand how to use google finance but the 20 min delay on prices is a drag.
我已经了解如何使用谷歌金融,但价格延迟 20 分钟是一个拖累。 I've updated the recalculation for my sheets to on change and every minute but the delay will still happen.
我已将我的工作表的重新计算更新为每分钟更改一次,但延迟仍然会发生。 So my real question is if and how could I pull a stock price from the Nasdaq into google sheets for a more real time feel.
所以我真正的问题是我是否以及如何将股票价格从纳斯达克拉到谷歌表格中以获得更实时的感觉。
What you can try is having script and have it triggered every minute.您可以尝试使用脚本并每分钟触发一次。
I tried fetching from NASDAQ but it takes too long.我尝试从纳斯达克获取,但时间太长了。 I used WSJ instead but the issue is it randomly errors out due to something I was never able to point out.
我改用《华尔街日报》,但问题是由于我无法指出的事情而随机出错。 Thus I added a column to identify when the data was last updated.
因此,我添加了一个列来标识上次更新数据的时间。 Don't worry though, it will be updated within the next run.
不过不用担心,它将在下一次运行中更新。
function getPrice() {
var sheet = SpreadsheetApp.getActiveSheet();
// tickers will be checked on column A starting 2nd row
var values = sheet.getRange("A2:A" + sheet.getLastRow()).getValues().flat();
sheet.getRange("A1:C1").setValues([["Tickers", "Price", "Last Updated"]]);
values.forEach(function (ticker, index){
var url = "https://www.wsj.com/market-data/quotes/" + ticker;
Utilities.sleep(2000);
var html = UrlFetchApp.fetch(url).getContentText();
Utilities.sleep(2000);
var price = html.match(/quote_val">([\d ,.]+)/);
// since it randomly errors out on [1], check if price is null
// add date and time too on column C to confirm when was the data last updated
if(price){
sheet.getRange(index + 2, 2).setValue(price[1].trim());
sheet.getRange(index + 2, 3).setValue(new Date());
}
});
// call to remove existing triggers and create another one
createTrigger();
}
function createTrigger(){
// Delete all existing triggers before creating one
// Ensuring none will exist before creating trigger.
var triggers = ScriptApp.getProjectTriggers();
triggers.forEach(function (trigger){
ScriptApp.deleteTrigger(trigger);
});
// Create trigger after every run which is per minute
ScriptApp.newTrigger('getPrice')
.timeBased()
.after(60 * 1000)
.create();
}
GOOGLEFINANCE
recalculation is set to 20 minutes and cant be re-set GOOGLEFINANCE
重新计算设置为 20 分钟且无法重新设置
you will need to either scrape it from somewhere (yahoo finance, coinmarketcap) or like MK mentioned you will need to pay for (API) it because free plans may not be enough for you.您将需要从某个地方(雅虎金融、coinmarketcap)刮掉它,或者像 MK 提到的那样,您需要为它付费(API),因为免费计划可能对您来说还不够。 see: https://coinmarketcap.com/api/pricing/
见: https://coinmarketcap.com/api/pricing/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.