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:
"id": "bitcoin",
"name": "Bitcoin",
"symbol": "BTC",
"rank": "1",
"price_usd": "573.137",
"price_btc": "1.0",
"24h_volume_usd": "72855700.0",
"market_cap_usd": "9080883500.0",
"available_supply": "15844176.0",
"total_supply": "15844176.0",
"percent_change_1h": "0.04",
"percent_change_24h": "-0.3",
"percent_change_7d": "-0.57",
"last_updated": "1472762067"
So to get the current total supply of BTC, the function would be:
cmc("BTC","total_supply",A1)
Hope this is useful!