Skip to content

Commit 4607154

Browse files
committed
(feature) add errors in case of missing filters in chan sub handlers, closes #432
1 parent 35a9057 commit 4607154

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/ws2_manager.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ module.exports = class WS2Manager extends EventEmitter {
334334
*/
335335
onCandle ({ key, cbGID }, cb) {
336336
const s = this.getSocketWithDataChannel('candles', { key })
337+
338+
if (!s) {
339+
throw new Error('no data socket available; did you provide a key?')
340+
}
341+
337342
s.ws.onCandle({ key, cbGID }, cb)
338343
}
339344

@@ -354,6 +359,11 @@ module.exports = class WS2Manager extends EventEmitter {
354359
if (len) filter.len = len
355360

356361
const s = this.getSocketWithDataChannel('book', filter)
362+
363+
if (!s) {
364+
throw new Error('no data socket available; did you provide a symbol?')
365+
}
366+
357367
s.ws.onOrderBook({ cbGID, ...filter }, cb)
358368
}
359369

@@ -366,6 +376,11 @@ module.exports = class WS2Manager extends EventEmitter {
366376
*/
367377
onTrades ({ symbol, cbGID }, cb) {
368378
const s = this.getSocketWithDataChannel('trades', { symbol })
379+
380+
if (!s) {
381+
throw new Error('no data socket available; did you provide a symbol?')
382+
}
383+
369384
s.ws.onTrades({ symbol, cbGID }, cb)
370385
}
371386

@@ -378,6 +393,11 @@ module.exports = class WS2Manager extends EventEmitter {
378393
*/
379394
onTicker ({ symbol = '', cbGID } = {}, cb) {
380395
const s = this.getSocketWithDataChannel('ticker', { symbol })
396+
397+
if (!s) {
398+
throw new Error('no data socket available; did you provide a symbol?')
399+
}
400+
381401
s.ws.onTicker({ symbol, cbGID }, cb)
382402
}
383403
}

0 commit comments

Comments
 (0)