Skip to content

Instantly share code, notes, and snippets.

@altitdb
Created December 12, 2017 13:15
Show Gist options
  • Save altitdb/9df1c69ac01704c7e3bb4e11c1d88e54 to your computer and use it in GitHub Desktop.
Save altitdb/9df1c69ac01704c7e3bb4e11c1d88e54 to your computer and use it in GitHub Desktop.
//https://coinmarketcap.com/api/
//https://blockchain.info/ticker
function getReal() {
return getBitcoinBrl() / getBitcoinUsd();
}
function getBitcoinBrl() {
return getValue("bitcoin", "BRL");
}
function getBitcoinUsd() {
return getValue("bitcoin", "USD");
}
function getEthereumBrl() {
return getValue("ethereum", "BRL");
}
function getEthereumUsd() {
return getValue("ethereum", "USD");
}
function getValue(coin, convert) {
var url = 'https://api.coinmarketcap.com/v1/ticker/' + coin + '/?convert=BRL';
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
var data = JSON.parse(json);
var value = 0;
if (convert == 'BRL') {
value = data[0].price_brl;
} else {
value = data[0].price_usd;
}
Logger.log("Price " + coin + "/" + convert + ": " + value);
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment