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

Commit ecf5403

Browse files
author
Jon Eyrick
authored
Merge from development
2 parents e65a006 + 1c2e3e0 commit ecf5403

File tree

7 files changed

+69
-3790
lines changed

7 files changed

+69
-3790
lines changed

ISSUE_TEMPLATE.md

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,2 @@
1-
**Title**
2-
- bug: XYZ broken
3-
- feature: please add
4-
- enhancement: add this to existing features
5-
6-
**Short Description:**
7-
- Unable to get a result from blah
8-
9-
**Platform:**
10-
- windows
11-
- linux
12-
- macos
13-
14-
**node version:**
15-
- 9.11
16-
17-
**Long descrption**
18-
- Doing xyz results in ypr and failing when fph
19-
20-
**code**
21-
```
22-
const util = require('util');
23-
const binance = require('node-binance-api');
24-
binance.options({
25-
APIKEY: '<key>',
26-
APISECRET: '<secret>',
27-
useServerTime: true, // If you get timestamp errors, synchronize to server time at startup
28-
test: true // If you want to use sandbox mode where orders are simulated
29-
});
30-
31-
util.inspect( binance );
32-
```
33-
34-
**result**
35-
```
36-
{
37-
"result":"result"
38-
}
39-
```
40-
41-
thank you
1+
SUPPORT IS NO LONGER OFFERED BY BINANCE
2+
Please do not post an issue unless it is a feature request

