Skip to content

Commit

Permalink
Added websocket reconnect to trades function
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Eyrick authored Dec 27, 2017
1 parent 641e80b commit b33d31d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions node-binance-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,15 @@ module.exports = function() {
};
const depthData = function(data) { // Used for /depth endpoint
let bids = {}, asks = {}, obj;
for ( obj of data.bids ) {
bids[obj[0]] = parseFloat(obj[1]);
if ( typeof data.bids !== "undefined" ) {
for ( obj of data.bids ) {
bids[obj[0]] = parseFloat(obj[1]);
}
}
for ( obj of data.asks ) {
asks[obj[0]] = parseFloat(obj[1]);
if ( typeof data.asks !== "undefined" ) {
for ( obj of data.asks ) {
asks[obj[0]] = parseFloat(obj[1]);
}
}
return {bids:bids, asks:asks};
}
Expand Down Expand Up @@ -606,7 +610,10 @@ module.exports = function() {
},
trades: function(symbols, callback) {
for ( let symbol of symbols ) {
subscribe(symbol.toLowerCase()+"@aggTrade", callback);
let reconnect = function() {
if ( options.reconnect ) subscribe(symbol.toLowerCase()+"@aggTrade", callback, reconnect);
};
subscribe(symbol.toLowerCase()+"@aggTrade", callback, reconnect);
}
},
chart: function chart(symbols, interval, callback) {
Expand Down

0 comments on commit b33d31d

Please sign in to comment.