Reputation: 318
following this answer on stack I was able to correctly fetch all orders or trades data from my personal binance account.
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());
It works just fine but, since I needed to pull also deposit and withdraw data, I thought I'd made a new dedicated script.
And it does not work:
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());
now there are several tickets on github for this problem, but none seems to fit my case: can anyone tell me what is wrong with my code? thanks
Github 1 Github 2 Binance Official Documentation
Upvotes: 3
Views: 5835
Reputation: 201378
I could understand like above from your script and replying. If my understanding is correct, how about the following modification?
var string = "/wapi/v3/withdrawHistory.html?timestamp=" + curTime;
To:
var string = "timestamp=" + curTime;
and
From:var url = "https://api.binance.com" + string + "&signature=" + sKey;
To:
var url = "https://api.binance.com/wapi/v3/withdrawHistory.html?" + string + "&signature=" + sKey;
Upvotes: 2