Google APP Script Function For Cryptocurrencies

in #code7 years ago (edited)

notepad.png

Heres a little script I wrote for use in google sheets. It fetches the cryptocurrency valued off coinbase.com No Steem Dollars yet. As you can see the script is using the coinbase API. I will be looking at other APIs to improve this script in the long run.

  1. To use this add a new script to your google docs by going to Tools-->Script Editor Then just past this script.
  2. To call it just use it like any one of your formulas. "=CryptoCoinValue(coin,type).
    coin is BTC, LTC, or ETH
    type is transaction type or buy, sell, spot


//Coin is the Traded Coin Type BTC, ETH, LTC
//Price is the Transaction Type buy, sell, spot

function CryptoCoinValue(coin, type) {
coin = coin.toUpperCase();
type = type.toLowerCase();
if ((coin === 'BTC') || (coin === 'ETH') || (coin === 'LTC')) {
} else{
return "INVALID COIN"
}
if ((type ==='sell')||(type ==='buy')||(type ==='spot')) {
}else{
return 'INVALID PRICE TYPE';
}
//'https://api.coinbase.com/v2/prices/BTC-USD/sell'
var url = 'https://api.coinbase.com/v2/prices/'+coin+'-USD/'+type;
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
var json = response.getContentText();
var data = JSON.parse(json).data;
if(data.amount == null){
return url;
}
Logger.log(data.amount);
return data.amount;
}

Sort:  

Looks great. I have no idea anything you just said. But nice job all around!

Coin Marketplace

STEEM 0.16
TRX 0.16
JST 0.030
BTC 59358.13
ETH 2471.72
USDT 1.00
SBD 2.45