Created
January 11, 2022 19:09
-
-
Save CastleCorp/a42d8b059a98472e466600b56988c801 to your computer and use it in GitHub Desktop.
Get the price of a crypto token from an 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
/** | |
* @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