ccxt 4.4.1 → 4.4.2

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 (48) hide show
  1. package/README.md +4 -4
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/base/Exchange.js +69 -0
  5. package/dist/cjs/src/binance.js +78 -8
  6. package/dist/cjs/src/cryptocom.js +1 -1
  7. package/dist/cjs/src/currencycom.js +1 -2
  8. package/dist/cjs/src/htx.js +1 -1
  9. package/dist/cjs/src/mexc.js +69 -1
  10. package/dist/cjs/src/pro/binance.js +3 -63
  11. package/dist/cjs/src/pro/bitget.js +1 -9
  12. package/dist/cjs/src/pro/bitmex.js +11 -1
  13. package/dist/cjs/src/pro/bybit.js +2 -54
  14. package/dist/cjs/src/pro/cryptocom.js +2 -40
  15. package/dist/cjs/src/pro/gate.js +1 -9
  16. package/dist/cjs/src/pro/hyperliquid.js +4 -36
  17. package/dist/cjs/src/pro/kucoin.js +2 -59
  18. package/dist/cjs/src/pro/kucoinfutures.js +139 -1
  19. package/dist/cjs/src/pro/okx.js +8 -36
  20. package/dist/cjs/src/xt.js +1 -1
  21. package/examples/js/cli.js +8 -4
  22. package/js/ccxt.d.ts +3 -3
  23. package/js/ccxt.js +1 -1
  24. package/js/src/base/Exchange.d.ts +2 -0
  25. package/js/src/base/Exchange.js +70 -1
  26. package/js/src/base/types.d.ts +5 -4
  27. package/js/src/binance.js +78 -8
  28. package/js/src/cryptocom.js +1 -1
  29. package/js/src/currencycom.js +1 -2
  30. package/js/src/htx.js +1 -1
  31. package/js/src/mexc.js +69 -1
  32. package/js/src/pro/binance.d.ts +0 -1
  33. package/js/src/pro/binance.js +4 -64
  34. package/js/src/pro/bitget.js +1 -9
  35. package/js/src/pro/bitmex.js +11 -1
  36. package/js/src/pro/bybit.d.ts +1 -2
  37. package/js/src/pro/bybit.js +3 -55
  38. package/js/src/pro/cryptocom.d.ts +1 -2
  39. package/js/src/pro/cryptocom.js +3 -41
  40. package/js/src/pro/gate.js +2 -10
  41. package/js/src/pro/hyperliquid.js +5 -37
  42. package/js/src/pro/kucoin.d.ts +0 -1
  43. package/js/src/pro/kucoin.js +3 -60
  44. package/js/src/pro/kucoinfutures.d.ts +7 -1
  45. package/js/src/pro/kucoinfutures.js +139 -1
  46. package/js/src/pro/okx.js +9 -37
  47. package/js/src/xt.js +1 -1
  48. package/package.json +1 -1
@@ -1016,7 +1016,7 @@ class bybit extends bybit$1 {
1016
1016
  messageHashes.push(messageHash);
1017
1017
  subMessageHashes.push('trade:' + symbol);
1018
1018
  }
1019
- return await this.unWatchTopics(url, 'trade', symbols, messageHashes, subMessageHashes, topics, params);
1019
+ return await this.unWatchTopics(url, 'trades', symbols, messageHashes, subMessageHashes, topics, params);
1020
1020
  }
1021
1021
  async unWatchTrades(symbol, params = {}) {
1022
1022
  /**
@@ -2483,65 +2483,13 @@ class bybit extends bybit$1 {
2483
2483
  for (let j = 0; j < messageHashes.length; j++) {
2484
2484
  const unsubHash = messageHashes[j];
2485
2485
  const subHash = subMessageHashes[j];
2486
- if (unsubHash in client.subscriptions) {
2487
- delete client.subscriptions[unsubHash];
2488
- }
2489
- if (subHash in client.subscriptions) {
2490
- delete client.subscriptions[subHash];
2491
- }
2492
- const error = new errors.UnsubscribeError(this.id + ' ' + messageHash);
2493
- client.reject(error, subHash);
2494
- client.resolve(true, unsubHash);
2486
+ this.cleanUnsubscription(client, subHash, unsubHash);
2495
2487
  }
2496
2488
  this.cleanCache(subscription);
2497
2489
  }
2498
2490
  }
2499
2491
  return message;
2500
2492
  }
2501
- cleanCache(subscription) {
2502
- const topic = this.safeString(subscription, 'topic');
2503
- const symbols = this.safeList(subscription, 'symbols', []);
2504
- const symbolsLength = symbols.length;
2505
- if (topic === 'ohlcv') {
2506
- const symbolsAndTimeFrames = this.safeList(subscription, 'symbolsAndTimeframes', []);
2507
- for (let i = 0; i < symbolsAndTimeFrames.length; i++) {
2508
- const symbolAndTimeFrame = symbolsAndTimeFrames[i];
2509
- const symbol = this.safeString(symbolAndTimeFrame, 0);
2510
- const timeframe = this.safeString(symbolAndTimeFrame, 1);
2511
- delete this.ohlcvs[symbol][timeframe];
2512
- }
2513
- }
2514
- else if (symbolsLength > 0) {
2515
- for (let i = 0; i < symbols.length; i++) {
2516
- const symbol = symbols[i];
2517
- if (topic === 'trade') {
2518
- delete this.trades[symbol];
2519
- }
2520
- else if (topic === 'orderbook') {
2521
- delete this.orderbooks[symbol];
2522
- }
2523
- else if (topic === 'ticker') {
2524
- delete this.tickers[symbol];
2525
- }
2526
- }
2527
- }
2528
- else {
2529
- if (topic === 'myTrades') {
2530
- // don't reset this.myTrades directly here
2531
- // because in c# we need to use a different object
2532
- const keys = Object.keys(this.myTrades);
2533
- for (let i = 0; i < keys.length; i++) {
2534
- delete this.myTrades[keys[i]];
2535
- }
2536
- }
2537
- else if (topic === 'orders') {
2538
- const orderSymbols = Object.keys(this.orders);
2539
- for (let i = 0; i < orderSymbols.length; i++) {
2540
- delete this.orders[orderSymbols[i]];
2541
- }
2542
- }
2543
- }
2544
- }
2545
2493
  }
2546
2494
 
2547
2495
  module.exports = bybit;
@@ -371,7 +371,7 @@ class cryptocom extends cryptocom$1 {
371
371
  messageHashes.push('unsubscribe:trades:' + market['symbol']);
372
372
  topics.push(currentTopic);
373
373
  }
374
- return await this.unWatchPublicMultiple('trade', symbols, messageHashes, topics, topics, params);
374
+ return await this.unWatchPublicMultiple('trades', symbols, messageHashes, topics, topics, params);
375
375
  }
376
376
  handleTrades(client, message) {
377
377
  //
@@ -1205,50 +1205,12 @@ class cryptocom extends cryptocom$1 {
1205
1205
  for (let j = 0; j < messageHashes.length; j++) {
1206
1206
  const unsubHash = messageHashes[j];
1207
1207
  const subHash = subMessageHashes[j];
1208
- if (unsubHash in client.subscriptions) {
1209
- delete client.subscriptions[unsubHash];
1210
- }
1211
- if (subHash in client.subscriptions) {
1212
- delete client.subscriptions[subHash];
1213
- }
1214
- const error = new errors.UnsubscribeError(this.id + ' ' + subHash);
1215
- client.reject(error, subHash);
1216
- client.resolve(true, unsubHash);
1208
+ this.cleanUnsubscription(client, subHash, unsubHash);
1217
1209
  }
1218
1210
  this.cleanCache(subscription);
1219
1211
  }
1220
1212
  }
1221
1213
  }
1222
- cleanCache(subscription) {
1223
- const topic = this.safeString(subscription, 'topic');
1224
- const symbols = this.safeList(subscription, 'symbols', []);
1225
- const symbolsLength = symbols.length;
1226
- if (topic === 'ohlcv') {
1227
- const symbolsAndTimeFrames = this.safeList(subscription, 'symbolsAndTimeframes', []);
1228
- for (let i = 0; i < symbolsAndTimeFrames.length; i++) {
1229
- const symbolAndTimeFrame = symbolsAndTimeFrames[i];
1230
- const symbol = this.safeString(symbolAndTimeFrame, 0);
1231
- const timeframe = this.safeString(symbolAndTimeFrame, 1);
1232
- if (timeframe in this.ohlcvs[symbol]) {
1233
- delete this.ohlcvs[symbol][timeframe];
1234
- }
1235
- }
1236
- }
1237
- else if (symbolsLength > 0) {
1238
- for (let i = 0; i < symbols.length; i++) {
1239
- const symbol = symbols[i];
1240
- if (topic === 'trade') {
1241
- delete this.trades[symbol];
1242
- }
1243
- else if (topic === 'orderbook') {
1244
- delete this.orderbooks[symbol];
1245
- }
1246
- else if (topic === 'ticker') {
1247
- delete this.tickers[symbol];
1248
- }
1249
- }
1250
- }
1251
- }
1252
1214
  }
1253
1215
 
1254
1216
  module.exports = cryptocom;
@@ -1660,15 +1660,7 @@ class gate extends gate$1 {
1660
1660
  for (let j = 0; j < messageHashes.length; j++) {
1661
1661
  const unsubHash = messageHashes[j];
1662
1662
  const subHash = subMessageHashes[j];
1663
- if (unsubHash in client.subscriptions) {
1664
- delete client.subscriptions[unsubHash];
1665
- }
1666
- if (subHash in client.subscriptions) {
1667
- delete client.subscriptions[subHash];
1668
- }
1669
- const error = new errors.UnsubscribeError(this.id + ' ' + messageHash);
1670
- client.reject(error, subHash);
1671
- client.resolve(true, unsubHash);
1663
+ this.cleanUnsubscription(client, subHash, unsubHash);
1672
1664
  }
1673
1665
  this.cleanCache(subscription);
1674
1666
  }
@@ -841,15 +841,7 @@ class hyperliquid extends hyperliquid$1 {
841
841
  const symbol = this.safeSymbol(marketId);
842
842
  const subMessageHash = 'orderbook:' + symbol;
843
843
  const messageHash = 'unsubscribe:' + subMessageHash;
844
- if (messageHash in client.subscriptions) {
845
- delete client.subscriptions[messageHash];
846
- }
847
- if (subMessageHash in client.subscriptions) {
848
- delete client.subscriptions[subMessageHash];
849
- }
850
- const error = new errors.UnsubscribeError(this.id + ' ' + subMessageHash);
851
- client.reject(error, subMessageHash);
852
- client.resolve(true, messageHash);
844
+ this.cleanUnsubscription(client, subMessageHash, messageHash);
853
845
  if (symbol in this.orderbooks) {
854
846
  delete this.orderbooks[symbol];
855
847
  }
@@ -861,15 +853,7 @@ class hyperliquid extends hyperliquid$1 {
861
853
  const symbol = this.safeSymbol(marketId);
862
854
  const subMessageHash = 'trade:' + symbol;
863
855
  const messageHash = 'unsubscribe:' + subMessageHash;
864
- if (messageHash in client.subscriptions) {
865
- delete client.subscriptions[messageHash];
866
- }
867
- if (subMessageHash in client.subscriptions) {
868
- delete client.subscriptions[subMessageHash];
869
- }
870
- const error = new errors.UnsubscribeError(this.id + ' ' + subMessageHash);
871
- client.reject(error, subMessageHash);
872
- client.resolve(true, messageHash);
856
+ this.cleanUnsubscription(client, subMessageHash, messageHash);
873
857
  if (symbol in this.trades) {
874
858
  delete this.trades[symbol];
875
859
  }
@@ -878,15 +862,7 @@ class hyperliquid extends hyperliquid$1 {
878
862
  //
879
863
  const subMessageHash = 'tickers';
880
864
  const messageHash = 'unsubscribe:' + subMessageHash;
881
- if (messageHash in client.subscriptions) {
882
- delete client.subscriptions[messageHash];
883
- }
884
- if (subMessageHash in client.subscriptions) {
885
- delete client.subscriptions[subMessageHash];
886
- }
887
- const error = new errors.UnsubscribeError(this.id + ' ' + subMessageHash);
888
- client.reject(error, subMessageHash);
889
- client.resolve(true, messageHash);
865
+ this.cleanUnsubscription(client, subMessageHash, messageHash);
890
866
  const symbols = Object.keys(this.tickers);
891
867
  for (let i = 0; i < symbols.length; i++) {
892
868
  delete this.tickers[symbols[i]];
@@ -900,15 +876,7 @@ class hyperliquid extends hyperliquid$1 {
900
876
  const timeframe = this.findTimeframe(interval);
901
877
  const subMessageHash = 'candles:' + timeframe + ':' + symbol;
902
878
  const messageHash = 'unsubscribe:' + subMessageHash;
903
- if (messageHash in client.subscriptions) {
904
- delete client.subscriptions[messageHash];
905
- }
906
- if (subMessageHash in client.subscriptions) {
907
- delete client.subscriptions[subMessageHash];
908
- }
909
- const error = new errors.UnsubscribeError(this.id + ' ' + subMessageHash);
910
- client.reject(error, subMessageHash);
911
- client.resolve(true, messageHash);
879
+ this.cleanUnsubscription(client, subMessageHash, messageHash);
912
880
  if (symbol in this.ohlcvs) {
913
881
  if (timeframe in this.ohlcvs[symbol]) {
914
882
  delete this.ohlcvs[symbol][timeframe];
@@ -535,8 +535,6 @@ class kucoin extends kucoin$1 {
535
535
  * @description unWatches trades stream
536
536
  * @see https://www.kucoin.com/docs/websocket/spot-trading/public-channels/match-execution-data
537
537
  * @param {string} symbol unified symbol of the market to fetch trades for
538
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
539
- * @param {int} [limit] the maximum amount of trades to fetch
540
538
  * @param {object} [params] extra parameters specific to the exchange API endpoint
541
539
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
542
540
  */
@@ -923,64 +921,9 @@ class kucoin extends kucoin$1 {
923
921
  for (let i = 0; i < messageHashes.length; i++) {
924
922
  const messageHash = messageHashes[i];
925
923
  const subHash = subMessageHashes[i];
926
- if (messageHash in client.subscriptions) {
927
- delete client.subscriptions[messageHash];
928
- }
929
- if (subHash in client.subscriptions) {
930
- delete client.subscriptions[subHash];
931
- }
932
- const error = new errors.UnsubscribeError(this.id + ' ' + subHash);
933
- client.reject(error, subHash);
934
- client.resolve(true, messageHash);
935
- this.cleanCache(subscription);
936
- }
937
- }
938
- }
939
- cleanCache(subscription) {
940
- const topic = this.safeString(subscription, 'topic');
941
- const symbols = this.safeList(subscription, 'symbols', []);
942
- const symbolsLength = symbols.length;
943
- if (symbolsLength > 0) {
944
- for (let i = 0; i < symbols.length; i++) {
945
- const symbol = symbols[i];
946
- if (topic === 'trades') {
947
- if (symbol in this.trades) {
948
- delete this.trades[symbol];
949
- }
950
- }
951
- else if (topic === 'orderbook') {
952
- if (symbol in this.orderbooks) {
953
- delete this.orderbooks[symbol];
954
- }
955
- }
956
- else if (topic === 'ticker') {
957
- if (symbol in this.tickers) {
958
- delete this.tickers[symbol];
959
- }
960
- }
961
- }
962
- }
963
- else {
964
- if (topic === 'myTrades') {
965
- // don't reset this.myTrades directly here
966
- // because in c# we need to use a different object
967
- const keys = Object.keys(this.myTrades);
968
- for (let i = 0; i < keys.length; i++) {
969
- delete this.myTrades[keys[i]];
970
- }
971
- }
972
- else if (topic === 'orders') {
973
- const orderSymbols = Object.keys(this.orders);
974
- for (let i = 0; i < orderSymbols.length; i++) {
975
- delete this.orders[orderSymbols[i]];
976
- }
977
- }
978
- else if (topic === 'ticker') {
979
- const tickerSymbols = Object.keys(this.tickers);
980
- for (let i = 0; i < tickerSymbols.length; i++) {
981
- delete this.tickers[tickerSymbols[i]];
982
- }
924
+ this.cleanUnsubscription(client, subHash, messageHash);
983
925
  }
926
+ this.cleanCache(subscription);
984
927
  }
985
928
  }
986
929
  handleSystemStatus(client, message) {
@@ -175,6 +175,27 @@ class kucoinfutures extends kucoinfutures$1 {
175
175
  };
176
176
  return await this.watchMultiple(url, messageHashes, this.extend(request, params), subscriptionHashes, subscriptionArgs);
177
177
  }
178
+ async unSubscribeMultiple(url, messageHashes, topic, subscriptionHashes, params = {}, subscription = undefined) {
179
+ const requestId = this.requestId().toString();
180
+ const request = {
181
+ 'id': requestId,
182
+ 'type': 'unsubscribe',
183
+ 'topic': topic,
184
+ 'response': true,
185
+ };
186
+ const message = this.extend(request, params);
187
+ if (subscription !== undefined) {
188
+ subscription[requestId] = requestId;
189
+ }
190
+ const client = this.client(url);
191
+ for (let i = 0; i < subscriptionHashes.length; i++) {
192
+ const subscriptionHash = subscriptionHashes[i];
193
+ if (!(subscriptionHash in client.subscriptions)) {
194
+ client.subscriptions[requestId] = subscriptionHash;
195
+ }
196
+ }
197
+ return await this.watchMultiple(url, messageHashes, message, subscriptionHashes, subscription);
198
+ }
178
199
  async watchTicker(symbol, params = {}) {
179
200
  /**
180
201
  * @method
@@ -518,7 +539,7 @@ class kucoinfutures extends kucoinfutures$1 {
518
539
  async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
519
540
  /**
520
541
  * @method
521
- * @name kucoinfutures#watchTrades
542
+ * @name kucoinfutures#watchTradesForSymbols
522
543
  * @description get the list of most recent trades for a particular symbol
523
544
  * @param {string} symbol unified symbol of the market to fetch trades for
524
545
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
@@ -552,6 +573,49 @@ class kucoinfutures extends kucoinfutures$1 {
552
573
  }
553
574
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
554
575
  }
576
+ async unWatchTrades(symbol, params = {}) {
577
+ /**
578
+ * @method
579
+ * @name kucoinfutures#unWatchTrades
580
+ * @description unWatches trades stream
581
+ * @see https://docs.kucoin.com/futures/#execution-data
582
+ * @param {string} symbol unified symbol of the market to fetch trades for
583
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
584
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
585
+ */
586
+ return await this.unWatchTradesForSymbols([symbol], params);
587
+ }
588
+ async unWatchTradesForSymbols(symbols, params = {}) {
589
+ /**
590
+ * @method
591
+ * @name kucoinfutures#unWatchTradesForSymbols
592
+ * @description get the list of most recent trades for a particular symbol
593
+ * @param {string} symbol unified symbol of the market to fetch trades for
594
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
595
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
596
+ */
597
+ await this.loadMarkets();
598
+ symbols = this.marketSymbols(symbols, undefined, false);
599
+ const url = await this.negotiate(false);
600
+ symbols = this.marketSymbols(symbols);
601
+ const marketIds = this.marketIds(symbols);
602
+ const topic = '/contractMarket/execution:' + marketIds.join(',');
603
+ const subscriptionHashes = [];
604
+ const messageHashes = [];
605
+ for (let i = 0; i < symbols.length; i++) {
606
+ const symbol = symbols[i];
607
+ messageHashes.push('unsubscribe:trades:' + symbol);
608
+ subscriptionHashes.push('trades:' + symbol);
609
+ }
610
+ const subscription = {
611
+ 'messageHashes': messageHashes,
612
+ 'subMessageHashes': subscriptionHashes,
613
+ 'topic': 'trades',
614
+ 'unsubscribe': true,
615
+ 'symbols': symbols,
616
+ };
617
+ return await this.unSubscribeMultiple(url, messageHashes, topic, messageHashes, params, subscription);
618
+ }
555
619
  handleTrade(client, message) {
556
620
  //
557
621
  // {
@@ -686,6 +750,7 @@ class kucoinfutures extends kucoinfutures$1 {
686
750
  * @method
687
751
  * @name kucoinfutures#watchOrderBookForSymbols
688
752
  * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
753
+ * @see https://docs.kucoin.com/futures/#level-2-market-data
689
754
  * @param {string[]} symbols unified array of symbols
690
755
  * @param {int} [limit] the maximum amount of order book entries to return
691
756
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -719,6 +784,48 @@ class kucoinfutures extends kucoinfutures$1 {
719
784
  const orderbook = await this.subscribeMultiple(url, messageHashes, topic, subscriptionHashes, subscriptionArgs, params);
720
785
  return orderbook.limit();
721
786
  }
787
+ async unWatchOrderBook(symbol, params = {}) {
788
+ /**
789
+ * @method
790
+ * @name kucoinfutures#unWatchOrderBook
791
+ * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
792
+ * @see https://docs.kucoin.com/futures/#level-2-market-data
793
+ * @param {string} symbol unified symbol of the market to fetch the order book for
794
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
795
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
796
+ */
797
+ return await this.unWatchOrderBookForSymbols([symbol], params);
798
+ }
799
+ async unWatchOrderBookForSymbols(symbols, params = {}) {
800
+ /**
801
+ * @method
802
+ * @name kucoinfutures#unWatchOrderBookForSymbols
803
+ * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
804
+ * @param {string[]} symbols unified array of symbols
805
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
806
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
807
+ */
808
+ await this.loadMarkets();
809
+ symbols = this.marketSymbols(symbols);
810
+ const marketIds = this.marketIds(symbols);
811
+ const url = await this.negotiate(false);
812
+ const topic = '/contractMarket/level2:' + marketIds.join(',');
813
+ const subscriptionHashes = [];
814
+ const messageHashes = [];
815
+ for (let i = 0; i < symbols.length; i++) {
816
+ const symbol = symbols[i];
817
+ messageHashes.push('unsubscribe:orderbook:' + symbol);
818
+ subscriptionHashes.push('orderbook:' + symbol);
819
+ }
820
+ const subscription = {
821
+ 'messageHashes': messageHashes,
822
+ 'symbols': symbols,
823
+ 'unsubscribe': true,
824
+ 'topic': 'orderbook',
825
+ 'subMessageHashes': subscriptionHashes,
826
+ };
827
+ return await this.unSubscribeMultiple(url, messageHashes, topic, messageHashes, params, subscription);
828
+ }
722
829
  handleDelta(orderbook, delta) {
723
830
  orderbook['nonce'] = this.safeInteger(delta, 'sequence');
724
831
  const timestamp = this.safeInteger(delta, 'timestamp');
@@ -1136,6 +1243,36 @@ class kucoinfutures extends kucoinfutures$1 {
1136
1243
  }
1137
1244
  this.handleErrors(undefined, undefined, client.url, undefined, undefined, data, message, undefined, undefined);
1138
1245
  }
1246
+ handleSubscriptionStatus(client, message) {
1247
+ //
1248
+ // {
1249
+ // "id": "1578090438322",
1250
+ // "type": "ack"
1251
+ // }
1252
+ //
1253
+ const id = this.safeString(message, 'id');
1254
+ if (!(id in client.subscriptions)) {
1255
+ return;
1256
+ }
1257
+ const subscriptionHash = this.safeString(client.subscriptions, id);
1258
+ const subscription = this.safeValue(client.subscriptions, subscriptionHash);
1259
+ delete client.subscriptions[id];
1260
+ const method = this.safeValue(subscription, 'method');
1261
+ if (method !== undefined) {
1262
+ method.call(this, client, message, subscription);
1263
+ }
1264
+ const isUnSub = this.safeBool(subscription, 'unsubscribe', false);
1265
+ if (isUnSub) {
1266
+ const messageHashes = this.safeList(subscription, 'messageHashes', []);
1267
+ const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
1268
+ for (let i = 0; i < messageHashes.length; i++) {
1269
+ const messageHash = messageHashes[i];
1270
+ const subHash = subMessageHashes[i];
1271
+ this.cleanUnsubscription(client, subHash, messageHash);
1272
+ }
1273
+ this.cleanCache(subscription);
1274
+ }
1275
+ }
1139
1276
  handleMessage(client, message) {
1140
1277
  const type = this.safeString(message, 'type');
1141
1278
  const methods = {
@@ -1144,6 +1281,7 @@ class kucoinfutures extends kucoinfutures$1 {
1144
1281
  'message': this.handleSubject,
1145
1282
  'pong': this.handlePong,
1146
1283
  'error': this.handleErrorMessage,
1284
+ 'ack': this.handleSubscriptionStatus,
1147
1285
  };
1148
1286
  const method = this.safeValue(methods, type);
1149
1287
  if (method !== undefined) {
@@ -2331,64 +2331,36 @@ class okx extends okx$1 {
2331
2331
  handleUnSubscriptionTrades(client, symbol) {
2332
2332
  const subMessageHash = 'trades:' + symbol;
2333
2333
  const messageHash = 'unsubscribe:trades:' + symbol;
2334
- if (subMessageHash in client.subscriptions) {
2335
- delete client.subscriptions[subMessageHash];
2334
+ this.cleanUnsubscription(client, subMessageHash, messageHash);
2335
+ if (symbol in this.trades) {
2336
+ delete this.trades[symbol];
2336
2337
  }
2337
- if (messageHash in client.subscriptions) {
2338
- delete client.subscriptions[messageHash];
2339
- }
2340
- delete this.trades[symbol];
2341
- const error = new errors.UnsubscribeError(this.id + ' ' + subMessageHash);
2342
- client.reject(error, subMessageHash);
2343
- client.resolve(true, messageHash);
2344
2338
  }
2345
2339
  handleUnsubscriptionOrderBook(client, symbol, channel) {
2346
2340
  const subMessageHash = channel + ':' + symbol;
2347
2341
  const messageHash = 'unsubscribe:orderbook:' + symbol;
2348
- if (subMessageHash in client.subscriptions) {
2349
- delete client.subscriptions[subMessageHash];
2350
- }
2351
- if (messageHash in client.subscriptions) {
2352
- delete client.subscriptions[messageHash];
2342
+ this.cleanUnsubscription(client, subMessageHash, messageHash);
2343
+ if (symbol in this.orderbooks) {
2344
+ delete this.orderbooks[symbol];
2353
2345
  }
2354
- delete this.orderbooks[symbol];
2355
- const error = new errors.UnsubscribeError(this.id + ' ' + subMessageHash);
2356
- client.reject(error, subMessageHash);
2357
- client.resolve(true, messageHash);
2358
2346
  }
2359
2347
  handleUnsubscriptionOHLCV(client, symbol, channel) {
2360
2348
  const tf = channel.replace('candle', '');
2361
2349
  const timeframe = this.findTimeframe(tf);
2362
2350
  const subMessageHash = 'multi:' + channel + ':' + symbol;
2363
2351
  const messageHash = 'unsubscribe:' + subMessageHash;
2364
- if (subMessageHash in client.subscriptions) {
2365
- delete client.subscriptions[subMessageHash];
2366
- }
2367
- if (messageHash in client.subscriptions) {
2368
- delete client.subscriptions[messageHash];
2369
- }
2352
+ this.cleanUnsubscription(client, subMessageHash, messageHash);
2370
2353
  if (timeframe in this.ohlcvs[symbol]) {
2371
2354
  delete this.ohlcvs[symbol][timeframe];
2372
2355
  }
2373
- const error = new errors.UnsubscribeError(this.id + ' ' + subMessageHash);
2374
- client.reject(error, subMessageHash);
2375
- client.resolve(true, messageHash);
2376
2356
  }
2377
2357
  handleUnsubscriptionTicker(client, symbol, channel) {
2378
2358
  const subMessageHash = channel + '::' + symbol;
2379
2359
  const messageHash = 'unsubscribe:ticker:' + symbol;
2380
- if (subMessageHash in client.subscriptions) {
2381
- delete client.subscriptions[subMessageHash];
2382
- }
2383
- if (messageHash in client.subscriptions) {
2384
- delete client.subscriptions[messageHash];
2385
- }
2360
+ this.cleanUnsubscription(client, subMessageHash, messageHash);
2386
2361
  if (symbol in this.tickers) {
2387
2362
  delete this.tickers[symbol];
2388
2363
  }
2389
- const error = new errors.UnsubscribeError(this.id + ' ' + subMessageHash);
2390
- client.reject(error, subMessageHash);
2391
- client.resolve(true, messageHash);
2392
2364
  }
2393
2365
  handleUnsubscription(client, message) {
2394
2366
  //
@@ -1372,7 +1372,7 @@ class xt extends xt$1 {
1372
1372
  this.safeNumber(ohlcv, 'h'),
1373
1373
  this.safeNumber(ohlcv, 'l'),
1374
1374
  this.safeNumber(ohlcv, 'c'),
1375
- this.safeNumber2(ohlcv, volumeIndex, 'v'),
1375
+ this.safeNumber2(ohlcv, 'q', volumeIndex),
1376
1376
  ];
1377
1377
  }
1378
1378
  async fetchOrderBook(symbol, limit = undefined, params = {}) {
@@ -11,6 +11,10 @@ const fsPromises = fs.promises;
11
11
  ansi.nice
12
12
  const log = ololog.configure ({ locate: false }).unlimited
13
13
  const { ExchangeError , NetworkError} = ccxt
14
+
15
+ function jsonStringify (obj, indent = undefined) {
16
+ return JSON.stringify (obj, function(k, v) { return v === undefined ? null : v; }, indent);
17
+ }
14
18
  //-----------------------------------------------------------------------------
15
19
 
16
20
  let [processPath, , exchangeId, methodName, ... params] = process.argv.filter (x => !x.startsWith ('--'))
@@ -164,7 +168,7 @@ function createResponseTemplate(exchange, methodName, args, result) {
164
168
  }
165
169
  log('Report: (paste inside static/response/' + exchange.id + '.json ->' + methodName + ')')
166
170
  log.green('-------------------------------------------')
167
- log (JSON.stringify (final, function(k, v) { return v === undefined ? null : v; }, 2))
171
+ log (jsonStringify (final, 2))
168
172
  log.green('-------------------------------------------')
169
173
  }
170
174
 
@@ -206,7 +210,7 @@ function printUsage () {
206
210
 
207
211
  const printHumanReadable = (exchange, result) => {
208
212
  if (raw) {
209
- return log (JSON.stringify(result))
213
+ return log (jsonStringify (result))
210
214
  }
211
215
  if (!no_table && Array.isArray (result) || table) {
212
216
  result = Object.values (result)
@@ -227,7 +231,7 @@ const printHumanReadable = (exchange, result) => {
227
231
  dash: '-'.lightGray.dim,
228
232
  print: x => {
229
233
  if (typeof x === 'object') {
230
- const j = JSON.stringify (x).trim ()
234
+ const j = jsonStringify (x).trim ()
231
235
  if (j.length < 100) return j
232
236
  }
233
237
  return String (x)
@@ -302,7 +306,7 @@ async function run () {
302
306
  } catch {
303
307
  await exchange.loadMarkets ()
304
308
  if (cache_markets) {
305
- await fsPromises.writeFile (path, JSON.stringify (exchange.markets))
309
+ await fsPromises.writeFile (path, jsonStringify (exchange.markets))
306
310
  }
307
311
  }
308
312
  }
package/js/ccxt.d.ts CHANGED
@@ -2,9 +2,9 @@ import { Exchange } from './src/base/Exchange.js';
2
2
  import { Precise } from './src/base/Precise.js';
3
3
  import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
- import type { Int, int, Str, Strings, Num, Bool, IndexType, OrderSide, OrderType, MarketType, SubType, Dict, NullableDict, List, NullableList, Fee, OHLCV, OHLCVC, implicitReturnType, Market, Currency, Dictionary, MinMax, FeeInterface, TradingFeeInterface, MarketInterface, Trade, Order, OrderBook, Ticker, Transaction, Tickers, CurrencyInterface, Balance, BalanceAccount, Account, PartialBalances, Balances, DepositAddress, WithdrawalResponse, DepositAddressResponse, FundingRate, FundingRates, Position, BorrowInterest, LeverageTier, LedgerEntry, DepositWithdrawFeeNetwork, DepositWithdrawFee, TransferEntry, CrossBorrowRate, IsolatedBorrowRate, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, CancellationRequest, FundingHistory, MarginMode, Greeks, Conversion, Option, LastPrice, Leverage, MarginModification, Leverages, LastPrices, Currencies, TradingFees, MarginModes, OptionChain, IsolatedBorrowRates, CrossBorrowRates, LeverageTiers } from './src/base/types.js';
5
+ import type { Int, int, Str, Strings, Num, Bool, IndexType, OrderSide, OrderType, MarketType, SubType, Dict, NullableDict, List, NullableList, Fee, OHLCV, OHLCVC, implicitReturnType, Market, Currency, Dictionary, MinMax, FeeInterface, TradingFeeInterface, MarketInterface, Trade, Order, OrderBook, Ticker, Transaction, Tickers, CurrencyInterface, Balance, BalanceAccount, Account, PartialBalances, Balances, DepositAddress, WithdrawalResponse, DepositAddressResponse, FundingRate, FundingRates, Position, BorrowInterest, LeverageTier, LedgerEntry, DepositWithdrawFeeNetwork, DepositWithdrawFee, TransferEntry, CrossBorrowRate, IsolatedBorrowRate, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, CancellationRequest, FundingHistory, MarketMarginModes, MarginMode, Greeks, Conversion, Option, LastPrice, Leverage, MarginModification, Leverages, LastPrices, Currencies, TradingFees, MarginModes, OptionChain, IsolatedBorrowRates, CrossBorrowRates, LeverageTiers } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError } from './src/base/errors.js';
7
- declare const version = "4.4.0";
7
+ declare const version = "4.4.1";
8
8
  import ace from './src/ace.js';
9
9
  import alpaca from './src/alpaca.js';
10
10
  import ascendex from './src/ascendex.js';
@@ -555,5 +555,5 @@ declare const ccxt: {
555
555
  zaif: typeof zaif;
556
556
  zonda: typeof zonda;
557
557
  } & typeof functions & typeof errors;
558
- export { version, Exchange, exchanges, pro, Precise, functions, errors, BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError, Int, int, Str, Strings, Num, Bool, IndexType, OrderSide, OrderType, MarketType, SubType, Dict, NullableDict, List, NullableList, Fee, OHLCV, OHLCVC, implicitReturnType, Market, Currency, Dictionary, MinMax, FeeInterface, TradingFeeInterface, MarketInterface, Trade, Order, OrderBook, Ticker, Transaction, Tickers, CurrencyInterface, Balance, BalanceAccount, Account, PartialBalances, Balances, DepositAddress, WithdrawalResponse, DepositAddressResponse, FundingRate, FundingRates, Position, BorrowInterest, LeverageTier, LedgerEntry, DepositWithdrawFeeNetwork, DepositWithdrawFee, TransferEntry, CrossBorrowRate, IsolatedBorrowRate, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, CancellationRequest, FundingHistory, MarginMode, Greeks, Conversion, Option, LastPrice, Leverage, MarginModification, Leverages, LastPrices, Currencies, TradingFees, MarginModes, OptionChain, IsolatedBorrowRates, CrossBorrowRates, LeverageTiers, ace, alpaca, ascendex, bequant, bigone, binance, binancecoinm, binanceus, binanceusdm, bingx, bit2c, bitbank, bitbns, bitcoincom, bitfinex, bitfinex2, bitflyer, bitget, bithumb, bitmart, bitmex, bitopro, bitpanda, bitrue, bitso, bitstamp, bitteam, bitvavo, bl3p, blockchaincom, blofin, btcalpha, btcbox, btcmarkets, btcturk, bybit, cex, coinbase, coinbaseadvanced, coinbaseexchange, coinbaseinternational, coincheck, coinex, coinlist, coinmate, coinmetro, coinone, coinsph, coinspot, cryptocom, currencycom, delta, deribit, digifinex, exmo, fmfwio, gate, gateio, gemini, hashkey, hitbtc, hollaex, htx, huobi, huobijp, hyperliquid, idex, independentreserve, indodax, kraken, krakenfutures, kucoin, kucoinfutures, kuna, latoken, lbank, luno, lykke, mercado, mexc, ndax, novadax, oceanex, okcoin, okx, onetrading, oxfun, p2b, paradex, paymium, phemex, poloniex, poloniexfutures, probit, timex, tokocrypto, tradeogre, upbit, vertex, wavesexchange, wazirx, whitebit, woo, woofipro, xt, yobit, zaif, zonda, };
558
+ export { version, Exchange, exchanges, pro, Precise, functions, errors, BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError, Int, int, Str, Strings, Num, Bool, IndexType, OrderSide, OrderType, MarketType, SubType, Dict, NullableDict, List, NullableList, Fee, OHLCV, OHLCVC, implicitReturnType, Market, Currency, Dictionary, MinMax, FeeInterface, TradingFeeInterface, MarketMarginModes, MarketInterface, Trade, Order, OrderBook, Ticker, Transaction, Tickers, CurrencyInterface, Balance, BalanceAccount, Account, PartialBalances, Balances, DepositAddress, WithdrawalResponse, DepositAddressResponse, FundingRate, FundingRates, Position, BorrowInterest, LeverageTier, LedgerEntry, DepositWithdrawFeeNetwork, DepositWithdrawFee, TransferEntry, CrossBorrowRate, IsolatedBorrowRate, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, CancellationRequest, FundingHistory, MarginMode, Greeks, Conversion, Option, LastPrice, Leverage, MarginModification, Leverages, LastPrices, Currencies, TradingFees, MarginModes, OptionChain, IsolatedBorrowRates, CrossBorrowRates, LeverageTiers, ace, alpaca, ascendex, bequant, bigone, binance, binancecoinm, binanceus, binanceusdm, bingx, bit2c, bitbank, bitbns, bitcoincom, bitfinex, bitfinex2, bitflyer, bitget, bithumb, bitmart, bitmex, bitopro, bitpanda, bitrue, bitso, bitstamp, bitteam, bitvavo, bl3p, blockchaincom, blofin, btcalpha, btcbox, btcmarkets, btcturk, bybit, cex, coinbase, coinbaseadvanced, coinbaseexchange, coinbaseinternational, coincheck, coinex, coinlist, coinmate, coinmetro, coinone, coinsph, coinspot, cryptocom, currencycom, delta, deribit, digifinex, exmo, fmfwio, gate, gateio, gemini, hashkey, hitbtc, hollaex, htx, huobi, huobijp, hyperliquid, idex, independentreserve, indodax, kraken, krakenfutures, kucoin, kucoinfutures, kuna, latoken, lbank, luno, lykke, mercado, mexc, ndax, novadax, oceanex, okcoin, okx, onetrading, oxfun, p2b, paradex, paymium, phemex, poloniex, poloniexfutures, probit, timex, tokocrypto, tradeogre, upbit, vertex, wavesexchange, wazirx, whitebit, woo, woofipro, xt, yobit, zaif, zonda, };
559
559
  export default ccxt;
package/js/ccxt.js CHANGED
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
38
38
  import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.4.1';
41
+ const version = '4.4.2';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';