Skip to content
This repository was archived by the owner on Oct 30, 2023. It is now read-only.

Commit a084335

Browse files
author
Jon Eyrick
authored
Fix POST requests by afsharsafavi
2 parents 47fc9a3 + 2be0359 commit a084335

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

node-binance-api.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,17 @@ let api = function Binance() {
123123
'X-MBX-APIKEY': key || ''
124124
}
125125
})
126-
126+
const reqObjPOST = (url, data = {}, method = 'POST', key) => ({
127+
url: url,
128+
form : data,
129+
method: method,
130+
timeout: Binance.options.recvWindow,
131+
headers: {
132+
'User-Agent': userAgent,
133+
'Content-type': contentType,
134+
'X-MBX-APIKEY': key || ''
135+
}
136+
})
127137
/**
128138
* Create a http request to the public API
129139
* @param {string} url - The http endpoint
@@ -198,14 +208,23 @@ let api = function Binance() {
198208
return a;
199209
}, []).join('&');
200210
let signature = crypto.createHmac('sha256', Binance.options.APISECRET).update(query).digest('hex'); // set the HMAC hash header
201-
let urlstring = method === 'POST' ? `${url}?signature=${signature}` : `${url}?${query}&signature=${signature}`;
202-
let opt = reqObj(
203-
urlstring,
204-
data,
205-
method,
206-
Binance.options.APIKEY
207-
);
208-
proxyRequest(opt, callback);
211+
if (method==='POST') {
212+
let opt = reqObjPOST(
213+
url + '?signature=' + signature,
214+
data,
215+
method,
216+
Binance.options.APIKEY
217+
);
218+
proxyRequest(opt, callback);
219+
} else {
220+
let opt = reqObj(
221+
url + '?' + query + '&signature=' + signature,
222+
data,
223+
method,
224+
Binance.options.APIKEY
225+
);
226+
proxyRequest(opt, callback);
227+
}
209228
};
210229

211230
/**

0 commit comments

Comments
 (0)