Skip to content

Instantly share code, notes, and snippets.

@zkarpinski
Created March 24, 2014 06:17
Show Gist options
  • Save zkarpinski/9735060 to your computer and use it in GitHub Desktop.
Save zkarpinski/9735060 to your computer and use it in GitHub Desktop.
Returns the last trade price for a desired crypto-currency coin.
//*NOTE* 500 Server Internal Server Error status very common when used with multiple coins
//Returns the price of the desired coin in BTC or LTC
function GetCryptCoin(coin,base){
const url = "http://pubapi.cryptsy.com/api.php?method=marketdatav2";
if (base === null){base = "BTC"}
var response = UrlFetchApp.fetch(url).getResponseCode();
if (response == 200) {
var cryptsydata = UrlFetchApp.fetch(url).getContentText();
var object = JSON.parse(cryptsydata);
return object["return"]["markets"][coin + "\/"+base]["lasttradeprice"];
} else {
return "Can't contact server";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment