## Manager WSv2 connection pool manager. Limits active channel subscriptions per socket, opening new sockets/closing existing one as needed. **Kind**: global class * [Manager](#Manager) * [new Manager(args)](#new_Manager_new) * [.hasPlugin(plugin)](#Manager+hasPlugin) ⇒ boolean * [.addPlugin(plugin)](#Manager+addPlugin) * [.auth(args)](#Manager+auth) * [.getWS(id)](#Manager+getWS) ⇒ Object * [.getWSIndex(id)](#Manager+getWSIndex) ⇒ number * [.getWSByIndex(index)](#Manager+getWSByIndex) ⇒ Object * [.updateWS(id, state)](#Manager+updateWS) * [.closeAllSockets()](#Manager+closeAllSockets) * [.reconnectAllSockets()](#Manager+reconnectAllSockets) * [.closeWS(id)](#Manager+closeWS) * [.openWS()](#Manager+openWS) ⇒ Object * [.onWS(eventName, filterValue, cb)](#Manager+onWS) * [.onceWS(eventName, filterValue, cb)](#Manager+onceWS) * [.notifyPlugins(type, section, name, args)](#Manager+notifyPlugins) * [.withFreeDataSocket(cb)](#Manager+withFreeDataSocket) * [.withDataSocket(filterCb, cb)](#Manager+withDataSocket) * [.withAuthSocket(cb)](#Manager+withAuthSocket) * [.withSocket(cb)](#Manager+withSocket) * [.sampleWS()](#Manager+sampleWS) ⇒ Object * [.sampleWSI()](#Manager+sampleWSI) ⇒ number * [.applyWS(index, cb)](#Manager+applyWS) ### new Manager(args) | Param | Type | Description | | --- | --- | --- | | args | Object | | | args.wsURL | string | defaults to production Bitfinex WSv2 API url | | args.agent | Object | connection agent | | args.apiKey | string | used to authenticate sockets | | args.apiSecret | string | used to authenticate sockets | | args.authToken | string | used to authenticate sockets; has priority over API key/secret | | args.autoResubscribe | boolean | default true | | args.channelsPerSocket | number | defaults to 30 | | args.dms | number | dead-man-switch flag sent on auth, active 4 | | args.calc | number | | | args.transform | boolean | if true, raw API data arrays will be automatically converted to bfx-api-node-models instances | | args.plugins | Object | optional set of plugins to use | | args.channelFilters | Array.<string> | During authentication you can provide an array to indicate which information/messages you are interested to receive (default = everything). | ### manager.hasPlugin(plugin) ⇒ boolean **Kind**: instance method of [Manager](#Manager) **Returns**: boolean - hasPlugin | Param | Type | | --- | --- | | plugin | Object | ### manager.addPlugin(plugin) No-op if the plugin is already registered **Kind**: instance method of [Manager](#Manager) | Param | Type | | --- | --- | | plugin | Object | ### manager.auth(args) Authenticates all open API connections **Kind**: instance method of [Manager](#Manager) | Param | Type | Description | | --- | --- | --- | | args | Object | optional, defaults to values provided to constructor | | args.apiKey | string | | | args.apiSecret | string | | | args.authToken | string | | | args.dms | number | dead man switch, active 4 | | args.calc | number | | | args.forceAuth | boolean | | ### manager.getWS(id) ⇒ Object Returns a connection state object by ID **Kind**: instance method of [Manager](#Manager) **Returns**: Object - state - connection state | Param | Type | Description | | --- | --- | --- | | id | number | connection ID | ### manager.getWSIndex(id) ⇒ number Returns the index of a connection within the internal pool by ID **Kind**: instance method of [Manager](#Manager) **Returns**: number - index - within internal pool | Param | Type | Description | | --- | --- | --- | | id | number | connection ID | ### manager.getWSByIndex(index) ⇒ Object Returns a connection state object by pool index **Kind**: instance method of [Manager](#Manager) **Returns**: Object - state - connection state | Param | Type | Description | | --- | --- | --- | | index | number | within internal pool | ### manager.updateWS(id, state) Updates an internal connection by ID, emitting the socket:updated event if the connection exists. **Kind**: instance method of [Manager](#Manager) | Param | Type | Description | | --- | --- | --- | | id | number | | | state | Object | new connection state | ### manager.closeAllSockets() Closes all connections in the pool **Kind**: instance method of [Manager](#Manager) ### manager.reconnectAllSockets() Closes and re-opens all connections in the pool **Kind**: instance method of [Manager](#Manager) ### manager.closeWS(id) Closes a connection by ID, no-op if the connection is not found. **Kind**: instance method of [Manager](#Manager) | Param | Type | | --- | --- | | id | number | ### manager.openWS() ⇒ Object Creates & opens a new WSv2 connection, adds it to the pool, and returns it **Kind**: instance method of [Manager](#Manager) **Returns**: Object - connection ### manager.onWS(eventName, filterValue, cb) Creates an event handler that updates the relevant internal socket state object. **Kind**: instance method of [Manager](#Manager) | Param | Type | Description | | --- | --- | --- | | eventName | string | | | filterValue | Object | value(s) to check for | | cb | function | | ### manager.onceWS(eventName, filterValue, cb) Creates an event handler that updates the relevant internal socket state object, and only fires once **Kind**: instance method of [Manager](#Manager) | Param | Type | Description | | --- | --- | --- | | eventName | string | | | filterValue | Object | value(s) to check for | | cb | function | | ### manager.notifyPlugins(type, section, name, args) Calls every matching plugin with the provided arguments, and updates the relevant ws/rest state objects internally. State objects are only updated if plugin handlers return valid objects **Kind**: instance method of [Manager](#Manager) | Param | Type | Description | | --- | --- | --- | | type | string | ws2 or rest2 | | section | string | event section | | name | string | event name | | args | Object | plugin handler arguments | ### manager.withFreeDataSocket(cb) Calls the provided function with a connection instance that can subscribe to at least 1 more data channel. If no such connection is found, a new one is opened. **Kind**: instance method of [Manager](#Manager) | Param | Type | | --- | --- | | cb | function | ### manager.withDataSocket(filterCb, cb) Calls the provided function with a connection instance that is subscribed to a channel matching the provided filter callback, which is called with each subscribed channel descriptor. **Kind**: instance method of [Manager](#Manager) | Param | Type | | --- | --- | | filterCb | function | | cb | function | ### manager.withAuthSocket(cb) Calls the provided function with an authenticated socket instance; updates the socket state with the returned result. **Kind**: instance method of [Manager](#Manager) | Param | Type | | --- | --- | | cb | function | ### manager.withSocket(cb) Calls the provided function with a random open connection instance. If none exists, this is a no-op. **Kind**: instance method of [Manager](#Manager) | Param | Type | | --- | --- | | cb | function | ### manager.sampleWS() ⇒ Object Returns a random connection from the pool **Kind**: instance method of [Manager](#Manager) **Returns**: Object - state ### manager.sampleWSI() ⇒ number Returns a random connection index from the pool **Kind**: instance method of [Manager](#Manager) **Returns**: number - index ### manager.applyWS(index, cb) Calls the provided callback with the connection at the specified pool index, and saves the return value as the new connection instance. **Kind**: instance method of [Manager](#Manager) | Param | Type | | --- | --- | | index | number | | cb | function |