Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shopglobal/974e415b0435fdf724db0714261bdeb5 to your computer and use it in GitHub Desktop.
Save shopglobal/974e415b0435fdf724db0714261bdeb5 to your computer and use it in GitHub Desktop.
Map current cryptocurrency prices into Google Sheets
/* USAGE:
* Sheet -> Tools -> Script Editor...
* Paste this script
* Update the map (below) to your preferences
* Create a button in your Sheet and Assign Script: `test`
* et voila profit
*/
function test() {
// maps currencies.tokens to sheet ranges
getPrices({
'USD': {
'ETH': 'G6',
'DASH': 'H6',
'LTC': 'I6',
'GNT': 'J6',
'REP': 'K6',
'BAT': 'L6'
}
});
}
function getPrices(model) {
for (var currency in model) {
var tokens = Object.keys(model[currency]).toString();
var url = 'https://min-api.cryptocompare.com/data/price?fsym=' + currency + '&tsyms=' + tokens;
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
var json = JSON.parse(response.getContentText());
for (var token in model[currency]) {
updatePrice(
model[currency][token],
json[token]
);
}
}
}
function updatePrice(range, price) {
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(range).setValue(1/price);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment