Skip to content

Instantly share code, notes, and snippets.

@CastleCorp
Created January 11, 2022 19:09
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 CastleCorp/a42d8b059a98472e466600b56988c801 to your computer and use it in GitHub Desktop.
Save CastleCorp/a42d8b059a98472e466600b56988c801 to your computer and use it in GitHub Desktop.
Get the price of a crypto token from an API
/**
* @author Parker Thomas
* @date 1/11/2022
*
* @def getPrice(url, token)
* @param url: the API endpoint to hit
* @param token: the token name to retrieve the price
* Returns the price of the given token from the API
*
* For example, use this API endpoint: https://blockchain.info/ticker
*/
function getPrice(url, token) {
var response = UrlFetchApp.fetch(url);
var responseJSON = JSON.parse(response.getContentText());
return responseJSON[token].last;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment