Skip to content

Commit 46af211

Browse files
committed
(fix) eventName resolution in trades handler
1 parent 1b1c1f3 commit 46af211

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/transports/ws2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ class WSv2 extends EventEmitter {
682682
* @private
683683
*/
684684
_handleTradeMessage (msg, chanData) {
685-
const eventName = msg.length === 3 ? msg[1] : 'trades'
685+
const eventName = _isString(msg[1]) ? msg[1] : 'trades'
686686
let payload = getMessagePayload(msg)
687687

688688
if (!Array.isArray(payload[0])) {

test/lib/transports/ws2-unit.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,3 +1539,25 @@ describe('WSv2 seq audit: _validateMessageSeq', () => {
15391539
assert.equal(ws._validateMessageSeq([0, 'n', nSuccess, 5, 4]), null)
15401540
})
15411541
})
1542+
1543+
describe('_handleTradeMessage', () => {
1544+
it('correctly forwards payloads w/ seq numbers', (done) => {
1545+
const ws = new WSv2()
1546+
const payload = [
1547+
[286614318, 1535531325604, 0.05, 7073.51178714],
1548+
[286614249, 1535531321436, 0.0215938, 7073.6],
1549+
[286614248, 1535531321430, 0.0284062, 7073.51178714]
1550+
]
1551+
const msg = [1710, payload, 1]
1552+
1553+
ws.onTrades({ pair: 'tBTCUSD' }, (data) => {
1554+
assert.deepStrictEqual(data, payload)
1555+
done()
1556+
})
1557+
1558+
ws._handleTradeMessage(msg, {
1559+
channel: 'trades',
1560+
pair: 'tBTCUSD'
1561+
})
1562+
})
1563+
})

0 commit comments

Comments
 (0)