Integration of Bittrex API with Google Sheets using Google Apps Script

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

//Enable 2FA (https://bittrex.com/Manage?view=2fa) on your account. API Keys cannot be generated unless 2FA is enabled.
function Bittrex(){
  var key = '<Your API key here>';
  var secret = '<Your Secret key here>';

  var baseUrl = 'https://bittrex.com/api/v1.1/';
  var nonce = Math.floor(new Date().getTime()/1000);
  
  var uri = baseUrl.concat("account/getbalance?apikey=" + key + "&nonce=" + nonce + "&currency=BTC")
   
  var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, uri, secret);
 
 var apisign = signature.map(function(byte) {
    return ('0' + (byte & 0xFF).toString(16)).slice(-2);
  }).join('');
 
  var headers = {
    "apisign": apisign
  }
  var params = {
    "method": "get",
    'contentType': 'application/json',
    "headers": headers
  }
  var response = UrlFetchApp.fetch(uri, params);
  Logger.log(response);
  var data = JSON.parse(response.getContentText());
  Logger.log(data.result.Available);
  return data.result.Available;
}

Leave a Reply