Skip to content

Commit

Permalink
(BREAKING) Singleton VS New Object. Thanks usama33!
Browse files Browse the repository at this point in the history
⚠ Breaking Changes: ⚠

🔧 Singleton VS New Object: (Thanks usama33!)
	The API is now instantiated like this:
```js
const binance = new Binance().options({
	APIKEY: "",
	APISECRET: "",
	useServerTime: true
});
```

or this:

```js
const Binance = require('node-binance-api');
const binance = new Binance().options("options.json");
```

🔧 default recvWindow changed to 5000 as recommended by Binance

🔧 lastEventUpdateTime added to the response of depthCache callback, as third parameter. Thanks yanislk!
  • Loading branch information
Jon Eyrick authored Jun 9, 2018
1 parent b068e53 commit 57706f6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions node-binance-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* Node Binance Api
* @module jaggedsoft/node-binance-api
*/
module.exports = function() {
function Binance() {
if (!(this instanceof Binance)) { return new Binance(); }
'use strict';
const WebSocket = require('ws');
const request = require('request');
Expand All @@ -34,7 +35,7 @@ module.exports = function() {
let klineQueue = {};
let ohlc = {};
const default_options = {
recvWindow: 60000, // to be lowered to 5000 in v0.5
recvWindow: 5000,
useServerTime: false,
reconnect: true,
verbose: false,
Expand Down Expand Up @@ -703,6 +704,7 @@ module.exports = function() {
}
context.skipCount = 0;
context.lastEventUpdateId = depth.u;
context.lastEventUpdateTime = depth.E;
}

// This now conforms 100% to the Binance docs constraints on managing a local order book
Expand Down Expand Up @@ -1012,6 +1014,7 @@ module.exports = function() {
if ( callback ) callback();
});
} else if ( callback ) callback();
return this;
},

/**
Expand Down Expand Up @@ -1656,7 +1659,7 @@ module.exports = function() {
} catch (err) {
return terminate(context.endpointId, true);
}
if ( callback ) callback(symbol, depthCache[symbol]);
if ( callback ) callback(symbol, depthCache[symbol], context);
}
};

Expand Down Expand Up @@ -1920,5 +1923,6 @@ module.exports = function() {
}
}
};
}();
};
module.exports = Binance;
//https://github.com/binance-exchange/binance-official-api-docs

0 comments on commit 57706f6

Please sign in to comment.