ccxt 4.3.87 → 4.3.89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/ace.js +1 -0
  5. package/dist/cjs/src/alpaca.js +1 -0
  6. package/dist/cjs/src/ascendex.js +7 -19
  7. package/dist/cjs/src/base/Exchange.js +2 -2
  8. package/dist/cjs/src/bigone.js +1 -0
  9. package/dist/cjs/src/bingx.js +1 -0
  10. package/dist/cjs/src/bit2c.js +1 -0
  11. package/dist/cjs/src/bitbank.js +1 -0
  12. package/dist/cjs/src/bitfinex.js +1 -0
  13. package/dist/cjs/src/bitflyer.js +1 -0
  14. package/dist/cjs/src/bitget.js +1 -0
  15. package/dist/cjs/src/bitmex.js +1 -0
  16. package/dist/cjs/src/bitopro.js +1 -0
  17. package/dist/cjs/src/bitrue.js +62 -71
  18. package/dist/cjs/src/bitso.js +1 -0
  19. package/dist/cjs/src/bitstamp.js +1 -0
  20. package/dist/cjs/src/bitvavo.js +1 -0
  21. package/dist/cjs/src/blockchaincom.js +1 -0
  22. package/dist/cjs/src/btcalpha.js +1 -0
  23. package/dist/cjs/src/btcbox.js +1 -0
  24. package/dist/cjs/src/btcmarkets.js +1 -0
  25. package/dist/cjs/src/bybit.js +2 -0
  26. package/dist/cjs/src/cex.js +1 -0
  27. package/dist/cjs/src/coinbaseexchange.js +1 -0
  28. package/dist/cjs/src/cryptocom.js +0 -12
  29. package/dist/cjs/src/kraken.js +48 -48
  30. package/dist/cjs/src/kucoin.js +2 -0
  31. package/dist/cjs/src/mexc.js +1 -61
  32. package/dist/cjs/src/okcoin.js +4 -9
  33. package/dist/cjs/src/onetrading.js +1 -0
  34. package/dist/cjs/src/phemex.js +1 -0
  35. package/dist/cjs/src/poloniexfutures.js +1 -0
  36. package/dist/cjs/src/pro/bitfinex.js +1 -0
  37. package/dist/cjs/src/pro/bitfinex2.js +1 -0
  38. package/dist/cjs/src/pro/bitopro.js +1 -0
  39. package/dist/cjs/src/pro/bitstamp.js +1 -0
  40. package/dist/cjs/src/pro/bitvavo.js +1 -0
  41. package/dist/cjs/src/pro/blockchaincom.js +1 -0
  42. package/dist/cjs/src/pro/bybit.js +290 -1
  43. package/dist/cjs/src/pro/cex.js +2 -0
  44. package/dist/cjs/src/pro/coincheck.js +1 -0
  45. package/dist/cjs/src/pro/coinone.js +1 -0
  46. package/dist/cjs/src/pro/hashkey.js +1 -0
  47. package/dist/cjs/src/pro/hitbtc.js +1 -0
  48. package/dist/cjs/src/pro/hollaex.js +1 -0
  49. package/dist/cjs/src/pro/htx.js +1 -0
  50. package/dist/cjs/src/pro/huobijp.js +1 -0
  51. package/dist/cjs/src/pro/hyperliquid.js +7 -0
  52. package/dist/cjs/src/pro/independentreserve.js +1 -0
  53. package/dist/cjs/src/pro/lbank.js +1 -0
  54. package/dist/cjs/src/pro/luno.js +1 -0
  55. package/dist/cjs/src/pro/ndax.js +5 -0
  56. package/dist/cjs/src/pro/okcoin.js +7 -0
  57. package/dist/cjs/src/pro/onetrading.js +1 -0
  58. package/dist/cjs/src/pro/paradex.js +1 -0
  59. package/dist/cjs/src/probit.js +1 -0
  60. package/dist/cjs/src/vertex.js +1 -0
  61. package/dist/cjs/src/woo.js +1 -0
  62. package/dist/cjs/src/woofipro.js +1 -0
  63. package/js/ccxt.d.ts +1 -1
  64. package/js/ccxt.js +1 -1
  65. package/js/src/abstract/kucoin.d.ts +1 -0
  66. package/js/src/abstract/kucoinfutures.d.ts +1 -0
  67. package/js/src/ace.js +1 -0
  68. package/js/src/alpaca.js +1 -0
  69. package/js/src/ascendex.d.ts +0 -1
  70. package/js/src/ascendex.js +7 -19
  71. package/js/src/base/Exchange.d.ts +1 -1
  72. package/js/src/base/Exchange.js +2 -2
  73. package/js/src/bigone.js +1 -0
  74. package/js/src/bingx.js +1 -0
  75. package/js/src/bit2c.js +1 -0
  76. package/js/src/bitbank.js +1 -0
  77. package/js/src/bitfinex.js +1 -0
  78. package/js/src/bitflyer.js +1 -0
  79. package/js/src/bitget.js +1 -0
  80. package/js/src/bitmex.js +1 -0
  81. package/js/src/bitopro.js +1 -0
  82. package/js/src/bitrue.d.ts +0 -1
  83. package/js/src/bitrue.js +62 -71
  84. package/js/src/bitso.js +1 -0
  85. package/js/src/bitstamp.js +1 -0
  86. package/js/src/bitvavo.js +1 -0
  87. package/js/src/blockchaincom.js +1 -0
  88. package/js/src/btcalpha.js +1 -0
  89. package/js/src/btcbox.js +1 -0
  90. package/js/src/btcmarkets.js +1 -0
  91. package/js/src/bybit.js +2 -0
  92. package/js/src/cex.js +1 -0
  93. package/js/src/coinbaseexchange.js +1 -0
  94. package/js/src/coinex.d.ts +1 -1
  95. package/js/src/cryptocom.d.ts +0 -1
  96. package/js/src/cryptocom.js +0 -12
  97. package/js/src/kraken.js +48 -48
  98. package/js/src/kucoin.js +2 -0
  99. package/js/src/mexc.js +1 -61
  100. package/js/src/okcoin.d.ts +0 -1
  101. package/js/src/okcoin.js +4 -9
  102. package/js/src/onetrading.js +1 -0
  103. package/js/src/phemex.js +1 -0
  104. package/js/src/poloniexfutures.js +1 -0
  105. package/js/src/pro/bitfinex.js +1 -0
  106. package/js/src/pro/bitfinex2.js +1 -0
  107. package/js/src/pro/bitopro.js +1 -0
  108. package/js/src/pro/bitstamp.js +1 -0
  109. package/js/src/pro/bitvavo.js +1 -0
  110. package/js/src/pro/blockchaincom.js +1 -0
  111. package/js/src/pro/bybit.d.ts +12 -1
  112. package/js/src/pro/bybit.js +291 -2
  113. package/js/src/pro/cex.js +2 -0
  114. package/js/src/pro/coincheck.js +1 -0
  115. package/js/src/pro/coinone.js +1 -0
  116. package/js/src/pro/hashkey.js +1 -0
  117. package/js/src/pro/hitbtc.js +1 -0
  118. package/js/src/pro/hollaex.js +1 -0
  119. package/js/src/pro/htx.js +1 -0
  120. package/js/src/pro/huobijp.js +1 -0
  121. package/js/src/pro/hyperliquid.js +7 -0
  122. package/js/src/pro/independentreserve.js +1 -0
  123. package/js/src/pro/lbank.js +1 -0
  124. package/js/src/pro/luno.js +1 -0
  125. package/js/src/pro/ndax.js +5 -0
  126. package/js/src/pro/okcoin.js +7 -0
  127. package/js/src/pro/onetrading.js +1 -0
  128. package/js/src/pro/paradex.js +1 -0
  129. package/js/src/probit.js +1 -0
  130. package/js/src/vertex.js +1 -0
  131. package/js/src/woo.js +1 -0
  132. package/js/src/woofipro.js +1 -0
  133. package/package.json +1 -1
