ccxt 4.3.95 → 4.3.97

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 (55) hide show
  1. package/README.md +4 -4
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -7
  4. package/dist/cjs/src/base/Exchange.js +0 -4
  5. package/dist/cjs/src/binance.js +3 -0
  6. package/dist/cjs/src/bingx.js +2 -1
  7. package/dist/cjs/src/blofin.js +0 -1
  8. package/dist/cjs/src/bybit.js +8 -2
  9. package/dist/cjs/src/coinex.js +16 -3
  10. package/dist/cjs/src/hyperliquid.js +262 -32
  11. package/dist/cjs/src/kucoin.js +12 -12
  12. package/dist/cjs/src/mexc.js +6 -0
  13. package/dist/cjs/src/okx.js +0 -1
  14. package/dist/cjs/src/p2b.js +0 -1
  15. package/dist/cjs/src/pro/binance.js +100 -2
  16. package/dist/cjs/src/pro/bybit.js +65 -4
  17. package/dist/cjs/src/pro/cryptocom.js +224 -0
  18. package/dist/cjs/src/pro/gate.js +179 -0
  19. package/dist/cjs/src/pro/kucoin.js +132 -0
  20. package/dist/cjs/src/pro/okx.js +264 -35
  21. package/dist/cjs/src/tradeogre.js +0 -1
  22. package/js/ccxt.d.ts +2 -8
  23. package/js/ccxt.js +2 -6
  24. package/js/src/base/Exchange.d.ts +0 -2
  25. package/js/src/base/Exchange.js +0 -4
  26. package/js/src/binance.js +3 -0
  27. package/js/src/bingx.js +2 -1
  28. package/js/src/blofin.js +0 -1
  29. package/js/src/bybit.js +8 -2
  30. package/js/src/coinex.js +16 -3
  31. package/js/src/hyperliquid.d.ts +22 -0
  32. package/js/src/hyperliquid.js +262 -32
  33. package/js/src/kucoin.d.ts +1 -1
  34. package/js/src/kucoin.js +12 -12
  35. package/js/src/mexc.js +6 -0
  36. package/js/src/okx.js +0 -1
  37. package/js/src/p2b.js +0 -1
  38. package/js/src/pro/binance.d.ts +2 -0
  39. package/js/src/pro/binance.js +100 -2
  40. package/js/src/pro/bybit.d.ts +3 -1
  41. package/js/src/pro/bybit.js +65 -4
  42. package/js/src/pro/cryptocom.d.ts +10 -1
  43. package/js/src/pro/cryptocom.js +225 -1
  44. package/js/src/pro/gate.d.ts +7 -1
  45. package/js/src/pro/gate.js +180 -1
  46. package/js/src/pro/kucoin.d.ts +5 -1
  47. package/js/src/pro/kucoin.js +133 -1
  48. package/js/src/pro/okx.d.ts +10 -1
  49. package/js/src/pro/okx.js +264 -35
  50. package/js/src/tradeogre.js +0 -1
  51. package/package.json +1 -1
  52. package/js/src/abstract/bitbay.d.ts +0 -56
  53. package/js/src/abstract/bitbay.js +0 -11
  54. package/js/src/abstract/hitbtc3.d.ts +0 -118
  55. package/js/src/abstract/hitbtc3.js +0 -11
@@ -385,6 +385,34 @@ class gate extends gate$1 {
385
385
  const orderbook = await this.subscribePublic(url, messageHash, payload, channel, query, subscription);
386
386
  return orderbook.limit();
387
387
  }
388
+ async unWatchOrderBook(symbol, params = {}) {
389
+ /**
390
+ * @method
391
+ * @name gate#unWatchOrderBook
392
+ * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
393
+ * @param {string} symbol unified symbol of the market to fetch the order book for
394
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
395
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
396
+ */
397
+ await this.loadMarkets();
398
+ const market = this.market(symbol);
399
+ symbol = market['symbol'];
400
+ const marketId = market['id'];
401
+ let interval = '100ms';
402
+ [interval, params] = this.handleOptionAndParams(params, 'watchOrderBook', 'interval', interval);
403
+ const messageType = this.getTypeByMarket(market);
404
+ const channel = messageType + '.order_book_update';
405
+ const subMessageHash = 'orderbook' + ':' + symbol;
406
+ const messageHash = 'unsubscribe:orderbook' + ':' + symbol;
407
+ const url = this.getUrlByMarket(market);
408
+ const payload = [marketId, interval];
409
+ const limit = this.safeInteger(params, 'limit', 100);
410
+ if (market['contract']) {
411
+ const stringLimit = limit.toString();
412
+ payload.push(stringLimit);
413
+ }
414
+ return await this.unSubscribePublicMultiple(url, 'orderbook', [symbol], [messageHash], [subMessageHash], payload, channel, params);
415
+ }
388
416
  handleOrderBookSubscription(client, message, subscription) {
389
417
  const symbol = this.safeString(subscription, 'symbol');
390
418
  const limit = this.safeInteger(subscription, 'limit');
@@ -717,6 +745,42 @@ class gate extends gate$1 {
717
745
  }
718
746
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
719
747
  }
748
+ async unWatchTradesForSymbols(symbols, params = {}) {
749
+ /**
750
+ * @method
751
+ * @name gate#unWatchTradesForSymbols
752
+ * @description get the list of most recent trades for a particular symbol
753
+ * @param {string} symbol unified symbol of the market to fetch trades for
754
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
755
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
756
+ */
757
+ await this.loadMarkets();
758
+ symbols = this.marketSymbols(symbols);
759
+ const marketIds = this.marketIds(symbols);
760
+ const market = this.market(symbols[0]);
761
+ const messageType = this.getTypeByMarket(market);
762
+ const channel = messageType + '.trades';
763
+ const subMessageHashes = [];
764
+ const messageHashes = [];
765
+ for (let i = 0; i < symbols.length; i++) {
766
+ const symbol = symbols[i];
767
+ subMessageHashes.push('trades:' + symbol);
768
+ messageHashes.push('unsubscribe:trades:' + symbol);
769
+ }
770
+ const url = this.getUrlByMarket(market);
771
+ return await this.unSubscribePublicMultiple(url, 'trades', symbols, messageHashes, subMessageHashes, marketIds, channel, params);
772
+ }
773
+ async unWatchTrades(symbol, params = {}) {
774
+ /**
775
+ * @method
776
+ * @name gate#unWatchTrades
777
+ * @description get the list of most recent trades for a particular symbol
778
+ * @param {string} symbol unified symbol of the market to fetch trades for
779
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
780
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
781
+ */
782
+ return await this.unWatchTradesForSymbols([symbol], params);
783
+ }
720
784
  handleTrades(client, message) {
721
785
  //
722
786
  // {
@@ -1558,6 +1622,96 @@ class gate extends gate$1 {
1558
1622
  delete client.subscriptions[id];
1559
1623
  }
1560
1624
  }
