Skip to content

Instantly share code, notes, and snippets.

@zkarpinski
Created March 24, 2014 06:31
Show Gist options
  • Save zkarpinski/9735177 to your computer and use it in GitHub Desktop.
Save zkarpinski/9735177 to your computer and use it in GitHub Desktop.
Parses and returns current Bitcoin price in the desired currency.
//GetBTCPrice
//Parses BTC price from a selected exchange.
function GetBTCPrice(currency){
//TODO: Change to a better exchange like Mt. Gox. ^_^
if (currency === null){currency = "usd";}
var url = "https://btc-e.com/api/2/btc_" + currency.toLowerCase() + "/ticker";
var response = UrlFetchApp.fetch(url).getResponseCode();
if (response == 200)
{
var btcdata = UrlFetchApp.fetch(url).getContentText();
var object = JSON.parse(btcdata);
return object["ticker"]["sell"];
} else {
return "Server error";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment