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
package/dist/cjs/ccxt.js CHANGED
@@ -194,7 +194,7 @@ var xt$1 = require('./src/pro/xt.js');
194
194
 
195
195
  //-----------------------------------------------------------------------------
196
196
  // this is updated by vss.js when building
197
- const version = '4.4.1';
197
+ const version = '4.4.2';
198
198
  Exchange["default"].ccxtVersion = version;
199
199
  const exchanges = {
200
200
  'ace': ace,
@@ -2398,6 +2398,10 @@ class Exchange {
2398
2398
  'max': undefined,
2399
2399
  },
2400
2400
  },
2401
+ 'marginModes': {
2402
+ 'cross': undefined,
2403
+ 'isolated': undefined,
2404
+ },
2401
2405
  'created': undefined,
2402
2406
  'info': undefined,
2403
2407
  };
@@ -6504,6 +6508,71 @@ class Exchange {
6504
6508
  */
6505
6509
  throw new errors.NotSupported(this.id + ' fetchTransfers () is not supported yet');
6506
6510
  }
6511
+ cleanUnsubscription(client, subHash, unsubHash) {
6512
+ if (unsubHash in client.subscriptions) {
6513
+ delete client.subscriptions[unsubHash];
6514
+ }
6515
+ if (subHash in client.subscriptions) {
6516
+ delete client.subscriptions[subHash];
6517
+ }
6518
+ if (subHash in client.futures) {
6519
+ const error = new errors.UnsubscribeError(this.id + ' ' + subHash);
6520
+ client.reject(error, subHash);
6521
+ }
6522
+ client.resolve(true, unsubHash);
6523
+ }
6524
+ cleanCache(subscription) {
6525
+ const topic = this.safeString(subscription, 'topic');
6526
+ const symbols = this.safeList(subscription, 'symbols', []);
6527
+ const symbolsLength = symbols.length;
6528
+ if (topic === 'ohlcv') {
6529
+ const symbolsAndTimeFrames = this.safeList(subscription, 'symbolsAndTimeframes', []);
6530
+ for (let i = 0; i < symbolsAndTimeFrames.length; i++) {
6531
+ const symbolAndTimeFrame = symbolsAndTimeFrames[i];
6532
+ const symbol = this.safeString(symbolAndTimeFrame, 0);
6533
+ const timeframe = this.safeString(symbolAndTimeFrame, 1);
6534
+ if (timeframe in this.ohlcvs[symbol]) {
6535
+ delete this.ohlcvs[symbol][timeframe];
6536
+ }
6537
+ }
6538
+ }
6539
+ else if (symbolsLength > 0) {
6540
+ for (let i = 0; i < symbols.length; i++) {
6541
+ const symbol = symbols[i];
6542
+ if (topic === 'trades') {
6543
+ delete this.trades[symbol];
6544
+ }
6545
+ else if (topic === 'orderbook') {
6546
+ delete this.orderbooks[symbol];
6547
+ }
6548
+ else if (topic === 'ticker') {
6549
+ delete this.tickers[symbol];
6550
+ }
6551
+ }
6552
+ }
6553
+ else {
6554
+ if (topic === 'myTrades') {
6555
+ // don't reset this.myTrades directly here
6556
+ // because in c# we need to use a different object
6557
+ const keys = Object.keys(this.myTrades);
6558
+ for (let i = 0; i < keys.length; i++) {
6559
+ delete this.myTrades[keys[i]];
6560
+ }
6561
+ }
6562
+ else if (topic === 'orders') {
6563
+ const orderSymbols = Object.keys(this.orders);
6564
+ for (let i = 0; i < orderSymbols.length; i++) {
6565
+ delete this.orders[orderSymbols[i]];
6566
+ }
6567
+ }
6568
+ else if (topic === 'ticker') {
6569
+ const tickerSymbols = Object.keys(this.tickers);
6570
+ for (let i = 0; i < tickerSymbols.length; i++) {
6571
+ delete this.tickers[tickerSymbols[i]];
6572
+ }
6573
+ }
6574
+ }
6575
+ }
6507
6576
  }
6508
6577
 
6509
6578
  exports.Exchange = Exchange;
@@ -2641,6 +2641,7 @@ class binance extends binance$1 {
2641
2641
  * @name binance#fetchCurrencies
2642
2642
  * @description fetches all available currencies on an exchange
2643
2643
  * @see https://developers.binance.com/docs/wallet/capital/all-coins-info
2644
+ * @see https://developers.binance.com/docs/margin_trading/market-data/Get-All-Margin-Assets
2644
2645
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2645
2646
  * @returns {object} an associative dictionary of currencies
2646
2647
  */
@@ -2660,9 +2661,13 @@ class binance extends binance$1 {
2660
2661
  if (apiBackup !== undefined) {
2661
2662
  return undefined;
2662
2663
  }
2663
- const response = await this.sapiGetCapitalConfigGetall(params);
2664
+ const promises = [this.sapiGetCapitalConfigGetall(params), this.sapiGetMarginAllAssets(params)];
2665
+ const results = await Promise.all(promises);
2666
+ const responseCurrencies = results[0];
2667
+ const responseMarginables = results[1];
2668
+ const marginablesById = this.indexBy(responseMarginables, 'assetName');
2664
2669
  const result = {};
2665
- for (let i = 0; i < response.length; i++) {
2670
+ for (let i = 0; i < responseCurrencies.length; i++) {
2666
2671
  //
2667
2672
  // {
2668
2673
  // "coin": "LINK",
@@ -2758,7 +2763,7 @@ class binance extends binance$1 {
2758
2763
  // ]
2759
2764
  // }
2760
2765
  //
2761
- const entry = response[i];
2766
+ const entry = responseCurrencies[i];
2762
2767
  const id = this.safeString(entry, 'coin');
2763
2768
  const name = this.safeString(entry, 'name');
2764
2769
  const code = this.safeCurrencyCode(id);
@@ -2813,6 +2818,17 @@ class binance extends binance$1 {
2813
2818
  }
2814
2819
  const trading = this.safeBool(entry, 'trading');
2815
2820
  const active = (isWithdrawEnabled && isDepositEnabled && trading);
2821
+ const marginEntry = this.safeDict(marginablesById, id, {});
2822
+ //
2823
+ // {
2824
+ // assetName: "BTC",
2825
+ // assetFullName: "Bitcoin",
2826
+ // isBorrowable: true,
2827
+ // isMortgageable: true,
2828
+ // userMinBorrow: "0",
2829
+ // userMinRepay: "0",
2830
+ // }
2831
+ //
2816
2832
  result[code] = {
2817
2833
  'id': id,
2818
2834
  'name': name,
@@ -2826,6 +2842,7 @@ class binance extends binance$1 {
2826
2842
  'fee': fee,
2827
2843
  'fees': fees,
2828
2844
  'limits': this.limits,
2845
+ 'margin': this.safeBool(marginEntry, 'isBorrowable'),
2829
2846
  };
2830
2847
  }
2831
2848
  return result;
@@ -2839,6 +2856,8 @@ class binance extends binance$1 {
2839
2856
  * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Exchange-Information // swap
2840
2857
  * @see https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/Exchange-Information // future
2841
2858
  * @see https://developers.binance.com/docs/derivatives/option/market-data/Exchange-Information // option
2859
+ * @see https://developers.binance.com/docs/margin_trading/market-data/Get-All-Cross-Margin-Pairs // cross margin
2860
+ * @see https://developers.binance.com/docs/margin_trading/market-data/Get-All-Isolated-Margin-Symbol // isolated margin
2842
2861
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2843
2862
  * @returns {object[]} an array of objects representing market data
2844
2863
  */
@@ -2853,10 +2872,16 @@ class binance extends binance$1 {
2853
2872
  }
2854
2873
  fetchMarkets.push(type);
2855
2874
  }
2875
+ let fetchMargins = false;
2856
2876
  for (let i = 0; i < fetchMarkets.length; i++) {
2857
2877
  const marketType = fetchMarkets[i];
2858
2878
  if (marketType === 'spot') {
2859
2879
  promisesRaw.push(this.publicGetExchangeInfo(params));
2880
+ if (this.checkRequiredCredentials(false) && !sandboxMode) {
2881
+ fetchMargins = true;
2882
+ promisesRaw.push(this.sapiGetMarginAllPairs(params));
2883
+ promisesRaw.push(this.sapiGetMarginIsolatedAllPairs(params));
2884
+ }
2860
2885
  }
2861
2886
  else if (marketType === 'linear') {
2862
2887
  promisesRaw.push(this.fapiPublicGetExchangeInfo(params));
@@ -2871,12 +2896,27 @@ class binance extends binance$1 {
2871
2896
  throw new errors.ExchangeError(this.id + ' fetchMarkets() this.options fetchMarkets "' + marketType + '" is not a supported market type');
2872
2897
  }
2873
2898
  }
2874
- const promises = await Promise.all(promisesRaw);
2899
+ const results = await Promise.all(promisesRaw);
2875
2900
  let markets = [];
2876
- for (let i = 0; i < fetchMarkets.length; i++) {
2877
- const promise = this.safeDict(promises, i);
2878
- const promiseMarkets = this.safeList2(promise, 'symbols', 'optionSymbols', []);
2879
- markets = this.arrayConcat(markets, promiseMarkets);
2901
+ this.options['crossMarginPairsData'] = [];
2902
+ this.options['isolatedMarginPairsData'] = [];
2903
+ for (let i = 0; i < results.length; i++) {
2904
+ const res = this.safeValue(results, i);
2905
+ if (fetchMargins && Array.isArray(res)) {
2906
+ const keysList = Object.keys(this.indexBy(res, 'symbol'));
2907
+ const length = (Object.keys(this.options['crossMarginPairsData'])).length;
2908
+ // first one is the cross-margin promise
2909
+ if (length === 0) {
2910
+ this.options['crossMarginPairsData'] = keysList;
2911
+ }
2912
+ else {
2913
+ this.options['isolatedMarginPairsData'] = keysList;
2914
+ }
2915
+ }
2916
+ else {
2917
+ const resultMarkets = this.safeList2(res, 'symbols', 'optionSymbols', []);
2918
+ markets = this.arrayConcat(markets, resultMarkets);
2919
+ }
2880
2920
  }
2881
2921
  //
2882
2922
  // spot / margin
@@ -2922,6 +2962,20 @@ class binance extends binance$1 {
2922
2962
  // ],
2923
2963
  // }
2924
2964
  //
2965
+ // cross & isolated pairs response:
2966
+ //
2967
+ // [
2968
+ // {
2969
+ // symbol: "BTCUSDT",
2970
+ // base: "BTC",
2971
+ // quote: "USDT",
2972
+ // isMarginTrade: true,
2973
+ // isBuyAllowed: true,
2974
+ // isSellAllowed: true,
2975
+ // id: "376870555451677893", // doesn't exist in isolated
2976
+ // },
2977
+ // ]
2978
+ //
2925
2979
  // futures/usdt-margined (fapi)
2926
2980
  //
2927
2981
  // {
@@ -3156,6 +3210,21 @@ class binance extends binance$1 {
3156
3210
  }
3157
3211
  }
3158
3212
  const isMarginTradingAllowed = this.safeBool(market, 'isMarginTradingAllowed', false);
3213
+ let marginModes = undefined;
3214
+ if (spot) {
3215
+ const hasCrossMargin = this.inArray(id, this.options['crossMarginPairsData']);
3216
+ const hasIsolatedMargin = this.inArray(id, this.options['isolatedMarginPairsData']);
3217
+ marginModes = {
3218
+ 'cross': hasCrossMargin,
3219
+ 'isolated': hasIsolatedMargin,
3220
+ };
3221
+ }
3222
+ else if (linear || inverse) {
3223
+ marginModes = {
3224
+ 'cross': true,
3225
+ 'isolated': true,
3226
+ };
3227
+ }
3159
3228
  let unifiedType = undefined;
3160
3229
  if (spot) {
3161
3230
  unifiedType = 'spot';
@@ -3187,6 +3256,7 @@ class binance extends binance$1 {
3187
3256
  'type': unifiedType,
3188
3257
  'spot': spot,
3189
3258
  'margin': spot && isMarginTradingAllowed,
3259
+ 'marginModes': marginModes,
3190
3260
  'swap': swap,
3191
3261
  'future': future,
3192
3262
  'option': option,
@@ -138,7 +138,7 @@ class cryptocom extends cryptocom$1 {
138
138
  'www': 'https://crypto.com/',
139
139
  'referral': {
140
140
  'url': 'https://crypto.com/exch/kdacthrnxt',
141
- 'discount': 0.15,
141
+ 'discount': 0.75,
142
142
  },
143
143
  'doc': [
144
144
  'https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html',
@@ -1989,7 +1989,7 @@ class currencycom extends currencycom$1 {
1989
1989
  'collateral': undefined,
1990
1990
  'side': side,
1991
1991
  // 'realizedProfit': this.safeNumber (position, 'rpl'),
1992
- 'unrealizedProfit': unrealizedProfit,
1992
+ 'unrealizedPnl': unrealizedProfit,
1993
1993
  'leverage': leverage,
1994
1994
  'percentage': undefined,
1995
1995
  'marginMode': undefined,
@@ -2003,7 +2003,6 @@ class currencycom extends currencycom$1 {
2003
2003
  'maintenanceMarginPercentage': undefined,
2004
2004
  'marginRatio': undefined,
2005
2005
  'id': undefined,
2006
- 'unrealizedPnl': undefined,
2007
2006
  'hedged': undefined,
2008
2007
  'stopLossPrice': undefined,
2009
2008
  'takeProfitPrice': undefined,
@@ -7642,7 +7642,7 @@ class htx extends htx$1 {
7642
7642
  'entryPrice': entryPrice,
7643
7643
  'collateral': this.parseNumber(collateral),
7644
7644
  'side': side,
7645
- 'unrealizedProfit': unrealizedProfit,
7645
+ 'unrealizedPnl': unrealizedProfit,
7646
7646
  'leverage': this.parseNumber(leverage),
7647
7647
  'percentage': this.parseNumber(percentage),
7648
7648
  'marginMode': marginMode,
@@ -1019,6 +1019,15 @@ class mexc extends mexc$1 {
1019
1019
  return this.arrayConcat(spotMarket, swapMarket);
1020
1020
  }
1021
1021
  async fetchSpotMarkets(params = {}) {
1022
+ /**
1023
+ * @ignore
1024
+ * @method
1025
+ * @name mexc#fetchMarkets
1026
+ * @description retrieves data on all spot markets for mexc
1027
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#exchange-information
1028
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1029
+ * @returns {object[]} an array of objects representing market data
1030
+ */
1022
1031
  const response = await this.spotPublicGetExchangeInfo(params);
1023
1032
  //
1024
1033
  // {
@@ -1136,6 +1145,15 @@ class mexc extends mexc$1 {
1136
1145
  return result;
1137
1146
  }
1138
1147
  async fetchSwapMarkets(params = {}) {
1148
+ /**
1149
+ * @ignore
1150
+ * @method
1151
+ * @name mexc#fetchMarkets
1152
+ * @description retrieves data on all swap markets for mexc
1153
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-contract-information
1154
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1155
+ * @returns {object[]} an array of objects representing market data
1156
+ */
1139
1157
  const response = await this.contractPublicGetDetail(params);
1140
1158
  //
1141
1159
  // {
@@ -1727,6 +1745,8 @@ class mexc extends mexc$1 {
1727
1745
  * @method
1728
1746
  * @name mexc#fetchTickers
1729
1747
  * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1748
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#24hr-ticker-price-change-statistics
1749
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-contract-trend-data
1730
1750
  * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1731
1751
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1732
1752
  * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -1815,6 +1835,8 @@ class mexc extends mexc$1 {
1815
1835
  * @method
1816
1836
  * @name mexc#fetchTicker
1817
1837
  * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
1838
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#24hr-ticker-price-change-statistics
1839
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-contract-trend-data
1818
1840
  * @param {string} symbol unified symbol of the market to fetch the ticker for
1819
1841
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1820
1842
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -2005,6 +2027,7 @@ class mexc extends mexc$1 {
2005
2027
  * @method
2006
2028
  * @name mexc#fetchBidsAsks
2007
2029
  * @description fetches the bid and ask price and volume for multiple markets
2030
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#symbol-order-book-ticker
2008
2031
  * @param {string[]|undefined} symbols unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned
2009
2032
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2010
2033
  * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -2150,6 +2173,23 @@ class mexc extends mexc$1 {
2150
2173
  return this.extend(request, params);
2151
2174
  }
2152
2175
  async createSpotOrder(market, type, side, amount, price = undefined, marginMode = undefined, params = {}) {
2176
+ /**
2177
+ * @ignore
2178
+ * @method
2179
+ * @name mexc#createSpotOrder
2180
+ * @description create a trade order
2181
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#new-order
2182
+ * @param {string} symbol unified symbol of the market to create an order in
2183
+ * @param {string} type 'market' or 'limit'
2184
+ * @param {string} side 'buy' or 'sell'
2185
+ * @param {float} amount how much of currency you want to trade in units of base currency
2186
+ * @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
2187
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2188
+ * @param {string} [params.marginMode] only 'isolated' is supported for spot-margin trading
2189
+ * @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
2190
+ * @param {bool} [params.postOnly] if true, the order will only be posted if it will be a maker order
2191
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2192
+ */
2153
2193
  await this.loadMarkets();
2154
2194
  const request = this.createSpotOrderRequest(market, type, side, amount, price, marginMode, params);
2155
2195
  const response = await this.spotPrivatePostOrder(this.extend(request, params));
@@ -2180,6 +2220,32 @@ class mexc extends mexc$1 {
2180
2220
  return order;
2181
2221
  }
2182
2222
  async createSwapOrder(market, type, side, amount, price = undefined, marginMode = undefined, params = {}) {
2223
+ /**
2224
+ * @ignore
2225
+ * @method
2226
+ * @name mexc#createOrder
2227
+ * @description create a trade order
2228
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#new-order
2229
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#order-under-maintenance
2230
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#trigger-order-under-maintenance
2231
+ * @param {string} symbol unified symbol of the market to create an order in
2232
+ * @param {string} type 'market' or 'limit'
2233
+ * @param {string} side 'buy' or 'sell'
2234
+ * @param {float} amount how much of currency you want to trade in units of base currency
2235
+ * @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
2236
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2237
+ * @param {string} [params.marginMode] only 'isolated' is supported for spot-margin trading
2238
+ * @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
2239
+ * @param {bool} [params.postOnly] if true, the order will only be posted if it will be a maker order
2240
+ * @param {bool} [params.reduceOnly] indicates if this order is to reduce the size of a position
2241
+ *
2242
+ * EXCHANGE SPECIFIC PARAMETERS
2243
+ * @param {int} [params.leverage] leverage is necessary on isolated margin
2244
+ * @param {long} [params.positionId] it is recommended to fill in this parameter when closing a position
2245
+ * @param {string} [params.externalOid] external order ID
2246
+ * @param {int} [params.positionMode] 1:hedge, 2:one-way, default: the user's current config
2247
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2248
+ */
2183
2249
  await this.loadMarkets();
2184
2250
  const symbol = market['symbol'];
2185
2251
  const unavailableContracts = this.safeValue(this.options, 'unavailableContracts', {});
@@ -2355,6 +2421,8 @@ class mexc extends mexc$1 {
2355
2421
  * @method
2356
2422
  * @name mexc#fetchOrder
2357
2423
  * @description fetches information on an order made by the user
2424
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#query-order
2425
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#query-the-order-based-on-the-order-number
2358
2426
  * @param {string} symbol unified symbol of the market the order was made in
2359
2427
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2360
2428
  * @param {string} [params.marginMode] only 'isolated' is supported, for spot-margin trading
@@ -4812,7 +4880,7 @@ class mexc extends mexc$1 {
4812
4880
  'entryPrice': entryPrice,
4813
4881
  'collateral': undefined,
4814
4882
  'side': side,
4815
- 'unrealizedProfit': undefined,
4883
+ 'unrealizedPnl': undefined,
4816
4884
  'leverage': this.parseNumber(leverage),
4817
4885
  'percentage': undefined,
4818
4886
  'marginMode': marginType,
@@ -1023,70 +1023,10 @@ class binance extends binance$1 {
1023
1023
  for (let j = 0; j < messageHashes.length; j++) {
1024
1024
  const unsubHash = messageHashes[j];
1025
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);
1026
+ this.cleanUnsubscription(client, subHash, unsubHash);
1035
1027
  }
1036
1028
  this.cleanCache(subscription);
1037
1029
  }
1038
- cleanCache(subscription) {
1039
- const topic = this.safeString(subscription, 'topic');
1040
- const symbols = this.safeList(subscription, 'symbols', []);
1041
- const symbolsLength = symbols.length;
1042
- if (topic === 'ohlcv') {
1043
- const symbolsAndTimeFrames = this.safeList(subscription, 'symbolsAndTimeframes', []);
1044
- for (let i = 0; i < symbolsAndTimeFrames.length; i++) {
1045
- const symbolAndTimeFrame = symbolsAndTimeFrames[i];
1046
- const symbol = this.safeString(symbolAndTimeFrame, 0);
1047
- const timeframe = this.safeString(symbolAndTimeFrame, 1);
1048
- if (timeframe in this.ohlcvs[symbol]) {
1049
- delete this.ohlcvs[symbol][timeframe];
1050
- }
1051
- }
1052
- }
1053
- else if (symbolsLength > 0) {
1054
- for (let i = 0; i < symbols.length; i++) {
1055
- const symbol = symbols[i];
1056
- if (topic === 'trade') {
1057
- delete this.trades[symbol];
1058
- }
1059
- else if (topic === 'orderbook') {
1060
- delete this.orderbooks[symbol];
1061
- }
1062
- else if (topic === 'ticker') {
1063
- delete this.tickers[symbol];
1064
- }
1065
- }
1066
- }
1067
- else {
1068
- if (topic === 'myTrades') {
1069
- // don't reset this.myTrades directly here
1070
- // because in c# we need to use a different object
1071
- const keys = Object.keys(this.myTrades);
1072
- for (let i = 0; i < keys.length; i++) {
1073
- delete this.myTrades[keys[i]];
1074
- }
1075
- }
1076
- else if (topic === 'orders') {
1077
- const orderSymbols = Object.keys(this.orders);
1078
- for (let i = 0; i < orderSymbols.length; i++) {
1079
- delete this.orders[orderSymbols[i]];
1080
- }
1081
- }
1082
- else if (topic === 'ticker') {
1083
- const tickerSymbols = Object.keys(this.tickers);
1084
- for (let i = 0; i < tickerSymbols.length; i++) {
1085
- delete this.tickers[tickerSymbols[i]];
1086
- }
1087
- }
1088
- }
1089
- }
1090
1030
  async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
1091
1031
  /**
1092
1032
  * @method
@@ -1208,7 +1148,7 @@ class binance extends binance$1 {
1208
1148
  'subMessageHashes': subMessageHashes,
1209
1149
  'messageHashes': messageHashes,
1210
1150
  'symbols': symbols,
1211
- 'topic': 'trade',
1151
+ 'topic': 'trades',
1212
1152
  };
1213
1153
  return await this.watchMultiple(url, messageHashes, this.extend(request, query), messageHashes, subscription);
1214
1154
  }
@@ -1973,7 +1913,7 @@ class binance extends binance$1 {
1973
1913
  if (this.newUpdates) {
1974
1914
  return result;
1975
1915
  }
1976
- return this.filterByArray(this.tickers, 'symbol', symbols);
1916
+ return this.filterByArray(this.bidsasks, 'symbol', symbols);
1977
1917
  }
1978
1918
  async watchMultiTickerHelper(methodName, channelName, symbols = undefined, params = {}) {
1979
1919
  await this.loadMarkets();
@@ -2010,15 +2010,7 @@ class bitget extends bitget$1 {
2010
2010
  delete this.ohlcvs[symbol][timeframe];
2011
2011
  }
2012
2012
  }
2013
- if (subMessageHash in client.subscriptions) {
2014
- delete client.subscriptions[subMessageHash];
2015
- }
2016
- if (messageHash in client.subscriptions) {
2017
- delete client.subscriptions[messageHash];
2018
- }
2019
- const error = new errors.UnsubscribeError(this.id + ' ohlcv ' + timeframe + ' ' + symbol);
2020
- client.reject(error, subMessageHash);
2021
- client.resolve(true, messageHash);
2013
+ this.cleanUnsubscription(client, subMessageHash, messageHash);
2022
2014
  }
2023
2015
  handleUnSubscriptionStatus(client, message) {
2024
2016
  //
@@ -59,6 +59,7 @@ class bitmex extends bitmex$1 {
59
59
  * @method
60
60
  * @name bitmex#watchTicker
61
61
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
62
+ * @see https://www.bitmex.com/app/wsAPI#Subscriptions
62
63
  * @param {string} symbol unified symbol of the market to fetch the ticker for
63
64
  * @param {object} [params] extra parameters specific to the exchange API endpoint
64
65
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -73,6 +74,7 @@ class bitmex extends bitmex$1 {
73
74
  * @method
74
75
  * @name bitmex#watchTickers
75
76
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
77
+ * @see https://www.bitmex.com/app/wsAPI#Subscriptions
76
78
  * @param {string[]} symbols unified symbol of the market to fetch the ticker for
77
79
  * @param {object} [params] extra parameters specific to the exchange API endpoint
78
80
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -461,6 +463,7 @@ class bitmex extends bitmex$1 {
461
463
  * @method
462
464
  * @name bitmex#watchBalance
463
465
  * @description watch balance and get the amount of funds available for trading or funds locked in orders
466
+ * @see https://www.bitmex.com/app/wsAPI#Subscriptions
464
467
  * @param {object} [params] extra parameters specific to the exchange API endpoint
465
468
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
466
469
  */
@@ -668,6 +671,7 @@ class bitmex extends bitmex$1 {
668
671
  * @method
669
672
  * @name bitmex#watchTrades
670
673
  * @description get the list of most recent trades for a particular symbol
674
+ * @see https://www.bitmex.com/app/wsAPI#Subscriptions
671
675
  * @param {string} symbol unified symbol of the market to fetch trades for
672
676
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
673
677
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -720,8 +724,8 @@ class bitmex extends bitmex$1 {
720
724
  /**
721
725
  * @method
722
726
  * @name bitmex#watchPositions
723
- * @see https://www.bitmex.com/app/wsAPI
724
727
  * @description watch all open positions
728
+ * @see https://www.bitmex.com/app/wsAPI#Subscriptions
725
729
  * @param {string[]|undefined} symbols list of unified market symbols
726
730
  * @param {object} params extra parameters specific to the exchange API endpoint
727
731
  * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
@@ -925,6 +929,7 @@ class bitmex extends bitmex$1 {
925
929
  * @method
926
930
  * @name bitmex#watchOrders
927
931
  * @description watches information on multiple orders made by the user
932
+ * @see https://www.bitmex.com/app/wsAPI#Subscriptions
928
933
  * @param {string} symbol unified market symbol of the market orders were made in
929
934
  * @param {int} [since] the earliest time in ms to fetch orders for
930
935
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -1140,6 +1145,7 @@ class bitmex extends bitmex$1 {
1140
1145
  * @method
1141
1146
  * @name bitmex#watchMyTrades
1142
1147
  * @description watches information on multiple trades made by the user
1148
+ * @see https://www.bitmex.com/app/wsAPI#Subscriptions
1143
1149
  * @param {string} symbol unified market symbol of the market trades were made in
1144
1150
  * @param {int} [since] the earliest time in ms to fetch trades for
1145
1151
  * @param {int} [limit] the maximum number of trade structures to retrieve
@@ -1257,6 +1263,7 @@ class bitmex extends bitmex$1 {
1257
1263
  * @method
1258
1264
  * @name bitmex#watchOrderBook
1259
1265
  * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
1266
+ * @see https://www.bitmex.com/app/wsAPI#OrderBookL2
1260
1267
  * @param {string} symbol unified symbol of the market to fetch the order book for
1261
1268
  * @param {int} [limit] the maximum amount of order book entries to return
1262
1269
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -1269,6 +1276,7 @@ class bitmex extends bitmex$1 {
1269
1276
  * @method
1270
1277
  * @name bitmex#watchOrderBookForSymbols
1271
1278
  * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
1279
+ * @see https://www.bitmex.com/app/wsAPI#OrderBookL2
1272
1280
  * @param {string[]} symbols unified array of symbols
1273
1281
  * @param {int} [limit] the maximum amount of order book entries to return
1274
1282
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -1312,6 +1320,7 @@ class bitmex extends bitmex$1 {
1312
1320
  * @method
1313
1321
  * @name bitmex#watchTradesForSymbols
1314
1322
  * @description get the list of most recent trades for a list of symbols
1323
+ * @see https://www.bitmex.com/app/wsAPI#Subscriptions
1315
1324
  * @param {string[]} symbols unified symbol of the market to fetch trades for
1316
1325
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
1317
1326
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -1349,6 +1358,7 @@ class bitmex extends bitmex$1 {
1349
1358
  * @method
1350
1359
  * @name bitmex#watchOHLCV
1351
1360
  * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1361
+ * @see https://www.bitmex.com/app/wsAPI#Subscriptions
1352
1362
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1353
1363
  * @param {string} timeframe the length of time each candle represents
1354
1364
  * @param {int} [since] timestamp in ms of the earliest candle to fetch