@@ -23,6 +23,7 @@ export default class bitopro extends bitoproRest {
23
23
  'watchTicker': true,
24
24
  'watchTickers': false,
25
25
  'watchTrades': true,
26
+ 'watchTradesForSymbols': false,
26
27
  },
27
28
  'urls': {
28
29
  'ws': {
@@ -17,6 +17,7 @@ export default class bitstamp extends bitstampRest {
17
17
  'watchOrderBook': true,
18
18
  'watchOrders': true,
19
19
  'watchTrades': true,
20
+ 'watchTradesForSymbols': false,
20
21
  'watchOHLCV': false,
21
22
  'watchTicker': false,
22
23
  'watchTickers': false,
@@ -642,6 +642,7 @@ export default class bitvavo extends bitvavoRest {
642
642
  * @name bitvavo#fetchOrderWs
643
643
  * @see https://docs.bitvavo.com/#tag/General/paths/~1assets/get
644
644
  * @description fetches information on an order made by the user
645
+ * @param {string} id the order id
645
646
  * @param {string} symbol unified symbol of the market the order was made in
646
647
  * @param {object} [params] extra parameters specific to the bitvavo api endpoint
647
648
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -18,6 +18,7 @@ export default class blockchaincom extends blockchaincomRest {
18
18
  'watchTicker': true,
19
19
  'watchTickers': false,
20
20
  'watchTrades': true,
21
+ 'watchTradesForSymbols': false,
21
22
  'watchMyTrades': false,
22
23
  'watchOrders': true,
23
24
  'watchOrderBook': true,
@@ -1,5 +1,5 @@
1
1
  import bybitRest from '../bybit.js';
2
- import type { Int, OHLCV, Str, Strings, Ticker, OrderBook, Order, Trade, Tickers, Position, Balances, OrderType, OrderSide, Num, Liquidation } from '../base/types.js';
2
+ import type { Int, OHLCV, Str, Strings, Ticker, OrderBook, Order, Trade, Tickers, Position, Balances, OrderType, OrderSide, Num, Dict, Liquidation } from '../base/types.js';
3
3
  import Client from '../base/ws/Client.js';
4
4
  export default class bybit extends bybitRest {
5
5
  describe(): any;
@@ -11,6 +11,8 @@ export default class bybit extends bybitRest {
11
11
  cancelOrderWs(id: string, symbol?: Str, params?: {}): Promise<Order>;
12
12
  watchTicker(symbol: string, params?: {}): Promise<Ticker>;
13
13
  watchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
14
+ unWatchTickers(symbols?: Strings, params?: {}): Promise<any>;
15
+ unWatchTicker(symbols: string, params?: {}): Promise<any>;
14
16
  handleTicker(client: Client, message: any): void;
15
17
  watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
16
18
  watchOHLCVForSymbols(symbolsAndTimeframes: string[][], since?: Int, limit?: Int, params?: {}): Promise<import("../base/types.js").Dictionary<import("../base/types.js").Dictionary<OHLCV[]>>>;
@@ -18,15 +20,20 @@ export default class bybit extends bybitRest {
18
20
  parseWsOHLCV(ohlcv: any, market?: any): OHLCV;
19
21
  watchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
20
22
  watchOrderBookForSymbols(symbols: string[], limit?: Int, params?: {}): Promise<OrderBook>;
23
+ unWatchOrderBookForSymbols(symbols: Strings, params?: {}): Promise<any>;
24
+ unWatchOrderBook(symbol: string, params?: {}): Promise<any>;
21
25
  handleOrderBook(client: Client, message: any): void;
22
26
  handleDelta(bookside: any, delta: any): void;
23
27
  handleDeltas(bookside: any, deltas: any): void;
24
28
  watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
25
29
  watchTradesForSymbols(symbols: string[], since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
30
+ unWatchTradesForSymbols(symbols: Strings, params?: {}): Promise<any>;
31
+ unWatchTrades(symbol: string, params?: {}): Promise<any>;
26
32
  handleTrades(client: Client, message: any): void;
27
33
  parseWsTrade(trade: any, market?: any): Trade;
28
34
  getPrivateType(url: any): "spot" | "unified" | "usdc";
29
35
  watchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
36
+ unWatchMyTrades(symbol?: Str, params?: {}): Promise<any>;
30
37
  handleMyTrades(client: Client, message: any): void;
31
38
  watchPositions(symbols?: Strings, since?: Int, limit?: Int, params?: {}): Promise<Position[]>;
32
39
  setPositionsCache(client: Client, symbols?: Strings): void;
@@ -36,6 +43,7 @@ export default class bybit extends bybitRest {
36
43
  handleLiquidation(client: Client, message: any): void;
37
44
  parseWsLiquidation(liquidation: any, market?: any): Liquidation;
38
45
  watchOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
46
+ unWatchOrders(symbol?: Str, params?: {}): Promise<any>;
39
47
  handleOrderWs(client: Client, message: any): void;
40
48
  handleOrder(client: Client, message: any): void;
41
49
  parseWsSpotOrder(order: any, market?: any): Order;
@@ -43,6 +51,7 @@ export default class bybit extends bybitRest {
43
51
  handleBalance(client: Client, message: any): void;
44
52
  parseWsBalance(balance: any, accountType?: any): void;
45
53
  watchTopics(url: any, messageHashes: any, topics: any, params?: {}): Promise<any>;
54
+ unWatchTopics(url: string, topic: string, symbols: string[], messageHashes: string[], subMessageHashes: string[], topics: any, params?: {}): Promise<any>;
46
55
  authenticate(url: any, params?: {}): Promise<any>;
47
56
  handleErrorMessage(client: Client, message: any): boolean;
48
57
  handleMessage(client: Client, message: any): void;
@@ -53,4 +62,6 @@ export default class bybit extends bybitRest {
53
62
  handlePong(client: Client, message: any): any;
54
63
  handleAuthenticate(client: Client, message: any): any;
55
64
  handleSubscriptionStatus(client: Client, message: any): any;
65
+ handleUnSubscribe(client: Client, message: any): any;
66
+ cleanCache(subscription: Dict): void;
56
67
  }
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import bybitRest from '../bybit.js';
9
- import { ArgumentsRequired, AuthenticationError, ExchangeError, BadRequest } from '../base/errors.js';
9
+ import { ArgumentsRequired, AuthenticationError, ExchangeError, BadRequest, UnsubscribeError } from '../base/errors.js';
10
10
  import { ArrayCache, ArrayCacheBySymbolById, ArrayCacheBySymbolBySide, ArrayCacheByTimestamp } from '../base/ws/Cache.js';
11
11
  import { sha256 } from '../static_dependencies/noble-hashes/sha256.js';
12
12
  // ---------------------------------------------------------------------------
@@ -393,6 +393,49 @@ export default class bybit extends bybitRest {
393
393
  }
394
394
  return this.filterByArray(this.tickers, 'symbol', symbols);
395
395
  }
396
+ async unWatchTickers(symbols = undefined, params = {}) {
397
+ /**
398
+ * @method
399
+ * @name bybit#unWatchTickers
400
+ * @description unWatches a price ticker
401
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/ticker
402
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/etp-ticker
403
+ * @param {string[]} symbols unified symbol of the market to fetch the ticker for
404
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
405
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
406
+ */
407
+ await this.loadMarkets();
408
+ symbols = this.marketSymbols(symbols, undefined, false);
409
+ const options = this.safeValue(this.options, 'watchTickers', {});
410
+ const topic = this.safeString(options, 'name', 'tickers');
411
+ const messageHashes = [];
412
+ const subMessageHashes = [];
413
+ const marketIds = this.marketIds(symbols);
414
+ const topics = [];
415
+ for (let i = 0; i < marketIds.length; i++) {
416
+ const marketId = marketIds[i];
417
+ const symbol = symbols[i];
418
+ topics.push(topic + '.' + marketId);
419
+ subMessageHashes.push('ticker:' + symbol);
420
+ messageHashes.push('unsubscribe:ticker:' + symbol);
421
+ }
422
+ const url = await this.getUrlByMarketType(symbols[0], false, 'watchTickers', params);
423
+ return await this.unWatchTopics(url, 'ticker', symbols, messageHashes, subMessageHashes, topics, params);
424
+ }
425
+ async unWatchTicker(symbols, params = {}) {
426
+ /**
427
+ * @method
428
+ * @name bybit#unWatchTicker
429
+ * @description unWatches a price ticker
430
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/ticker
431
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/etp-ticker
432
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
433
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
434
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
435
+ */
436
+ await this.loadMarkets();
437
+ return await this.unWatchTickers([symbols], params);
438
+ }
396
439
  handleTicker(client, message) {
397
440
  //
398
441
  // linear
@@ -726,6 +769,56 @@ export default class bybit extends bybitRest {
726
769
  const orderbook = await this.watchTopics(url, messageHashes, topics, params);
727
770
  return orderbook.limit();
728
771
  }
772
+ async unWatchOrderBookForSymbols(symbols, params = {}) {
773
+ /**
774
+ * @method
775
+ * @name bybit#unWatchOrderBookForSymbols
776
+ * @description unsubscribe from the orderbook channel
777
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/orderbook
778
+ * @param {string[]} symbols unified symbol of the market to unwatch the trades for
779
+ * @param {int} [params.limit] orderbook limit, default is undefined
780
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
781
+ */
782
+ await this.loadMarkets();
783
+ symbols = this.marketSymbols(symbols, undefined, false);
784
+ let channel = 'orderbook.';
785
+ let limit = this.safeInteger(params, 'limit');
786
+ if (limit !== undefined) {
787
+ params = this.omit(params, 'limit');
788
+ }
789
+ else {
790
+ const firstMarket = this.market(symbols[0]);
791
+ limit = firstMarket['spot'] ? 50 : 500;
792
+ }
793
+ channel += limit.toString();
794
+ const subMessageHashes = [];
795
+ const messageHashes = [];
796
+ const topics = [];
797
+ for (let i = 0; i < symbols.length; i++) {
798
+ const symbol = symbols[i];
799
+ const market = this.market(symbol);
800
+ const marketId = market['id'];
801
+ const topic = channel + '.' + marketId;
802
+ messageHashes.push('unsubscribe:orderbook:' + symbol);
803
+ subMessageHashes.push('orderbook:' + symbol);
804
+ topics.push(topic);
805
+ }
806
+ const url = await this.getUrlByMarketType(symbols[0], false, 'watchOrderBook', params);
807
+ return await this.unWatchTopics(url, 'orderbook', symbols, messageHashes, subMessageHashes, topics, params);
808
+ }
809
+ async unWatchOrderBook(symbol, params = {}) {
810
+ /**
811
+ * @method
812
+ * @name bybit#unWatchOrderBook
813
+ * @description unsubscribe from the orderbook channel
814
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/orderbook
815
+ * @param {string[]} symbols unified symbol of the market to unwatch the trades for
816
+ * @param {int} [params.limit] orderbook limit, default is undefined
817
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
818
+ */
819
+ await this.loadMarkets();
820
+ return await this.unWatchOrderBookForSymbols([symbol], params);
821
+ }
729
822
  handleOrderBook(client, message) {
730
823
  //
731
824
  // {
@@ -850,6 +943,44 @@ export default class bybit extends bybitRest {
850
943
  }
851
944
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
852
945
  }
946
+ async unWatchTradesForSymbols(symbols, params = {}) {
947
+ /**
948
+ * @method
949
+ * @name bybit#unWatchTradesForSymbols
950
+ * @description unsubscribe from the trades channel
951
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/trade
952
+ * @param {string[]} symbols unified symbol of the market to unwatch the trades for
953
+ * @returns {any} status of the unwatch request
954
+ */
955
+ await this.loadMarkets();
956
+ symbols = this.marketSymbols(symbols, undefined, false, true);
957
+ const url = await this.getUrlByMarketType(symbols[0], false, 'unWatchTradesForSymbols', params);
958
+ const messageHashes = [];
959
+ const topics = [];
960
+ const subMessageHashes = [];
961
+ for (let i = 0; i < symbols.length; i++) {
962
+ const symbol = symbols[i];
963
+ const market = this.market(symbol);
964
+ const topic = 'publicTrade.' + market['id'];
965
+ topics.push(topic);
966
+ const messageHash = 'unsubscribe:trade:' + symbol;
967
+ messageHashes.push(messageHash);
968
+ subMessageHashes.push('trade:' + symbol);
969
+ }
970
+ return await this.unWatchTopics(url, 'trade', symbols, messageHashes, subMessageHashes, topics, params);
971
+ }
972
+ async unWatchTrades(symbol, params = {}) {
973
+ /**
974
+ * @method
975
+ * @name bybit#unWatchTrades
976
+ * @description unsubscribe from the trades channel
977
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/trade
978
+ * @param {string} symbol unified symbol of the market to unwatch the trades for
979
+ * @returns {any} status of the unwatch request
980
+ */
981
+ await this.loadMarkets();
982
+ return await this.unWatchTradesForSymbols([symbol], params);
983
+ }
853
984
  handleTrades(client, message) {
854
985
  //
855
986
  // {
@@ -1008,6 +1139,35 @@ export default class bybit extends bybitRest {
1008
1139
  }
1009
1140
  return this.filterBySymbolSinceLimit(trades, symbol, since, limit, true);
1010
1141
  }
1142
+ async unWatchMyTrades(symbol = undefined, params = {}) {
1143
+ /**
1144
+ * @method
1145
+ * @name bybit#unWatchMyTrades
1146
+ * @description unWatches information on multiple trades made by the user
1147
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/private/execution
1148
+ * @param {string} symbol unified market symbol of the market orders were made in
1149
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1150
+ * @param {boolean} [params.unifiedMargin] use unified margin account
1151
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1152
+ */
1153
+ const method = 'watchMyTrades';
1154
+ const messageHash = 'unsubscribe:myTrades';
1155
+ let subHash = 'myTrades';
1156
+ await this.loadMarkets();
1157
+ if (symbol !== undefined) {
1158
+ symbol = this.symbol(symbol);
1159
+ subHash += ':' + symbol;
1160
+ }
1161
+ const url = await this.getUrlByMarketType(symbol, true, method, params);
1162
+ await this.authenticate(url);
1163
+ const topicByMarket = {
1164
+ 'spot': 'ticketInfo',
1165
+ 'unified': 'execution',
1166
+ 'usdc': 'user.openapi.perp.trade',
1167
+ };
1168
+ const topic = this.safeValue(topicByMarket, this.getPrivateType(url));
1169
+ return await this.unWatchTopics(url, 'myTrades', [], [messageHash], [subHash], [topic], params);
1170
+ }
1011
1171
  handleMyTrades(client, message) {
1012
1172
  //
1013
1173
  // spot
@@ -1372,6 +1532,35 @@ export default class bybit extends bybitRest {
1372
1532
  }
1373
1533
  return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
1374
1534
  }
1535
+ async unWatchOrders(symbol = undefined, params = {}) {
1536
+ /**
1537
+ * @method
1538
+ * @name bybit#unWatchOrders
1539
+ * @description unWatches information on multiple orders made by the user
1540
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/private/order
1541
+ * @param {string} symbol unified market symbol of the market orders were made in
1542
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1543
+ * @param {boolean} [params.unifiedMargin] use unified margin account
1544
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1545
+ */
1546
+ await this.loadMarkets();
1547
+ const method = 'watchOrders';
1548
+ const messageHash = 'unsubscribe:orders';
1549
+ let subHash = 'orders';
1550
+ if (symbol !== undefined) {
1551
+ symbol = this.symbol(symbol);
1552
+ subHash += ':' + symbol;
1553
+ }
1554
+ const url = await this.getUrlByMarketType(symbol, true, method, params);
1555
+ await this.authenticate(url);
1556
+ const topicsByMarket = {
1557
+ 'spot': ['order', 'stopOrder'],
1558
+ 'unified': ['order'],
1559
+ 'usdc': ['user.openapi.perp.order'],
1560
+ };
1561
+ const topics = this.safeValue(topicsByMarket, this.getPrivateType(url));
1562
+ return await this.unWatchTopics(url, 'orders', [], [messageHash], [subHash], topics, params);
1563
+ }
1375
1564
  handleOrderWs(client, message) {
1376
1565
  //
1377
1566
  // {
@@ -1954,7 +2143,24 @@ export default class bybit extends bybitRest {
1954
2143
  'args': topics,
1955
2144
  };
1956
2145
  const message = this.extend(request, params);
1957
- return await this.watchMultiple(url, messageHashes, message, topics);
2146
+ return await this.watchMultiple(url, messageHashes, message, messageHashes);
2147
+ }
2148
+ async unWatchTopics(url, topic, symbols, messageHashes, subMessageHashes, topics, params = {}) {
2149
+ const reqId = this.requestId();
2150
+ const request = {
2151
+ 'op': 'unsubscribe',
2152
+ 'req_id': reqId,
2153
+ 'args': topics,
2154
+ };
2155
+ const subscription = {
2156
+ 'id': reqId,
2157
+ 'topic': topic,
2158
+ 'messageHashes': messageHashes,
2159
+ 'subMessageHashes': subMessageHashes,
2160
+ 'symbols': symbols,
2161
+ };
2162
+ const message = this.extend(request, params);
2163
+ return await this.watchMultiple(url, messageHashes, message, messageHashes, subscription);
1958
2164
  }
1959
2165
  async authenticate(url, params = {}) {
1960
2166
  this.checkRequiredCredentials();
@@ -2105,6 +2311,7 @@ export default class bybit extends bybitRest {
2105
2311
  'order.amend': this.handleOrderWs,
2106
2312
  'order.cancel': this.handleOrderWs,
2107
2313
  'auth': this.handleAuthenticate,
2314
+ 'unsubscribe': this.handleUnSubscribe,
2108
2315
  };
2109
2316
  const exacMethod = this.safeValue(methods, topic);
2110
2317
  if (exacMethod !== undefined) {
@@ -2195,4 +2402,86 @@ export default class bybit extends bybitRest {
2195
2402
  //
2196
2403
  return message;
2197
2404
  }
2405
+ handleUnSubscribe(client, message) {
2406
+ //
2407
+ // {"success":true,"ret_msg":"","conn_id":"7188110e-6908-41e9-b863-6365127e92ad","req_id":"3","op":"unsubscribe"}
2408
+ //
2409
+ // client.subscription will be something like:
2410
+ // {
2411
+ // "publicTrade.LTCUSDT":true,
2412
+ // "publicTrade.ADAUSDT":true,
2413
+ // "unsubscribe:trade:LTC/USDT:USDT": {
2414
+ // "id":4,
2415
+ // "subHash": "trade:LTC/USDT"
2416
+ // },
2417
+ // }
2418
+ const reqId = this.safeString(message, 'req_id');
2419
+ const keys = Object.keys(client.subscriptions);
2420
+ for (let i = 0; i < keys.length; i++) {
2421
+ const messageHash = keys[i];
2422
+ if (!(messageHash in client.subscriptions)) {
2423
+ continue;
2424
+ // the previous iteration can have deleted the messageHash from the subscriptions
2425
+ }
2426
+ if (messageHash.startsWith('unsubscribe')) {
2427
+ const subscription = client.subscriptions[messageHash];
2428
+ const subId = this.safeString(subscription, 'id');
2429
+ if (reqId !== subId) {
2430
+ continue;
2431
+ }
2432
+ const messageHashes = this.safeList(subscription, 'messageHashes', []);
2433
+ const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
2434
+ for (let j = 0; j < messageHashes.length; j++) {
2435
+ const unsubHash = messageHashes[j];
2436
+ const subHash = subMessageHashes[j];
2437
+ if (unsubHash in client.subscriptions) {
2438
+ delete client.subscriptions[unsubHash];
2439
+ }
2440
+ if (subHash in client.subscriptions) {
2441
+ delete client.subscriptions[subHash];
2442
+ }
2443
+ const error = new UnsubscribeError(this.id + ' ' + messageHash);
2444
+ client.reject(error, subHash);
2445
+ client.resolve(true, unsubHash);
2446
+ this.cleanCache(subscription);
2447
+ }
2448
+ }
2449
+ }
2450
+ return message;
2451
+ }
2452
+ cleanCache(subscription) {
2453
+ const topic = this.safeString(subscription, 'topic');
2454
+ const symbols = this.safeList(subscription, 'symbols', []);
2455
+ const symbolsLength = symbols.length;
2456
+ if (symbolsLength > 0) {
2457
+ for (let i = 0; i < symbols.length; i++) {
2458
+ const symbol = symbols[i];
2459
+ if (topic === 'trade') {
2460
+ delete this.trades[symbol];
2461
+ }
2462
+ else if (topic === 'orderbook') {
2463
+ delete this.orderbooks[symbol];
2464
+ }
2465
+ else if (topic === 'ticker') {
2466
+ delete this.tickers[symbol];
2467
+ }
2468
+ }
2469
+ }
2470
+ else {
2471
+ if (topic === 'myTrades') {
2472
+ // don't reset this.myTrades directly here
2473
+ // because in c# we need to use a different object
2474
+ const keys = Object.keys(this.myTrades);
2475
+ for (let i = 0; i < keys.length; i++) {
2476
+ delete this.myTrades[keys[i]];
2477
+ }
2478
+ }
2479
+ else if (topic === 'orders') {
2480
+ const orderSymbols = Object.keys(this.orders);
2481
+ for (let i = 0; i < orderSymbols.length; i++) {
2482
+ delete this.orders[orderSymbols[i]];
2483
+ }
2484
+ }
2485
+ }
2486
+ }
2198
2487
  }
package/js/src/pro/cex.js CHANGED
@@ -20,6 +20,7 @@ export default class cex extends cexRest {
20
20
  'watchTicker': true,
21
21
  'watchTickers': true,
22
22
  'watchTrades': true,
23
+ 'watchTradesForSymbols': false,
23
24
  'watchMyTrades': true,
24
25
  'watchOrders': true,
25
26
  'watchOrderBook': true,
@@ -1194,6 +1195,7 @@ export default class cex extends cexRest {
1194
1195
  * @name cex#fetchOrderWs
1195
1196
  * @description fetches information on an order made by the user
1196
1197
  * @see https://docs.cex.io/#ws-api-get-order
1198
+ * @param {string} id the order id
1197
1199
  * @param {string} symbol not used by cex fetchOrder
1198
1200
  * @param {object} [params] extra parameters specific to the cex api endpoint
1199
1201
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -17,6 +17,7 @@ export default class coincheck extends coincheckRest {
17
17
  'watchOrderBook': true,
18
18
  'watchOrders': false,
19
19
  'watchTrades': true,
20
+ 'watchTradesForSymbols': false,
20
21
  'watchOHLCV': false,
21
22
  'watchTicker': false,
22
23
  'watchTickers': false,
@@ -17,6 +17,7 @@ export default class coinone extends coinoneRest {
17
17
  'watchOrderBook': true,
18
18
  'watchOrders': false,
19
19
  'watchTrades': true,
20
+ 'watchTradesForSymbols': false,
20
21
  'watchOHLCV': false,
21
22
  'watchTicker': true,
22
23
  'watchTickers': false,
@@ -20,6 +20,7 @@ export default class hashkey extends hashkeyRest {
20
20
  'watchOrders': true,
21
21
  'watchTicker': true,
22
22
  'watchTrades': true,
23
+ 'watchTradesForSymbols': false,
23
24
  'watchPositions': false,
24
25
  },
25
26
  'urls': {
@@ -18,6 +18,7 @@ export default class hitbtc extends hitbtcRest {
18
18
  'watchTicker': true,
19
19
  'watchTickers': true,
20
20
  'watchTrades': true,
21
+ 'watchTradesForSymbols': false,
21
22
  'watchOrderBook': true,
22
23
  'watchBalance': true,
23
24
  'watchOrders': true,
@@ -23,6 +23,7 @@ export default class hollaex extends hollaexRest {
23
23
  'watchTicker': false,
24
24
  'watchTickers': false,
25
25
  'watchTrades': true,
26
+ 'watchTradesForSymbols': false,
26
27
  },
27
28
  'urls': {
28
29
  'api': {
package/js/src/pro/htx.js CHANGED
@@ -29,6 +29,7 @@ export default class htx extends htxRest {
29
29
  'watchTickers': false,
30
30
  'watchTicker': true,
31
31
  'watchTrades': true,
32
+ 'watchTradesForSymbols': false,
32
33
  'watchMyTrades': true,
33
34
  'watchBalance': true,
34
35
  'watchOHLCV': true,
@@ -18,6 +18,7 @@ export default class huobijp extends huobijpRest {
18
18
  'watchTickers': false,
19
19
  'watchTicker': true,
20
20
  'watchTrades': true,
21
+ 'watchTradesForSymbols': false,
21
22
  'watchBalance': false,
22
23
  'watchOHLCV': true,
23
24
  },
@@ -25,6 +25,7 @@ export default class hyperliquid extends hyperliquidRest {
25
25
  'watchTicker': false,
26
26
  'watchTickers': true,
27
27
  'watchTrades': true,
28
+ 'watchTradesForSymbols': false,
28
29
  'watchPosition': false,
29
30
  },
30
31
  'urls': {
@@ -140,6 +141,7 @@ export default class hyperliquid extends hyperliquidRest {
140
141
  * @method
141
142
  * @name hyperliquid#watchOrderBook
142
143
  * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
144
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
143
145
  * @param {string} symbol unified symbol of the market to fetch the order book for
144
146
  * @param {int} [limit] the maximum amount of order book entries to return
145
147
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -213,6 +215,7 @@ export default class hyperliquid extends hyperliquidRest {
213
215
  * @method
214
216
  * @name hyperliquid#watchTickers
215
217
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
218
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
216
219
  * @param {string[]} symbols unified symbol of the market to fetch the ticker for
217
220
  * @param {object} [params] extra parameters specific to the exchange API endpoint
218
221
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -239,6 +242,7 @@ export default class hyperliquid extends hyperliquidRest {
239
242
  * @method
240
243
  * @name hyperliquid#watchMyTrades
241
244
  * @description watches information on multiple trades made by the user
245
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
242
246
  * @param {string} symbol unified market symbol of the market orders were made in
243
247
  * @param {int} [since] the earliest time in ms to fetch orders for
244
248
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -406,6 +410,7 @@ export default class hyperliquid extends hyperliquidRest {
406
410
  * @method
407
411
  * @name hyperliquid#watchTrades
408
412
  * @description watches information on multiple trades made in a market
413
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
409
414
  * @param {string} symbol unified market symbol of the market trades were made in
410
415
  * @param {int} [since] the earliest time in ms to fetch trades for
411
416
  * @param {int} [limit] the maximum number of trade structures to retrieve
@@ -536,6 +541,7 @@ export default class hyperliquid extends hyperliquidRest {
536
541
  * @method
537
542
  * @name hyperliquid#watchOHLCV
538
543
  * @description watches historical candlestick data containing the open, high, low, close price, and the volume of a market
544
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
539
545
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
540
546
  * @param {string} timeframe the length of time each candle represents
541
547
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -621,6 +627,7 @@ export default class hyperliquid extends hyperliquidRest {
621
627
  * @method
622
628
  * @name hyperliquid#watchOrders
623
629
  * @description watches information on multiple orders made by the user
630
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
624
631
  * @param {string} symbol unified market symbol of the market orders were made in
625
632
  * @param {int} [since] the earliest time in ms to fetch orders for
626
633
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -18,6 +18,7 @@ export default class independentreserve extends independentreserveRest {
18
18
  'watchTicker': false,
19
19
  'watchTickers': false,
20
20
  'watchTrades': true,
21
+ 'watchTradesForSymbols': false,
21
22
  'watchMyTrades': false,
22
23
  'watchOrders': false,
23
24
  'watchOrderBook': true,
@@ -21,6 +21,7 @@ export default class lbank extends lbankRest {
21
21
  'watchTicker': true,
22
22
  'watchTickers': false,
23
23
  'watchTrades': true,
24
+ 'watchTradesForSymbols': false,
24
25
  'watchMyTrades': false,
25
26
  'watchOrders': true,
26
27
  'watchOrderBook': true,
@@ -16,6 +16,7 @@ export default class luno extends lunoRest {
16
16
  'watchTicker': false,
17
17
  'watchTickers': false,
18
18
  'watchTrades': true,
19
+ 'watchTradesForSymbols': false,
19
20
  'watchMyTrades': false,
20
21
  'watchOrders': undefined,
21
22
  'watchOrderBook': true,
@@ -15,6 +15,7 @@ export default class ndax extends ndaxRest {
15
15
  'ws': true,
16
16
  'watchOrderBook': true,
17
17
  'watchTrades': true,
18
+ 'watchTradesForSymbols': false,
18
19
  'watchTicker': true,
19
20
  'watchOHLCV': true,
20
21
  },
@@ -43,6 +44,7 @@ export default class ndax extends ndaxRest {
43
44
  * @method
44
45
  * @name ndax#watchTicker
45
46
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
47
+ * @see https://apidoc.ndax.io/#subscribelevel1
46
48
  * @param {string} symbol unified symbol of the market to fetch the ticker for
47
49
  * @param {object} [params] extra parameters specific to the exchange API endpoint
48
50
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -108,6 +110,7 @@ export default class ndax extends ndaxRest {
108
110
  * @method
109
111
  * @name ndax#watchTrades
110
112
  * @description get the list of most recent trades for a particular symbol
113
+ * @see https://apidoc.ndax.io/#subscribetrades
111
114
  * @param {string} symbol unified symbol of the market to fetch trades for
112
115
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
113
116
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -189,6 +192,7 @@ export default class ndax extends ndaxRest {
189
192
  * @method
190
193
  * @name ndax#watchOHLCV
191
194
  * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
195
+ * @see https://apidoc.ndax.io/#subscribeticker
192
196
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
193
197
  * @param {string} timeframe the length of time each candle represents
194
198
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -321,6 +325,7 @@ export default class ndax extends ndaxRest {
321
325
  * @method
322
326
  * @name ndax#watchOrderBook
323
327
  * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
328
+ * @see https://apidoc.ndax.io/#subscribelevel2
324
329
  * @param {string} symbol unified symbol of the market to fetch the order book for
325
330
  * @param {int} [limit] the maximum amount of order book entries to return
326
331
  * @param {object} [params] extra parameters specific to the exchange API endpoint