ccxt 4.2.57 → 4.2.59

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 (110) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +4 -5
  3. package/build.sh +1 -1
  4. package/cleanup.sh +3 -0
  5. package/dist/ccxt.browser.js +772 -497
  6. package/dist/ccxt.browser.min.js +7 -7
  7. package/dist/cjs/ccxt.js +1 -1
  8. package/dist/cjs/src/alpaca.js +90 -88
  9. package/dist/cjs/src/base/Exchange.js +24 -1
  10. package/dist/cjs/src/binance.js +43 -30
  11. package/dist/cjs/src/bingx.js +15 -4
  12. package/dist/cjs/src/bitget.js +72 -57
  13. package/dist/cjs/src/bitmex.js +13 -29
  14. package/dist/cjs/src/bitrue.js +24 -15
  15. package/dist/cjs/src/blofin.js +25 -2
  16. package/dist/cjs/src/bybit.js +11 -3
  17. package/dist/cjs/src/coinbase.js +24 -14
  18. package/dist/cjs/src/currencycom.js +15 -5
  19. package/dist/cjs/src/delta.js +14 -1
  20. package/dist/cjs/src/gate.js +1 -1
  21. package/dist/cjs/src/hitbtc.js +12 -1
  22. package/dist/cjs/src/krakenfutures.js +22 -7
  23. package/dist/cjs/src/kuna.js +14 -11
  24. package/dist/cjs/src/lbank.js +1 -1
  25. package/dist/cjs/src/mexc.js +20 -20
  26. package/dist/cjs/src/okx.js +32 -2
  27. package/dist/cjs/src/phemex.js +1 -1
  28. package/dist/cjs/src/pro/alpaca.js +1 -1
  29. package/dist/cjs/src/pro/binance.js +1 -1
  30. package/dist/cjs/src/pro/bitfinex2.js +1 -1
  31. package/dist/cjs/src/pro/bitget.js +1 -1
  32. package/dist/cjs/src/pro/bitmart.js +51 -89
  33. package/dist/cjs/src/pro/bitvavo.js +1 -1
  34. package/dist/cjs/src/pro/bybit.js +1 -1
  35. package/dist/cjs/src/pro/coinex.js +1 -1
  36. package/dist/cjs/src/pro/cryptocom.js +1 -1
  37. package/dist/cjs/src/pro/deribit.js +201 -84
  38. package/dist/cjs/src/pro/gate.js +1 -1
  39. package/dist/cjs/src/pro/independentreserve.js +1 -1
  40. package/dist/cjs/src/pro/kraken.js +1 -1
  41. package/dist/cjs/src/pro/kucoinfutures.js +1 -1
  42. package/dist/cjs/src/pro/mexc.js +5 -3
  43. package/dist/cjs/src/pro/okx.js +1 -1
  44. package/dist/cjs/src/pro/whitebit.js +4 -6
  45. package/dist/cjs/src/pro/woo.js +1 -1
  46. package/dist/cjs/src/probit.js +1 -1
  47. package/dist/cjs/src/wavesexchange.js +1 -1
  48. package/dist/cjs/src/woo.js +22 -6
  49. package/js/ccxt.d.ts +3 -3
  50. package/js/ccxt.js +1 -1
  51. package/js/src/alpaca.js +90 -88
  52. package/js/src/base/Exchange.d.ts +6 -4
  53. package/js/src/base/Exchange.js +24 -1
  54. package/js/src/base/types.d.ts +9 -0
  55. package/js/src/binance.d.ts +3 -2
  56. package/js/src/binance.js +43 -30
  57. package/js/src/bingx.d.ts +3 -2
  58. package/js/src/bingx.js +15 -4
  59. package/js/src/bitget.d.ts +3 -2
  60. package/js/src/bitget.js +72 -57
  61. package/js/src/bitmex.d.ts +3 -3
  62. package/js/src/bitmex.js +13 -29
  63. package/js/src/bitrue.js +24 -15
  64. package/js/src/blofin.d.ts +3 -2
  65. package/js/src/blofin.js +25 -2
  66. package/js/src/bybit.d.ts +3 -6
  67. package/js/src/bybit.js +11 -3
  68. package/js/src/coinbase.js +24 -14
  69. package/js/src/currencycom.d.ts +3 -2
  70. package/js/src/currencycom.js +15 -5
  71. package/js/src/delta.d.ts +3 -2
  72. package/js/src/delta.js +14 -1
  73. package/js/src/gate.js +1 -1
  74. package/js/src/hitbtc.d.ts +3 -2
  75. package/js/src/hitbtc.js +12 -1
  76. package/js/src/krakenfutures.d.ts +3 -2
  77. package/js/src/krakenfutures.js +22 -7
  78. package/js/src/kuna.js +14 -11
  79. package/js/src/lbank.js +1 -1
  80. package/js/src/mexc.d.ts +3 -13
  81. package/js/src/mexc.js +20 -20
  82. package/js/src/okx.d.ts +3 -2
  83. package/js/src/okx.js +32 -2
  84. package/js/src/phemex.js +1 -1
  85. package/js/src/pro/alpaca.js +1 -1
  86. package/js/src/pro/binance.js +1 -1
  87. package/js/src/pro/bitfinex2.js +1 -1
  88. package/js/src/pro/bitget.js +1 -1
  89. package/js/src/pro/bitmart.d.ts +2 -2
  90. package/js/src/pro/bitmart.js +51 -89
  91. package/js/src/pro/bitvavo.js +1 -1
  92. package/js/src/pro/bybit.js +1 -1
  93. package/js/src/pro/coinex.js +1 -1
  94. package/js/src/pro/cryptocom.js +1 -1
  95. package/js/src/pro/deribit.d.ts +5 -0
  96. package/js/src/pro/deribit.js +202 -85
  97. package/js/src/pro/gate.js +1 -1
  98. package/js/src/pro/independentreserve.js +1 -1
  99. package/js/src/pro/kraken.js +1 -1
  100. package/js/src/pro/kucoinfutures.js +1 -1
  101. package/js/src/pro/mexc.js +6 -4
  102. package/js/src/pro/okx.js +1 -1
  103. package/js/src/pro/whitebit.js +4 -6
  104. package/js/src/pro/woo.js +1 -1
  105. package/js/src/probit.js +1 -1
  106. package/js/src/wavesexchange.js +1 -1
  107. package/js/src/woo.d.ts +3 -5
  108. package/js/src/woo.js +22 -6
  109. package/package.json +1 -1
  110. package/skip-tests.json +8 -3
@@ -3065,10 +3065,12 @@ class coinbase extends coinbase$1 {
3065
3065
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
3066
3066
  */
3067
3067
  await this.loadMarkets();
3068
+ const maxLimit = 300;
3069
+ limit = (limit === undefined) ? maxLimit : Math.min(limit, maxLimit);
3068
3070
  let paginate = false;
3069
3071
  [paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate', false);
3070
3072
  if (paginate) {
3071
- return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 299);
3073
+ return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, maxLimit - 1);
3072
3074
  }
3073
3075
  const market = this.market(symbol);
3074
3076
  const request = {
@@ -3078,20 +3080,20 @@ class coinbase extends coinbase$1 {
3078
3080
  const until = this.safeValueN(params, ['until', 'till', 'end']);
3079
3081
  params = this.omit(params, ['until', 'till']);
3080
3082
  const duration = this.parseTimeframe(timeframe);
3081
- const candles300 = 300 * duration;
3083
+ const requestedDuration = limit * duration;
3082
3084
  let sinceString = undefined;
3083
3085
  if (since !== undefined) {
3084
3086
  sinceString = this.numberToString(this.parseToInt(since / 1000));
3085
3087
  }
3086
3088
  else {
3087
3089
  const now = this.seconds().toString();
3088
- sinceString = Precise["default"].stringSub(now, candles300.toString());
3090
+ sinceString = Precise["default"].stringSub(now, requestedDuration.toString());
3089
3091
  }
3090
3092
  request['start'] = sinceString;
3091
3093
  let endString = this.numberToString(until);
3092
3094
  if (until === undefined) {
3093
3095
  // 300 candles max
3094
- endString = Precise["default"].stringAdd(sinceString, candles300.toString());
3096
+ endString = Precise["default"].stringAdd(sinceString, requestedDuration.toString());
3095
3097
  }
3096
3098
  request['end'] = endString;
3097
3099
  const response = await this.v3PrivateGetBrokerageProductsProductIdCandles(this.extend(request, params));
@@ -3151,8 +3153,19 @@ class coinbase extends coinbase$1 {
3151
3153
  const request = {
3152
3154
  'product_id': market['id'],
3153
3155
  };
3156
+ if (since !== undefined) {
3157
+ request['start'] = this.numberToString(this.parseToInt(since / 1000));
3158
+ }
3154
3159
  if (limit !== undefined) {
3155
- request['limit'] = limit;
3160
+ request['limit'] = Math.min(limit, 1000);
3161
+ }
3162
+ let until = undefined;
3163
+ [until, params] = this.handleOptionAndParams(params, 'fetchTrades', 'until');
3164
+ if (until !== undefined) {
3165
+ request['end'] = this.numberToString(this.parseToInt(until / 1000));
3166
+ }
3167
+ else if (since !== undefined) {
3168
+ throw new errors.ArgumentsRequired(this.id + ' fetchTrades() requires a `until` parameter when you use `since` argument');
3156
3169
  }
3157
3170
  const response = await this.v3PrivateGetBrokerageProductsProductIdTicker(this.extend(request, params));
3158
3171
  //
@@ -3286,7 +3299,7 @@ class coinbase extends coinbase$1 {
3286
3299
  // }
3287
3300
  // }
3288
3301
  //
3289
- const data = this.safeValue(response, 'pricebook', {});
3302
+ const data = this.safeDict(response, 'pricebook', {});
3290
3303
  const time = this.safeString(data, 'time');
3291
3304
  const timestamp = this.parse8601(time);
3292
3305
  return this.parseOrderBook(data, symbol, timestamp, 'bids', 'asks', 'price', 'size');
@@ -3739,7 +3752,7 @@ class coinbase extends coinbase$1 {
3739
3752
  }
3740
3753
  else {
3741
3754
  this.checkRequiredCredentials();
3742
- const nonce = this.nonce().toString();
3755
+ const timestampString = this.seconds().toString();
3743
3756
  let payload = '';
3744
3757
  if (method !== 'GET') {
3745
3758
  if (Object.keys(query).length) {
@@ -3747,17 +3760,14 @@ class coinbase extends coinbase$1 {
3747
3760
  payload = body;
3748
3761
  }
3749
3762
  }
3750
- else {
3751
- if (Object.keys(query).length) {
3752
- payload += '?' + this.urlencode(query);
3753
- }
3754
- }
3755
- const auth = nonce + method + savedPath + payload;
3763
+ // 'GET' doesn't need payload in the signature. inside url is enough
3764
+ // https://docs.cloud.coinbase.com/advanced-trade-api/docs/auth#example-request
3765
+ const auth = timestampString + method + savedPath + payload;
3756
3766
  const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256);
3757
3767
  headers = {
3758
3768
  'CB-ACCESS-KEY': this.apiKey,
3759
3769
  'CB-ACCESS-SIGN': signature,
3760
- 'CB-ACCESS-TIMESTAMP': nonce,
3770
+ 'CB-ACCESS-TIMESTAMP': timestampString,
3761
3771
  'Content-Type': 'application/json',
3762
3772
  };
3763
3773
  }
@@ -1806,12 +1806,22 @@ class currencycom extends currencycom$1 {
1806
1806
  };
1807
1807
  const response = await this.privateGetV2LeverageSettings(this.extend(request, params));
1808
1808
  //
1809
- // {
1810
- // "values": [ 1, 2, 5, 10, ],
1811
- // "value": "10",
1812
- // }
1809
+ // {
1810
+ // "values": [ 1, 2, 5, 10, ],
1811
+ // "value": "10",
1812
+ // }
1813
1813
  //
1814
- return this.safeNumber(response, 'value');
1814
+ return this.parseLeverage(response, market);
1815
+ }
1816
+ parseLeverage(leverage, market = undefined) {
1817
+ const leverageValue = this.safeInteger(leverage, 'value');
1818
+ return {
1819
+ 'info': leverage,
1820
+ 'symbol': market['symbol'],
1821
+ 'marginMode': undefined,
1822
+ 'longLeverage': leverageValue,
1823
+ 'shortLeverage': leverageValue,
1824
+ };
1815
1825
  }
1816
1826
  async fetchDepositAddress(code, params = {}) {
1817
1827
  /**
@@ -2811,6 +2811,7 @@ class delta extends delta$1 {
2811
2811
  const request = {
2812
2812
  'product_id': market['numericId'],
2813
2813
  };
2814
+ const response = await this.privateGetProductsProductIdOrdersLeverage(this.extend(request, params));
2814
2815
  //
2815
2816
  // {
2816
2817
  // "result": {
@@ -2824,7 +2825,19 @@ class delta extends delta$1 {
2824
2825
  // "success": true
2825
2826
  // }
2826
2827
  //
2827
- return await this.privateGetProductsProductIdOrdersLeverage(this.extend(request, params));
2828
+ const result = this.safeDict(response, 'result', {});
2829
+ return this.parseLeverage(result, market);
2830
+ }
2831
+ parseLeverage(leverage, market = undefined) {
2832
+ const marketId = this.safeString(leverage, 'index_symbol');
2833
+ const leverageValue = this.safeInteger(leverage, 'leverage');
2834
+ return {
2835
+ 'info': leverage,
2836
+ 'symbol': this.safeSymbol(marketId, market),
2837
+ 'marginMode': this.safeStringLower(leverage, 'margin_mode'),
2838
+ 'longLeverage': leverageValue,
2839
+ 'shortLeverage': leverageValue,
2840
+ };
2828
2841
  }
2829
2842
  async setLeverage(leverage, symbol = undefined, params = {}) {
2830
2843
  /**
@@ -959,7 +959,7 @@ class gate extends gate$1 {
959
959
  * @param {object} [params] extra parameters specific to the exchange API endpoint
960
960
  * @returns {object[]} an array of objects representing market data
961
961
  */
962
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
962
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
963
963
  let rawPromises = [
964
964
  this.fetchContractMarkets(params),
965
965
  this.fetchOptionMarkets(params),
@@ -3399,7 +3399,18 @@ class hitbtc extends hitbtc$1 {
3399
3399
  // ]
3400
3400
  // }
3401
3401
  //
3402
- return this.safeNumber(response, 'leverage');
3402
+ return this.parseLeverage(response, market);
3403
+ }
3404
+ parseLeverage(leverage, market = undefined) {
3405
+ const marketId = this.safeString(leverage, 'symbol');
3406
+ const leverageValue = this.safeInteger(leverage, 'leverage');
3407
+ return {
3408
+ 'info': leverage,
3409
+ 'symbol': this.safeSymbol(marketId, market),
3410
+ 'marginMode': this.safeStringLower(leverage, 'type'),
3411
+ 'longLeverage': leverageValue,
3412
+ 'shortLeverage': leverageValue,
3413
+ };
3403
3414
  }
3404
3415
  async setLeverage(leverage, symbol = undefined, params = {}) {
3405
3416
  /**
@@ -2456,7 +2456,7 @@ class krakenfutures extends krakenfutures$1 {
2456
2456
  //
2457
2457
  return await this.privatePutLeveragepreferences(this.extend(request, params));
2458
2458
  }
2459
- async fetchLeverage(symbol = undefined, params = {}) {
2459
+ async fetchLeverage(symbol, params = {}) {
2460
2460
  /**
2461
2461
  * @method
2462
2462
  * @name krakenfutures#fetchLeverage
@@ -2470,17 +2470,32 @@ class krakenfutures extends krakenfutures$1 {
2470
2470
  throw new errors.ArgumentsRequired(this.id + ' fetchLeverage() requires a symbol argument');
2471
2471
  }
2472
2472
  await this.loadMarkets();
2473
+ const market = this.market(symbol);
2473
2474
  const request = {
2474
2475
  'symbol': this.marketId(symbol).toUpperCase(),
2475
2476
  };
2477
+ const response = await this.privateGetLeveragepreferences(this.extend(request, params));
2476
2478
  //
2477
- // {
2478
- // "result": "success",
2479
- // "serverTime": "2023-08-01T09:54:08.900Z",
2480
- // "leveragePreferences": [ { symbol: "PF_LTCUSD", maxLeverage: "5.00" } ]
2481
- // }
2479
+ // {
2480
+ // "result": "success",
2481
+ // "serverTime": "2023-08-01T09:54:08.900Z",
2482
+ // "leveragePreferences": [ { symbol: "PF_LTCUSD", maxLeverage: "5.00" } ]
2483
+ // }
2482
2484
  //
2483
- return await this.privateGetLeveragepreferences(this.extend(request, params));
2485
+ const leveragePreferences = this.safeList(response, 'leveragePreferences', []);
2486
+ const data = this.safeDict(leveragePreferences, 0, {});
2487
+ return this.parseLeverage(data, market);
2488
+ }
2489
+ parseLeverage(leverage, market = undefined) {
2490
+ const marketId = this.safeString(leverage, 'symbol');
2491
+ const leverageValue = this.safeInteger(leverage, 'maxLeverage');
2492
+ return {
2493
+ 'info': leverage,
2494
+ 'symbol': this.safeSymbol(marketId, market),
2495
+ 'marginMode': undefined,
2496
+ 'longLeverage': leverageValue,
2497
+ 'shortLeverage': leverageValue,
2498
+ };
2484
2499
  }
2485
2500
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
2486
2501
  if (response === undefined) {
@@ -806,7 +806,7 @@ class kuna extends kuna$1 {
806
806
  await this.loadMarkets();
807
807
  const market = this.market(symbol);
808
808
  const request = {
809
- 'pair': market['id'],
809
+ 'pairs': market['id'],
810
810
  };
811
811
  if (limit !== undefined) {
812
812
  request['limit'] = limit;
@@ -814,18 +814,21 @@ class kuna extends kuna$1 {
814
814
  const response = await this.v4PublicGetTradePublicBookPairs(this.extend(request, params));
815
815
  //
816
816
  // {
817
- // "data": {
818
- // "id": "3e5591ba-2778-4d85-8851-54284045ea44", // Unique identifier of a trade
819
- // "pair": "BTC_USDT", // Market pair that is being traded
820
- // "quoteQuantity": "11528.8118", // Qty of the quote asset, USDT in this example
821
- // "matchPrice": "18649", // Exchange price at the moment of execution
822
- // "matchQuantity": "0.6182", // Qty of the base asset, BTC in this example
823
- // "createdAt": "2022-09-23T14:30:41.486Z", // Date-time of trade execution, UTC
824
- // "side": "Ask" // Trade type: `Ask` or `Bid`. Bid for buying base asset, Ask for selling base asset (e.g. for BTC_USDT trading pair, BTC is the base asset).
825
- // }
817
+ // 'data': [
818
+ // {
819
+ // 'createdAt': '2024-03-02T00:10:49.385Z',
820
+ // 'id': '3b42878a-3688-4bc1-891e-5cc2fc902142',
821
+ // 'matchPrice': '62181.31',
822
+ // 'matchQuantity': '0.00568',
823
+ // 'pair': 'BTC_USDT',
824
+ // 'quoteQuantity': '353.1898408',
825
+ // 'side': 'Bid'
826
+ // },
827
+ // ...
828
+ // ]
826
829
  // }
827
830
  //
828
- const data = this.safeValue(response, 'data', {});
831
+ const data = this.safeList(response, 'data', []);
829
832
  return this.parseTrades(data, market, since, limit);
830
833
  }
831
834
  parseTrade(trade, market = undefined) {
@@ -2691,7 +2691,7 @@ class lbank extends lbank$1 {
2691
2691
  const uppercaseHash = hash.toUpperCase();
2692
2692
  let sign = undefined;
2693
2693
  if (signatureMethod === 'RSA') {
2694
- const cacheSecretAsPem = this.safeValue(this.options, 'cacheSecretAsPem', true);
2694
+ const cacheSecretAsPem = this.safeBool(this.options, 'cacheSecretAsPem', true);
2695
2695
  let pem = undefined;
2696
2696
  if (cacheSecretAsPem) {
2697
2697
  pem = this.safeValue(this.options, 'pem');
@@ -5422,30 +5422,30 @@ class mexc extends mexc$1 {
5422
5422
  // }
5423
5423
  //
5424
5424
  const data = this.safeList(response, 'data', []);
5425
- const longLeverage = this.safeDict(data, 0);
5426
- return this.parseLeverage(longLeverage, market);
5425
+ return this.parseLeverage(data, market);
5427
5426
  }
5428
5427
  parseLeverage(leverage, market = undefined) {
5429
- //
5430
- // {
5431
- // "level": 1,
5432
- // "maxVol": 463300,
5433
- // "mmr": 0.004,
5434
- // "imr": 0.005,
5435
- // "positionType": 1,
5436
- // "openType": 1,
5437
- // "leverage": 20,
5438
- // "limitBySys": false,
5439
- // "currentMmr": 0.004
5440
- // }
5441
- //
5442
- const marketId = this.safeString(leverage, 'symbol');
5443
- market = this.safeMarket(marketId, market, undefined, 'contract');
5428
+ let marginMode = undefined;
5429
+ let longLeverage = undefined;
5430
+ let shortLeverage = undefined;
5431
+ for (let i = 0; i < leverage.length; i++) {
5432
+ const entry = leverage[i];
5433
+ const openType = this.safeInteger(entry, 'openType');
5434
+ const positionType = this.safeInteger(entry, 'positionType');
5435
+ if (positionType === 1) {
5436
+ longLeverage = this.safeInteger(entry, 'leverage');
5437
+ }
5438
+ else if (positionType === 2) {
5439
+ shortLeverage = this.safeInteger(entry, 'leverage');
5440
+ }
5441
+ marginMode = (openType === 1) ? 'isolated' : 'cross';
5442
+ }
5444
5443
  return {
5445
5444
  'info': leverage,
5446
5445
  'symbol': market['symbol'],
5447
- 'leverage': this.safeInteger(leverage, 'leverage'),
5448
- 'marginMode': undefined,
5446
+ 'marginMode': marginMode,
5447
+ 'longLeverage': longLeverage,
5448
+ 'shortLeverage': shortLeverage,
5449
5449
  };
5450
5450
  }
5451
5451
  handleMarginModeAndParams(methodName, params = {}, defaultValue = undefined) {
@@ -5496,7 +5496,7 @@ class mexc extends mexc$1 {
5496
5496
  'source': this.safeString(this.options, 'broker', 'CCXT'),
5497
5497
  };
5498
5498
  }
5499
- if ((method === 'POST') || (method === 'PUT')) {
5499
+ if ((method === 'POST') || (method === 'PUT') || (method === 'DELETE')) {
5500
5500
  headers['Content-Type'] = 'application/json';
5501
5501
  }
5502
5502
  }
@@ -1557,7 +1557,7 @@ class okx extends okx$1 {
1557
1557
  // while fetchCurrencies is a public API method by design
1558
1558
  // therefore we check the keys here
1559
1559
  // and fallback to generating the currencies from the markets
1560
- const isSandboxMode = this.safeValue(this.options, 'sandboxMode', false);
1560
+ const isSandboxMode = this.safeBool(this.options, 'sandboxMode', false);
1561
1561
  if (!this.checkRequiredCredentials(false) || isSandboxMode) {
1562
1562
  return undefined;
1563
1563
  }
@@ -5161,7 +5161,37 @@ class okx extends okx$1 {
5161
5161
  // "msg": ""
5162
5162
  // }
5163
5163
  //
5164
- return response;
5164
+ const data = this.safeList(response, 'data', []);
5165
+ return this.parseLeverage(data, market);
5166
+ }
5167
+ parseLeverage(leverage, market = undefined) {
5168
+ let marketId = undefined;
5169
+ let marginMode = undefined;
5170
+ let longLeverage = undefined;
5171
+ let shortLeverage = undefined;
5172
+ for (let i = 0; i < leverage.length; i++) {
5173
+ const entry = leverage[i];
5174
+ marginMode = this.safeStringLower(entry, 'mgnMode');
5175
+ marketId = this.safeString(entry, 'instId');
5176
+ const positionSide = this.safeStringLower(entry, 'posSide');
5177
+ if (positionSide === 'long') {
5178
+ longLeverage = this.safeInteger(entry, 'lever');
5179
+ }
5180
+ else if (positionSide === 'short') {
5181
+ shortLeverage = this.safeInteger(entry, 'lever');
5182
+ }
5183
+ else {
5184
+ longLeverage = this.safeInteger(entry, 'lever');
5185
+ shortLeverage = this.safeInteger(entry, 'lever');
5186
+ }
5187
+ }
5188
+ return {
5189
+ 'info': leverage,
5190
+ 'symbol': this.safeSymbol(marketId, market),
5191
+ 'marginMode': marginMode,
5192
+ 'longLeverage': longLeverage,
5193
+ 'shortLeverage': shortLeverage,
5194
+ };
5165
5195
  }
5166
5196
  async fetchPosition(symbol, params = {}) {
5167
5197
  /**
@@ -2419,7 +2419,7 @@ class phemex extends phemex$1 {
2419
2419
  }
2420
2420
  parseOrder(order, market = undefined) {
2421
2421
  const isSwap = this.safeBool(market, 'swap', false);
2422
- const hasPnl = ('closedPnl' in order);
2422
+ const hasPnl = ('closedPnl' in order) || ('closedPnlRv' in order) || ('totalPnlRv' in order);
2423
2423
  if (isSwap || hasPnl) {
2424
2424
  return this.parseSwapOrder(order, market);
2425
2425
  }
@@ -610,7 +610,7 @@ class alpaca extends alpaca$1 {
610
610
  for (let i = 0; i < message.length; i++) {
611
611
  const data = message[i];
612
612
  const T = this.safeString(data, 'T');
613
- const msg = this.safeValue(data, 'msg', {});
613
+ const msg = this.safeString(data, 'msg');
614
614
  if (T === 'subscription') {
615
615
  this.handleSubscription(client, data);
616
616
  return;
@@ -2465,7 +2465,7 @@ class binance extends binance$1 {
2465
2465
  this.setBalanceCache(client, type, isPortfolioMargin);
2466
2466
  this.setPositionsCache(client, type, symbols, isPortfolioMargin);
2467
2467
  const fetchPositionsSnapshot = this.handleOption('watchPositions', 'fetchPositionsSnapshot', true);
2468
- const awaitPositionsSnapshot = this.safeValue('watchPositions', 'awaitPositionsSnapshot', true);
2468
+ const awaitPositionsSnapshot = this.safeBool('watchPositions', 'awaitPositionsSnapshot', true);
2469
2469
  const cache = this.safeValue(this.positions, type);
2470
2470
  if (fetchPositionsSnapshot && awaitPositionsSnapshot && cache === undefined) {
2471
2471
  const snapshot = await client.future(type + ':fetchPositionsSnapshot');
@@ -53,7 +53,7 @@ class bitfinex2 extends bitfinex2$1 {
53
53
  'symbol': marketId,
54
54
  };
55
55
  const result = await this.watch(url, messageHash, this.deepExtend(request, params), messageHash, { 'checksum': false });
56
- const checksum = this.safeValue(this.options, 'checksum', true);
56
+ const checksum = this.safeBool(this.options, 'checksum', true);
57
57
  if (checksum && !client.subscriptions[messageHash]['checksum'] && (channel === 'book')) {
58
58
  client.subscriptions[messageHash]['checksum'] = true;
59
59
  await client.send({
@@ -536,7 +536,7 @@ class bitget extends bitget$1 {
536
536
  this.handleDeltas(storedOrderBook['bids'], bids);
537
537
  storedOrderBook['timestamp'] = timestamp;
538
538
  storedOrderBook['datetime'] = this.iso8601(timestamp);
539
- const checksum = this.safeValue(this.options, 'checksum', true);
539
+ const checksum = this.safeBool(this.options, 'checksum', true);
540
540
  const isSnapshot = this.safeString(message, 'action') === 'snapshot'; // snapshot does not have a checksum
541
541
  if (!isSnapshot && checksum) {
542
542
  const storedAsks = storedOrderBook['asks'];
@@ -107,11 +107,12 @@ class bitmart extends bitmart$1 {
107
107
  }
108
108
  return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash);
109
109
  }
110
- async subscribeMultiple(channel, type, symbols, params = {}) {
110
+ async subscribeMultiple(channel, type, symbols = undefined, params = {}) {
111
+ symbols = this.marketSymbols(symbols, type, false, true);
111
112
  const url = this.implodeHostname(this.urls['api']['ws'][type]['public']);
112
113
  const channelType = (type === 'spot') ? 'spot' : 'futures';
113
114
  const actionType = (type === 'spot') ? 'op' : 'action';
114
- const rawSubscriptions = [];
115
+ let rawSubscriptions = [];
115
116
  const messageHashes = [];
116
117
  for (let i = 0; i < symbols.length; i++) {
117
118
  const market = this.market(symbols[i]);
@@ -119,6 +120,10 @@ class bitmart extends bitmart$1 {
119
120
  rawSubscriptions.push(message);
120
121
  messageHashes.push(channel + ':' + market['symbol']);
121
122
  }
123
+ // as an exclusion, futures "tickers" need one generic request for all symbols
124
+ if ((type !== 'spot') && (channel === 'ticker')) {
125
+ rawSubscriptions = [channelType + '/' + channel];
126
+ }
122
127
  const request = {
123
128
  'args': rawSubscriptions,
124
129
  };
@@ -321,13 +326,8 @@ class bitmart extends bitmart$1 {
321
326
  */
322
327
  await this.loadMarkets();
323
328
  symbol = this.symbol(symbol);
324
- const market = this.market(symbol);
325
- let type = 'spot';
326
- [type, params] = this.handleMarketTypeAndParams('watchTicker', market, params);
327
- if (type === 'swap') {
328
- throw new errors.NotSupported(this.id + ' watchTicker() does not support ' + type + ' markets. Use watchTickers() instead');
329
- }
330
- return await this.subscribe('ticker', symbol, type, params);
329
+ const tickers = await this.watchTickers([symbol], params);
330
+ return tickers[symbol];
331
331
  }
332
332
  async watchTickers(symbols = undefined, params = {}) {
333
333
  /**
@@ -341,40 +341,12 @@ class bitmart extends bitmart$1 {
341
341
  */
342
342
  await this.loadMarkets();
343
343
  const market = this.getMarketFromSymbols(symbols);
344
- let type = 'spot';
345
- [type, params] = this.handleMarketTypeAndParams('watchTickers', market, params);
346
- const url = this.implodeHostname(this.urls['api']['ws'][type]['public']);
347
- symbols = this.marketSymbols(symbols);
348
- let messageHash = 'tickers::' + type;
349
- if (symbols !== undefined) {
350
- messageHash += '::' + symbols.join(',');
351
- }
352
- let request = undefined;
353
- let tickers = undefined;
354
- const isSpot = (type === 'spot');
355
- if (isSpot) {
356
- if (symbols === undefined) {
357
- throw new errors.ArgumentsRequired(this.id + ' watchTickers() for ' + type + ' market type requires symbols argument to be provided');
358
- }
359
- const marketIds = this.marketIds(symbols);
360
- const finalArray = [];
361
- for (let i = 0; i < marketIds.length; i++) {
362
- finalArray.push('spot/ticker:' + marketIds[i]);
363
- }
364
- request = {
365
- 'op': 'subscribe',
366
- 'args': finalArray,
367
- };
368
- tickers = await this.watch(url, messageHash, this.deepExtend(request, params), messageHash);
369
- }
370
- else {
371
- request = {
372
- 'action': 'subscribe',
373
- 'args': ['futures/ticker'],
374
- };
375
- tickers = await this.watch(url, messageHash, this.deepExtend(request, params), messageHash);
376
- }
344
+ let marketType = undefined;
345
+ [marketType, params] = this.handleMarketTypeAndParams('watchTickers', market, params);
346
+ const ticker = await this.subscribeMultiple('ticker', marketType, symbols, params);
377
347
  if (this.newUpdates) {
348
+ const tickers = {};
349
+ tickers[ticker['symbol']] = ticker;
378
350
  return tickers;
379
351
  }
380
352
  return this.filterByArray(this.tickers, 'symbol', symbols);
@@ -850,21 +822,34 @@ class bitmart extends bitmart$1 {
850
822
  if (data === undefined) {
851
823
  return;
852
824
  }
853
- let stored = undefined;
854
825
  let symbol = undefined;
855
- for (let i = 0; i < data.length; i++) {
856
- const trade = this.parseWsTrade(data[i]);
857
- symbol = trade['symbol'];
858
- const tradesLimit = this.safeInteger(this.options, 'tradesLimit', 1000);
859
- stored = this.safeValue(this.trades, symbol);
860
- if (stored === undefined) {
861
- stored = new Cache.ArrayCache(tradesLimit);
862
- this.trades[symbol] = stored;
826
+ const length = data.length;
827
+ const isSwap = ('group' in message);
828
+ if (isSwap) {
829
+ // in swap, chronologically decreasing: 1709536849322, 1709536848954,
830
+ const maxLen = Math.max(length - 1, 0);
831
+ for (let i = maxLen; i >= 0; i--) {
832
+ symbol = this.handleTradeLoop(data[i]);
833
+ }
834
+ }
835
+ else {
836
+ // in spot, chronologically increasing: 1709536771200, 1709536771226,
837
+ for (let i = 0; i < length; i++) {
838
+ symbol = this.handleTradeLoop(data[i]);
863
839
  }
864
- stored.append(trade);
865
840
  }
866
- const messageHash = 'trade:' + symbol;
867
- client.resolve(stored, messageHash);
841
+ client.resolve(this.trades[symbol], 'trade:' + symbol);
842
+ }
843
+ handleTradeLoop(entry) {
844
+ const trade = this.parseWsTrade(entry);
845
+ const symbol = trade['symbol'];
846
+ const tradesLimit = this.safeInteger(this.options, 'tradesLimit', 1000);
847
+ if (this.safeValue(this.trades, symbol) === undefined) {
848
+ this.trades[symbol] = new Cache.ArrayCache(tradesLimit);
849
+ }
850
+ const stored = this.trades[symbol];
851
+ stored.append(trade);
852
+ return symbol;
868
853
  }
869
854
  parseWsTrade(trade, market = undefined) {
870
855
  // spot
@@ -943,45 +928,22 @@ class bitmart extends bitmart$1 {
943
928
  //
944
929
  const table = this.safeString(message, 'table');
945
930
  const isSpot = (table !== undefined);
946
- const data = this.safeValue(message, 'data');
947
- if (data === undefined) {
948
- return;
949
- }
931
+ let rawTickers = [];
950
932
  if (isSpot) {
951
- for (let i = 0; i < data.length; i++) {
952
- const ticker = this.parseTicker(data[i]);
953
- const symbol = ticker['symbol'];
954
- const marketId = this.safeString(ticker['info'], 'symbol');
955
- const messageHash = table + ':' + marketId;
956
- this.tickers[symbol] = ticker;
957
- client.resolve(ticker, messageHash);
958
- this.resolveMessageHashesForSymbol(client, symbol, ticker, 'tickers::');
959
- }
933
+ rawTickers = this.safeList(message, 'data', []);
960
934
  }
961
935
  else {
962
- // on each update for contract markets, single ticker is provided
963
- const ticker = this.parseWsSwapTicker(data);
964
- const symbol = this.safeString(ticker, 'symbol');
965
- this.tickers[symbol] = ticker;
966
- client.resolve(ticker, 'tickers::swap');
967
- this.resolveMessageHashesForSymbol(client, symbol, ticker, 'tickers::');
936
+ rawTickers = [this.safeValue(message, 'data', {})];
968
937
  }
969
- }
970
- resolveMessageHashesForSymbol(client, symbol, result, prexif) {
971
- const prefixSeparator = '::';
972
- const symbolsSeparator = ',';
973
- const messageHashes = this.findMessageHashes(client, prexif);
974
- for (let i = 0; i < messageHashes.length; i++) {
975
- const messageHash = messageHashes[i];
976
- const parts = messageHash.split(prefixSeparator);
977
- const length = parts.length;
978
- const symbolsString = parts[length - 1];
979
- const symbols = symbolsString.split(symbolsSeparator);
980
- if (this.inArray(symbol, symbols)) {
981
- const response = {};
982
- response[symbol] = result;
983
- client.resolve(response, messageHash);
984
- }
938
+ if (!rawTickers.length) {
939
+ return;
940
+ }
941
+ for (let i = 0; i < rawTickers.length; i++) {
942
+ const ticker = isSpot ? this.parseTicker(rawTickers[i]) : this.parseWsSwapTicker(rawTickers[i]);
943
+ const symbol = ticker['symbol'];
944
+ this.tickers[symbol] = ticker;
945
+ const messageHash = 'ticker:' + symbol;
946
+ client.resolve(ticker, messageHash);
985
947
  }
986
948
  }
987
949
  parseWsSwapTicker(ticker, market = undefined) {