0

当我尝试使用以下代码块获取历史报价时,stockInfo 数组返回为空。根据 FinanceApp.getHistoricalStockInfo 函数调用中指定的标准,我应该得到 2012 年 11 月 30 日交易日 GOOG 股票的价格。

function TestMethod()
{
  var ss = SpreadsheetApp.getActiveSheet();
  var date = new Date(2012, 11, 30);
  var retValue = FinanceApp.getHistoricalStockInfo("GOOG", date, date, 1);
  var ret = retValue.stockInfo[0];  

  Logger.log(ret);  /* This comes back as 'undefined' */
  Logger.log(retValue.close);  /* This comes back as 'undefined' */

  if (retValue != undefined && retValue.stockInfo[0] != undefined)
    Logger.log(retValue);
}

直到大约 10 天前,这种方法才能正常工作。我也尝试将其发布到谷歌群组论坛,但尚未有人回复。

4

1 回答 1

2

当您设置 1 天的间隔时,您将必须在开始日期和结束日期之间至少相差一天。例如

function TestMethod(){
  var ss = SpreadsheetApp.getActiveSheet();
  var startDate = new Date(2012, 10, 30);
  var endDate = new Date(2012, 11, 1);
  var retValue = FinanceApp.getHistoricalStockInfo('GOOG', startDate, endDate, 1);
  var ret = retValue.stockInfo[0];  

  Logger.log(ret); 
  Logger.log(retValue);  
}
于 2012-12-04T06:21:41.323 回答