1625
+ handleUnSubscribe(client, message) {
1626
+ //
1627
+ // {
1628
+ // "time":1725534679,
1629
+ // "time_ms":1725534679786,
1630
+ // "id":2,
1631
+ // "conn_id":"fac539b443fd7002",
1632
+ // "trace_id":"efe1d282b630b4aa266b84bee177791a",
1633
+ // "channel":"spot.trades",
1634
+ // "event":"unsubscribe",
1635
+ // "payload":[
1636
+ // "LTC_USDT"
1637
+ // ],
1638
+ // "result":{
1639
+ // "status":"success"
1640
+ // },
1641
+ // "requestId":"efe1d282b630b4aa266b84bee177791a"
1642
+ // }
1643
+ //
1644
+ const id = this.safeString(message, 'id');
1645
+ const keys = Object.keys(client.subscriptions);
1646
+ for (let i = 0; i < keys.length; i++) {
1647
+ const messageHash = keys[i];
1648
+ if (!(messageHash in client.subscriptions)) {
1649
+ continue;
1650
+ // the previous iteration can have deleted the messageHash from the subscriptions
1651
+ }
1652
+ if (messageHash.startsWith('unsubscribe')) {
1653
+ const subscription = client.subscriptions[messageHash];
1654
+ const subId = this.safeString(subscription, 'id');
1655
+ if (id !== subId) {
1656
+ continue;
1657
+ }
1658
+ const messageHashes = this.safeList(subscription, 'messageHashes', []);
1659
+ const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
1660
+ for (let j = 0; j < messageHashes.length; j++) {
1661
+ const unsubHash = messageHashes[j];
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);
1672
+ }
1673
+ this.cleanCache(subscription);
1674
+ }
1675
+ }
1676
+ }
1677
+ cleanCache(subscription) {
1678
+ const topic = this.safeString(subscription, 'topic', '');
1679
+ const symbols = this.safeList(subscription, 'symbols', []);
1680
+ const symbolsLength = symbols.length;
1681
+ if (topic === 'ohlcv') {
1682
+ const symbolsAndTimeFrames = this.safeList(subscription, 'symbolsAndTimeframes', []);
1683
+ for (let i = 0; i < symbolsAndTimeFrames.length; i++) {
1684
+ const symbolAndTimeFrame = symbolsAndTimeFrames[i];
1685
+ const symbol = this.safeString(symbolAndTimeFrame, 0);
1686
+ const timeframe = this.safeString(symbolAndTimeFrame, 1);
1687
+ delete this.ohlcvs[symbol][timeframe];
1688
+ }
1689
+ }
1690
+ else if (symbolsLength > 0) {
1691
+ for (let i = 0; i < symbols.length; i++) {
1692
+ const symbol = symbols[i];
1693
+ if (topic.endsWith('trades')) {
1694
+ delete this.trades[symbol];
1695
+ }
1696
+ else if (topic === 'orderbook') {
1697
+ delete this.orderbooks[symbol];
1698
+ }
1699
+ else if (topic === 'ticker') {
1700
+ delete this.tickers[symbol];
1701
+ }
1702
+ }
1703
+ }
1704
+ else {
1705
+ if (topic.endsWith('trades')) {
1706
+ // don't reset this.myTrades directly here
1707
+ // because in c# we need to use a different object
1708
+ const keys = Object.keys(this.trades);
1709
+ for (let i = 0; i < keys.length; i++) {
1710
+ delete this.trades[keys[i]];
1711
+ }
1712
+ }
1713
+ }
1714
+ }
1561
1715
  handleMessage(client, message) {
1562
1716
  //
1563
1717
  // subscribe
@@ -1656,6 +1810,10 @@ class gate extends gate$1 {
1656
1810
  this.handleSubscriptionStatus(client, message);
1657
1811
  return;
1658
1812
  }
1813
+ if (event === 'unsubscribe') {
1814
+ this.handleUnSubscribe(client, message);
1815
+ return;
1816
+ }
1659
1817
  const channel = this.safeString(message, 'channel', '');
1660
1818
  const channelParts = channel.split('.');
1661
1819
  const channelType = this.safeValue(channelParts, 1);
@@ -1775,6 +1933,27 @@ class gate extends gate$1 {
1775
1933
  const message = this.extend(request, params);
1776
1934
  return await this.watchMultiple(url, messageHashes, message, messageHashes);
1777
1935
  }
1936
+ async unSubscribePublicMultiple(url, topic, symbols, messageHashes, subMessageHashes, payload, channel, params = {}) {
1937
+ const requestId = this.requestId();
1938
+ const time = this.seconds();
1939
+ const request = {
1940
+ 'id': requestId,
1941
+ 'time': time,
1942
+ 'channel': channel,
1943
+ 'event': 'unsubscribe',
1944
+ 'payload': payload,
1945
+ };
1946
+ const sub = {
1947
+ 'id': requestId.toString(),
1948
+ 'topic': topic,
1949
+ 'unsubscribe': true,
1950
+ 'messageHashes': messageHashes,
1951
+ 'subMessageHashes': subMessageHashes,
1952
+ 'symbols': symbols,
1953
+ };
1954
+ const message = this.extend(request, params);
1955
+ return await this.watchMultiple(url, messageHashes, message, messageHashes, sub);
1956
+ }
1778
1957
  async authenticate(url, messageType) {
1779
1958
  const channel = messageType + '.login';
1780
1959
  const client = this.client(url);
@@ -154,6 +154,27 @@ class kucoin extends kucoin$1 {
154
154
  }
155
155
  return await this.watchMultiple(url, messageHashes, message, subscriptionHashes, subscription);
156
156
  }
157
+ async unSubscribeMultiple(url, messageHashes, topic, subscriptionHashes, params = {}, subscription = undefined) {
158
+ const requestId = this.requestId().toString();
159
+ const request = {
160
+ 'id': requestId,
161
+ 'type': 'unsubscribe',
162
+ 'topic': topic,
163
+ 'response': true,
164
+ };
165
+ const message = this.extend(request, params);
166
+ if (subscription !== undefined) {
167
+ subscription[requestId] = requestId;
168
+ }
169
+ const client = this.client(url);
170
+ for (let i = 0; i < subscriptionHashes.length; i++) {
171
+ const subscriptionHash = subscriptionHashes[i];
172
+ if (!(subscriptionHash in client.subscriptions)) {
173
+ client.subscriptions[requestId] = subscriptionHash;
174
+ }
175
+ }
176
+ return await this.watchMultiple(url, messageHashes, message, subscriptionHashes, subscription);
177
+ }
157
178
  async watchTicker(symbol, params = {}) {
158
179
  /**
159
180
  * @method
@@ -507,6 +528,51 @@ class kucoin extends kucoin$1 {
507
528
  }
508
529
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
509
530
  }
531
+ async unWatchTradesForSymbols(symbols, params = {}) {
532
+ /**
533
+ * @method
534
+ * @name kucoin#unWatchTradesForSymbols
535
+ * @description unWatches trades stream
536
+ * @see https://www.kucoin.com/docs/websocket/spot-trading/public-channels/match-execution-data
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
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
541
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
542
+ */
543
+ await this.loadMarkets();
544
+ symbols = this.marketSymbols(symbols, undefined, false);
545
+ const marketIds = this.marketIds(symbols);
546
+ const url = await this.negotiate(false);
547
+ const messageHashes = [];
548
+ const subscriptionHashes = [];
549
+ const topic = '/market/match:' + marketIds.join(',');
550
+ for (let i = 0; i < symbols.length; i++) {
551
+ const symbol = symbols[i];
552
+ messageHashes.push('unsubscribe:trades:' + symbol);
553
+ subscriptionHashes.push('trades:' + symbol);
554
+ }
555
+ const subscription = {
556
+ 'messageHashes': messageHashes,
557
+ 'subMessageHashes': subscriptionHashes,
558
+ 'topic': 'trades',
559
+ 'unsubscribe': true,
560
+ 'symbols': symbols,
561
+ };
562
+ return await this.unSubscribeMultiple(url, messageHashes, topic, messageHashes, params, subscription);
563
+ }
564
+ async unWatchTrades(symbol, params = {}) {
565
+ /**
566
+ * @method
567
+ * @name kucoin#unWatchTrades
568
+ * @description unWatches trades stream
569
+ * @see https://www.kucoin.com/docs/websocket/spot-trading/public-channels/match-execution-data
570
+ * @param {string} symbol unified symbol of the market to fetch trades for
571
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
572
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
573
+ */
574
+ return await this.unWatchTradesForSymbols([symbol], params);
575
+ }
510
576
  handleTrade(client, message) {
511
577
  //
512
578
  // {
@@ -791,6 +857,72 @@ class kucoin extends kucoin$1 {
791
857
  if (method !== undefined) {
792
858
  method.call(this, client, message, subscription);
793
859
  }
860
+ const isUnSub = this.safeBool(subscription, 'unsubscribe', false);
861
+ if (isUnSub) {
862
+ const messageHashes = this.safeList(subscription, 'messageHashes', []);
863
+ const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
864
+ for (let i = 0; i < messageHashes.length; i++) {
865
+ const messageHash = messageHashes[i];
866
+ const subHash = subMessageHashes[i];
867
+ if (messageHash in client.subscriptions) {
868
+ delete client.subscriptions[messageHash];
869
+ }
870
+ if (subHash in client.subscriptions) {
871
+ delete client.subscriptions[subHash];
872
+ }
873
+ const error = new errors.UnsubscribeError(this.id + ' ' + subHash);
874
+ client.reject(error, subHash);
875
+ client.resolve(true, messageHash);
876
+ this.cleanCache(subscription);
877
+ }
878
+ }
879
+ }
880
+ cleanCache(subscription) {
881
+ const topic = this.safeString(subscription, 'topic');
882
+ const symbols = this.safeList(subscription, 'symbols', []);
883
+ const symbolsLength = symbols.length;
884
+ if (symbolsLength > 0) {
885
+ for (let i = 0; i < symbols.length; i++) {
886
+ const symbol = symbols[i];
887
+ if (topic === 'trades') {
888
+ if (symbol in this.trades) {
889
+ delete this.trades[symbol];
890
+ }
891
+ }
892
+ else if (topic === 'orderbook') {
893
+ if (symbol in this.orderbooks) {
894
+ delete this.orderbooks[symbol];
895
+ }
896
+ }
897
+ else if (topic === 'ticker') {
898
+ if (symbol in this.tickers) {
899
+ delete this.tickers[symbol];
900
+ }
901
+ }
902
+ }
903
+ }
904
+ else {
905
+ if (topic === 'myTrades') {
906
+ // don't reset this.myTrades directly here
907
+ // because in c# we need to use a different object
908
+ const keys = Object.keys(this.myTrades);
909
+ for (let i = 0; i < keys.length; i++) {
910
+ delete this.myTrades[keys[i]];
911
+ }
912
+ }
913
+ else if (topic === 'orders') {
914
+ const orderSymbols = Object.keys(this.orders);
915
+ for (let i = 0; i < orderSymbols.length; i++) {
916
+ delete this.orders[orderSymbols[i]];
917
+ }
918
+ }
919
+ else if (topic === 'ticker') {
920
+ const tickerSymbols = Object.keys(this.tickers);
921
+ for (let i = 0; i < tickerSymbols.length; i++) {
922
+ delete this.tickers[tickerSymbols[i]];
923
+ }
924
+ }
925
+ }
794
926
  }
795
927
  handleSystemStatus(client, message) {
796
928
  //