diff --git a/ts/src/pro/bybit.ts b/ts/src/pro/bybit.ts index d179b7e4ab692..347627e08d06b 100644 --- a/ts/src/pro/bybit.ts +++ b/ts/src/pro/bybit.ts @@ -1,4 +1,3 @@ - // --------------------------------------------------------------------------- import bybitRest from '../bybit.js'; @@ -1581,6 +1580,32 @@ export default class bybit extends bybitRest { client.resolve (newPositions, 'positions'); } + /** + * @method + * @name bybit#unwatchPositions + * @description unWatches all open positions + * @see https://bybit-exchange.github.io/docs/v5/websocket/private/position + * @param {string[]} [symbols] list of unified market symbols + * @param {object} [params] extra parameters specific to the exchange API endpoint + * @returns {object} status of the unwatch request + */ + async unwatchPositions (symbols: Strings = undefined, params = {}): Promise { + await this.loadMarkets (); + const method = 'watchPositions'; + let messageHash = 'unsubscribe:positions'; + let subHash = 'positions'; + if (!this.isEmpty (symbols)) { + symbols = this.marketSymbols (symbols); + messageHash += '::' + symbols.join (','); + subHash += '::' + symbols.join (','); + } + const firstSymbol = this.safeString (symbols, 0); + const url = await this.getUrlByMarketType (firstSymbol, true, method, params); + await this.authenticate (url); + const topics = [ 'position' ]; + return await this.unWatchTopics (url, 'positions', symbols, [ messageHash ], [ subHash ], topics, params); + } + /** * @method * @name bybit#watchLiquidations @@ -2658,4 +2683,5 @@ export default class bybit extends bybitRest { } return message; } + } diff --git a/ts/src/test/tests.ts b/ts/src/test/tests.ts index 7b9b115c2d239..76cbc2dcc6d21 100644 --- a/ts/src/test/tests.ts +++ b/ts/src/test/tests.ts @@ -814,6 +814,7 @@ class testMainClass { 'watchOrders': [ symbol ], 'watchPosition': [ symbol ], 'watchPositions': [ symbol ], + 'unwatchPositions': [ symbol ], }; } const market = exchange.market (symbol);