Skip to content

Instantly share code, notes, and snippets.

@truth3
Created July 8, 2019 23:44
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 truth3/46fd85a19c9027903af611b0ac7ce744 to your computer and use it in GitHub Desktop.
Save truth3/46fd85a19c9027903af611b0ac7ce744 to your computer and use it in GitHub Desktop.
The modified code which is tuned to request data from your own server instead of coin market cap directly
function get_curr_coinmarketcap_price(crypto_id, unused_param) {
// note that the unused_param is to to force the function to rerun
// and recalcuate the functions results when the function is called with
// new input
// https://stackoverflow.com/questions/17341399/refresh-data-retrieved-by-a-custom-function-in-google-spreadsheet
// create a string that is the first part of our API calls url
var url1 = 'https://yourserver.com/crypto-prices.php?crypto_id=';
// append crypto_id to our url so we can tell the API that we want prices
// only for that id
var full_url = url1 + crypto_id +'/';
var response = UrlFetchApp.fetch(full_url);
//return response.getContentText();
// parse the JSON string and build it into JavaScript objects
var data = JSON.parse(response.getContentText());
// return the first (should be only) price from data
// extract the value in the dictionary with a key of 'price_usd'
return data[0]['price_usd'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment