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'; } 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; } //'https://api.coinbase.com/v2/prices/BTC-USD/sell' var url = 'https://api.coinbase.com/v2/prices/'+coin+'-USD/'+type;

Sort:  

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