按照堆栈上的这个答案,我能够正确地从我的个人币安账户中获取所有订单或交易数据。
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×tamp=" + 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 上有几张票可以解决这个问题,但似乎没有一张适合我的情况:谁能告诉我我的代码有什么问题?谢谢