Integration of Bitstamp API with Google Sheets using Google Apps Script

In this Post, we Integrate google sheets to Bitstamp API through the ‘authenticated’ section of the API so I can access my account information.
This Script is to Get account balances from Bitstamp.

function Bitstamp() {
eval(UrlFetchApp.fetch('https://cdnjs.cloudflare.com/ajax/libs/jsSHA/2.3.1/sha256.js').getContentText());
  var key = '<Your API key here>';
  var secret = '<Your API secret here>';
  var customer_id = '<Your customer id here>';
  var nonce = new Date().getTime().toString();
  var message = nonce + customer_id + key
  var shaObj = new jsSHA("SHA-256", "BYTES");
  shaObj.setHMACKey(secret, "BYTES");
  shaObj.update(message);
  var signature = shaObj.getHMAC("HEX").toString().toUpperCase();
  Logger.log(signature)
  var url = "https://www.bitstamp.net/api/v2/balance/";
  var formData = {
    "key": key,
    "signature": signature,
    "nonce": nonce
  };
  var options = {
    "method": "post",
    "muteHttpExceptions": true,
    "payload": formData
  };
  var response = UrlFetchApp.fetch(url, options);
  Logger.log(response);
  var data = JSON.parse(response.getContentText());
  Logger.log(data);
}

Leave a Reply