How do I retrieve Google Finance Historical data in Google Sheets using the API?

时光怂恿深爱的人放手 提交于 2019-12-11 07:35:12

问题


To reproduce this problem, create a new sheet. In cell A1, insert this formula:

=GoogleFinance("AMZN", "all", "1/1/2018", "2/1/2018")

The output (Formatting doesn't matter for this problem):

Date    Open    High    Low Close   Volume
1/2/2018 16:00:00   1172    1190    1170.51 1189.01 2694494
1/3/2018 16:00:00   1188.3  1205.49 1188.3  1204.2  3108793
1/4/2018 16:00:00   1205    1215.8699   1204.66 1209.59 3022089
1/5/2018 16:00:00   1217.51 1229.14 1210    1229.14 3544743
1/8/2018 16:00:00   1236    1253.079    1232.03 1246.87 4279475
1/9/2018 16:00:00   1256.9  1259.33 1241.76 1252.7  3661316
1/10/2018 16:00:00  1245.15 1254.33 1237.23 1254.33 2686017
1/11/2018 16:00:00  1259.74 1276.77 1256.46 1276.68 3125048
1/12/2018 16:00:00  1273.3925   1305.76 1273.3925   1305.2  5443730
1/16/2018 16:00:00  1323    1339.94 1292.3  1304.86 7220701
1/17/2018 16:00:00  1312.24 1314    1280.88 1295    5253754
1/18/2018 16:00:00  1293.95 1304.6  1284.02 1293.32 4026915
1/19/2018 16:00:00  1312    1313    1292.99 1294.58 4578536
1/22/2018 16:00:00  1297.17 1327.45 1296.6636   1327.31 4140061
1/23/2018 16:00:00  1338.09 1364.9  1337.34 1362.54 5169306
1/24/2018 16:00:00  1374.82 1388.16 1338    1357.51 6807457
1/25/2018 16:00:00  1368    1378.34 1357.62 1377.95 4753012
1/26/2018 16:00:00  1392.01 1402.53 1380.91 1402.05 4857310
1/29/2018 16:00:00  1409.18 1431.39 1400.44 1417.68 5701898
1/30/2018 16:00:00  1403.17 1439.25 1392    1437.82 5871942
1/31/2018 16:00:00  1451.3  1472.58 1450.04 1450.89 6424693

All is well so far. BUT, when I try to retrieve this data via the API (And I want to point out that all OTHER data is retrieved just fine), I get simple a "#N/A" for cell A1, and no values for all the other cells. It's like they're empty. I've tried retrieving just the values, but also all the gridinfo, both cases, it's like these values were never there.

Things I've tried:

  • Setting a cell to "=TODAY()" before reading (some comments say that triggers a refresh of the data).
  • Looping with a delay trying to read the data, but that runs forever.
  • All this works flawlessly in the browser, but not over API calls
  • Other cells referencing this data fails with "#N/A"
  • If I add the add-on CryptoFinance, and insert this function "=CRYPTOFINANCE("COINMARKETCAP")", a range of cells are populated, similar to GoogleFinance. However, these cells CAN be retrieved via API calls. Works like a charm.
  • Any 'single' cell using googlefinance works fine, so if I add cell I1 shown below, THAT value is retrieved just fine

    =GoogleFinance("AMZN", "price")
    

It just simply seems like the data is not there when using the HISTORICAL data from google finance (as per the API call).

I have not posted my code, since it seems this is more a case of googlefinance not working than anything else, and specifically when returning a 'range' of data instead of single cell values.

Thoughts?


回答1:


Duh.

Tucked at the very bottom of the Google Finance Documentation I finally noticed this little gem:

Historical data cannot be downloaded or accessed via the Sheets API or Apps Script. If you attempt to do so, you will see a #N/A error in place of the values in the corresponding cells of your spreadsheet.



来源:https://stackoverflow.com/questions/49045208/how-do-i-retrieve-google-finance-historical-data-in-google-sheets-using-the-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!