Allow to unsubscribe from ws topic
This commit is contained in:
@@ -37,6 +37,10 @@ to the server once connection has been lost.
|
|||||||
- `topics` {String|Array} Single topic as string or multiple topics as array of strings.
|
- `topics` {String|Array} Single topic as string or multiple topics as array of strings.
|
||||||
Subscribe to one or multiple topics. See [available topics](#available-topics)
|
Subscribe to one or multiple topics. See [available topics](#available-topics)
|
||||||
|
|
||||||
|
### ws.unsubscribe(topics)
|
||||||
|
|
||||||
|
- `topics` {String|Array} Single topic as string or multiple topics as array of strings.
|
||||||
|
Unsubscribe from one or multiple topics.
|
||||||
|
|
||||||
### ws.close()
|
### ws.close()
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,17 @@ module.exports = class WebsocketClient extends EventEmitter {
|
|||||||
this.ws.send(msgStr);
|
this.ws.send(msgStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsubscribe(topics) {
|
||||||
|
if(!Array.isArray(topics)) topics = [topics];
|
||||||
|
|
||||||
|
const msgStr = JSON.stringify({
|
||||||
|
op: 'unsubscribe',
|
||||||
|
'args': topics
|
||||||
|
});
|
||||||
|
|
||||||
|
this.ws.send(msgStr);
|
||||||
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
this.logger.info('Closing connection', {category: 'bybit-ws'});
|
this.logger.info('Closing connection', {category: 'bybit-ws'});
|
||||||
this.readyState = READY_STATE_CLOSING;
|
this.readyState = READY_STATE_CLOSING;
|
||||||
|
|||||||
Reference in New Issue
Block a user