ccxt 4.2.57 → 4.2.58

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 (68) hide show
  1. package/README.md +4 -5
  2. package/build.sh +1 -1
  3. package/dist/ccxt.browser.js +462 -280
  4. package/dist/ccxt.browser.min.js +7 -7
  5. package/dist/cjs/ccxt.js +1 -1
  6. package/dist/cjs/src/alpaca.js +90 -88
  7. package/dist/cjs/src/base/Exchange.js +22 -1
  8. package/dist/cjs/src/binance.js +41 -28
  9. package/dist/cjs/src/bingx.js +12 -1
  10. package/dist/cjs/src/bitget.js +71 -56
  11. package/dist/cjs/src/bitmex.js +12 -28
  12. package/dist/cjs/src/bitrue.js +24 -15
  13. package/dist/cjs/src/blofin.js +24 -1
  14. package/dist/cjs/src/bybit.js +11 -3
  15. package/dist/cjs/src/currencycom.js +15 -5
  16. package/dist/cjs/src/delta.js +14 -1
  17. package/dist/cjs/src/gate.js +1 -1
  18. package/dist/cjs/src/hitbtc.js +12 -1
  19. package/dist/cjs/src/krakenfutures.js +22 -7
  20. package/dist/cjs/src/kuna.js +14 -11
  21. package/dist/cjs/src/mexc.js +19 -19
  22. package/dist/cjs/src/okx.js +31 -1
  23. package/dist/cjs/src/pro/alpaca.js +1 -1
  24. package/dist/cjs/src/pro/whitebit.js +4 -6
  25. package/dist/cjs/src/probit.js +1 -1
  26. package/dist/cjs/src/wavesexchange.js +1 -1
  27. package/dist/cjs/src/woo.js +20 -4
  28. package/js/ccxt.d.ts +3 -3
  29. package/js/ccxt.js +1 -1
  30. package/js/src/alpaca.js +90 -88
  31. package/js/src/base/Exchange.d.ts +6 -4
  32. package/js/src/base/Exchange.js +22 -1
  33. package/js/src/base/types.d.ts +9 -0
  34. package/js/src/binance.d.ts +3 -2
  35. package/js/src/binance.js +41 -28
  36. package/js/src/bingx.d.ts +3 -2
  37. package/js/src/bingx.js +12 -1
  38. package/js/src/bitget.d.ts +3 -2
  39. package/js/src/bitget.js +71 -56
  40. package/js/src/bitmex.d.ts +3 -3
  41. package/js/src/bitmex.js +12 -28
  42. package/js/src/bitrue.js +24 -15
  43. package/js/src/blofin.d.ts +3 -2
  44. package/js/src/blofin.js +24 -1
  45. package/js/src/bybit.d.ts +3 -6
  46. package/js/src/bybit.js +11 -3
  47. package/js/src/currencycom.d.ts +3 -2
  48. package/js/src/currencycom.js +15 -5
  49. package/js/src/delta.d.ts +3 -2
  50. package/js/src/delta.js +14 -1
  51. package/js/src/gate.js +1 -1
  52. package/js/src/hitbtc.d.ts +3 -2
  53. package/js/src/hitbtc.js +12 -1
  54. package/js/src/krakenfutures.d.ts +3 -2
  55. package/js/src/krakenfutures.js +22 -7
  56. package/js/src/kuna.js +14 -11
  57. package/js/src/mexc.d.ts +3 -13
  58. package/js/src/mexc.js +19 -19
  59. package/js/src/okx.d.ts +3 -2
  60. package/js/src/okx.js +31 -1
  61. package/js/src/pro/alpaca.js +1 -1
  62. package/js/src/pro/whitebit.js +4 -6
  63. package/js/src/probit.js +1 -1
  64. package/js/src/wavesexchange.js +1 -1
  65. package/js/src/woo.d.ts +3 -5
  66. package/js/src/woo.js +20 -4
  67. package/package.json +1 -1
  68. package/skip-tests.json +6 -1
package/js/src/binance.js CHANGED
@@ -97,7 +97,8 @@ export default class binance extends Exchange {
97
97
  'fetchLastPrices': true,
98
98
  'fetchLedger': true,
99
99
  'fetchLedgerEntry': true,
100
- 'fetchLeverage': true,
100
+ 'fetchLeverage': 'emulated',
101
+ 'fetchLeverages': true,
101
102
  'fetchLeverageTiers': true,
102
103
  'fetchLiquidations': false,
103
104
  'fetchMarginMode': 'emulated',
@@ -10391,31 +10392,27 @@ export default class binance extends Exchange {
10391
10392
  //
10392
10393
  return response;
10393
10394
  }
10394
- async fetchLeverage(symbol, params = {}) {
10395
+ async fetchLeverages(symbols = undefined, params = {}) {
10395
10396
  /**
10396
10397
  * @method
10397
- * @name binance#fetchLeverage
10398
- * @description fetch the set leverage for a market
10398
+ * @name binance#fetchLeverages
10399
+ * @description fetch the set leverage for all markets
10399
10400
  * @see https://binance-docs.github.io/apidocs/futures/en/#account-information-v2-user_data
10400
10401
  * @see https://binance-docs.github.io/apidocs/delivery/en/#account-information-user_data
10401
10402
  * @see https://binance-docs.github.io/apidocs/pm/en/#get-um-account-detail-user_data
10402
10403
  * @see https://binance-docs.github.io/apidocs/pm/en/#get-cm-account-detail-user_data
10403
- * @param {string} symbol unified market symbol
10404
+ * @param {string[]} [symbols] a list of unified market symbols
10404
10405
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10405
- * @returns {object} a [leverage structure]{@link https://docs.ccxt.com/#/?id=leverage-structure}
10406
+ * @returns {object} a list of [leverage structures]{@link https://docs.ccxt.com/#/?id=leverage-structure}
10406
10407
  */
10407
10408
  await this.loadMarkets();
10408
10409
  await this.loadLeverageBrackets(false, params);
10409
- const market = this.market(symbol);
10410
- if (!market['contract']) {
10411
- throw new NotSupported(this.id + ' fetchLeverage() supports linear and inverse contracts only');
10412
- }
10413
10410
  let type = undefined;
10414
- [type, params] = this.handleMarketTypeAndParams('fetchLeverage', market, params);
10411
+ [type, params] = this.handleMarketTypeAndParams('fetchLeverages', undefined, params);
10415
10412
  let subType = undefined;
10416
- [subType, params] = this.handleSubTypeAndParams('fetchLeverage', market, params, 'linear');
10413
+ [subType, params] = this.handleSubTypeAndParams('fetchLeverages', undefined, params, 'linear');
10417
10414
  let isPortfolioMargin = undefined;
10418
- [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchLeverage', 'papi', 'portfolioMargin', false);
10415
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchLeverages', 'papi', 'portfolioMargin', false);
10419
10416
  let response = undefined;
10420
10417
  if (this.isLinear(type, subType)) {
10421
10418
  if (isPortfolioMargin) {
@@ -10434,23 +10431,39 @@ export default class binance extends Exchange {
10434
10431
  }
10435
10432
  }
10436
10433
  else {
10437
- throw new NotSupported(this.id + ' fetchPositions() supports linear and inverse contracts only');
10434
+ throw new NotSupported(this.id + ' fetchLeverages() supports linear and inverse contracts only');
10438
10435
  }
10439
- const positions = this.safeList(response, 'positions', []);
10440
- for (let i = 0; i < positions.length; i++) {
10441
- const position = positions[i];
10442
- const innerSymbol = this.safeString(position, 'symbol');
10443
- if (innerSymbol === market['id']) {
10444
- const isolated = this.safeBool(position, 'isolated');
10445
- const marginMode = isolated ? 'isolated' : 'cross';
10446
- return {
10447
- 'info': position,
10448
- 'marginMode': marginMode,
10449
- 'leverage': this.safeInteger(position, 'leverage'),
10450
- };
10451
- }
10436
+ const leverages = this.safeList(response, 'positions', []);
10437
+ return this.parseLeverages(leverages, symbols, 'symbol');
10438
+ }
10439
+ parseLeverage(leverage, market = undefined) {
10440
+ const marketId = this.safeString(leverage, 'symbol');
10441
+ const marginModeRaw = this.safeBool(leverage, 'isolated');
10442
+ let marginMode = undefined;
10443
+ if (marginModeRaw !== undefined) {
10444
+ marginMode = marginModeRaw ? 'isolated' : 'cross';
10452
10445
  }
10453
- return response;
10446
+ const side = this.safeStringLower(leverage, 'positionSide');
10447
+ let longLeverage = undefined;
10448
+ let shortLeverage = undefined;
10449
+ const leverageValue = this.safeInteger(leverage, 'leverage');
10450
+ if (side === 'both') {
10451
+ longLeverage = leverageValue;
10452
+ shortLeverage = leverageValue;
10453
+ }
10454
+ else if (side === 'long') {
10455
+ longLeverage = leverageValue;
10456
+ }
10457
+ else if (side === 'short') {
10458
+ shortLeverage = leverageValue;
10459
+ }
10460
+ return {
10461
+ 'info': leverage,
10462
+ 'symbol': this.safeSymbol(marketId, market),
10463
+ 'marginMode': marginMode,
10464
+ 'longLeverage': longLeverage,
10465
+ 'shortLeverage': shortLeverage,
10466
+ };
10454
10467
  }
10455
10468
  async fetchSettlementHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
10456
10469
  /**
package/js/src/bingx.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/bingx.js';
2
- import type { TransferEntry, Int, OrderSide, OHLCV, FundingRateHistory, Order, OrderType, OrderRequest, Str, Trade, Balances, Transaction, Ticker, OrderBook, Tickers, Market, Strings, Currency, Position, Dict } from './base/types.js';
2
+ import type { TransferEntry, Int, OrderSide, OHLCV, FundingRateHistory, Order, OrderType, OrderRequest, Str, Trade, Balances, Transaction, Ticker, OrderBook, Tickers, Market, Strings, Currency, Position, Dict, Leverage } from './base/types.js';
3
3
  /**
4
4
  * @class bingx
5
5
  * @augments Exchange
@@ -110,7 +110,8 @@ export default class bingx extends Exchange {
110
110
  parseTransactionStatus(status: string): string;
111
111
  setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<any>;
112
112
  setMargin(symbol: string, amount: number, params?: {}): Promise<any>;
113
- fetchLeverage(symbol: string, params?: {}): Promise<any>;
113
+ fetchLeverage(symbol: string, params?: {}): Promise<Leverage>;
114
+ parseLeverage(leverage: any, market?: any): Leverage;
114
115
  setLeverage(leverage: Int, symbol?: Str, params?: {}): Promise<any>;
115
116
  fetchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
116
117
  parseDepositWithdrawFee(fee: any, currency?: Currency): {
package/js/src/bingx.js CHANGED
@@ -3499,7 +3499,18 @@ export default class bingx extends Exchange {
3499
3499
  // }
3500
3500
  // }
3501
3501
  //
3502
- return response;
3502
+ const data = this.safeDict(response, 'data', {});
3503
+ return this.parseLeverage(data, market);
3504
+ }
3505
+ parseLeverage(leverage, market = undefined) {
3506
+ const marketId = this.safeString(leverage, 'symbol');
3507
+ return {
3508
+ 'info': leverage,
3509
+ 'symbol': this.safeSymbol(marketId, market),
3510
+ 'marginMode': undefined,
3511
+ 'longLeverage': this.safeInteger(leverage, 'longLeverage'),
3512
+ 'shortLeverage': this.safeInteger(leverage, 'shortLeverage'),
3513
+ };
3503
3514
  }
3504
3515
  async setLeverage(leverage, symbol = undefined, params = {}) {
3505
3516
  /**
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/bitget.js';
2
- import type { Int, OrderSide, OrderType, Trade, OHLCV, Order, FundingRateHistory, OrderRequest, FundingHistory, Balances, Str, Transaction, Ticker, OrderBook, Tickers, Market, Strings, Currency, Position, Liquidation, TransferEntry } from './base/types.js';
2
+ import type { Int, OrderSide, OrderType, Trade, OHLCV, Order, FundingRateHistory, OrderRequest, FundingHistory, Balances, Str, Transaction, Ticker, OrderBook, Tickers, Market, Strings, Currency, Position, Liquidation, TransferEntry, Leverage } from './base/types.js';
3
3
  /**
4
4
  * @class bitget
5
5
  * @augments Exchange
@@ -157,7 +157,8 @@ export default class bitget extends Exchange {
157
157
  };
158
158
  reduceMargin(symbol: string, amount: any, params?: {}): Promise<any>;
159
159
  addMargin(symbol: string, amount: any, params?: {}): Promise<any>;
160
- fetchLeverage(symbol: string, params?: {}): Promise<any>;
160
+ fetchLeverage(symbol: string, params?: {}): Promise<Leverage>;
161
+ parseLeverage(leverage: any, market?: any): Leverage;
161
162
  setLeverage(leverage: Int, symbol?: Str, params?: {}): Promise<any>;
162
163
  setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<any>;
163
164
  setPositionMode(hedged: boolean, symbol?: Str, params?: {}): Promise<any>;
package/js/src/bitget.js CHANGED
@@ -1428,7 +1428,7 @@ export default class bitget extends Exchange {
1428
1428
  let defaultProductType = undefined;
1429
1429
  if ((subType !== undefined) && (market === undefined)) {
1430
1430
  // set default only if subType is defined and market is not defined, since there is also USDC productTypes which are also linear
1431
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
1431
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
1432
1432
  if (sandboxMode) {
1433
1433
  defaultProductType = (subType === 'linear') ? 'SUSDT-FUTURES' : 'SCOIN-FUTURES';
1434
1434
  }
@@ -1497,7 +1497,7 @@ export default class bitget extends Exchange {
1497
1497
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1498
1498
  * @returns {object[]} an array of objects representing market data
1499
1499
  */
1500
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
1500
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
1501
1501
  let types = this.safeValue(this.options, 'fetchMarkets', ['spot', 'swap']);
1502
1502
  if (sandboxMode) {
1503
1503
  types = ['swap'];
@@ -1952,7 +1952,7 @@ export default class bitget extends Exchange {
1952
1952
  * @returns {object} a [leverage tiers structure]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}
1953
1953
  */
1954
1954
  await this.loadMarkets();
1955
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
1955
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
1956
1956
  let market = undefined;
1957
1957
  if (sandboxMode) {
1958
1958
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -2488,7 +2488,7 @@ export default class bitget extends Exchange {
2488
2488
  * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
2489
2489
  */
2490
2490
  await this.loadMarkets();
2491
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
2491
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
2492
2492
  let market = undefined;
2493
2493
  if (sandboxMode) {
2494
2494
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -2651,7 +2651,7 @@ export default class bitget extends Exchange {
2651
2651
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
2652
2652
  */
2653
2653
  await this.loadMarkets();
2654
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
2654
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
2655
2655
  let market = undefined;
2656
2656
  if (sandboxMode) {
2657
2657
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -2755,7 +2755,7 @@ export default class bitget extends Exchange {
2755
2755
  let market = undefined;
2756
2756
  if (symbols !== undefined) {
2757
2757
  const symbol = this.safeValue(symbols, 0);
2758
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
2758
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
2759
2759
  if (sandboxMode) {
2760
2760
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
2761
2761
  market = this.market(sandboxSymbol);
@@ -2973,7 +2973,7 @@ export default class bitget extends Exchange {
2973
2973
  if (paginate) {
2974
2974
  return await this.fetchPaginatedCallCursor('fetchTrades', symbol, since, limit, params, 'idLessThan', 'idLessThan');
2975
2975
  }
2976
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
2976
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
2977
2977
  let market = undefined;
2978
2978
  if (sandboxMode) {
2979
2979
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -3292,7 +3292,7 @@ export default class bitget extends Exchange {
3292
3292
  if (paginate) {
3293
3293
  return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 1000);
3294
3294
  }
3295
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
3295
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
3296
3296
  let market = undefined;
3297
3297
  if (sandboxMode) {
3298
3298
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -4112,7 +4112,7 @@ export default class bitget extends Exchange {
4112
4112
  return this.parseOrder(data, market);
4113
4113
  }
4114
4114
  createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
4115
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
4115
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
4116
4116
  let market = undefined;
4117
4117
  if (sandboxMode) {
4118
4118
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -4383,7 +4383,7 @@ export default class bitget extends Exchange {
4383
4383
  const orderRequest = this.createOrderRequest(marketId, type, side, amount, price, orderParams);
4384
4384
  ordersRequests.push(orderRequest);
4385
4385
  }
4386
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
4386
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
4387
4387
  let market = undefined;
4388
4388
  if (sandboxMode) {
4389
4389
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -4480,7 +4480,7 @@ export default class bitget extends Exchange {
4480
4480
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4481
4481
  */
4482
4482
  await this.loadMarkets();
4483
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
4483
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
4484
4484
  let market = undefined;
4485
4485
  if (sandboxMode) {
4486
4486
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -4646,7 +4646,7 @@ export default class bitget extends Exchange {
4646
4646
  throw new ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
4647
4647
  }
4648
4648
  await this.loadMarkets();
4649
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
4649
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
4650
4650
  let market = undefined;
4651
4651
  if (sandboxMode) {
4652
4652
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -4786,7 +4786,7 @@ export default class bitget extends Exchange {
4786
4786
  throw new ArgumentsRequired(this.id + ' cancelOrders() requires a symbol argument');
4787
4787
  }
4788
4788
  await this.loadMarkets();
4789
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
4789
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
4790
4790
  let market = undefined;
4791
4791
  if (sandboxMode) {
4792
4792
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -4880,7 +4880,7 @@ export default class bitget extends Exchange {
4880
4880
  throw new ArgumentsRequired(this.id + ' cancelAllOrders() requires a symbol argument');
4881
4881
  }
4882
4882
  await this.loadMarkets();
4883
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
4883
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
4884
4884
  let market = undefined;
4885
4885
  if (sandboxMode) {
4886
4886
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -4984,7 +4984,7 @@ export default class bitget extends Exchange {
4984
4984
  throw new ArgumentsRequired(this.id + ' fetchOrder() requires a symbol argument');
4985
4985
  }
4986
4986
  await this.loadMarkets();
4987
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
4987
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
4988
4988
  let market = undefined;
4989
4989
  if (sandboxMode) {
4990
4990
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -5100,7 +5100,7 @@ export default class bitget extends Exchange {
5100
5100
  * @param {int} [limit] the maximum number of open order structures to retrieve
5101
5101
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5102
5102
  * @param {int} [params.until] the latest time in ms to fetch orders for
5103
- * @param {string} [params.planType] *contract stop only* 'normal_plan': average trigger order, 'track_plan': trailing stop order, default is 'normal_plan'
5103
+ * @param {string} [params.planType] *contract stop only* 'normal_plan': average trigger order, 'profit_loss': opened tp/sl orders, 'track_plan': trailing stop order, default is 'normal_plan'
5104
5104
  * @param {boolean} [params.stop] set to true for fetching trigger orders
5105
5105
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
5106
5106
  * @param {string} [params.isPlan] *swap only* 'plan' for stop orders and 'profit_loss' for tp/sl orders, default is 'plan'
@@ -5108,7 +5108,7 @@ export default class bitget extends Exchange {
5108
5108
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
5109
5109
  */
5110
5110
  await this.loadMarkets();
5111
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
5111
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
5112
5112
  let market = undefined;
5113
5113
  let type = undefined;
5114
5114
  let request = {};
@@ -5146,8 +5146,10 @@ export default class bitget extends Exchange {
5146
5146
  return await this.fetchPaginatedCallCursor('fetchOpenOrders', symbol, since, limit, params, cursorReceived, 'idLessThan');
5147
5147
  }
5148
5148
  let response = undefined;
5149
- const trailing = this.safeValue(params, 'trailing');
5150
- const stop = this.safeValue2(params, 'stop', 'trigger');
5149
+ const trailing = this.safeBool(params, 'trailing');
5150
+ const stop = this.safeBool2(params, 'stop', 'trigger');
5151
+ const planTypeDefined = this.safeString(params, 'planType') !== undefined;
5152
+ const isStop = (stop || planTypeDefined);
5151
5153
  params = this.omit(params, ['stop', 'trigger', 'trailing']);
5152
5154
  [request, params] = this.handleUntilOption('endTime', request, params);
5153
5155
  if (since !== undefined) {
@@ -5196,7 +5198,7 @@ export default class bitget extends Exchange {
5196
5198
  request['planType'] = planType;
5197
5199
  response = await this.privateMixGetV2MixOrderOrdersPlanPending(this.extend(request, query));
5198
5200
  }
5199
- else if (stop) {
5201
+ else if (isStop) {
5200
5202
  const planType = this.safeString(query, 'planType', 'normal_plan');
5201
5203
  request['planType'] = planType;
5202
5204
  response = await this.privateMixGetV2MixOrderOrdersPlanPending(this.extend(request, query));
@@ -5463,7 +5465,7 @@ export default class bitget extends Exchange {
5463
5465
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
5464
5466
  */
5465
5467
  await this.loadMarkets();
5466
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
5468
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
5467
5469
  let market = undefined;
5468
5470
  if (sandboxMode) {
5469
5471
  if (symbol !== undefined) {
@@ -5496,7 +5498,7 @@ export default class bitget extends Exchange {
5496
5498
  }
5497
5499
  let response = undefined;
5498
5500
  const trailing = this.safeValue(params, 'trailing');
5499
- const stop = this.safeValue2(params, 'stop', 'trigger');
5501
+ const stop = this.safeBool2(params, 'stop', 'trigger');
5500
5502
  params = this.omit(params, ['stop', 'trigger', 'trailing']);
5501
5503
  [request, params] = this.handleUntilOption('endTime', request, params);
5502
5504
  if (since !== undefined) {
@@ -5780,7 +5782,7 @@ export default class bitget extends Exchange {
5780
5782
  params = this.omit(params, 'symbol');
5781
5783
  let market = undefined;
5782
5784
  if (symbol !== undefined) {
5783
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
5785
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
5784
5786
  if (sandboxMode) {
5785
5787
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
5786
5788
  market = this.market(sandboxSymbol);
@@ -6000,7 +6002,7 @@ export default class bitget extends Exchange {
6000
6002
  throw new ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
6001
6003
  }
6002
6004
  await this.loadMarkets();
6003
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
6005
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
6004
6006
  let market = undefined;
6005
6007
  if (sandboxMode) {
6006
6008
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -6179,7 +6181,7 @@ export default class bitget extends Exchange {
6179
6181
  * @returns {object} a [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
6180
6182
  */
6181
6183
  await this.loadMarkets();
6182
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
6184
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
6183
6185
  let market = undefined;
6184
6186
  if (sandboxMode) {
6185
6187
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -6255,7 +6257,7 @@ export default class bitget extends Exchange {
6255
6257
  let market = undefined;
6256
6258
  if (symbols !== undefined) {
6257
6259
  const first = this.safeString(symbols, 0);
6258
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
6260
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
6259
6261
  if (sandboxMode) {
6260
6262
  const sandboxSymbol = this.convertSymbolForSandbox(first);
6261
6263
  market = this.market(sandboxSymbol);
@@ -6575,7 +6577,7 @@ export default class bitget extends Exchange {
6575
6577
  if (paginate) {
6576
6578
  return await this.fetchPaginatedCallIncremental('fetchFundingRateHistory', symbol, since, limit, params, 'pageNo', 100);
6577
6579
  }
6578
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
6580
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
6579
6581
  let market = undefined;
6580
6582
  if (sandboxMode) {
6581
6583
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -6639,7 +6641,7 @@ export default class bitget extends Exchange {
6639
6641
  * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
6640
6642
  */
6641
6643
  await this.loadMarkets();
6642
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
6644
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
6643
6645
  let market = undefined;
6644
6646
  if (sandboxMode) {
6645
6647
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -6726,7 +6728,7 @@ export default class bitget extends Exchange {
6726
6728
  if (paginate) {
6727
6729
  return await this.fetchPaginatedCallCursor('fetchFundingHistory', symbol, since, limit, params, 'endId', 'idLessThan');
6728
6730
  }
6729
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
6731
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
6730
6732
  let market = undefined;
6731
6733
  if (sandboxMode) {
6732
6734
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -6822,7 +6824,7 @@ export default class bitget extends Exchange {
6822
6824
  async modifyMarginHelper(symbol, amount, type, params = {}) {
6823
6825
  await this.loadMarkets();
6824
6826
  const holdSide = this.safeString(params, 'holdSide');
6825
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
6827
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
6826
6828
  let market = undefined;
6827
6829
  if (sandboxMode) {
6828
6830
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -6915,7 +6917,7 @@ export default class bitget extends Exchange {
6915
6917
  * @returns {object} a [leverage structure]{@link https://docs.ccxt.com/#/?id=leverage-structure}
6916
6918
  */
6917
6919
  await this.loadMarkets();
6918
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
6920
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
6919
6921
  let market = undefined;
6920
6922
  if (sandboxMode) {
6921
6923
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -6936,28 +6938,41 @@ export default class bitget extends Exchange {
6936
6938
  // {
6937
6939
  // "code": "00000",
6938
6940
  // "msg": "success",
6939
- // "requestTime": 1700625127294,
6940
- // "data": [
6941
- // {
6942
- // "marginCoin": "USDT",
6943
- // "locked": "0",
6944
- // "available": "0",
6945
- // "crossedMaxAvailable": "0",
6946
- // "isolatedMaxAvailable": "0",
6947
- // "maxTransferOut": "0",
6948
- // "accountEquity": "0",
6949
- // "usdtEquity": "0.000000005166",
6950
- // "btcEquity": "0",
6951
- // "crossedRiskRate": "0",
6952
- // "unrealizedPL": "0",
6953
- // "coupon": "0",
6954
- // "crossedUnrealizedPL": null,
6955
- // "isolatedUnrealizedPL": null
6956
- // }
6957
- // ]
6941
+ // "requestTime": 1709366911964,
6942
+ // "data": {
6943
+ // "marginCoin": "USDT",
6944
+ // "locked": "0",
6945
+ // "available": "0",
6946
+ // "crossedMaxAvailable": "0",
6947
+ // "isolatedMaxAvailable": "0",
6948
+ // "maxTransferOut": "0",
6949
+ // "accountEquity": "0",
6950
+ // "usdtEquity": "0.000000009166",
6951
+ // "btcEquity": "0",
6952
+ // "crossedRiskRate": "0",
6953
+ // "crossedMarginLeverage": 20,
6954
+ // "isolatedLongLever": 20,
6955
+ // "isolatedShortLever": 20,
6956
+ // "marginMode": "crossed",
6957
+ // "posMode": "hedge_mode",
6958
+ // "unrealizedPL": "0",
6959
+ // "coupon": "0",
6960
+ // "crossedUnrealizedPL": "0",
6961
+ // "isolatedUnrealizedPL": ""
6962
+ // }
6958
6963
  // }
6959
6964
  //
6960
- return response;
6965
+ const data = this.safeDict(response, 'data', {});
6966
+ return this.parseLeverage(data, market);
6967
+ }
6968
+ parseLeverage(leverage, market = undefined) {
6969
+ return {
6970
+ 'info': leverage,
6971
+ 'symbol': market['symbol'],
6972
+ 'marginMode': 'isolated',
6973
+ 'longLeverage': this.safeInteger(leverage, 'isolatedLongLever'),
6974
+ 'shortLeverage': this.safeInteger(leverage, 'isolatedShortLever'),
6975
+ };
6961
6976
  }
6962
6977
  async setLeverage(leverage, symbol = undefined, params = {}) {
6963
6978
  /**
@@ -6975,7 +6990,7 @@ export default class bitget extends Exchange {
6975
6990
  throw new ArgumentsRequired(this.id + ' setLeverage() requires a symbol argument');
6976
6991
  }
6977
6992
  await this.loadMarkets();
6978
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
6993
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
6979
6994
  let market = undefined;
6980
6995
  if (sandboxMode) {
6981
6996
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -7033,7 +7048,7 @@ export default class bitget extends Exchange {
7033
7048
  throw new ArgumentsRequired(this.id + ' setMarginMode() marginMode must be either isolated or crossed (cross)');
7034
7049
  }
7035
7050
  await this.loadMarkets();
7036
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
7051
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
7037
7052
  let market = undefined;
7038
7053
  if (sandboxMode) {
7039
7054
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -7083,7 +7098,7 @@ export default class bitget extends Exchange {
7083
7098
  const posMode = hedged ? 'hedge_mode' : 'one_way_mode';
7084
7099
  let market = undefined;
7085
7100
  if (symbol !== undefined) {
7086
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
7101
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
7087
7102
  if (sandboxMode) {
7088
7103
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
7089
7104
  market = this.market(sandboxSymbol);
@@ -7122,7 +7137,7 @@ export default class bitget extends Exchange {
7122
7137
  * @returns {object} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure}
7123
7138
  */
7124
7139
  await this.loadMarkets();
7125
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
7140
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
7126
7141
  let market = undefined;
7127
7142
  if (sandboxMode) {
7128
7143
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -8156,7 +8171,7 @@ export default class bitget extends Exchange {
8156
8171
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
8157
8172
  */
8158
8173
  await this.loadMarkets();
8159
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
8174
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
8160
8175
  let market = undefined;
8161
8176
  if (sandboxMode) {
8162
8177
  const sandboxSymbol = this.convertSymbolForSandbox(symbol);
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/bitmex.js';
2
- import type { Int, OrderSide, OrderType, Trade, OHLCV, Order, Liquidation, OrderBook, Balances, Str, Transaction, Ticker, Tickers, Market, Strings, Currency } from './base/types.js';
2
+ import type { Int, OrderSide, OrderType, Trade, OHLCV, Order, Liquidation, OrderBook, Balances, Str, Transaction, Ticker, Tickers, Market, Strings, Currency, Leverage, Leverages } from './base/types.js';
3
3
  /**
4
4
  * @class bitmex
5
5
  * @augments Exchange
@@ -62,8 +62,8 @@ export default class bitmex extends Exchange {
62
62
  cancelOrder(id: string, symbol?: Str, params?: {}): Promise<Order>;
63
63
  cancelOrders(ids: any, symbol?: Str, params?: {}): Promise<Order[]>;
64
64
  cancelAllOrders(symbol?: Str, params?: {}): Promise<Order[]>;
65
- fetchLeverages(symbols?: string[], params?: {}): Promise<any[]>;
66
- fetchLeverage(symbol: string, params?: {}): Promise<any[]>;
65
+ fetchLeverages(symbols?: string[], params?: {}): Promise<Leverages>;
66
+ parseLeverage(leverage: any, market?: any): Leverage;
67
67
  fetchPositions(symbols?: Strings, params?: {}): Promise<import("./base/types.js").Position[]>;
68
68
  parsePosition(position: any, market?: Market): import("./base/types.js").Position;
69
69
  withdraw(code: string, amount: number, address: any, tag?: any, params?: {}): Promise<Transaction>;
package/js/src/bitmex.js CHANGED
@@ -62,7 +62,7 @@ export default class bitmex extends Exchange {
62
62
  'fetchFundingRates': true,
63
63
  'fetchIndexOHLCV': false,
64
64
  'fetchLedger': true,
65
- 'fetchLeverage': true,
65
+ 'fetchLeverage': 'emulated',
66
66
  'fetchLeverages': true,
67
67
  'fetchLeverageTiers': false,
68
68
  'fetchLiquidations': true,
@@ -2129,34 +2129,18 @@ export default class bitmex extends Exchange {
2129
2129
  * @returns {object} a list of [leverage structures]{@link https://docs.ccxt.com/#/?id=leverage-structure}
2130
2130
  */
2131
2131
  await this.loadMarkets();
2132
- const positions = await this.fetchPositions(symbols, params);
2133
- const result = [];
2134
- for (let i = 0; i < positions.length; i++) {
2135
- const entry = positions[i];
2136
- const marketId = this.safeString(entry, 'symbol');
2137
- const market = this.safeMarket(marketId, undefined, undefined, 'contract');
2138
- result.push({
2139
- 'info': entry,
2140
- 'symbol': market['symbol'],
2141
- 'leverage': this.safeInteger(entry, 'leverage'),
2142
- 'marginMode': this.safeString(entry, 'marginMode'),
2143
- });
2144
- }
2145
- return result;
2132
+ const leverages = await this.fetchPositions(symbols, params);
2133
+ return this.parseLeverages(leverages, symbols, 'symbol');
2146
2134
  }
2147
- async fetchLeverage(symbol, params = {}) {
2148
- /**
2149
- * @method
2150
- * @name bitmex#fetchLeverage
2151
- * @description fetch the set leverage for a market
2152
- * @see https://www.bitmex.com/api/explorer/#!/Position/Position_get
2153
- * @param {string} symbol unified market symbol
2154
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2155
- * @returns {object} a [leverage structure]{@link https://docs.ccxt.com/#/?id=leverage-structure}
2156
- */
2157
- await this.loadMarkets();
2158
- const leverage = await this.fetchLeverages([symbol], params);
2159
- return leverage;
2135
+ parseLeverage(leverage, market = undefined) {
2136
+ const marketId = this.safeString(leverage, 'symbol');
2137
+ return {
2138
+ 'info': leverage,
2139
+ 'symbol': this.safeSymbol(marketId, market),
2140
+ 'marginMode': this.safeStringLower(leverage, 'marginMode'),
2141
+ 'longLeverage': this.safeInteger(leverage, 'leverage'),
2142
+ 'shortLeverage': this.safeInteger(leverage, 'leverage'),
2143
+ };
2160
2144
  }
2161
2145
  async fetchPositions(symbols = undefined, params = {}) {
2162
2146
  /**