user4737227
user4737227

Reputation:

Fetch API data from Bittrex

I'm trying to fetch the API data with Google Apps Script about my balance on Bittrex but it returns me nothing, no errors and only blank cells. This is the code I've written based on the documentation here: https://bittrex.com/Home/Api

function getBalance() {

  var ss = SpreadsheetApp.openById("***");
  var data = ss.getSheetByName("Data");
  var key = ss.getSheetByName("Api").getRange('A2').getValue();
  var secret = ss.getSheetByName("Api").getRange('B2').getValue();
  var baseUrl = 'https://bittrex.com/api/v1.1/';
  var nonce = Math.floor(new Date().getTime()/1000);


  var command = "/account/getbalances";
  var uri = baseUrl.concat(command + "?apikey=" + key + "&nonce=" + nonce);

  var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512,
                      uri,
                      secret);


  signature = signature.map(function(byte) {
  return ('0' + (byte & 0xFF).toString(16)).slice(-2);
  }).join('')


  var headers = {
    "apisign": signature
  }

  var params = {
    "method": "get",
    "headers": headers,
  }

  var response = UrlFetchApp.fetch(uri, params);
  var json = JSON.parse(response.getContentText());


  var blnc = [];
  blnc.push(['Balance']);

  for(var key in json.result)
   {
    blnc[0].push(json.result[key]);
   }

  askRange = data.getRange(2, 2, blnc.length, 1);
  askRange.setValues(blnc);


}

The askrange last number is "1" because the script only pass the "Balance" value to the spreadsheet, but the values should be something around 210. Any help? Thank you

Upvotes: 0

Views: 1752

Answers (1)

user4737227
user4737227

Reputation:

I solved it, the problem was in the "command" variable, there was a slash not needed that generated an url with a double slash

Upvotes: 1

Related Questions