ccxt 4.2.39 → 4.2.40

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 (47) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +923 -310
  3. package/dist/ccxt.browser.min.js +2 -2
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/ascendex.js +28 -24
  6. package/dist/cjs/src/base/Exchange.js +14 -14
  7. package/dist/cjs/src/binance.js +372 -146
  8. package/dist/cjs/src/bingx.js +250 -23
  9. package/dist/cjs/src/bitget.js +13 -2
  10. package/dist/cjs/src/bybit.js +3 -1
  11. package/dist/cjs/src/coinbase.js +8 -6
  12. package/dist/cjs/src/coinbasepro.js +1 -0
  13. package/dist/cjs/src/coinlist.js +9 -7
  14. package/dist/cjs/src/coinmetro.js +2 -1
  15. package/dist/cjs/src/krakenfutures.js +126 -2
  16. package/dist/cjs/src/mexc.js +43 -43
  17. package/dist/cjs/src/okx.js +9 -15
  18. package/dist/cjs/src/phemex.js +1 -0
  19. package/dist/cjs/src/pro/bitmart.js +38 -20
  20. package/dist/cjs/src/pro/bybit.js +5 -5
  21. package/js/ccxt.d.ts +1 -1
  22. package/js/ccxt.js +1 -1
  23. package/js/src/abstract/bingx.d.ts +4 -0
  24. package/js/src/abstract/coinbasepro.d.ts +1 -0
  25. package/js/src/ascendex.js +28 -24
  26. package/js/src/base/Exchange.d.ts +8 -8
  27. package/js/src/base/Exchange.js +14 -14
  28. package/js/src/binance.d.ts +1 -1
  29. package/js/src/binance.js +372 -146
  30. package/js/src/bingx.d.ts +1 -0
  31. package/js/src/bingx.js +250 -23
  32. package/js/src/bitget.js +13 -2
  33. package/js/src/bybit.js +3 -1
  34. package/js/src/coinbase.js +8 -6
  35. package/js/src/coinbasepro.js +1 -0
  36. package/js/src/coinlist.js +9 -7
  37. package/js/src/coinmetro.js +2 -1
  38. package/js/src/krakenfutures.d.ts +2 -0
  39. package/js/src/krakenfutures.js +126 -2
  40. package/js/src/mexc.js +43 -43
  41. package/js/src/okx.js +9 -15
  42. package/js/src/phemex.js +1 -0
  43. package/js/src/pro/bitmart.d.ts +2 -0
  44. package/js/src/pro/bitmart.js +38 -20
  45. package/js/src/pro/bybit.d.ts +1 -1
  46. package/js/src/pro/bybit.js +5 -5
  47. package/package.json +1 -1
@@ -2649,7 +2649,7 @@ class binance extends binance$1 {
2649
2649
  let minPrecision = undefined;
2650
2650
  let isWithdrawEnabled = true;
2651
2651
  let isDepositEnabled = true;
2652
- const networkList = this.safeValue(entry, 'networkList', []);
2652
+ const networkList = this.safeList(entry, 'networkList', []);
2653
2653
  const fees = {};
2654
2654
  let fee = undefined;
2655
2655
  for (let j = 0; j < networkList.length; j++) {
@@ -2657,12 +2657,12 @@ class binance extends binance$1 {
2657
2657
  const network = this.safeString(networkItem, 'network');
2658
2658
  // const name = this.safeString (networkItem, 'name');
2659
2659
  const withdrawFee = this.safeNumber(networkItem, 'withdrawFee');
2660
- const depositEnable = this.safeValue(networkItem, 'depositEnable');
2661
- const withdrawEnable = this.safeValue(networkItem, 'withdrawEnable');
2660
+ const depositEnable = this.safeBool(networkItem, 'depositEnable');
2661
+ const withdrawEnable = this.safeBool(networkItem, 'withdrawEnable');
2662
2662
  isDepositEnabled = isDepositEnabled || depositEnable;
2663
2663
  isWithdrawEnabled = isWithdrawEnabled || withdrawEnable;
2664
2664
  fees[network] = withdrawFee;
2665
- const isDefault = this.safeValue(networkItem, 'isDefault');
2665
+ const isDefault = this.safeBool(networkItem, 'isDefault');
2666
2666
  if (isDefault || (fee === undefined)) {
2667
2667
  fee = withdrawFee;
2668
2668
  }
@@ -2673,7 +2673,7 @@ class binance extends binance$1 {
2673
2673
  minPrecision = (minPrecision === undefined) ? precisionTick : Precise["default"].stringMin(minPrecision, precisionTick);
2674
2674
  }
2675
2675
  }
2676
- const trading = this.safeValue(entry, 'trading');
2676
+ const trading = this.safeBool(entry, 'trading');
2677
2677
  const active = (isWithdrawEnabled && isDepositEnabled && trading);
2678
2678
  let maxDecimalPlaces = undefined;
2679
2679
  if (minPrecision !== undefined) {
@@ -2709,8 +2709,8 @@ class binance extends binance$1 {
2709
2709
  * @returns {object[]} an array of objects representing market data
2710
2710
  */
2711
2711
  const promisesRaw = [];
2712
- const rawFetchMarkets = this.safeValue(this.options, 'fetchMarkets', ['spot', 'linear', 'inverse']);
2713
- const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
2712
+ const rawFetchMarkets = this.safeList(this.options, 'fetchMarkets', ['spot', 'linear', 'inverse']);
2713
+ const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
2714
2714
  const fetchMarkets = [];
2715
2715
  for (let i = 0; i < rawFetchMarkets.length; i++) {
2716
2716
  const type = rawFetchMarkets[i];
@@ -2988,7 +2988,7 @@ class binance extends binance$1 {
2988
2988
  }
2989
2989
  const settle = this.safeCurrencyCode(settleId);
2990
2990
  const spot = !contract;
2991
- const filters = this.safeValue(market, 'filters', []);
2991
+ const filters = this.safeList(market, 'filters', []);
2992
2992
  const filtersByType = this.indexBy(filters, 'filterType');
2993
2993
  const status = this.safeString2(market, 'status', 'contractStatus');
2994
2994
  let contractSize = undefined;
@@ -3011,11 +3011,11 @@ class binance extends binance$1 {
3011
3011
  linear = settle === quote;
3012
3012
  inverse = settle === base;
3013
3013
  const feesType = linear ? 'linear' : 'inverse';
3014
- fees = this.safeValue(this.fees, feesType, {});
3014
+ fees = this.safeDict(this.fees, feesType, {});
3015
3015
  }
3016
3016
  let active = (status === 'TRADING');
3017
3017
  if (spot) {
3018
- const permissions = this.safeValue(market, 'permissions', []);
3018
+ const permissions = this.safeList(market, 'permissions', []);
3019
3019
  for (let j = 0; j < permissions.length; j++) {
3020
3020
  if (permissions[j] === 'TRD_GRP_003') {
3021
3021
  active = false;
@@ -3093,7 +3093,7 @@ class binance extends binance$1 {
3093
3093
  'created': this.safeInteger(market, 'onboardDate'), // present in inverse & linear apis
3094
3094
  };
3095
3095
  if ('PRICE_FILTER' in filtersByType) {
3096
- const filter = this.safeValue(filtersByType, 'PRICE_FILTER', {});
3096
+ const filter = this.safeDict(filtersByType, 'PRICE_FILTER', {});
3097
3097
  // PRICE_FILTER reports zero values for maxPrice
3098
3098
  // since they updated filter types in November 2018
3099
3099
  // https://github.com/ccxt/ccxt/issues/4286
@@ -3105,7 +3105,7 @@ class binance extends binance$1 {
3105
3105
  entry['precision']['price'] = this.precisionFromString(filter['tickSize']);
3106
3106
  }
3107
3107
  if ('LOT_SIZE' in filtersByType) {
3108
- const filter = this.safeValue(filtersByType, 'LOT_SIZE', {});
3108
+ const filter = this.safeDict(filtersByType, 'LOT_SIZE', {});
3109
3109
  const stepSize = this.safeString(filter, 'stepSize');
3110
3110
  entry['precision']['amount'] = this.precisionFromString(stepSize);
3111
3111
  entry['limits']['amount'] = {
@@ -3114,14 +3114,14 @@ class binance extends binance$1 {
3114
3114
  };
3115
3115
  }
3116
3116
  if ('MARKET_LOT_SIZE' in filtersByType) {
3117
- const filter = this.safeValue(filtersByType, 'MARKET_LOT_SIZE', {});
3117
+ const filter = this.safeDict(filtersByType, 'MARKET_LOT_SIZE', {});
3118
3118
  entry['limits']['market'] = {
3119
3119
  'min': this.safeNumber(filter, 'minQty'),
3120
3120
  'max': this.safeNumber(filter, 'maxQty'),
3121
3121
  };
3122
3122
  }
3123
3123
  if (('MIN_NOTIONAL' in filtersByType) || ('NOTIONAL' in filtersByType)) { // notional added in 12/04/23 to spot testnet
3124
- const filter = this.safeValue2(filtersByType, 'MIN_NOTIONAL', 'NOTIONAL', {});
3124
+ const filter = this.safeDict2(filtersByType, 'MIN_NOTIONAL', 'NOTIONAL', {});
3125
3125
  entry['limits']['cost']['min'] = this.safeNumber2(filter, 'minNotional', 'notional');
3126
3126
  entry['limits']['cost']['max'] = this.safeNumber(filter, 'maxNotional');
3127
3127
  }
@@ -3815,7 +3815,7 @@ class binance extends binance$1 {
3815
3815
  }
3816
3816
  }
3817
3817
  if (Array.isArray(response)) {
3818
- const firstTicker = this.safeValue(response, 0, {});
3818
+ const firstTicker = this.safeDict(response, 0, {});
3819
3819
  return this.parseTicker(firstTicker, market);
3820
3820
  }
3821
3821
  return this.parseTicker(response, market);
@@ -5241,7 +5241,7 @@ class binance extends binance$1 {
5241
5241
  cost = this.safeString(order, 'cumBase', cost);
5242
5242
  let type = this.safeStringLower(order, 'type');
5243
5243
  const side = this.safeStringLower(order, 'side');
5244
- const fills = this.safeValue(order, 'fills', []);
5244
+ const fills = this.safeList(order, 'fills', []);
5245
5245
  let timeInForce = this.safeString(order, 'timeInForce');
5246
5246
  if (timeInForce === 'GTX') {
5247
5247
  // GTX means "Good Till Crossing" and is an equivalent way of saying Post Only
@@ -5274,7 +5274,7 @@ class binance extends binance$1 {
5274
5274
  'type': type,
5275
5275
  'timeInForce': timeInForce,
5276
5276
  'postOnly': postOnly,
5277
- 'reduceOnly': this.safeValue(order, 'reduceOnly'),
5277
+ 'reduceOnly': this.safeBool(order, 'reduceOnly'),
5278
5278
  'side': side,
5279
5279
  'price': price,
5280
5280
  'triggerPrice': stopPrice,
@@ -5308,7 +5308,7 @@ class binance extends binance$1 {
5308
5308
  const side = this.safeString(rawOrder, 'side');
5309
5309
  const amount = this.safeValue(rawOrder, 'amount');
5310
5310
  const price = this.safeValue(rawOrder, 'price');
5311
- const orderParams = this.safeValue(rawOrder, 'params', {});
5311
+ const orderParams = this.safeDict(rawOrder, 'params', {});
5312
5312
  const orderRequest = this.createOrderRequest(marketId, type, side, amount, price, orderParams);
5313
5313
  ordersRequests.push(orderRequest);
5314
5314
  }
@@ -6700,11 +6700,11 @@ class binance extends binance$1 {
6700
6700
  // },
6701
6701
  // ]
6702
6702
  // }
6703
- const results = this.safeValue(response, 'userAssetDribblets', []);
6703
+ const results = this.safeList(response, 'userAssetDribblets', []);
6704
6704
  const rows = this.safeInteger(response, 'total', 0);
6705
6705
  const data = [];
6706
6706
  for (let i = 0; i < rows; i++) {
6707
- const logs = this.safeValue(results[i], 'userAssetDribbletDetails', []);
6707
+ const logs = this.safeList(results[i], 'userAssetDribbletDetails', []);
6708
6708
  for (let j = 0; j < logs.length; j++) {
6709
6709
  logs[j]['isDustTrade'] = true;
6710
6710
  data.push(logs[j]);
@@ -6811,7 +6811,7 @@ class binance extends binance$1 {
6811
6811
  let currency = undefined;
6812
6812
  let response = undefined;
6813
6813
  const request = {};
6814
- const legalMoney = this.safeValue(this.options, 'legalMoney', {});
6814
+ const legalMoney = this.safeDict(this.options, 'legalMoney', {});
6815
6815
  const fiatOnly = this.safeBool(params, 'fiat', false);
6816
6816
  params = this.omit(params, 'fiatOnly');
6817
6817
  const until = this.safeInteger(params, 'until');
@@ -6923,7 +6923,7 @@ class binance extends binance$1 {
6923
6923
  if (paginate) {
6924
6924
  return await this.fetchPaginatedCallDynamic('fetchWithdrawals', code, since, limit, params);
6925
6925
  }
6926
- const legalMoney = this.safeValue(this.options, 'legalMoney', {});
6926
+ const legalMoney = this.safeDict(this.options, 'legalMoney', {});
6927
6927
  const fiatOnly = this.safeBool(params, 'fiat', false);
6928
6928
  params = this.omit(params, 'fiatOnly');
6929
6929
  const request = {};
@@ -7067,7 +7067,7 @@ class binance extends binance$1 {
7067
7067
  'Refund Failed': 'failed',
7068
7068
  },
7069
7069
  };
7070
- const statuses = this.safeValue(statusesByType, type, {});
7070
+ const statuses = this.safeDict(statusesByType, type, {});
7071
7071
  return this.safeString(statuses, status, status);
7072
7072
  }
7073
7073
  parseTransaction(transaction, currency = undefined) {
@@ -7232,7 +7232,7 @@ class binance extends binance$1 {
7232
7232
  const type = this.safeString(transfer, 'type');
7233
7233
  let fromAccount = undefined;
7234
7234
  let toAccount = undefined;
7235
- const accountsById = this.safeValue(this.options, 'accountsById', {});
7235
+ const accountsById = this.safeDict(this.options, 'accountsById', {});
7236
7236
  if (type !== undefined) {
7237
7237
  const parts = type.split('_');
7238
7238
  fromAccount = this.safeValue(parts, 0);
@@ -7268,20 +7268,16 @@ class binance extends binance$1 {
7268
7268
  // }
7269
7269
  //
7270
7270
  const marketId = this.safeString(income, 'symbol');
7271
- const symbol = this.safeSymbol(marketId, market, undefined, 'swap');
7272
- const amount = this.safeNumber(income, 'income');
7273
7271
  const currencyId = this.safeString(income, 'asset');
7274
- const code = this.safeCurrencyCode(currencyId);
7275
- const id = this.safeString(income, 'tranId');
7276
7272
  const timestamp = this.safeInteger(income, 'time');
7277
7273
  return {
7278
7274
  'info': income,
7279
- 'symbol': symbol,
7280
- 'code': code,
7275
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'swap'),
7276
+ 'code': this.safeCurrencyCode(currencyId),
7281
7277
  'timestamp': timestamp,
7282
7278
  'datetime': this.iso8601(timestamp),
7283
- 'id': id,
7284
- 'amount': amount,
7279
+ 'id': this.safeString(income, 'tranId'),
7280
+ 'amount': this.safeNumber(income, 'income'),
7285
7281
  };
7286
7282
  }
7287
7283
  async transfer(code, amount, fromAccount, toAccount, params = {}) {
@@ -7330,7 +7326,7 @@ class binance extends binance$1 {
7330
7326
  throw new errors.ArgumentsRequired(this.id + ' transfer () requires params["symbol"] when toAccount is ' + toAccount);
7331
7327
  }
7332
7328
  }
7333
- const accountsById = this.safeValue(this.options, 'accountsById', {});
7329
+ const accountsById = this.safeDict(this.options, 'accountsById', {});
7334
7330
  const fromIsolated = !(fromId in accountsById);
7335
7331
  const toIsolated = !(toId in accountsById);
7336
7332
  if (fromIsolated && (market === undefined)) {
@@ -7420,7 +7416,7 @@ class binance extends binance$1 {
7420
7416
  const defaultTo = (fromAccount === 'future') ? 'spot' : 'future';
7421
7417
  const toAccount = this.safeString(params, 'toAccount', defaultTo);
7422
7418
  let type = this.safeString(params, 'type');
7423
- const accountsByType = this.safeValue(this.options, 'accountsByType', {});
7419
+ const accountsByType = this.safeDict(this.options, 'accountsByType', {});
7424
7420
  const fromId = this.safeString(accountsByType, fromAccount);
7425
7421
  const toId = this.safeString(accountsByType, toAccount);
7426
7422
  if (type === undefined) {
@@ -7464,7 +7460,7 @@ class binance extends binance$1 {
7464
7460
  // ]
7465
7461
  // }
7466
7462
  //
7467
- const rows = this.safeValue(response, 'rows', []);
7463
+ const rows = this.safeList(response, 'rows', []);
7468
7464
  return this.parseTransfers(rows, currency, since, limit);
7469
7465
  }
7470
7466
  async fetchDepositAddress(code, params = {}) {
@@ -7483,7 +7479,7 @@ class binance extends binance$1 {
7483
7479
  'coin': currency['id'],
7484
7480
  // 'network': 'ETH', // 'BSC', 'XMR', you can get network and isDefault in networkList in the response of sapiGetCapitalConfigDetail
7485
7481
  };
7486
- const networks = this.safeValue(this.options, 'networks', {});
7482
+ const networks = this.safeDict(this.options, 'networks', {});
7487
7483
  let network = this.safeStringUpper(params, 'network'); // this line allows the user to specify either ERC20 or ETH
7488
7484
  network = this.safeString(networks, network, network); // handle ERC20>ETH alias
7489
7485
  if (network !== undefined) {
@@ -7510,7 +7506,7 @@ class binance extends binance$1 {
7510
7506
  const url = this.safeString(response, 'url');
7511
7507
  let impliedNetwork = undefined;
7512
7508
  if (url !== undefined) {
7513
- const reverseNetworks = this.safeValue(this.options, 'reverseNetworks', {});
7509
+ const reverseNetworks = this.safeDict(this.options, 'reverseNetworks', {});
7514
7510
  const parts = url.split('/');
7515
7511
  let topLevel = this.safeString(parts, 2);
7516
7512
  if ((topLevel === 'blockchair.com') || (topLevel === 'viewblock.io')) {
@@ -7525,7 +7521,7 @@ class binance extends binance$1 {
7525
7521
  'TRX': { 'TRC20': 'TRX' },
7526
7522
  });
7527
7523
  if (code in impliedNetworks) {
7528
- const conversion = this.safeValue(impliedNetworks, code, {});
7524
+ const conversion = this.safeDict(impliedNetworks, code, {});
7529
7525
  impliedNetwork = this.safeString(conversion, impliedNetwork, impliedNetwork);
7530
7526
  }
7531
7527
  }
@@ -7641,7 +7637,7 @@ class binance extends binance$1 {
7641
7637
  const entry = response[i];
7642
7638
  const currencyId = this.safeString(entry, 'coin');
7643
7639
  const code = this.safeCurrencyCode(currencyId);
7644
- const networkList = this.safeValue(entry, 'networkList', []);
7640
+ const networkList = this.safeList(entry, 'networkList', []);
7645
7641
  withdrawFees[code] = {};
7646
7642
  for (let j = 0; j < networkList.length; j++) {
7647
7643
  const networkEntry = networkList[j];
@@ -7754,14 +7750,14 @@ class binance extends binance$1 {
7754
7750
  // ]
7755
7751
  // }
7756
7752
  //
7757
- const networkList = this.safeValue(fee, 'networkList', []);
7753
+ const networkList = this.safeList(fee, 'networkList', []);
7758
7754
  const result = this.depositWithdrawFee(fee);
7759
7755
  for (let j = 0; j < networkList.length; j++) {
7760
7756
  const networkEntry = networkList[j];
7761
7757
  const networkId = this.safeString(networkEntry, 'network');
7762
7758
  const networkCode = this.networkIdToCode(networkId);
7763
7759
  const withdrawFee = this.safeNumber(networkEntry, 'withdrawFee');
7764
- const isDefault = this.safeValue(networkEntry, 'isDefault');
7760
+ const isDefault = this.safeBool(networkEntry, 'isDefault');
7765
7761
  if (isDefault === true) {
7766
7762
  result['withdraw'] = {
7767
7763
  'fee': withdrawFee,
@@ -7809,7 +7805,7 @@ class binance extends binance$1 {
7809
7805
  if (tag !== undefined) {
7810
7806
  request['addressTag'] = tag;
7811
7807
  }
7812
- const networks = this.safeValue(this.options, 'networks', {});
7808
+ const networks = this.safeDict(this.options, 'networks', {});
7813
7809
  let network = this.safeStringUpper(params, 'network'); // this line allows the user to specify either ERC20 or ETH
7814
7810
  network = this.safeString(networks, network, network); // handle ERC20>ETH alias
7815
7811
  if (network !== undefined) {
@@ -7901,7 +7897,7 @@ class binance extends binance$1 {
7901
7897
  //
7902
7898
  let data = response;
7903
7899
  if (Array.isArray(data)) {
7904
- data = this.safeValue(data, 0, {});
7900
+ data = this.safeDict(data, 0, {});
7905
7901
  }
7906
7902
  return this.parseTradingFee(data);
7907
7903
  }
@@ -8315,8 +8311,8 @@ class binance extends binance$1 {
8315
8311
  };
8316
8312
  }
8317
8313
  parseAccountPositions(account) {
8318
- const positions = this.safeValue(account, 'positions');
8319
- const assets = this.safeValue(account, 'assets', []);
8314
+ const positions = this.safeList(account, 'positions');
8315
+ const assets = this.safeList(account, 'assets', []);
8320
8316
  const balances = {};
8321
8317
  for (let i = 0; i < assets.length; i++) {
8322
8318
  const entry = assets[i];
@@ -8335,13 +8331,17 @@ class binance extends binance$1 {
8335
8331
  const marketId = this.safeString(position, 'symbol');
8336
8332
  const market = this.safeMarket(marketId, undefined, undefined, 'contract');
8337
8333
  const code = market['linear'] ? market['quote'] : market['base'];
8338
- // sometimes not all the codes are correctly returned...
8339
- if (code in balances) {
8340
- const parsed = this.parseAccountPosition(this.extend(position, {
8341
- 'crossMargin': balances[code]['crossMargin'],
8342
- 'crossWalletBalance': balances[code]['crossWalletBalance'],
8343
- }), market);
8344
- result.push(parsed);
8334
+ const maintenanceMargin = this.safeString(position, 'maintMargin');
8335
+ // check for maintenance margin so empty positions are not returned
8336
+ if ((maintenanceMargin !== '0') && (maintenanceMargin !== '0.00000000')) {
8337
+ // sometimes not all the codes are correctly returned...
8338
+ if (code in balances) {
8339
+ const parsed = this.parseAccountPosition(this.extend(position, {
8340
+ 'crossMargin': balances[code]['crossMargin'],
8341
+ 'crossWalletBalance': balances[code]['crossWalletBalance'],
8342
+ }), market);
8343
+ result.push(parsed);
8344
+ }
8345
8345
  }
8346
8346
  }
8347
8347
  return result;
@@ -8349,6 +8349,7 @@ class binance extends binance$1 {
8349
8349
  parseAccountPosition(position, market = undefined) {
8350
8350
  //
8351
8351
  // usdm
8352
+ //
8352
8353
  // {
8353
8354
  // "symbol": "BTCBUSD",
8354
8355
  // "initialMargin": "0",
@@ -8369,6 +8370,7 @@ class binance extends binance$1 {
8369
8370
  // }
8370
8371
  //
8371
8372
  // coinm
8373
+ //
8372
8374
  // {
8373
8375
  // "symbol": "BTCUSD_210625",
8374
8376
  // "initialMargin": "0.00024393",
@@ -8387,6 +8389,46 @@ class binance extends binance$1 {
8387
8389
  // "crossWalletBalance": "34",
8388
8390
  // }
8389
8391
  //
8392
+ // linear portfolio margin
8393
+ //
8394
+ // {
8395
+ // "symbol": "CTSIUSDT",
8396
+ // "initialMargin": "0",
8397
+ // "maintMargin": "0",
8398
+ // "unrealizedProfit": "0.00000000",
8399
+ // "positionInitialMargin": "0",
8400
+ // "openOrderInitialMargin": "0",
8401
+ // "leverage": "20",
8402
+ // "entryPrice": "0.0",
8403
+ // "maxNotional": "25000",
8404
+ // "bidNotional": "0",
8405
+ // "askNotional": "0",
8406
+ // "positionSide": "SHORT",
8407
+ // "positionAmt": "0",
8408
+ // "updateTime": 0,
8409
+ // "notional": "0",
8410
+ // "breakEvenPrice": "0.0"
8411
+ // }
8412
+ //
8413
+ // inverse portoflio margin
8414
+ //
8415
+ // {
8416
+ // "symbol": "TRXUSD_PERP",
8417
+ // "initialMargin": "0",
8418
+ // "maintMargin": "0",
8419
+ // "unrealizedProfit": "0.00000000",
8420
+ // "positionInitialMargin": "0",
8421
+ // "openOrderInitialMargin": "0",
8422
+ // "leverage": "20",
8423
+ // "entryPrice": "0.00000000",
8424
+ // "positionSide": "SHORT",
8425
+ // "positionAmt": "0",
8426
+ // "maxQty": "5000000",
8427
+ // "updateTime": 0,
8428
+ // "notionalValue": "0",
8429
+ // "breakEvenPrice": "0.00000000"
8430
+ // }
8431
+ //
8390
8432
  const marketId = this.safeString(position, 'symbol');
8391
8433
  market = this.safeMarket(marketId, market, undefined, 'contract');
8392
8434
  const symbol = this.safeString(market, 'symbol');
@@ -8417,8 +8459,8 @@ class binance extends binance$1 {
8417
8459
  contractsStringAbs = Precise["default"].stringDiv(Precise["default"].stringAdd(contractsString, '0.5'), '1', 0);
8418
8460
  }
8419
8461
  const contracts = this.parseNumber(contractsStringAbs);
8420
- const leverageBrackets = this.safeValue(this.options, 'leverageBrackets', {});
8421
- const leverageBracket = this.safeValue(leverageBrackets, symbol, []);
8462
+ const leverageBrackets = this.safeDict(this.options, 'leverageBrackets', {});
8463
+ const leverageBracket = this.safeList(leverageBrackets, symbol, []);
8422
8464
  let maintenanceMarginPercentageString = undefined;
8423
8465
  for (let i = 0; i < leverageBracket.length; i++) {
8424
8466
  const bracket = leverageBracket[i];
@@ -8434,7 +8476,7 @@ class binance extends binance$1 {
8434
8476
  if (timestamp === 0) {
8435
8477
  timestamp = undefined;
8436
8478
  }
8437
- const isolated = this.safeValue(position, 'isolated');
8479
+ const isolated = this.safeBool(position, 'isolated');
8438
8480
  let marginMode = undefined;
8439
8481
  let collateralString = undefined;
8440
8482
  let walletBalance = undefined;
@@ -8587,11 +8629,45 @@ class binance extends binance$1 {
8587
8629
  // "isolatedWallet": "0.00268058"
8588
8630
  // }
8589
8631
  //
8632
+ // inverse portfolio margin
8633
+ //
8634
+ // {
8635
+ // "symbol": "ETHUSD_PERP",
8636
+ // "positionAmt": "1",
8637
+ // "entryPrice": "2422.400000007",
8638
+ // "markPrice": "2424.51267823",
8639
+ // "unRealizedProfit": "0.0000036",
8640
+ // "liquidationPrice": "293.57678898",
8641
+ // "leverage": "100",
8642
+ // "positionSide": "LONG",
8643
+ // "updateTime": 1707371941861,
8644
+ // "maxQty": "15",
8645
+ // "notionalValue": "0.00412454",
8646
+ // "breakEvenPrice": "2423.368960034"
8647
+ // }
8648
+ //
8649
+ // linear portfolio margin
8650
+ //
8651
+ // {
8652
+ // "symbol": "BTCUSDT",
8653
+ // "positionAmt": "0.01",
8654
+ // "entryPrice": "44525.0",
8655
+ // "markPrice": "45464.1735922",
8656
+ // "unRealizedProfit": "9.39173592",
8657
+ // "liquidationPrice": "38007.16308568",
8658
+ // "leverage": "100",
8659
+ // "positionSide": "LONG",
8660
+ // "updateTime": 1707371879042,
8661
+ // "maxNotionalValue": "500000.0",
8662
+ // "notional": "454.64173592",
8663
+ // "breakEvenPrice": "44542.81"
8664
+ // }
8665
+ //
8590
8666
  const marketId = this.safeString(position, 'symbol');
8591
8667
  market = this.safeMarket(marketId, market, undefined, 'contract');
8592
8668
  const symbol = this.safeString(market, 'symbol');
8593
- const leverageBrackets = this.safeValue(this.options, 'leverageBrackets', {});
8594
- const leverageBracket = this.safeValue(leverageBrackets, symbol, []);
8669
+ const leverageBrackets = this.safeDict(this.options, 'leverageBrackets', {});
8670
+ const leverageBracket = this.safeList(leverageBrackets, symbol, []);
8595
8671
  const notionalString = this.safeString2(position, 'notional', 'notionalValue');
8596
8672
  const notionalStringAbs = Precise["default"].stringAbs(notionalString);
8597
8673
  let maintenanceMarginPercentageString = undefined;
@@ -8628,7 +8704,7 @@ class binance extends binance$1 {
8628
8704
  const linear = ('notional' in position);
8629
8705
  if (marginMode === 'cross') {
8630
8706
  // calculate collateral
8631
- const precision = this.safeValue(market, 'precision', {});
8707
+ const precision = this.safeDict(market, 'precision', {});
8632
8708
  if (linear) {
8633
8709
  // walletBalance = (liquidationPrice * (±1 + mmp) ± entryPrice) * contracts
8634
8710
  let onePlusMaintenanceMarginPercentageString = undefined;
@@ -8735,12 +8811,24 @@ class binance extends binance$1 {
8735
8811
  const query = this.omit(params, 'type');
8736
8812
  let subType = undefined;
8737
8813
  [subType, params] = this.handleSubTypeAndParams('loadLeverageBrackets', undefined, params, 'linear');
8814
+ let isPortfolioMargin = undefined;
8815
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'loadLeverageBrackets', 'papi', 'portfolioMargin', false);
8738
8816
  let response = undefined;
8739
8817
  if (this.isLinear(type, subType)) {
8740
- response = await this.fapiPrivateGetLeverageBracket(query);
8818
+ if (isPortfolioMargin) {
8819
+ response = await this.papiGetUmLeverageBracket(query);
8820
+ }
8821
+ else {
8822
+ response = await this.fapiPrivateGetLeverageBracket(query);
8823
+ }
8741
8824
  }
8742
8825
  else if (this.isInverse(type, subType)) {
8743
- response = await this.dapiPrivateV2GetLeverageBracket(query);
8826
+ if (isPortfolioMargin) {
8827
+ response = await this.papiGetCmLeverageBracket(query);
8828
+ }
8829
+ else {
8830
+ response = await this.dapiPrivateV2GetLeverageBracket(query);
8831
+ }
8744
8832
  }
8745
8833
  else {
8746
8834
  throw new errors.NotSupported(this.id + ' loadLeverageBrackets() supports linear and inverse contracts only');
@@ -8750,7 +8838,7 @@ class binance extends binance$1 {
8750
8838
  const entry = response[i];
8751
8839
  const marketId = this.safeString(entry, 'symbol');
8752
8840
  const symbol = this.safeSymbol(marketId, undefined, undefined, 'contract');
8753
- const brackets = this.safeValue(entry, 'brackets', []);
8841
+ const brackets = this.safeList(entry, 'brackets', []);
8754
8842
  const result = [];
8755
8843
  for (let j = 0; j < brackets.length; j++) {
8756
8844
  const bracket = brackets[j];
@@ -8770,8 +8858,11 @@ class binance extends binance$1 {
8770
8858
  * @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
8771
8859
  * @see https://binance-docs.github.io/apidocs/futures/en/#notional-and-leverage-brackets-user_data
8772
8860
  * @see https://binance-docs.github.io/apidocs/delivery/en/#notional-bracket-for-symbol-user_data
8861
+ * @see https://binance-docs.github.io/apidocs/pm/en/#um-notional-and-leverage-brackets-user_data
8862
+ * @see https://binance-docs.github.io/apidocs/pm/en/#cm-notional-and-leverage-brackets-user_data
8773
8863
  * @param {string[]|undefined} symbols list of unified market symbols
8774
8864
  * @param {object} [params] extra parameters specific to the exchange API endpoint
8865
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the leverage tiers for a portfolio margin account
8775
8866
  * @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}, indexed by market symbols
8776
8867
  */
8777
8868
  await this.loadMarkets();
@@ -8779,12 +8870,24 @@ class binance extends binance$1 {
8779
8870
  [type, params] = this.handleMarketTypeAndParams('fetchLeverageTiers', undefined, params);
8780
8871
  let subType = undefined;
8781
8872
  [subType, params] = this.handleSubTypeAndParams('fetchLeverageTiers', undefined, params, 'linear');
8873
+ let isPortfolioMargin = undefined;
8874
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchLeverageTiers', 'papi', 'portfolioMargin', false);
8782
8875
  let response = undefined;
8783
8876
  if (this.isLinear(type, subType)) {
8784
- response = await this.fapiPrivateGetLeverageBracket(params);
8877
+ if (isPortfolioMargin) {
8878
+ response = await this.papiGetUmLeverageBracket(params);
8879
+ }
8880
+ else {
8881
+ response = await this.fapiPrivateGetLeverageBracket(params);
8882
+ }
8785
8883
  }
8786
8884
  else if (this.isInverse(type, subType)) {
8787
- response = await this.dapiPrivateV2GetLeverageBracket(params);
8885
+ if (isPortfolioMargin) {
8886
+ response = await this.papiGetCmLeverageBracket(params);
8887
+ }
8888
+ else {
8889
+ response = await this.dapiPrivateV2GetLeverageBracket(params);
8890
+ }
8788
8891
  }
8789
8892
  else {
8790
8893
  throw new errors.NotSupported(this.id + ' fetchLeverageTiers() supports linear and inverse contracts only');
@@ -8854,7 +8957,7 @@ class binance extends binance$1 {
8854
8957
  //
8855
8958
  const marketId = this.safeString(info, 'symbol');
8856
8959
  market = this.safeMarket(marketId, market, undefined, 'contract');
8857
- const brackets = this.safeValue(info, 'brackets', []);
8960
+ const brackets = this.safeList(info, 'brackets', []);
8858
8961
  const tiers = [];
8859
8962
  for (let j = 0; j < brackets.length; j++) {
8860
8963
  const bracket = brackets[j];
@@ -9069,8 +9172,11 @@ class binance extends binance$1 {
9069
9172
  * @description fetch account positions
9070
9173
  * @see https://binance-docs.github.io/apidocs/futures/en/#account-information-v2-user_data
9071
9174
  * @see https://binance-docs.github.io/apidocs/delivery/en/#account-information-user_data
9175
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-um-account-detail-user_data
9176
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-cm-account-detail-user_data
9072
9177
  * @param {string[]|undefined} symbols list of unified market symbols
9073
9178
  * @param {object} [params] extra parameters specific to the exchange API endpoint
9179
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch positions in a portfolio margin account
9074
9180
  * @returns {object} data on account positions
9075
9181
  */
9076
9182
  if (symbols !== undefined) {
@@ -9082,15 +9188,27 @@ class binance extends binance$1 {
9082
9188
  await this.loadLeverageBrackets(false, params);
9083
9189
  const defaultType = this.safeString(this.options, 'defaultType', 'future');
9084
9190
  const type = this.safeString(params, 'type', defaultType);
9085
- let query = this.omit(params, 'type');
9191
+ params = this.omit(params, 'type');
9086
9192
  let subType = undefined;
9087
- [subType, query] = this.handleSubTypeAndParams('fetchAccountPositions', undefined, params, 'linear');
9193
+ [subType, params] = this.handleSubTypeAndParams('fetchAccountPositions', undefined, params, 'linear');
9194
+ let isPortfolioMargin = undefined;
9195
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchAccountPositions', 'papi', 'portfolioMargin', false);
9088
9196
  let response = undefined;
9089
9197
  if (this.isLinear(type, subType)) {
9090
- response = await this.fapiPrivateV2GetAccount(query);
9198
+ if (isPortfolioMargin) {
9199
+ response = await this.papiGetUmAccount(params);
9200
+ }
9201
+ else {
9202
+ response = await this.fapiPrivateV2GetAccount(params);
9203
+ }
9091
9204
  }
9092
9205
  else if (this.isInverse(type, subType)) {
9093
- response = await this.dapiPrivateGetAccount(query);
9206
+ if (isPortfolioMargin) {
9207
+ response = await this.papiGetCmAccount(params);
9208
+ }
9209
+ else {
9210
+ response = await this.dapiPrivateGetAccount(params);
9211
+ }
9094
9212
  }
9095
9213
  else {
9096
9214
  throw new errors.NotSupported(this.id + ' fetchPositions() supports linear and inverse contracts only');
@@ -9107,8 +9225,11 @@ class binance extends binance$1 {
9107
9225
  * @description fetch positions risk
9108
9226
  * @see https://binance-docs.github.io/apidocs/futures/en/#position-information-v2-user_data
9109
9227
  * @see https://binance-docs.github.io/apidocs/delivery/en/#position-information-user_data
9228
+ * @see https://binance-docs.github.io/apidocs/pm/en/#query-um-position-information-user_data
9229
+ * @see https://binance-docs.github.io/apidocs/pm/en/#query-cm-position-information-user_data
9110
9230
  * @param {string[]|undefined} symbols list of unified market symbols
9111
9231
  * @param {object} [params] extra parameters specific to the exchange API endpoint
9232
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch positions for a portfolio margin account
9112
9233
  * @returns {object} data on the positions risk
9113
9234
  */
9114
9235
  if (symbols !== undefined) {
@@ -9124,71 +9245,124 @@ class binance extends binance$1 {
9124
9245
  const type = this.safeString(params, 'type', defaultType);
9125
9246
  let subType = undefined;
9126
9247
  [subType, params] = this.handleSubTypeAndParams('fetchPositionsRisk', undefined, params, 'linear');
9248
+ let isPortfolioMargin = undefined;
9249
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchPositionsRisk', 'papi', 'portfolioMargin', false);
9127
9250
  params = this.omit(params, 'type');
9128
9251
  let response = undefined;
9129
9252
  if (this.isLinear(type, subType)) {
9130
- response = await this.fapiPrivateV2GetPositionRisk(this.extend(request, params));
9131
- // ### Response examples ###
9132
- //
9133
- // For One-way position mode:
9134
- // [
9135
- // {
9136
- // "entryPrice": "0.00000",
9137
- // "marginType": "isolated",
9138
- // "isAutoAddMargin": "false",
9139
- // "isolatedMargin": "0.00000000",
9140
- // "leverage": "10",
9141
- // "liquidationPrice": "0",
9142
- // "markPrice": "6679.50671178",
9143
- // "maxNotionalValue": "20000000",
9144
- // "positionAmt": "0.000",
9145
- // "symbol": "BTCUSDT",
9146
- // "unRealizedProfit": "0.00000000",
9147
- // "positionSide": "BOTH",
9148
- // "updateTime": 0
9149
- // }
9150
- // ]
9151
- //
9152
- // For Hedge position mode:
9153
- // [
9154
- // {
9155
- // "entryPrice": "6563.66500",
9156
- // "marginType": "isolated",
9157
- // "isAutoAddMargin": "false",
9158
- // "isolatedMargin": "15517.54150468",
9159
- // "leverage": "10",
9160
- // "liquidationPrice": "5930.78",
9161
- // "markPrice": "6679.50671178",
9162
- // "maxNotionalValue": "20000000",
9163
- // "positionAmt": "20.000",
9164
- // "symbol": "BTCUSDT",
9165
- // "unRealizedProfit": "2316.83423560"
9166
- // "positionSide": "LONG",
9167
- // "updateTime": 1625474304765
9168
- // },
9169
- // {
9170
- // "entryPrice": "0.00000",
9171
- // "marginType": "isolated",
9172
- // "isAutoAddMargin": "false",
9173
- // "isolatedMargin": "5413.95799991",
9174
- // "leverage": "10",
9175
- // "liquidationPrice": "7189.95",
9176
- // "markPrice": "6679.50671178",
9177
- // "maxNotionalValue": "20000000",
9178
- // "positionAmt": "-10.000",
9179
- // "symbol": "BTCUSDT",
9180
- // "unRealizedProfit": "-1156.46711780",
9181
- // "positionSide": "SHORT",
9182
- // "updateTime": 0
9183
- // }
9184
- // ]
9253
+ if (isPortfolioMargin) {
9254
+ response = await this.papiGetUmPositionRisk(this.extend(request, params));
9255
+ }
9256
+ else {
9257
+ response = await this.fapiPrivateV2GetPositionRisk(this.extend(request, params));
9258
+ }
9185
9259
  }
9186
9260
  else if (this.isInverse(type, subType)) {
9187
- response = await this.dapiPrivateGetPositionRisk(this.extend(request, params));
9261
+ if (isPortfolioMargin) {
9262
+ response = await this.papiGetCmPositionRisk(this.extend(request, params));
9263
+ }
9264
+ else {
9265
+ response = await this.dapiPrivateGetPositionRisk(this.extend(request, params));
9266
+ }
9188
9267
  }
9189
9268
  else {
9190
9269
  throw new errors.NotSupported(this.id + ' fetchPositionsRisk() supports linear and inverse contracts only');
9191
9270
  }
9271
+ // ### Response examples ###
9272
+ //
9273
+ // For One-way position mode:
9274
+ //
9275
+ // [
9276
+ // {
9277
+ // "entryPrice": "0.00000",
9278
+ // "marginType": "isolated",
9279
+ // "isAutoAddMargin": "false",
9280
+ // "isolatedMargin": "0.00000000",
9281
+ // "leverage": "10",
9282
+ // "liquidationPrice": "0",
9283
+ // "markPrice": "6679.50671178",
9284
+ // "maxNotionalValue": "20000000",
9285
+ // "positionAmt": "0.000",
9286
+ // "symbol": "BTCUSDT",
9287
+ // "unRealizedProfit": "0.00000000",
9288
+ // "positionSide": "BOTH",
9289
+ // "updateTime": 0
9290
+ // }
9291
+ // ]
9292
+ //
9293
+ // For Hedge position mode:
9294
+ //
9295
+ // [
9296
+ // {
9297
+ // "entryPrice": "6563.66500",
9298
+ // "marginType": "isolated",
9299
+ // "isAutoAddMargin": "false",
9300
+ // "isolatedMargin": "15517.54150468",
9301
+ // "leverage": "10",
9302
+ // "liquidationPrice": "5930.78",
9303
+ // "markPrice": "6679.50671178",
9304
+ // "maxNotionalValue": "20000000",
9305
+ // "positionAmt": "20.000",
9306
+ // "symbol": "BTCUSDT",
9307
+ // "unRealizedProfit": "2316.83423560"
9308
+ // "positionSide": "LONG",
9309
+ // "updateTime": 1625474304765
9310
+ // },
9311
+ // {
9312
+ // "entryPrice": "0.00000",
9313
+ // "marginType": "isolated",
9314
+ // "isAutoAddMargin": "false",
9315
+ // "isolatedMargin": "5413.95799991",
9316
+ // "leverage": "10",
9317
+ // "liquidationPrice": "7189.95",
9318
+ // "markPrice": "6679.50671178",
9319
+ // "maxNotionalValue": "20000000",
9320
+ // "positionAmt": "-10.000",
9321
+ // "symbol": "BTCUSDT",
9322
+ // "unRealizedProfit": "-1156.46711780",
9323
+ // "positionSide": "SHORT",
9324
+ // "updateTime": 0
9325
+ // }
9326
+ // ]
9327
+ //
9328
+ // inverse portfolio margin:
9329
+ //
9330
+ // [
9331
+ // {
9332
+ // "symbol": "ETHUSD_PERP",
9333
+ // "positionAmt": "1",
9334
+ // "entryPrice": "2422.400000007",
9335
+ // "markPrice": "2424.51267823",
9336
+ // "unRealizedProfit": "0.0000036",
9337
+ // "liquidationPrice": "293.57678898",
9338
+ // "leverage": "100",
9339
+ // "positionSide": "LONG",
9340
+ // "updateTime": 1707371941861,
9341
+ // "maxQty": "15",
9342
+ // "notionalValue": "0.00412454",
9343
+ // "breakEvenPrice": "2423.368960034"
9344
+ // }
9345
+ // ]
9346
+ //
9347
+ // linear portfolio margin:
9348
+ //
9349
+ // [
9350
+ // {
9351
+ // "symbol": "BTCUSDT",
9352
+ // "positionAmt": "0.01",
9353
+ // "entryPrice": "44525.0",
9354
+ // "markPrice": "45464.1735922",
9355
+ // "unRealizedProfit": "9.39173592",
9356
+ // "liquidationPrice": "38007.16308568",
9357
+ // "leverage": "100",
9358
+ // "positionSide": "LONG",
9359
+ // "updateTime": 1707371879042,
9360
+ // "maxNotionalValue": "500000.0",
9361
+ // "notional": "454.64173592",
9362
+ // "breakEvenPrice": "44542.81"
9363
+ // }
9364
+ // ]
9365
+ //
9192
9366
  const result = [];
9193
9367
  for (let i = 0; i < response.length; i++) {
9194
9368
  const parsed = this.parsePositionRisk(response[i]);
@@ -9204,15 +9378,19 @@ class binance extends binance$1 {
9204
9378
  * @description fetch the history of funding payments paid and received on this account
9205
9379
  * @see https://binance-docs.github.io/apidocs/futures/en/#get-income-history-user_data
9206
9380
  * @see https://binance-docs.github.io/apidocs/delivery/en/#get-income-history-user_data
9381
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-um-income-history-user_data
9382
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-cm-income-history-user_data
9207
9383
  * @param {string} symbol unified market symbol
9208
9384
  * @param {int} [since] the earliest time in ms to fetch funding history for
9209
9385
  * @param {int} [limit] the maximum number of funding history structures to retrieve
9210
9386
  * @param {object} [params] extra parameters specific to the exchange API endpoint
9387
+ * @param {int} [params.until] timestamp in ms of the latest funding history entry
9388
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the funding history for a portfolio margin account
9211
9389
  * @returns {object} a [funding history structure]{@link https://docs.ccxt.com/#/?id=funding-history-structure}
9212
9390
  */
9213
9391
  await this.loadMarkets();
9214
9392
  let market = undefined;
9215
- const request = {
9393
+ let request = {
9216
9394
  'incomeType': 'FUNDING_FEE', // "TRANSFER","WELCOME_BONUS", "REALIZED_PNL","FUNDING_FEE", "COMMISSION" and "INSURANCE_CLEAR"
9217
9395
  };
9218
9396
  if (symbol !== undefined) {
@@ -9224,6 +9402,9 @@ class binance extends binance$1 {
9224
9402
  }
9225
9403
  let subType = undefined;
9226
9404
  [subType, params] = this.handleSubTypeAndParams('fetchFundingHistory', market, params, 'linear');
9405
+ let isPortfolioMargin = undefined;
9406
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchFundingHistory', 'papi', 'portfolioMargin', false);
9407
+ [request, params] = this.handleUntilOption('endTime', request, params);
9227
9408
  if (since !== undefined) {
9228
9409
  request['startTime'] = since;
9229
9410
  }
@@ -9235,10 +9416,20 @@ class binance extends binance$1 {
9235
9416
  params = this.omit(params, 'type');
9236
9417
  let response = undefined;
9237
9418
  if (this.isLinear(type, subType)) {
9238
- response = await this.fapiPrivateGetIncome(this.extend(request, params));
9419
+ if (isPortfolioMargin) {
9420
+ response = await this.papiGetUmIncome(this.extend(request, params));
9421
+ }
9422
+ else {
9423
+ response = await this.fapiPrivateGetIncome(this.extend(request, params));
9424
+ }
9239
9425
  }
9240
9426
  else if (this.isInverse(type, subType)) {
9241
- response = await this.dapiPrivateGetIncome(this.extend(request, params));
9427
+ if (isPortfolioMargin) {
9428
+ response = await this.papiGetCmIncome(this.extend(request, params));
9429
+ }
9430
+ else {
9431
+ response = await this.dapiPrivateGetIncome(this.extend(request, params));
9432
+ }
9242
9433
  }
9243
9434
  else {
9244
9435
  throw new errors.NotSupported(this.id + ' fetchFundingHistory() supports linear and inverse contracts only');
@@ -9613,12 +9804,15 @@ class binance extends binance$1 {
9613
9804
  * @see https://binance-docs.github.io/apidocs/voptions/en/#account-funding-flow-user_data
9614
9805
  * @see https://binance-docs.github.io/apidocs/futures/en/#get-income-history-user_data
9615
9806
  * @see https://binance-docs.github.io/apidocs/delivery/en/#get-income-history-user_data
9807
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-um-income-history-user_data
9808
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-cm-income-history-user_data
9616
9809
  * @param {string} code unified currency code
9617
9810
  * @param {int} [since] timestamp in ms of the earliest ledger entry
9618
9811
  * @param {int} [limit] max number of ledger entrys to return
9619
9812
  * @param {object} [params] extra parameters specific to the exchange API endpoint
9620
9813
  * @param {int} [params.until] timestamp in ms of the latest ledger entry
9621
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
9814
+ * @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)
9815
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the ledger for a portfolio margin account
9622
9816
  * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
9623
9817
  */
9624
9818
  await this.loadMarkets();
@@ -9647,6 +9841,8 @@ class binance extends binance$1 {
9647
9841
  params = this.omit(params, 'until');
9648
9842
  request['endTime'] = until;
9649
9843
  }
9844
+ let isPortfolioMargin = undefined;
9845
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchLedger', 'papi', 'portfolioMargin', false);
9650
9846
  let response = undefined;
9651
9847
  if (type === 'option') {
9652
9848
  this.checkRequiredArgument('fetchLedger', code, 'code');
@@ -9654,10 +9850,20 @@ class binance extends binance$1 {
9654
9850
  response = await this.eapiPrivateGetBill(this.extend(request, params));
9655
9851
  }
9656
9852
  else if (this.isLinear(type, subType)) {
9657
- response = await this.fapiPrivateGetIncome(this.extend(request, params));
9853
+ if (isPortfolioMargin) {
9854
+ response = await this.papiGetUmIncome(this.extend(request, params));
9855
+ }
9856
+ else {
9857
+ response = await this.fapiPrivateGetIncome(this.extend(request, params));
9858
+ }
9658
9859
  }
9659
9860
  else if (this.isInverse(type, subType)) {
9660
- response = await this.dapiPrivateGetIncome(this.extend(request, params));
9861
+ if (isPortfolioMargin) {
9862
+ response = await this.papiGetCmIncome(this.extend(request, params));
9863
+ }
9864
+ else {
9865
+ response = await this.dapiPrivateGetIncome(this.extend(request, params));
9866
+ }
9661
9867
  }
9662
9868
  else {
9663
9869
  throw new errors.NotSupported(this.id + ' fetchLedger() supports contract wallets only');
@@ -9675,7 +9881,7 @@ class binance extends binance$1 {
9675
9881
  // }
9676
9882
  // ]
9677
9883
  //
9678
- // futures (fapi, dapi)
9884
+ // futures (fapi, dapi, papi)
9679
9885
  //
9680
9886
  // [
9681
9887
  // {
@@ -9704,7 +9910,7 @@ class binance extends binance$1 {
9704
9910
  // "createDate": 1676621042489
9705
9911
  // }
9706
9912
  //
9707
- // futures (fapi, dapi)
9913
+ // futures (fapi, dapi, papi)
9708
9914
  //
9709
9915
  // {
9710
9916
  // "symbol": "",
@@ -9813,7 +10019,7 @@ class binance extends binance$1 {
9813
10019
  const isSpotOrMargin = (api.indexOf('sapi') > -1 || api === 'private');
9814
10020
  const marketType = isSpotOrMargin ? 'spot' : 'future';
9815
10021
  const defaultId = (!isSpotOrMargin) ? 'x-xcKtGhcu' : 'x-R4BD3S82';
9816
- const broker = this.safeValue(this.options, 'broker', {});
10022
+ const broker = this.safeDict(this.options, 'broker', {});
9817
10023
  const brokerId = this.safeString(broker, marketType, defaultId);
9818
10024
  params['newClientOrderId'] = brokerId + this.uuid22();
9819
10025
  }
@@ -9841,8 +10047,8 @@ class binance extends binance$1 {
9841
10047
  }
9842
10048
  else if ((path === 'batchOrders') || (path.indexOf('sub-account') >= 0) || (path === 'capital/withdraw/apply') || (path.indexOf('staking') >= 0)) {
9843
10049
  if ((method === 'DELETE') && (path === 'batchOrders')) {
9844
- const orderidlist = this.safeValue(extendedParams, 'orderidlist', []);
9845
- const origclientorderidlist = this.safeValue(extendedParams, 'origclientorderidlist', []);
10050
+ const orderidlist = this.safeList(extendedParams, 'orderidlist', []);
10051
+ const origclientorderidlist = this.safeList(extendedParams, 'origclientorderidlist', []);
9846
10052
  extendedParams = this.omit(extendedParams, ['orderidlist', 'origclientorderidlist']);
9847
10053
  query = this.rawencode(extendedParams);
9848
10054
  const orderidlistLength = orderidlist.length;
@@ -9911,8 +10117,8 @@ class binance extends binance$1 {
9911
10117
  marketType = 'portfoliomargin';
9912
10118
  }
9913
10119
  if (marketType !== undefined) {
9914
- const exceptionsForMarketType = this.safeValue(this.exceptions, marketType, {});
9915
- return this.safeValue(exceptionsForMarketType, exactOrBroad, {});
10120
+ const exceptionsForMarketType = this.safeDict(this.exceptions, marketType, {});
10121
+ return this.safeDict(exceptionsForMarketType, exactOrBroad, {});
9916
10122
  }
9917
10123
  return {};
9918
10124
  }
@@ -10146,7 +10352,7 @@ class binance extends binance$1 {
10146
10352
  // },
10147
10353
  // ]
10148
10354
  //
10149
- const rate = this.safeValue(response, 0);
10355
+ const rate = this.safeDict(response, 0);
10150
10356
  return this.parseBorrowRate(rate);
10151
10357
  }
10152
10358
  async fetchBorrowRateHistory(code, since = undefined, limit = undefined, params = {}) {
@@ -10250,7 +10456,7 @@ class binance extends binance$1 {
10250
10456
  // "success": true
10251
10457
  // }
10252
10458
  //
10253
- const data = this.safeValue(response, 'data');
10459
+ const data = this.safeDict(response, 'data');
10254
10460
  const giftcardCode = this.safeString(data, 'code');
10255
10461
  const id = this.safeString(data, 'referenceNo');
10256
10462
  return {
@@ -10359,7 +10565,7 @@ class binance extends binance$1 {
10359
10565
  // "total": 1
10360
10566
  // }
10361
10567
  //
10362
- const rows = this.safeValue(response, 'rows');
10568
+ const rows = this.safeList(response, 'rows');
10363
10569
  const interest = this.parseBorrowInterests(rows, market);
10364
10570
  return this.filterByCurrencySinceLimit(interest, code, since, limit);
10365
10571
  }
@@ -10386,9 +10592,11 @@ class binance extends binance$1 {
10386
10592
  * @name binance#repayCrossMargin
10387
10593
  * @description repay borrowed margin and interest
10388
10594
  * @see https://binance-docs.github.io/apidocs/spot/en/#margin-account-borrow-repay-margin
10595
+ * @see https://binance-docs.github.io/apidocs/pm/en/#margin-account-repay-margin
10389
10596
  * @param {string} code unified currency code of the currency to repay
10390
10597
  * @param {float} amount the amount to repay
10391
10598
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10599
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to repay margin in a portfolio margin account
10392
10600
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
10393
10601
  */
10394
10602
  await this.loadMarkets();
@@ -10396,10 +10604,18 @@ class binance extends binance$1 {
10396
10604
  const request = {
10397
10605
  'asset': currency['id'],
10398
10606
  'amount': this.currencyToPrecision(code, amount),
10399
- 'isIsolated': 'FALSE',
10400
- 'type': 'REPAY',
10401
10607
  };
10402
- const response = await this.sapiPostMarginBorrowRepay(this.extend(request, params));
10608
+ let response = undefined;
10609
+ let isPortfolioMargin = undefined;
10610
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'repayCrossMargin', 'papi', 'portfolioMargin', false);
10611
+ if (isPortfolioMargin) {
10612
+ response = await this.papiPostRepayLoan(this.extend(request, params));
10613
+ }
10614
+ else {
10615
+ request['isIsolated'] = 'FALSE';
10616
+ request['type'] = 'REPAY';
10617
+ response = await this.sapiPostMarginBorrowRepay(this.extend(request, params));
10618
+ }
10403
10619
  //
10404
10620
  // {
10405
10621
  // "tranId": 108988250265,
@@ -10445,9 +10661,11 @@ class binance extends binance$1 {
10445
10661
  * @name binance#borrowCrossMargin
10446
10662
  * @description create a loan to borrow margin
10447
10663
  * @see https://binance-docs.github.io/apidocs/spot/en/#margin-account-borrow-repay-margin
10664
+ * @see https://binance-docs.github.io/apidocs/pm/en/#margin-account-borrow-margin
10448
10665
  * @param {string} code unified currency code of the currency to borrow
10449
10666
  * @param {float} amount the amount to borrow
10450
10667
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10668
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to borrow margin in a portfolio margin account
10451
10669
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
10452
10670
  */
10453
10671
  await this.loadMarkets();
@@ -10455,10 +10673,18 @@ class binance extends binance$1 {
10455
10673
  const request = {
10456
10674
  'asset': currency['id'],
10457
10675
  'amount': this.currencyToPrecision(code, amount),
10458
- 'isIsolated': 'FALSE',
10459
- 'type': 'BORROW',
10460
10676
  };
10461
- const response = await this.sapiPostMarginBorrowRepay(this.extend(request, params));
10677
+ let response = undefined;
10678
+ let isPortfolioMargin = undefined;
10679
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'borrowCrossMargin', 'papi', 'portfolioMargin', false);
10680
+ if (isPortfolioMargin) {
10681
+ response = await this.papiPostMarginLoan(this.extend(request, params));
10682
+ }
10683
+ else {
10684
+ request['isIsolated'] = 'FALSE';
10685
+ request['type'] = 'BORROW';
10686
+ response = await this.sapiPostMarginBorrowRepay(this.extend(request, params));
10687
+ }
10462
10688
  //
10463
10689
  // {
10464
10690
  // "tranId": 108988250265,