ccxt 4.3.89 → 4.3.90

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 (57) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/alpaca.js +2 -2
  5. package/dist/cjs/src/ascendex.js +95 -97
  6. package/dist/cjs/src/bingx.js +31 -17
  7. package/dist/cjs/src/bitfinex2.js +21 -22
  8. package/dist/cjs/src/bitget.js +2 -2
  9. package/dist/cjs/src/bitmart.js +6 -9
  10. package/dist/cjs/src/coinbaseinternational.js +2 -1
  11. package/dist/cjs/src/coinex.js +1 -17
  12. package/dist/cjs/src/hitbtc.js +1 -0
  13. package/dist/cjs/src/htx.js +49 -49
  14. package/dist/cjs/src/huobijp.js +0 -9
  15. package/dist/cjs/src/latoken.js +1 -0
  16. package/dist/cjs/src/okx.js +1 -8
  17. package/dist/cjs/src/pro/binance.js +323 -0
  18. package/dist/cjs/src/pro/bingx.js +263 -91
  19. package/dist/cjs/src/pro/bithumb.js +5 -1
  20. package/dist/cjs/src/pro/bybit.js +1 -1
  21. package/dist/cjs/src/pro/coinex.js +994 -679
  22. package/dist/cjs/src/pro/lbank.js +2 -3
  23. package/dist/cjs/src/pro/okx.js +159 -3
  24. package/dist/cjs/src/whitebit.js +5 -3
  25. package/js/ccxt.d.ts +1 -1
  26. package/js/ccxt.js +1 -1
  27. package/js/src/alpaca.js +2 -2
  28. package/js/src/ascendex.js +95 -97
  29. package/js/src/bingx.js +31 -17
  30. package/js/src/bitfinex2.d.ts +0 -1
  31. package/js/src/bitfinex2.js +21 -22
  32. package/js/src/bitget.js +2 -2
  33. package/js/src/bitmart.d.ts +0 -1
  34. package/js/src/bitmart.js +6 -9
  35. package/js/src/coinbaseinternational.js +2 -1
  36. package/js/src/coinex.d.ts +0 -2
  37. package/js/src/coinex.js +1 -17
  38. package/js/src/hitbtc.js +1 -0
  39. package/js/src/htx.js +49 -49
  40. package/js/src/huobijp.d.ts +0 -1
  41. package/js/src/huobijp.js +0 -9
  42. package/js/src/latoken.js +1 -0
  43. package/js/src/okx.d.ts +0 -1
  44. package/js/src/okx.js +1 -8
  45. package/js/src/pro/binance.d.ts +9 -1
  46. package/js/src/pro/binance.js +327 -1
  47. package/js/src/pro/bingx.d.ts +2 -2
  48. package/js/src/pro/bingx.js +263 -91
  49. package/js/src/pro/bithumb.js +5 -1
  50. package/js/src/pro/bybit.js +1 -1
  51. package/js/src/pro/coinex.d.ts +12 -6
  52. package/js/src/pro/coinex.js +996 -681
  53. package/js/src/pro/lbank.js +2 -3
  54. package/js/src/pro/okx.d.ts +7 -0
  55. package/js/src/pro/okx.js +162 -4
  56. package/js/src/whitebit.js +5 -3
  57. package/package.json +1 -1
@@ -649,6 +649,81 @@ class binance extends binance$1 {
649
649
  const orderbook = await this.watchMultiple(url, messageHashes, this.extend(request, params), messageHashes, subscription);
650
650
  return orderbook.limit();
651
651
  }
