Last active
August 14, 2022 06:51
-
-
Save elvisciotti/106eda8d0e6312ccc17ebd427beff79f to your computer and use it in GitHub Desktop.
Google spreadsheet function to calculate the value of a CryptoCurrency using coinmarketcap 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
/** | |
* Return a cryptocurrency value in USD using coinmarketcap API | |
* | |
* @param string currency e.g. BTC, ETH | |
* | |
* @return float value | |
*/ | |
function coinmarketcap(currency) | |
{ | |
var body = UrlFetchApp.fetch("https://api.coinmarketcap.com/v1/ticker/"); | |
var json = JSON.parse(body); | |
currencyToValue = {}; | |
for (var i=0, l = json.length; i<l; i++) { | |
var row = json[i]; | |
if (currency === row.symbol) { | |
return row.price_usd; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment