Google Sheets Cryptocurrency Market Cap

Google sheets cryptocurrency market cap

Get cryptocurrency price on your google sheets with Coinmarketcap API

With all of the activity lately on Coinmarketcap.com, I've started a Google Sheets doc to keep track of some metrics.

For those interested, I've created a script to allow the retrieval of certain information based on CMC's api.

function onEdit(e) {
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(Math.random());
}

function search(symbol, myArray) {
for (var i=0; i < myArray.length; i++) {
if (myArray[i].symbol == symbol) {
return myArray[i];
}
}
return myArray[0];
}

function cmc(symbol, key, rand) {
var url = "https://api.coinmarketcap.com/v1/ticker/?convert=USD&limit=70";

var response = UrlFetchApp.fetch(url);
var text = response.getContentText();

var obj_array = JSON.parse(text);
var obj = search(symbol, obj_array);
var value = obj[key];

return parseFloat(value);
}

Add the code above to the script editor under tools and the following function is now available:

=cmc("BTC","price_usd",A1)

The "A1" is needed as the third parameter because Google Sheets is weird with its caching and won't update the API get without that.

Here's a sample of all the Symbols and Descriptions you can get from this function:

So to get the current total supply of BTC, the function would be:

cmc("BTC","total_supply",A1)

Hope this is useful!