README.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,7 @@ npm install node-binance-api --save
2323
const binance = require('node-binance-api')().options({
2424
APIKEY: '<key>',
2525
APISECRET: '<secret>',
26-
useServerTime: true, // If you get timestamp errors, synchronize to server time at startup
27-
test: true // If you want to use sandbox mode where orders are simulated
28-
});
29-
```
30-
31-
#### Instantiating Multiple Instances
32-
```javascript
33-
const Binance = require('node-binance-api');
34-
35-
const instance1 = new Binance().options({
36-
// ...
37-
});
38-
39-
const instance2 = new Binance().options({
40-
// ...
26+
useServerTime: true // If you get timestamp errors, synchronize to server time at startup
4127
});
4228
```
4329

@@ -1654,3 +1640,6 @@ binance.useServerTime(function() {
16541640
[![Views](http://hits.dwyl.io/jaggedsoft/node-binance-api.svg)](http://hits.dwyl.io/jaggedsoft/node-binance-api)
16551641

16561642
Thank you to all contributors: dmzoneill, dmitriz, keith1024, usama33, yanislk, learnathoner, vaielab, nickreese, Tuitio, grandmore, itnok, CollinEstes, sethyx, mstijak, MadDeveloper, balthazar, bitoiu, matthewwoop, robaleman, hems and others!
1643+
1644+
> # ⚠️ Binance no longer offers support for API projects.
1645+
> ## No support is offered. No questions will be answered.

examples/standalone.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Standalone async functions not requiring the library
2+
const axios = require( 'axios' );
3+
async function bookTicker( symbol = false ) {
4+
return new Promise( ( resolve, reject ) => {
5+
params = symbol ? `?symbol=${symbol}` : '';
6+
axios.get( 'https://api.binance.com/api/v3/ticker/bookTicker' + params )
7+
.then( function ( response ) {
8+
resolve( response.data );
9+
} )
10+
.catch( function ( error ) {
11+
throw error;
12+
} );
13+
} );
14+
}
15+
//console.log(await bookTicker());
16+
//console.log(await bookTicker("BTCUSDT"));

node-binance-api.js

Lines changed: 43 additions & 33 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-
202-
let opt = reqObj(
203-
url + '?' + query + '&signature=' + signature,
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
/**
@@ -313,14 +332,14 @@ let api = function Binance() {
313332
*/
314333
const handleSocketClose = function (reconnect, code, reason) {
315334
delete Binance.subscriptions[this.endpoint];
316-
if ( Binance.subscriptions && Object.keys(Binance.subscriptions).length === 0 ) {
335+
if (Binance.subscriptions && Object.keys(Binance.subscriptions).length === 0) {
317336
clearInterval(Binance.socketHeartbeatInterval);
318337
}
319338
Binance.options.log('WebSocket closed: ' + this.endpoint +
320339
(code ? ' (' + code + ')' : '') +
321340
(reason ? ' ' + reason : ''));
322-
if ( Binance.options.reconnect && this.reconnect && reconnect) {
323-
if ( this.endpoint && parseInt(this.endpoint.length, 10) === 60) Binance.options.log('Account data WebSocket reconnecting...');
341+
if (Binance.options.reconnect && this.reconnect && reconnect) {
342+
if (this.endpoint && parseInt(this.endpoint.length, 10) === 60) Binance.options.log('Account data WebSocket reconnecting...');
324343
else Binance.options.log('WebSocket reconnecting: ' + this.endpoint + '...');
325344
try {
326345
reconnect();
@@ -807,7 +826,7 @@ let api = function Binance() {
807826
* @param {float} float - get the price precision point
808827
* @return {int} - number of place
809828
*/
810-
getPrecision: function (float) { //
829+
getPrecision: function (float) {
811830
return float.toString().split('.')[1].length || 0;
812831
},
813832

@@ -818,8 +837,12 @@ let api = function Binance() {
818837
* @return {float} - number
819838
*/
820839
roundStep: function (qty, stepSize) {
821-
const precision = stepSize.toString().split('.')[1].length || 0;
822-
return ((Math.floor(qty / stepSize) | 0) * stepSize).toFixed(precision);
840+
// Integers do not require rounding
841+
if (Number.isInteger(qty)) return qty;
842+
const qtyString = qty.toFixed(16);
843+
const desiredDecimals = Math.max(stepSize.indexOf('1') - 1, 0);
844+
const decimalIndex = qtyString.indexOf('.');
845+
return parseFloat(qtyString.slice(0, decimalIndex + desiredDecimals + 1));
823846
},
824847

825848
/**
@@ -831,7 +854,7 @@ let api = function Binance() {
831854
roundTicks: function (price, tickSize) {
832855
const formatter = new Intl.NumberFormat('en-US', { style: 'decimal', minimumFractionDigits: 0, maximumFractionDigits: 8 });
833856
const precision = formatter.format(tickSize).split('.')[1].length || 0;
834-
if ( typeof price === 'string' ) price = parseFloat(price);
857+
if (typeof price === 'string') price = parseFloat(price);
835858
return price.toFixed(precision);
836859
},
837860

@@ -1127,7 +1150,7 @@ let api = function Binance() {
11271150
},
11281151

11291152
/**
1130-
* Cancels an order
1153+
* Gets the status of an order
11311154
* @param {string} symbol - the symbol to check
11321155
* @param {string} orderid - the orderid to check
11331156
* @param {function} callback - the callback function
@@ -1188,7 +1211,7 @@ let api = function Binance() {
11881211
if (callback) return callback.call(this, error, data, symbol);
11891212
});
11901213
},
1191-
1214+
11921215
/**
11931216
* Gets the depth information for a given symbol
11941217
* @param {string} symbol - the symbol
@@ -1238,19 +1261,6 @@ let api = function Binance() {
12381261
});
12391262
},
12401263

1241-
/**
1242-
* Gets the depth information for a given symbol
1243-
* @param {string} symbol - the symbol
1244-
* @param {function} callback - the callback function
1245-
* @param {int} limit - limit the number of returned orders
1246-
* @return {undefined}
1247-
*/
1248-
depth: function (symbol, callback, limit = 100) {
1249-
publicRequest(base + 'v1/depth', { symbol: symbol, limit: limit }, function (error, data) {
1250-
return callback.call(this, error, depthData(data), symbol);
1251-
});
1252-
},
1253-
12541264
/**
12551265
* Gets the prices of a given symbol(s)
12561266
* @param {string} symbol - the symbol
@@ -1427,7 +1437,7 @@ let api = function Binance() {
14271437
* @return {undefined}
14281438
*/
14291439
tradeFee: function (callback, symbol = false) {
1430-
let params = symbol ? {symbol:symbol} : {};
1440+
let params = symbol ? { symbol: symbol } : {};
14311441
signedRequest(wapi + 'v3/tradeFee.html', params, callback);
14321442
},
14331443

@@ -1844,7 +1854,7 @@ let api = function Binance() {
18441854
* @param {int} stagger - ms between each depth cache
18451855
* @return {Promise} the websocket endpoint
18461856
*/
1847-
depthCacheStaggered: function(symbols, callback, limit=100, stagger=200) {
1857+
depthCacheStaggered: function (symbols, callback, limit = 100, stagger = 200) {
18481858
if (!Array.isArray(symbols)) symbols = [symbols];
18491859
let chain = null;
18501860

0 commit comments

Comments
 (0)