Created
March 24, 2014 06:31
-
-
Save zkarpinski/9735177 to your computer and use it in GitHub Desktop.
Parses and returns current Bitcoin price in the desired currency.
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
//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