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
@@ -563,7 +563,7 @@ class mexc extends mexc$1 {
563
563
  'POKT': 'POKT',
564
564
  'QKC': 'QKC',
565
565
  'QTUM': 'QTUM',
566
- 'RAP20': 'RAP20 (Rangers Mainnet)',
566
+ 'RAP20': 'RAP20' + ' ' + '(Rangers Mainnet)',
567
567
  'REI': 'REI',
568
568
  'RSK': 'RBTC',
569
569
  'RVN': 'Ravencoin(RVN)',
@@ -713,69 +713,9 @@ class mexc extends mexc$1 {
713
713
  // OKB <> OKT (for usdt it's exception) for OKC, PMEER, FLARE, STRD, ZEL, FUND, "NONE", CRING, FREETON, QTZ (probably unique network is meant), HT, BSC(RACAV1), BSC(RACAV2), AMBROSUS, BAJUN, NOM. their individual info is at https://www.mexc.com/api/platform/asset/spot/{COINNAME}
714
714
  },
715
715
  'networksById': {
716
- 'Aleph Zero(AZERO)': 'AZERO',
717
- 'Alephium(ALPH)': 'ALPH',
718
- 'Algorand(ALGO)': 'ALGO',
719
- 'APTOS(APT)': 'APT',
720
- 'Arbitrum One(ARB)': 'ARB',
721
- 'Avalanche C Chain(AVAX CCHAIN)': 'AVAXC',
722
- 'Avalanche X Chain(AVAX XCHAIN)': 'AVAXX',
723
- 'BEP20(BSC)': 'BSC',
724
- 'Bitcoin Cash(BCH)': 'BCH',
725
- 'Bitcoin SV(BSV)': 'BSV',
726
- 'Bitcoin(BTC)': 'BTC',
727
- 'Bittensor(TAO)': 'TAO',
728
- 'BNB Beacon Chain(BEP2)': 'BEP2',
729
716
  'BNB Smart Chain(BEP20-RACAV1)': 'BSC',
730
717
  'BNB Smart Chain(BEP20-RACAV2)': 'BSC',
731
718
  'BNB Smart Chain(BEP20)': 'BSC',
732
- 'Cardano(ADA)': 'ADA',
733
- 'Celestia(TIA)': 'TIA',
734
- 'Chia(XCH)': 'XCH',
735
- 'Chiliz Chain(CHZ2)': 'CHZ2',
736
- 'Chiliz Legacy Chain(CHZ)': 'CHZ',
737
- 'Clore.ai(CLORE)': 'CLORE',
738
- 'Cosmos(ATOM)': 'ATOM',
739
- 'Dogechain(DC)': 'DC',
740
- 'Dogecoin(DOGE)': 'DOGE',
741
- 'Dymension(DYM)': 'DYM',
742
- 'Dynex(DNX)': 'DNX',
743
- 'Elysium(LAVA)': 'LAVA',
744
- 'Ethereum Classic(ETC)': 'ETC',
745
- 'Ethereum(ERC20)': 'ERC20',
746
- 'Fantom(FTM)': 'FTM',
747
- 'Hedera(HBAR)': 'HBAR',
748
- 'Index Chain': 'INDEX',
749
- 'Internet Computer(ICP)': 'ICP',
750
- 'Kaspa(KAS)': 'KAS',
751
- 'Klaytn(KLAY)': 'KLAY',
752
- 'Litecoin(LTC)': 'LTC',
753
- 'Mantle(MNT)': 'MNT',
754
- 'Mcoin Network': 'MCOIN',
755
- 'Meter(MTRG)': 'MTRG',
756
- 'Monero(XMR)': 'XMR',
757
- 'NEAR Protocol(NEAR)': 'NEAR',
758
- 'Neoxa Network': 'NEOXA',
759
- 'Neurai(XNA)': 'XNA',
760
- 'Omega Network(OMN)': 'OMN',
761
- 'Optimism(OP)': 'OPTIMISM',
762
- 'Polkadot(DOT)': 'DOT',
763
- 'Polygon(MATIC)': 'MATIC',
764
- 'RAP20 (Rangers Mainnet)': 'RAP20',
765
- 'Ravencoin(RVN)': 'RVN',
766
- 'Ripple(XRP)': 'XRP',
767
- 'Satoxcoin(SATOX)': 'SATOX',
768
- 'Solana(SOL)': 'SOL',
769
- 'Starknet(STARK)': 'STARK',
770
- 'Stellar(XLM)': 'XLM',
771
- 'Terra(LUNA)': 'LUNA',
772
- 'Toncoin(TON)': 'TON',
773
- 'Tron(TRC20)': 'TRC20',
774
- 'UGAS(Ultrain)': 'UGAS',
775
- 'VeChain(VET)': 'VET',
776
- 'Vexanium(VEX)': 'VEX',
777
- 'XPR Network': 'XPR',
778
- 'Zilliqa(ZIL)': 'ZIL',
779
719
  // TODO: uncomment below after deciding unified name
780
720
  // 'PEPE COIN BSC':
781
721
  // 'SMART BLOCKCHAIN':
@@ -577,6 +577,9 @@ class okcoin extends okcoin$1 {
577
577
  'defaultNetwork': 'ERC20',
578
578
  'networks': {
579
579
  'ERC20': 'Ethereum',
580
+ 'BTC': 'Bitcoin',
581
+ 'OMNI': 'Omni',
582
+ 'TRC20': 'TRON',
580
583
  },
581
584
  },
582
585
  'commonCurrencies': {
@@ -709,14 +712,6 @@ class okcoin extends okcoin$1 {
709
712
  'info': market,
710
713
  });
711
714
  }
712
- safeNetwork(networkId) {
713
- const networksById = {
714
- 'Bitcoin': 'BTC',
715
- 'Omni': 'OMNI',
716
- 'TRON': 'TRC20',
717
- };
718
- return this.safeString(networksById, networkId, networkId);
719
- }
720
715
  async fetchCurrencies(params = {}) {
721
716
  /**
722
717
  * @method
@@ -760,7 +755,7 @@ class okcoin extends okcoin$1 {
760
755
  if ((networkId !== undefined) && (networkId.indexOf('-') >= 0)) {
761
756
  const parts = networkId.split('-');
762
757
  const chainPart = this.safeString(parts, 1, networkId);
763
- const networkCode = this.safeNetwork(chainPart);
758
+ const networkCode = this.networkIdToCode(chainPart);
764
759
  const precision = this.parsePrecision(this.safeString(chain, 'wdTickSz'));
765
760
  if (maxPrecision === undefined) {
766
761
  maxPrecision = precision;
@@ -1641,6 +1641,7 @@ class onetrading extends onetrading$1 {
1641
1641
  * @method
1642
1642
  * @name onetrading#fetchOrder
1643
1643
  * @description fetches information on an order made by the user
1644
+ * @param {string} id the order id
1644
1645
  * @param {string} symbol not used by onetrading fetchOrder
1645
1646
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1646
1647
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -2983,6 +2983,7 @@ class phemex extends phemex$1 {
2983
2983
  * @name phemex#fetchOrder
2984
2984
  * @see https://phemex-docs.github.io/#query-orders-by-ids
2985
2985
  * @description fetches information on an order made by the user
2986
+ * @param {string} id the order id
2986
2987
  * @param {string} symbol unified symbol of the market the order was made in
2987
2988
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2988
2989
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -1415,6 +1415,7 @@ class poloniexfutures extends poloniexfutures$1 {
1415
1415
  * @description fetches information on an order made by the user
1416
1416
  * @see https://api-docs.poloniex.com/futures/api/orders#get-details-of-a-single-order
1417
1417
  * @see https://api-docs.poloniex.com/futures/api/orders#get-single-order-by-clientoid
1418
+ * @param {string} id the order id
1418
1419
  * @param {string} symbol unified symbol of the market the order was made in
1419
1420
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1420
1421
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -17,6 +17,7 @@ class bitfinex extends bitfinex$1 {
17
17
  'watchTickers': false,
18
18
  'watchOrderBook': true,
19
19
  'watchTrades': true,
20
+ 'watchTradesForSymbols': false,
20
21
  'watchBalance': false,
21
22
  'watchOHLCV': false, // missing on the exchange side in v1
22
23
  },
@@ -17,6 +17,7 @@ class bitfinex2 extends bitfinex2$1 {
17
17
  'watchTickers': false,
18
18
  'watchOrderBook': true,
19
19
  'watchTrades': true,
20
+ 'watchTradesForSymbols': false,
20
21
  'watchMyTrades': true,
21
22
  'watchBalance': true,
22
23
  'watchOHLCV': true,
@@ -20,6 +20,7 @@ class bitopro extends bitopro$1 {
20
20
  'watchTicker': true,
21
21
  'watchTickers': false,
22
22
  'watchTrades': true,
23
+ 'watchTradesForSymbols': false,
23
24
  },
24
25
  'urls': {
25
26
  'ws': {
@@ -14,6 +14,7 @@ class bitstamp extends bitstamp$1 {
14
14
  'watchOrderBook': true,
15
15
  'watchOrders': true,
16
16
  'watchTrades': true,
17
+ 'watchTradesForSymbols': false,
17
18
  'watchOHLCV': false,
18
19
  'watchTicker': false,
19
20
  'watchTickers': false,
@@ -639,6 +639,7 @@ class bitvavo extends bitvavo$1 {
639
639
  * @name bitvavo#fetchOrderWs
640
640
  * @see https://docs.bitvavo.com/#tag/General/paths/~1assets/get
641
641
  * @description fetches information on an order made by the user
642
+ * @param {string} id the order id
642
643
  * @param {string} symbol unified symbol of the market the order was made in
643
644
  * @param {object} [params] extra parameters specific to the bitvavo api endpoint
644
645
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -15,6 +15,7 @@ class blockchaincom extends blockchaincom$1 {
15
15
  'watchTicker': true,
16
16
  'watchTickers': false,
17
17
  'watchTrades': true,
18
+ 'watchTradesForSymbols': false,
18
19
  'watchMyTrades': false,
19
20
  'watchOrders': true,
20
21
  'watchOrderBook': true,
@@ -390,6 +390,49 @@ class bybit extends bybit$1 {
390
390
  }
391
391
  return this.filterByArray(this.tickers, 'symbol', symbols);
392
392
  }
393
+ async unWatchTickers(symbols = undefined, params = {}) {
394
+ /**
395
+ * @method
396
+ * @name bybit#unWatchTickers
397
+ * @description unWatches a price ticker
398
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/ticker
399
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/etp-ticker
400
+ * @param {string[]} symbols unified symbol of the market to fetch the ticker for
401
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
402
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
403
+ */
404
+ await this.loadMarkets();
405
+ symbols = this.marketSymbols(symbols, undefined, false);
406
+ const options = this.safeValue(this.options, 'watchTickers', {});
407
+ const topic = this.safeString(options, 'name', 'tickers');
408
+ const messageHashes = [];
409
+ const subMessageHashes = [];
410
+ const marketIds = this.marketIds(symbols);
411
+ const topics = [];
412
+ for (let i = 0; i < marketIds.length; i++) {
413
+ const marketId = marketIds[i];
414
+ const symbol = symbols[i];
415
+ topics.push(topic + '.' + marketId);
416
+ subMessageHashes.push('ticker:' + symbol);
417
+ messageHashes.push('unsubscribe:ticker:' + symbol);
418
+ }
419
+ const url = await this.getUrlByMarketType(symbols[0], false, 'watchTickers', params);
420
+ return await this.unWatchTopics(url, 'ticker', symbols, messageHashes, subMessageHashes, topics, params);
421
+ }
422
+ async unWatchTicker(symbols, params = {}) {
423
+ /**
424
+ * @method
425
+ * @name bybit#unWatchTicker
426
+ * @description unWatches a price ticker
427
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/ticker
428
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/etp-ticker
429
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
430
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
431
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
432
+ */
433
+ await this.loadMarkets();
434
+ return await this.unWatchTickers([symbols], params);
435
+ }
393
436
  handleTicker(client, message) {
394
437
  //
395
438
  // linear
@@ -723,6 +766,56 @@ class bybit extends bybit$1 {
723
766
  const orderbook = await this.watchTopics(url, messageHashes, topics, params);
724
767
  return orderbook.limit();
725
768
  }
769
+ async unWatchOrderBookForSymbols(symbols, params = {}) {
770
+ /**
771
+ * @method
772
+ * @name bybit#unWatchOrderBookForSymbols
773
+ * @description unsubscribe from the orderbook channel
774
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/orderbook
775
+ * @param {string[]} symbols unified symbol of the market to unwatch the trades for
776
+ * @param {int} [params.limit] orderbook limit, default is undefined
777
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
778
+ */
779
+ await this.loadMarkets();
780
+ symbols = this.marketSymbols(symbols, undefined, false);
781
+ let channel = 'orderbook.';
782
+ let limit = this.safeInteger(params, 'limit');
783
+ if (limit !== undefined) {
784
+ params = this.omit(params, 'limit');
785
+ }
786
+ else {
787
+ const firstMarket = this.market(symbols[0]);
788
+ limit = firstMarket['spot'] ? 50 : 500;
789
+ }
790
+ channel += limit.toString();
791
+ const subMessageHashes = [];
792
+ const messageHashes = [];
793
+ const topics = [];
794
+ for (let i = 0; i < symbols.length; i++) {
795
+ const symbol = symbols[i];
796
+ const market = this.market(symbol);
797
+ const marketId = market['id'];
798
+ const topic = channel + '.' + marketId;
799
+ messageHashes.push('unsubscribe:orderbook:' + symbol);
800
+ subMessageHashes.push('orderbook:' + symbol);
801
+ topics.push(topic);
802
+ }
803
+ const url = await this.getUrlByMarketType(symbols[0], false, 'watchOrderBook', params);
804
+ return await this.unWatchTopics(url, 'orderbook', symbols, messageHashes, subMessageHashes, topics, params);
805
+ }
806
+ async unWatchOrderBook(symbol, params = {}) {
807
+ /**
808
+ * @method
809
+ * @name bybit#unWatchOrderBook
810
+ * @description unsubscribe from the orderbook channel
811
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/orderbook
812
+ * @param {string[]} symbols unified symbol of the market to unwatch the trades for
813
+ * @param {int} [params.limit] orderbook limit, default is undefined
814
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
815
+ */
816
+ await this.loadMarkets();
817
+ return await this.unWatchOrderBookForSymbols([symbol], params);
818
+ }
726
819
  handleOrderBook(client, message) {
727
820
  //
728
821
  // {
@@ -847,6 +940,44 @@ class bybit extends bybit$1 {
847
940
  }
848
941
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
849
942
  }
943
+ async unWatchTradesForSymbols(symbols, params = {}) {
944
+ /**
945
+ * @method
946
+ * @name bybit#unWatchTradesForSymbols
947
+ * @description unsubscribe from the trades channel
948
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/trade
949
+ * @param {string[]} symbols unified symbol of the market to unwatch the trades for
950
+ * @returns {any} status of the unwatch request
951
+ */
952
+ await this.loadMarkets();
953
+ symbols = this.marketSymbols(symbols, undefined, false, true);
954
+ const url = await this.getUrlByMarketType(symbols[0], false, 'unWatchTradesForSymbols', params);
955
+ const messageHashes = [];
956
+ const topics = [];
957
+ const subMessageHashes = [];
958
+ for (let i = 0; i < symbols.length; i++) {
959
+ const symbol = symbols[i];
960
+ const market = this.market(symbol);
961
+ const topic = 'publicTrade.' + market['id'];
962
+ topics.push(topic);
963
+ const messageHash = 'unsubscribe:trade:' + symbol;
964
+ messageHashes.push(messageHash);
965
+ subMessageHashes.push('trade:' + symbol);
966
+ }
967
+ return await this.unWatchTopics(url, 'trade', symbols, messageHashes, subMessageHashes, topics, params);
968
+ }
969
+ async unWatchTrades(symbol, params = {}) {
970
+ /**
971
+ * @method
972
+ * @name bybit#unWatchTrades
973
+ * @description unsubscribe from the trades channel
974
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/trade
975
+ * @param {string} symbol unified symbol of the market to unwatch the trades for
976
+ * @returns {any} status of the unwatch request
977
+ */
978
+ await this.loadMarkets();
979
+ return await this.unWatchTradesForSymbols([symbol], params);
980
+ }
850
981
  handleTrades(client, message) {
851
982
  //
852
983
  // {
@@ -1005,6 +1136,35 @@ class bybit extends bybit$1 {
1005
1136
  }
1006
1137
  return this.filterBySymbolSinceLimit(trades, symbol, since, limit, true);
1007
1138
  }
1139
+ async unWatchMyTrades(symbol = undefined, params = {}) {
1140
+ /**
1141
+ * @method
1142
+ * @name bybit#unWatchMyTrades
1143
+ * @description unWatches information on multiple trades made by the user
1144
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/private/execution
1145
+ * @param {string} symbol unified market symbol of the market orders were made in
1146
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1147
+ * @param {boolean} [params.unifiedMargin] use unified margin account
1148
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1149
+ */
1150
+ const method = 'watchMyTrades';
1151
+ const messageHash = 'unsubscribe:myTrades';
1152
+ let subHash = 'myTrades';
1153
+ await this.loadMarkets();
1154
+ if (symbol !== undefined) {
1155
+ symbol = this.symbol(symbol);
1156
+ subHash += ':' + symbol;
1157
+ }
1158
+ const url = await this.getUrlByMarketType(symbol, true, method, params);
1159
+ await this.authenticate(url);
1160
+ const topicByMarket = {
1161
+ 'spot': 'ticketInfo',
1162
+ 'unified': 'execution',
1163
+ 'usdc': 'user.openapi.perp.trade',
1164
+ };
1165
+ const topic = this.safeValue(topicByMarket, this.getPrivateType(url));
1166
+ return await this.unWatchTopics(url, 'myTrades', [], [messageHash], [subHash], [topic], params);
1167
+ }
1008
1168
  handleMyTrades(client, message) {
1009
1169
  //
1010
1170
  // spot
@@ -1369,6 +1529,35 @@ class bybit extends bybit$1 {
1369
1529
  }
1370
1530
  return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
1371
1531
  }
1532
+ async unWatchOrders(symbol = undefined, params = {}) {
1533
+ /**
1534
+ * @method
1535
+ * @name bybit#unWatchOrders
1536
+ * @description unWatches information on multiple orders made by the user
1537
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/private/order
1538
+ * @param {string} symbol unified market symbol of the market orders were made in
1539
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1540
+ * @param {boolean} [params.unifiedMargin] use unified margin account
1541
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1542
+ */
1543
+ await this.loadMarkets();
1544
+ const method = 'watchOrders';
1545
+ const messageHash = 'unsubscribe:orders';
1546
+ let subHash = 'orders';
1547
+ if (symbol !== undefined) {
1548
+ symbol = this.symbol(symbol);
1549
+ subHash += ':' + symbol;
1550
+ }
1551
+ const url = await this.getUrlByMarketType(symbol, true, method, params);
1552
+ await this.authenticate(url);
1553
+ const topicsByMarket = {
1554
+ 'spot': ['order', 'stopOrder'],
1555
+ 'unified': ['order'],
1556
+ 'usdc': ['user.openapi.perp.order'],
1557
+ };
1558
+ const topics = this.safeValue(topicsByMarket, this.getPrivateType(url));
1559
+ return await this.unWatchTopics(url, 'orders', [], [messageHash], [subHash], topics, params);
1560
+ }
1372
1561
  handleOrderWs(client, message) {
1373
1562
  //
1374
1563
  // {
@@ -1951,7 +2140,24 @@ class bybit extends bybit$1 {
1951
2140
  'args': topics,
1952
2141
  };
1953
2142
  const message = this.extend(request, params);
1954
- return await this.watchMultiple(url, messageHashes, message, topics);
2143
+ return await this.watchMultiple(url, messageHashes, message, messageHashes);
2144
+ }
2145
+ async unWatchTopics(url, topic, symbols, messageHashes, subMessageHashes, topics, params = {}) {
2146
+ const reqId = this.requestId();
2147
+ const request = {
2148
+ 'op': 'unsubscribe',
2149
+ 'req_id': reqId,
2150
+ 'args': topics,
2151
+ };
2152
+ const subscription = {
2153
+ 'id': reqId,
2154
+ 'topic': topic,
2155
+ 'messageHashes': messageHashes,
2156
+ 'subMessageHashes': subMessageHashes,
2157
+ 'symbols': symbols,
2158
+ };
2159
+ const message = this.extend(request, params);
2160
+ return await this.watchMultiple(url, messageHashes, message, messageHashes, subscription);
1955
2161
  }
1956
2162
  async authenticate(url, params = {}) {
1957
2163
  this.checkRequiredCredentials();
@@ -2102,6 +2308,7 @@ class bybit extends bybit$1 {
2102
2308
  'order.amend': this.handleOrderWs,
2103
2309
  'order.cancel': this.handleOrderWs,
2104
2310
  'auth': this.handleAuthenticate,
2311
+ 'unsubscribe': this.handleUnSubscribe,
2105
2312
  };
2106
2313
  const exacMethod = this.safeValue(methods, topic);
2107
2314
  if (exacMethod !== undefined) {
@@ -2192,6 +2399,88 @@ class bybit extends bybit$1 {
2192
2399
  //
2193
2400
  return message;
2194
2401
  }
2402
+ handleUnSubscribe(client, message) {
2403
+ //
2404
+ // {"success":true,"ret_msg":"","conn_id":"7188110e-6908-41e9-b863-6365127e92ad","req_id":"3","op":"unsubscribe"}
2405
+ //
2406
+ // client.subscription will be something like:
2407
+ // {
2408
+ // "publicTrade.LTCUSDT":true,
2409
+ // "publicTrade.ADAUSDT":true,
2410
+ // "unsubscribe:trade:LTC/USDT:USDT": {
2411
+ // "id":4,
2412
+ // "subHash": "trade:LTC/USDT"
2413
+ // },
2414
+ // }
2415
+ const reqId = this.safeString(message, 'req_id');
2416
+ const keys = Object.keys(client.subscriptions);
2417
+ for (let i = 0; i < keys.length; i++) {
2418
+ const messageHash = keys[i];
2419
+ if (!(messageHash in client.subscriptions)) {
2420
+ continue;
2421
+ // the previous iteration can have deleted the messageHash from the subscriptions
2422
+ }
2423
+ if (messageHash.startsWith('unsubscribe')) {
2424
+ const subscription = client.subscriptions[messageHash];
2425
+ const subId = this.safeString(subscription, 'id');
2426
+ if (reqId !== subId) {
2427
+ continue;
2428
+ }
2429
+ const messageHashes = this.safeList(subscription, 'messageHashes', []);
2430
+ const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
2431
+ for (let j = 0; j < messageHashes.length; j++) {
2432
+ const unsubHash = messageHashes[j];
2433
+ const subHash = subMessageHashes[j];
2434
+ if (unsubHash in client.subscriptions) {
2435
+ delete client.subscriptions[unsubHash];
2436
+ }
2437
+ if (subHash in client.subscriptions) {
2438
+ delete client.subscriptions[subHash];
2439
+ }
2440
+ const error = new errors.UnsubscribeError(this.id + ' ' + messageHash);
2441
+ client.reject(error, subHash);
2442
+ client.resolve(true, unsubHash);
2443
+ this.cleanCache(subscription);
2444
+ }
2445
+ }
2446
+ }
2447
+ return message;
2448
+ }
2449
+ cleanCache(subscription) {
2450
+ const topic = this.safeString(subscription, 'topic');
2451
+ const symbols = this.safeList(subscription, 'symbols', []);
2452
+ const symbolsLength = symbols.length;
2453
+ if (symbolsLength > 0) {
2454
+ for (let i = 0; i < symbols.length; i++) {
2455
+ const symbol = symbols[i];
2456
+ if (topic === 'trade') {
2457
+ delete this.trades[symbol];
2458
+ }
2459
+ else if (topic === 'orderbook') {
2460
+ delete this.orderbooks[symbol];
2461
+ }
2462
+ else if (topic === 'ticker') {
2463
+ delete this.tickers[symbol];
2464
+ }
2465
+ }
2466
+ }
2467
+ else {
2468
+ if (topic === 'myTrades') {
2469
+ // don't reset this.myTrades directly here
2470
+ // because in c# we need to use a different object
2471
+ const keys = Object.keys(this.myTrades);
2472
+ for (let i = 0; i < keys.length; i++) {
2473
+ delete this.myTrades[keys[i]];
2474
+ }
2475
+ }
2476
+ else if (topic === 'orders') {
2477
+ const orderSymbols = Object.keys(this.orders);
2478
+ for (let i = 0; i < orderSymbols.length; i++) {
2479
+ delete this.orders[orderSymbols[i]];
2480
+ }
2481
+ }
2482
+ }
2483
+ }
2195
2484
  }
2196
2485
 
2197
2486
  module.exports = bybit;
@@ -17,6 +17,7 @@ class cex extends cex$1 {
17
17
  'watchTicker': true,
18
18
  'watchTickers': true,
19
19
  'watchTrades': true,
20
+ 'watchTradesForSymbols': false,
20
21
  'watchMyTrades': true,
21
22
  'watchOrders': true,
22
23
  'watchOrderBook': true,
@@ -1191,6 +1192,7 @@ class cex extends cex$1 {
1191
1192
  * @name cex#fetchOrderWs
1192
1193
  * @description fetches information on an order made by the user
1193
1194
  * @see https://docs.cex.io/#ws-api-get-order
1195
+ * @param {string} id the order id
1194
1196
  * @param {string} symbol not used by cex fetchOrder
1195
1197
  * @param {object} [params] extra parameters specific to the cex api endpoint
1196
1198
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -14,6 +14,7 @@ class coincheck extends coincheck$1 {
14
14
  'watchOrderBook': true,
15
15
  'watchOrders': false,
16
16
  'watchTrades': true,
17
+ 'watchTradesForSymbols': false,
17
18
  'watchOHLCV': false,
18
19
  'watchTicker': false,
19
20
  'watchTickers': false,
@@ -14,6 +14,7 @@ class coinone extends coinone$1 {
14
14
  'watchOrderBook': true,
15
15
  'watchOrders': false,
16
16
  'watchTrades': true,
17
+ 'watchTradesForSymbols': false,
17
18
  'watchOHLCV': false,
18
19
  'watchTicker': true,
19
20
  'watchTickers': false,
@@ -17,6 +17,7 @@ class hashkey extends hashkey$1 {
17
17
  'watchOrders': true,
18
18
  'watchTicker': true,
19
19
  'watchTrades': true,
20
+ 'watchTradesForSymbols': false,
20
21
  'watchPositions': false,
21
22
  },
22
23
  'urls': {
@@ -15,6 +15,7 @@ class hitbtc extends hitbtc$1 {
15
15
  'watchTicker': true,
16
16
  'watchTickers': true,
17
17
  'watchTrades': true,
18
+ 'watchTradesForSymbols': false,
18
19
  'watchOrderBook': true,
19
20
  'watchBalance': true,
20
21
  'watchOrders': true,
@@ -20,6 +20,7 @@ class hollaex extends hollaex$1 {
20
20
  'watchTicker': false,
21
21
  'watchTickers': false,
22
22
  'watchTrades': true,
23
+ 'watchTradesForSymbols': false,
23
24
  },
24
25
  'urls': {
25
26
  'api': {
@@ -26,6 +26,7 @@ class htx extends htx$1 {
26
26
  'watchTickers': false,
27
27
  'watchTicker': true,
28
28
  'watchTrades': true,
29
+ 'watchTradesForSymbols': false,
29
30
  'watchMyTrades': true,
30
31
  'watchBalance': true,
31
32
  'watchOHLCV': true,
@@ -15,6 +15,7 @@ class huobijp extends huobijp$1 {
15
15
  'watchTickers': false,
16
16
  'watchTicker': true,
17
17
  'watchTrades': true,
18
+ 'watchTradesForSymbols': false,
18
19
  'watchBalance': false,
19
20
  'watchOHLCV': true,
20
21
  },