652
+ async unWatchOrderBookForSymbols(symbols, params = {}) {
653
+ /**
654
+ * @method
655
+ * @name binance#unWatchOrderBookForSymbols
656
+ * @see https://binance-docs.github.io/apidocs/spot/en/#partial-book-depth-streams
657
+ * @see https://binance-docs.github.io/apidocs/spot/en/#diff-depth-stream
658
+ * @see https://binance-docs.github.io/apidocs/futures/en/#partial-book-depth-streams
659
+ * @see https://binance-docs.github.io/apidocs/futures/en/#diff-book-depth-streams
660
+ * @see https://binance-docs.github.io/apidocs/delivery/en/#partial-book-depth-streams
661
+ * @see https://binance-docs.github.io/apidocs/delivery/en/#diff-book-depth-streams
662
+ * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
663
+ * @param {string[]} symbols unified array of symbols
664
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
665
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
666
+ */
667
+ await this.loadMarkets();
668
+ symbols = this.marketSymbols(symbols, undefined, false, true, true);
669
+ const firstMarket = this.market(symbols[0]);
670
+ let type = firstMarket['type'];
671
+ if (firstMarket['contract']) {
672
+ type = firstMarket['linear'] ? 'future' : 'delivery';
673
+ }
674
+ const name = 'depth';
675
+ let streamHash = 'multipleOrderbook';
676
+ if (symbols !== undefined) {
677
+ streamHash += '::' + symbols.join(',');
678
+ }
679
+ const watchOrderBookRate = this.safeString(this.options, 'watchOrderBookRate', '100');
680
+ const subParams = [];
681
+ const subMessageHashes = [];
682
+ const messageHashes = [];
683
+ for (let i = 0; i < symbols.length; i++) {
684
+ const symbol = symbols[i];
685
+ const market = this.market(symbol);
686
+ subMessageHashes.push('orderbook::' + symbol);
687
+ messageHashes.push('unsubscribe:orderbook:' + symbol);
688
+ const subscriptionHash = market['lowercaseId'] + '@' + name;
689
+ const symbolHash = subscriptionHash + '@' + watchOrderBookRate + 'ms';
690
+ subParams.push(symbolHash);
691
+ }
692
+ const messageHashesLength = subMessageHashes.length;
693
+ const url = this.urls['api']['ws'][type] + '/' + this.stream(type, streamHash, messageHashesLength);
694
+ const requestId = this.requestId(url);
695
+ const request = {
696
+ 'method': 'UNSUBSCRIBE',
697
+ 'params': subParams,
698
+ 'id': requestId,
699
+ };
700
+ const subscription = {
701
+ 'unsubscribe': true,
702
+ 'id': requestId.toString(),
703
+ 'symbols': symbols,
704
+ 'subMessageHashes': subMessageHashes,
705
+ 'messageHashes': messageHashes,
706
+ 'topic': 'orderbook',
707
+ };
708
+ return await this.watchMultiple(url, messageHashes, this.extend(request, params), messageHashes, subscription);
709
+ }
710
+ async unWatchOrderBook(symbol, params = {}) {
711
+ /**
712
+ * @method
713
+ * @name binance#unWatchOrderBook
714
+ * @see https://binance-docs.github.io/apidocs/spot/en/#partial-book-depth-streams
715
+ * @see https://binance-docs.github.io/apidocs/spot/en/#diff-depth-stream
716
+ * @see https://binance-docs.github.io/apidocs/futures/en/#partial-book-depth-streams
717
+ * @see https://binance-docs.github.io/apidocs/futures/en/#diff-book-depth-streams
718
+ * @see https://binance-docs.github.io/apidocs/delivery/en/#partial-book-depth-streams
719
+ * @see https://binance-docs.github.io/apidocs/delivery/en/#diff-book-depth-streams
720
+ * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
721
+ * @param {string} symbol unified array of symbols
722
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
723
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
724
+ */
725
+ return await this.unWatchOrderBookForSymbols([symbol], params);
726
+ }
652
727
  async fetchOrderBookWs(symbol, limit = undefined, params = {}) {
653
728
  /**
654
729
  * @method
@@ -936,8 +1011,71 @@ class binance extends binance$1 {
936
1011
  if (method !== undefined) {
937
1012
  method.call(this, client, message, subscription);
938
1013
  }
1014
+ const isUnSubMessage = this.safeBool(subscription, 'unsubscribe', false);
1015
+ if (isUnSubMessage) {
1016
+ this.handleUnSubscription(client, subscription);
1017
+ }
939
1018
  return message;
940
1019
  }
1020
+ handleUnSubscription(client, subscription) {
1021
+ const messageHashes = this.safeList(subscription, 'messageHashes', []);
1022
+ const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
1023
+ for (let j = 0; j < messageHashes.length; j++) {
1024
+ const unsubHash = messageHashes[j];
1025
+ const subHash = subMessageHashes[j];
1026
+ if (unsubHash in client.subscriptions) {
1027
+ delete client.subscriptions[unsubHash];
1028
+ }
1029
+ if (subHash in client.subscriptions) {
1030
+ delete client.subscriptions[subHash];
1031
+ }
1032
+ const error = new errors.UnsubscribeError(this.id + ' ' + subHash);
1033
+ client.reject(error, subHash);
1034
+ client.resolve(true, unsubHash);
1035
+ this.cleanCache(subscription);
1036
+ }
1037
+ }
1038
+ cleanCache(subscription) {
1039
+ const topic = this.safeString(subscription, 'topic');
1040
+ const symbols = this.safeList(subscription, 'symbols', []);
1041
+ const symbolsLength = symbols.length;
1042
+ if (symbolsLength > 0) {
1043
+ for (let i = 0; i < symbols.length; i++) {
1044
+ const symbol = symbols[i];
1045
+ if (topic === 'trade') {
1046
+ delete this.trades[symbol];
1047
+ }
1048
+ else if (topic === 'orderbook') {
1049
+ delete this.orderbooks[symbol];
1050
+ }
1051
+ else if (topic === 'ticker') {
1052
+ delete this.tickers[symbol];
1053
+ }
1054
+ }
1055
+ }
1056
+ else {
1057
+ if (topic === 'myTrades') {
1058
+ // don't reset this.myTrades directly here
1059
+ // because in c# we need to use a different object
1060
+ const keys = Object.keys(this.myTrades);
1061
+ for (let i = 0; i < keys.length; i++) {
1062
+ delete this.myTrades[keys[i]];
1063
+ }
1064
+ }
1065
+ else if (topic === 'orders') {
1066
+ const orderSymbols = Object.keys(this.orders);
1067
+ for (let i = 0; i < orderSymbols.length; i++) {
1068
+ delete this.orders[orderSymbols[i]];
1069
+ }
1070
+ }
1071
+ else if (topic === 'ticker') {
1072
+ const tickerSymbols = Object.keys(this.tickers);
1073
+ for (let i = 0; i < tickerSymbols.length; i++) {
1074
+ delete this.tickers[tickerSymbols[i]];
1075
+ }
1076
+ }
1077
+ }
1078
+ }
941
1079
  async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
942
1080
  /**
943
1081
  * @method
@@ -1001,6 +1139,85 @@ class binance extends binance$1 {
1001
1139
  }
1002
1140
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
1003
1141
  }
1142
+ async unWatchTradesForSymbols(symbols, params = {}) {
1143
+ /**
1144
+ * @method
1145
+ * @name binance#unWatchTradesForSymbols
1146
+ * @description unsubscribes from the trades channel
1147
+ * @see https://binance-docs.github.io/apidocs/spot/en/#aggregate-trade-streams
1148
+ * @see https://binance-docs.github.io/apidocs/spot/en/#trade-streams
1149
+ * @see https://binance-docs.github.io/apidocs/futures/en/#aggregate-trade-streams
1150
+ * @see https://binance-docs.github.io/apidocs/delivery/en/#aggregate-trade-streams
1151
+ * @param {string[]} symbols unified symbol of the market to fetch trades for
1152
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1153
+ * @param {string} [params.name] the name of the method to call, 'trade' or 'aggTrade', default is 'trade'
1154
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
1155
+ */
1156
+ await this.loadMarkets();
1157
+ symbols = this.marketSymbols(symbols, undefined, false, true, true);
1158
+ let streamHash = 'multipleTrades';
1159
+ if (symbols !== undefined) {
1160
+ const symbolsLength = symbols.length;
1161
+ if (symbolsLength > 200) {
1162
+ throw new errors.BadRequest(this.id + ' watchTradesForSymbols() accepts 200 symbols at most. To watch more symbols call watchTradesForSymbols() multiple times');
1163
+ }
1164
+ streamHash += '::' + symbols.join(',');
1165
+ }
1166
+ let name = undefined;
1167
+ [name, params] = this.handleOptionAndParams(params, 'watchTradesForSymbols', 'name', 'trade');
1168
+ params = this.omit(params, 'callerMethodName');
1169
+ const firstMarket = this.market(symbols[0]);
1170
+ let type = firstMarket['type'];
1171
+ if (firstMarket['contract']) {
1172
+ type = firstMarket['linear'] ? 'future' : 'delivery';
1173
+ }
1174
+ const subMessageHashes = [];
1175
+ const subParams = [];
1176
+ const messageHashes = [];
1177
+ for (let i = 0; i < symbols.length; i++) {
1178
+ const symbol = symbols[i];
1179
+ const market = this.market(symbol);
1180
+ subMessageHashes.push('trade::' + symbol);
1181
+ messageHashes.push('unsubscribe:trade:' + symbol);
1182
+ const rawHash = market['lowercaseId'] + '@' + name;
1183
+ subParams.push(rawHash);
1184
+ }
1185
+ const query = this.omit(params, 'type');
1186
+ const subParamsLength = subParams.length;
1187
+ const url = this.urls['api']['ws'][type] + '/' + this.stream(type, streamHash, subParamsLength);
1188
+ const requestId = this.requestId(url);
1189
+ const request = {
1190
+ 'method': 'UNSUBSCRIBE',
1191
+ 'params': subParams,
1192
+ 'id': requestId,
1193
+ };
1194
+ const subscription = {
1195
+ 'unsubscribe': true,
1196
+ 'id': requestId.toString(),
1197
+ 'subMessageHashes': subMessageHashes,
1198
+ 'messageHashes': messageHashes,
1199
+ 'symbols': symbols,
1200
+ 'topic': 'trade',
1201
+ };
1202
+ return await this.watchMultiple(url, messageHashes, this.extend(request, query), messageHashes, subscription);
1203
+ }
1204
+ async unWatchTrades(symbol, params = {}) {
1205
+ /**
1206
+ * @method
1207
+ * @name binance#unWatchTrades
1208
+ * @description unsubscribes from the trades channel
1209
+ * @see https://binance-docs.github.io/apidocs/spot/en/#aggregate-trade-streams
1210
+ * @see https://binance-docs.github.io/apidocs/spot/en/#trade-streams
1211
+ * @see https://binance-docs.github.io/apidocs/futures/en/#aggregate-trade-streams
1212
+ * @see https://binance-docs.github.io/apidocs/delivery/en/#aggregate-trade-streams
1213
+ * @param {string} symbol unified symbol of the market to fetch trades for
1214
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1215
+ * @param {string} [params.name] the name of the method to call, 'trade' or 'aggTrade', default is 'trade'
1216
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
1217
+ */
1218
+ await this.loadMarkets();
1219
+ return await this.unWatchTradesForSymbols([symbol], params);
1220
+ }
1004
1221
  async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
1005
1222
  /**
1006
1223
  * @method
@@ -1534,6 +1751,112 @@ class binance extends binance$1 {
1534
1751
  }
1535
1752
  return this.filterByArray(this.tickers, 'symbol', symbols);
1536
1753
  }
1754
+ async unWatchTickers(symbols = undefined, params = {}) {
1755
+ /**
1756
+ * @method
1757
+ * @name binance#unWatchTickers
1758
+ * @see https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-mini-ticker-stream
1759
+ * @see https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-ticker-streams
1760
+ * @see https://binance-docs.github.io/apidocs/futures/en/#all-market-mini-tickers-stream
1761
+ * @see https://binance-docs.github.io/apidocs/futures/en/#individual-symbol-ticker-streams
1762
+ * @see https://binance-docs.github.io/apidocs/delivery/en/#all-market-mini-tickers-stream
1763
+ * @see https://binance-docs.github.io/apidocs/delivery/en/#individual-symbol-ticker-streams
1764
+ * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
1765
+ * @param {string[]} symbols unified symbol of the market to fetch the ticker for
1766
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1767
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1768
+ */
1769
+ let channelName = undefined;
1770
+ [channelName, params] = this.handleOptionAndParams(params, 'watchTickers', 'name', 'ticker');
1771
+ if (channelName === 'bookTicker') {
1772
+ throw new errors.BadRequest(this.id + ' deprecation notice - to subscribe for bids-asks, use watch_bids_asks() method instead');
1773
+ }
1774
+ await this.loadMarkets();
1775
+ const methodName = 'watchTickers';
1776
+ symbols = this.marketSymbols(symbols, undefined, true, false, true);
1777
+ let firstMarket = undefined;
1778
+ let marketType = undefined;
1779
+ const symbolsDefined = (symbols !== undefined);
1780
+ if (symbolsDefined) {
1781
+ firstMarket = this.market(symbols[0]);
1782
+ }
1783
+ [marketType, params] = this.handleMarketTypeAndParams(methodName, firstMarket, params);
1784
+ let subType = undefined;
1785
+ [subType, params] = this.handleSubTypeAndParams(methodName, firstMarket, params);
1786
+ let rawMarketType = undefined;
1787
+ if (this.isLinear(marketType, subType)) {
1788
+ rawMarketType = 'future';
1789
+ }
1790
+ else if (this.isInverse(marketType, subType)) {
1791
+ rawMarketType = 'delivery';
1792
+ }
1793
+ else if (marketType === 'spot') {
1794
+ rawMarketType = marketType;
1795
+ }
1796
+ else {
1797
+ throw new errors.NotSupported(this.id + ' ' + methodName + '() does not support options markets');
1798
+ }
1799
+ const isBidAsk = (channelName === 'bookTicker');
1800
+ const subscriptionArgs = [];
1801
+ const subMessageHashes = [];
1802
+ if (symbolsDefined) {
1803
+ for (let i = 0; i < symbols.length; i++) {
1804
+ const symbol = symbols[i];
1805
+ const market = this.market(symbol);
1806
+ subscriptionArgs.push(market['lowercaseId'] + '@' + channelName);
1807
+ subMessageHashes.push(this.getMessageHash(channelName, market['symbol'], isBidAsk));
1808
+ }
1809
+ }
1810
+ else {
1811
+ if (isBidAsk) {
1812
+ if (marketType === 'spot') {
1813
+ throw new errors.ArgumentsRequired(this.id + ' ' + methodName + '() requires symbols for this channel for spot markets');
1814
+ }
1815
+ subscriptionArgs.push('!' + channelName);
1816
+ }
1817
+ else {
1818
+ subscriptionArgs.push('!' + channelName + '@arr');
1819
+ }
1820
+ subMessageHashes.push(this.getMessageHash(channelName, undefined, isBidAsk));
1821
+ }
1822
+ let streamHash = channelName;
1823
+ if (symbolsDefined) {
1824
+ streamHash = channelName + '::' + symbols.join(',');
1825
+ }
1826
+ const url = this.urls['api']['ws'][rawMarketType] + '/' + this.stream(rawMarketType, streamHash);
1827
+ const requestId = this.requestId(url);
1828
+ const request = {
1829
+ 'method': 'UNSUBSCRIBE',
1830
+ 'params': subscriptionArgs,
1831
+ 'id': requestId,
1832
+ };
1833
+ const subscription = {
1834
+ 'unsubscribe': true,
1835
+ 'id': requestId.toString(),
1836
+ 'subMessageHashes': subMessageHashes,
1837
+ 'messageHashes': subMessageHashes,
1838
+ 'symbols': symbols,
1839
+ 'topic': 'ticker',
1840
+ };
1841
+ return await this.watchMultiple(url, subMessageHashes, this.extend(request, params), subMessageHashes, subscription);
1842
+ }
1843
+ async unWatchTicker(symbol, params = {}) {
1844
+ /**
1845
+ * @method
1846
+ * @name binance#unWatchTicker
1847
+ * @see https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-mini-ticker-stream
1848
+ * @see https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-ticker-streams
1849
+ * @see https://binance-docs.github.io/apidocs/futures/en/#all-market-mini-tickers-stream
1850
+ * @see https://binance-docs.github.io/apidocs/futures/en/#individual-symbol-ticker-streams
1851
+ * @see https://binance-docs.github.io/apidocs/delivery/en/#all-market-mini-tickers-stream
1852
+ * @see https://binance-docs.github.io/apidocs/delivery/en/#individual-symbol-ticker-streams
1853
+ * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
1854
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
1855
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1856
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1857
+ */
1858
+ return await this.unWatchTickers([symbol], params);
1859
+ }
1537
1860
  async watchBidsAsks(symbols = undefined, params = {}) {
1538
1861
  /**
1539
1862
  * @method