FinanceApp.getHistoricalStockInfo调用不返回正确的值

时间:2012-12-03 19:09:30

标签: google-apps-script google-finance-api

当我尝试使用以下代码块获取历史引号时,stockInfo数组将返回空白。根据FinanceApp.getHistoricalStockInfo函数调用中指定的条件,我应该得到11/30/2012交易日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天前。我已经尝试将此帖子发布到google群组论坛,但还没有人回复。

1 个答案:

答案 0 :(得分:2)

当您设置1天的间隔时,您必须在开始日期和结束日期之间至少有一天的差异。 e.g

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);  
}