{msg=此请求的签名无效。, success=false} Binance Api 提款和存款请求错误

{msg=Signature for this request is not valid., success=false} error for Binance Api withdraw and deposit request

之后,我能够从我的个人币安账户中正确获取所有订单或交易数据。

function connect() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];

  var key = '****';
  var secret = '****';

  var curTime = Number(new Date().getTime()).toFixed(0);
  var symbol = "TRXETH";
  var limit  = 13;
  var string = "symbol="+symbol+"&limit=12&timestamp=" + curTime;
  var sKey = Utilities.computeHmacSha256Signature(string, secret);
  sKey = sKey.map(function(e) {
      var v = (e < 0 ? e + 256 : e).toString(16);
      return v.length == 1 ? "0" + v : v;
  }).join("");
  var params = {
    'method': 'get',
    'headers': {'X-MBX-APIKEY': key},
    'muteHttpExceptions': true
  };
  var url = "https://api.binance.com/api/v3/myTrades?" + string + "&signature=" + sKey;
  var data = UrlFetchApp.fetch(url, params);
  var data = JSON.parse(data.getContentText());

它工作得很好,但是,因为我需要提取 还存入和提取数据 ,我想我已经制作了一个新的专用脚本。
而且不行:

function deposit() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];

  var key = '****';
  var secret = '****';

  var curTime = Number(new Date().getTime()).toFixed(0);
  var string = "/wapi/v3/withdrawHistory.html?timestamp=" + curTime;
  var sKey = Utilities.computeHmacSha256Signature(string, secret);
  sKey = sKey.map(function(e) {
      var v = (e < 0 ? e + 256 : e).toString(16);
      return v.length == 1 ? "0" + v : v;
  }).join("");
  var params = {
    'method': 'get',
    'headers': {'X-MBX-APIKEY': key},
    'muteHttpExceptions': true,
    //'signature': sKey
  };
  var url = "https://api.binance.com" + string + "&signature=" + sKey;
  var data = UrlFetchApp.fetch(url, params);
  var data = JSON.parse(data.getContentText());

现在 github 上有几张票解决这个问题,但 none 似乎适合我的情况:谁能告诉我我的代码有什么问题?谢谢

Github 1 Github 2 Binance Official Documentation

  • 您用于访问 Binance 的令牌 API 是正确的。
  • 您想使用币安提现历史的方法API。

从你的脚本和回复中我可以像上面那样理解。如果我的理解是正确的,下面的修改怎么样?

修改后的脚本:

从:
var string = "/wapi/v3/withdrawHistory.html?timestamp=" + curTime;
到:
var string = "timestamp=" + curTime;

从:
var url = "https://api.binance.com" + string + "&signature=" + sKey;
到:
var url = "https://api.binance.com/wapi/v3/withdrawHistory.html?" + string + "&signature=" + sKey;

参考: