Created
December 12, 2017 13:15
-
-
Save altitdb/9df1c69ac01704c7e3bb4e11c1d88e54 to your computer and use it in GitHub Desktop.
This file contains 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
//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