Binance API - Google Script - code":-1022,"msg":"Signature for this request is not valid

Viewed 11

I am trying to pull data from binance API to google sheets but I keep getting the following error:

code":-1022,"msg":"Signature for this request is not valid

I have checked that the keys are correct and regenerated new keys. but with no luck.

   function ImportBinance(calltype, refreshforcer) {

  refreshforcer = 2;
  var url;
  var method;

  if (calltype = "assets") 
  {
    url = "https://api.binance.com/sapi/v3/asset/getUserAsset?";
    method = "post";
  }
  
    if (calltype = "staking") 
  {
    url = "https://api.binance.com/sapi/v1/staking/position?product=STAKING&";
    method = "get";
  }


  var query = "";
  var options = "";


   var key = '**API Key***'; 
    var secret = '***API Secret***'; 
 
    var timestamp = Number(new Date().getTime()).toFixed(0);
    var timestampstring = "timestamp=" + timestamp; 


    var signature = Utilities.computeHmacSha256Signature(timestampstring, secret);
    signature = signature.map(function(e) {
        var v = (e < 0 ? e + 256 : e).toString(16);
        return v.length == 1 ? "0" + v : v;
    }).join("");
    var query = timestampstring + "&signature=" + signature;

    requestOptions = {
        'method': method,
        'headers': {'X-MBX-APIKEY': key},
        'muteHttpExceptions': false}

      url = url + query;
      var jsondata = UrlFetchApp.fetch(url,requestOptions);
      var object   = JSON.parse(jsondata.getContentText());

    Logger.log(object);
}
0 Answers
Related