Skip to content

Commit a54b360

Browse files
committed
refacto: dispatchRawTrades
Removed exchange id argument as same info could be extracted from the trade object
1 parent 3316b45 commit a54b360

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/server.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,10 @@ class Server extends EventEmitter {
249249
this.dispatchAggregateTrade.bind(this, exchange.id)
250250
)
251251
} else {
252-
exchange.on('trades', this.dispatchRawTrades.bind(this, exchange.id))
252+
exchange.on('trades', this.dispatchRawTrades.bind(this))
253253
}
254254

255-
exchange.on(
256-
'liquidations',
257-
this.dispatchRawTrades.bind(this, exchange.id)
258-
)
255+
exchange.on('liquidations', this.dispatchRawTrades.bind(this))
259256

260257
exchange.on('disconnected', (pair, apiId, apiLength) => {
261258
const id = exchange.id + ':' + pair
@@ -991,12 +988,16 @@ class Server extends EventEmitter {
991988
})
992989
}
993990

994-
dispatchRawTrades(exchange, data) {
995-
for (let i = 0; i < data.length; i++) {
996-
const trade = data[i]
991+
/**
992+
* @param {Trade[]} trades
993+
*/
994+
995+
dispatchRawTrades(trades) {
996+
for (let i = 0; i < trades.length; i++) {
997+
const trade = trades[i]
997998

998999
if (!trade.liquidation) {
999-
const identifier = exchange + ':' + trade.pair
1000+
const identifier = trade.exchange + ':' + trade.pair
10001001

10011002
// ping connection
10021003
connections[identifier].hit++
@@ -1011,9 +1012,9 @@ class Server extends EventEmitter {
10111012

10121013
if (config.broadcast) {
10131014
if (!config.broadcastAggr && !config.broadcastDebounce) {
1014-
this.broadcastTrades(data)
1015+
this.broadcastTrades(trades)
10151016
} else {
1016-
Array.prototype.push.apply(this.delayedForBroadcast, data)
1017+
Array.prototype.push.apply(this.delayedForBroadcast, trades)
10171018
}
10181019
}
10191020
}

0 commit comments

Comments
 (0)