Created
January 15, 2018 01:31
-
-
Save glebkuznetsov/2c8f39ec7c56569f8e9cf14957aa105a to your computer and use it in GitHub Desktop.
Google Apps Script to query crypto prices from cryptocompare.com API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function updateAssetPrices(sheetTab) { | |
| var currency = sheetTab.getRange('J1').getValue(); | |
| var response = UrlFetchApp.fetch( | |
| 'https://min-api.cryptocompare.com/data/price?fsym=' + currency + '&tsyms=USD') | |
| var jsonData = response.getContentText(); | |
| var data = JSON.parse(jsonData); | |
| sheetTab.getRange('J2').setValue(data.USD); | |
| sheetTab.getRange('J3').setValue( | |
| Utilities.formatDate(new Date(), "EST", "yyyy-MM-dd'T'HH:mm:ss'Z'")); | |
| } | |
| function onOpen() { | |
| var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
| var sheets = ss.getSheets(); | |
| for (var sheetNum = 0; sheetNum < sheets.length; sheetNum++){ | |
| updateAssetPrices(sheets[sheetNum]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment