it('_handleConfigEvent: emits error if config failed', (done) => { ws = createTestWSv2Instance() ws.on('error', (err) => { if (_includes(err.message, '42')) done() }) ws._handleConfigEvent({ status: 'bad', flags: 42 }) })
/** * Check if the instance is subscribed to the specified channel ID * * @param {number} chanId - ID of channel to query * @returns {boolean} isSubscribed */ hasChannel (chanId) { return _includes(Object.keys(this._channelMap), chanId) }
/** * NOTE: Cannot filter against pending subscriptions, due to unknown chanId * * @param {number} chanId - channel ID * @returns {object} wsState - undefined if not found */ getSocketWithChannel (chanId) { return this._sockets.find(s => { return ( s.ws.hasChannel(chanId) && !_includes(s.pendingUnsubscriptions, chanId) ) }) }
/** * Get the total number of data channels this instance is currently * subscribed too. * * @returns {number} count * @see WSv2#subscribeTrades * @see WSv2#subscribeTicker * @see WSv2#subscribeCandles * @see WSv2#subscribeOrderBook */ getDataChannelCount () { return Object .values(this._channelMap) .filter(c => _includes(DATA_CHANNEL_TYPES, c.channel)) .length }
if (_includes(err.message, 'seq #')) errorsSeen++
/** * Returns the first socket that is subscribed/pending sub to the specified * channel. * * @param {string} type - i.e. 'book' * @param {object} filter - i.e. { symbol: 'tBTCUSD', prec: 'R0' } * @returns {object} wsState - undefined if not found */ getSocketWithDataChannel (type, filter) { return this._sockets.find(s => { const subI = s.pendingSubscriptions.findIndex(s => ( s[0] === type && _isEqual(s[1], filter) )) if (subI !== -1) { return true } // Confirm unsub is not pending const cid = s.ws.getDataChannelId(type, filter) if (!cid) { return false } return cid && !_includes(s.pendingUnsubscriptions, cid) }) }