ccxt 4.2.39 → 4.2.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +1140 -341
  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 +561 -168
  8. package/dist/cjs/src/bingx.js +271 -25
  9. package/dist/cjs/src/bitforex.js +2 -2
  10. package/dist/cjs/src/bitget.js +13 -2
  11. package/dist/cjs/src/bybit.js +3 -1
  12. package/dist/cjs/src/coinbase.js +8 -6
  13. package/dist/cjs/src/coinbasepro.js +1 -0
  14. package/dist/cjs/src/coinlist.js +9 -7
  15. package/dist/cjs/src/coinmetro.js +2 -1
  16. package/dist/cjs/src/currencycom.js +1 -1
  17. package/dist/cjs/src/htx.js +1 -1
  18. package/dist/cjs/src/krakenfutures.js +126 -2
  19. package/dist/cjs/src/mexc.js +44 -44
  20. package/dist/cjs/src/okx.js +9 -15
  21. package/dist/cjs/src/phemex.js +1 -0
  22. package/dist/cjs/src/pro/bitmart.js +38 -20
  23. package/dist/cjs/src/pro/bybit.js +5 -5
  24. package/dist/cjs/src/pro/cex.js +1 -1
  25. package/dist/cjs/src/pro/gemini.js +1 -1
  26. package/js/ccxt.d.ts +1 -1
  27. package/js/ccxt.js +1 -1
  28. package/js/src/abstract/bingx.d.ts +4 -0
  29. package/js/src/abstract/coinbasepro.d.ts +1 -0
  30. package/js/src/ascendex.js +28 -24
  31. package/js/src/base/Exchange.d.ts +8 -8
  32. package/js/src/base/Exchange.js +14 -14
  33. package/js/src/binance.d.ts +1 -1
  34. package/js/src/binance.js +561 -168
  35. package/js/src/bingx.d.ts +2 -0
  36. package/js/src/bingx.js +271 -25
  37. package/js/src/bitforex.js +2 -2
  38. package/js/src/bitget.js +13 -2
  39. package/js/src/bybit.js +3 -1
  40. package/js/src/coinbase.js +8 -6
  41. package/js/src/coinbasepro.js +1 -0
  42. package/js/src/coinlist.js +9 -7
  43. package/js/src/coinmetro.js +2 -1
  44. package/js/src/currencycom.js +1 -1
  45. package/js/src/htx.js +1 -1
  46. package/js/src/krakenfutures.d.ts +2 -0
  47. package/js/src/krakenfutures.js +126 -2
  48. package/js/src/mexc.js +44 -44
  49. package/js/src/okx.js +9 -15
  50. package/js/src/phemex.js +1 -0
  51. package/js/src/pro/bitmart.d.ts +2 -0
  52. package/js/src/pro/bitmart.js +38 -20
  53. package/js/src/pro/bybit.d.ts +1 -1
  54. package/js/src/pro/bybit.js +5 -5
  55. package/js/src/pro/cex.js +1 -1
  56. package/js/src/pro/gemini.js +1 -1
  57. 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);
@@ -4337,20 +4337,73 @@ class binance extends binance$1 {
4337
4337
  // "time": 1676366446072
4338
4338
  // }
4339
4339
  //
4340
+ // fetchMyTrades: linear portfolio margin
4341
+ //
4342
+ // {
4343
+ // "symbol": "BTCUSDT",
4344
+ // "id": 4575108247,
4345
+ // "orderId": 261942655610,
4346
+ // "side": "SELL",
4347
+ // "price": "47263.40",
4348
+ // "qty": "0.010",
4349
+ // "realizedPnl": "27.38400000",
4350
+ // "marginAsset": "USDT",
4351
+ // "quoteQty": "472.63",
4352
+ // "commission": "0.18905360",
4353
+ // "commissionAsset": "USDT",
4354
+ // "time": 1707530039409,
4355
+ // "buyer": false,
4356
+ // "maker": false,
4357
+ // "positionSide": "LONG"
4358
+ // }
4359
+ //
4360
+ // fetchMyTrades: inverse portfolio margin
4361
+ //
4362
+ // {
4363
+ // "symbol": "ETHUSD_PERP",
4364
+ // "id": 701907838,
4365
+ // "orderId": 71548909034,
4366
+ // "pair": "ETHUSD",
4367
+ // "side": "SELL",
4368
+ // "price": "2498.15",
4369
+ // "qty": "1",
4370
+ // "realizedPnl": "0.00012517",
4371
+ // "marginAsset": "ETH",
4372
+ // "baseQty": "0.00400296",
4373
+ // "commission": "0.00000160",
4374
+ // "commissionAsset": "ETH",
4375
+ // "time": 1707530317519,
4376
+ // "positionSide": "LONG",
4377
+ // "buyer": false,
4378
+ // "maker": false
4379
+ // }
4380
+ //
4381
+ // fetchMyTrades: spot margin portfolio margin
4382
+ //
4383
+ // {
4384
+ // "symbol": "ADAUSDT",
4385
+ // "id": 470227543,
4386
+ // "orderId": 4421170947,
4387
+ // "price": "0.53880000",
4388
+ // "qty": "10.00000000",
4389
+ // "quoteQty": "5.38800000",
4390
+ // "commission": "0.00538800",
4391
+ // "commissionAsset": "USDT",
4392
+ // "time": 1707545780522,
4393
+ // "isBuyer": false,
4394
+ // "isMaker": false,
4395
+ // "isBestMatch": true
4396
+ // }
4397
+ //
4340
4398
  const timestamp = this.safeInteger2(trade, 'T', 'time');
4341
- const price = this.safeString2(trade, 'p', 'price');
4342
4399
  let amount = this.safeString2(trade, 'q', 'qty');
4343
4400
  amount = this.safeString(trade, 'quantity', amount);
4344
- const cost = this.safeString2(trade, 'quoteQty', 'baseQty'); // inverse futures
4345
4401
  const marketId = this.safeString(trade, 'symbol');
4346
- const isSpotTrade = ('isIsolated' in trade) || ('M' in trade) || ('orderListId' in trade);
4402
+ const isSpotTrade = ('isIsolated' in trade) || ('M' in trade) || ('orderListId' in trade) || ('isMaker' in trade);
4347
4403
  const marketType = isSpotTrade ? 'spot' : 'contract';
4348
4404
  market = this.safeMarket(marketId, market, undefined, marketType);
4349
4405
  const symbol = market['symbol'];
4350
- let id = this.safeString2(trade, 't', 'a');
4351
- id = this.safeString2(trade, 'tradeId', 'id', id);
4352
4406
  let side = undefined;
4353
- const orderId = this.safeString(trade, 'orderId');
4354
4407
  const buyerMaker = this.safeValue2(trade, 'm', 'isBuyerMaker');
4355
4408
  let takerOrMaker = undefined;
4356
4409
  if (buyerMaker !== undefined) {
@@ -4400,14 +4453,14 @@ class binance extends binance$1 {
4400
4453
  'timestamp': timestamp,
4401
4454
  'datetime': this.iso8601(timestamp),
4402
4455
  'symbol': symbol,
4403
- 'id': id,
4404
- 'order': orderId,
4456
+ 'id': this.safeStringN(trade, ['t', 'a', 'tradeId', 'id']),
4457
+ 'order': this.safeString(trade, 'orderId'),
4405
4458
  'type': this.safeStringLower(trade, 'type'),
4406
4459
  'side': side,
4407
4460
  'takerOrMaker': takerOrMaker,
4408
- 'price': price,
4461
+ 'price': this.safeString2(trade, 'p', 'price'),
4409
4462
  'amount': amount,
4410
- 'cost': cost,
4463
+ 'cost': this.safeString2(trade, 'quoteQty', 'baseQty'),
4411
4464
  'fee': fee,
4412
4465
  }, market);
4413
4466
  }
@@ -5241,7 +5294,7 @@ class binance extends binance$1 {
5241
5294
  cost = this.safeString(order, 'cumBase', cost);
5242
5295
  let type = this.safeStringLower(order, 'type');
5243
5296
  const side = this.safeStringLower(order, 'side');
5244
- const fills = this.safeValue(order, 'fills', []);
5297
+ const fills = this.safeList(order, 'fills', []);
5245
5298
  let timeInForce = this.safeString(order, 'timeInForce');
5246
5299
  if (timeInForce === 'GTX') {
5247
5300
  // GTX means "Good Till Crossing" and is an equivalent way of saying Post Only
@@ -5274,7 +5327,7 @@ class binance extends binance$1 {
5274
5327
  'type': type,
5275
5328
  'timeInForce': timeInForce,
5276
5329
  'postOnly': postOnly,
5277
- 'reduceOnly': this.safeValue(order, 'reduceOnly'),
5330
+ 'reduceOnly': this.safeBool(order, 'reduceOnly'),
5278
5331
  'side': side,
5279
5332
  'price': price,
5280
5333
  'triggerPrice': stopPrice,
@@ -5308,7 +5361,7 @@ class binance extends binance$1 {
5308
5361
  const side = this.safeString(rawOrder, 'side');
5309
5362
  const amount = this.safeValue(rawOrder, 'amount');
5310
5363
  const price = this.safeValue(rawOrder, 'price');
5311
- const orderParams = this.safeValue(rawOrder, 'params', {});
5364
+ const orderParams = this.safeDict(rawOrder, 'params', {});
5312
5365
  const orderRequest = this.createOrderRequest(marketId, type, side, amount, price, orderParams);
5313
5366
  ordersRequests.push(orderRequest);
5314
5367
  }
@@ -6496,12 +6549,16 @@ class binance extends binance$1 {
6496
6549
  * @see https://binance-docs.github.io/apidocs/futures/en/#account-trade-list-user_data
6497
6550
  * @see https://binance-docs.github.io/apidocs/delivery/en/#account-trade-list-user_data
6498
6551
  * @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-account-39-s-trade-list-user_data
6552
+ * @see https://binance-docs.github.io/apidocs/pm/en/#margin-account-trade-list-user_data
6553
+ * @see https://binance-docs.github.io/apidocs/pm/en/#um-account-trade-list-user_data
6554
+ * @see https://binance-docs.github.io/apidocs/pm/en/#cm-account-trade-list-user_data
6499
6555
  * @param {string} symbol unified market symbol
6500
6556
  * @param {int} [since] the earliest time in ms to fetch trades for
6501
6557
  * @param {int} [limit] the maximum number of trades structures to retrieve
6502
6558
  * @param {object} [params] extra parameters specific to the exchange API endpoint
6503
- * @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)
6559
+ * @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)
6504
6560
  * @param {int} [params.until] the latest time in ms to fetch entries for
6561
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch trades for a portfolio margin account
6505
6562
  * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
6506
6563
  */
6507
6564
  await this.loadMarkets();
@@ -6555,8 +6612,13 @@ class binance extends binance$1 {
6555
6612
  throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
6556
6613
  }
6557
6614
  [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
6615
+ let isPortfolioMargin = undefined;
6616
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchMyTrades', 'papi', 'portfolioMargin', false);
6558
6617
  if (type === 'spot' || type === 'margin') {
6559
- if ((type === 'margin') || (marginMode !== undefined)) {
6618
+ if (isPortfolioMargin) {
6619
+ response = await this.papiGetMarginMyTrades(this.extend(request, params));
6620
+ }
6621
+ else if ((type === 'margin') || (marginMode !== undefined)) {
6560
6622
  if (marginMode === 'isolated') {
6561
6623
  request['isIsolated'] = true;
6562
6624
  }
@@ -6567,10 +6629,20 @@ class binance extends binance$1 {
6567
6629
  }
6568
6630
  }
6569
6631
  else if (market['linear']) {
6570
- response = await this.fapiPrivateGetUserTrades(this.extend(request, params));
6632
+ if (isPortfolioMargin) {
6633
+ response = await this.papiGetUmUserTrades(this.extend(request, params));
6634
+ }
6635
+ else {
6636
+ response = await this.fapiPrivateGetUserTrades(this.extend(request, params));
6637
+ }
6571
6638
  }
6572
6639
  else if (market['inverse']) {
6573
- response = await this.dapiPrivateGetUserTrades(this.extend(request, params));
6640
+ if (isPortfolioMargin) {
6641
+ response = await this.papiGetCmUserTrades(this.extend(request, params));
6642
+ }
6643
+ else {
6644
+ response = await this.dapiPrivateGetUserTrades(this.extend(request, params));
6645
+ }
6574
6646
  }
6575
6647
  }
6576
6648
  //
@@ -6638,6 +6710,70 @@ class binance extends binance$1 {
6638
6710
  // }
6639
6711
  // ]
6640
6712
  //
6713
+ // linear portfolio margin
6714
+ //
6715
+ // [
6716
+ // {
6717
+ // "symbol": "BTCUSDT",
6718
+ // "id": 4575108247,
6719
+ // "orderId": 261942655610,
6720
+ // "side": "SELL",
6721
+ // "price": "47263.40",
6722
+ // "qty": "0.010",
6723
+ // "realizedPnl": "27.38400000",
6724
+ // "marginAsset": "USDT",
6725
+ // "quoteQty": "472.63",
6726
+ // "commission": "0.18905360",
6727
+ // "commissionAsset": "USDT",
6728
+ // "time": 1707530039409,
6729
+ // "buyer": false,
6730
+ // "maker": false,
6731
+ // "positionSide": "LONG"
6732
+ // }
6733
+ // ]
6734
+ //
6735
+ // inverse portfolio margin
6736
+ //
6737
+ // [
6738
+ // {
6739
+ // "symbol": "ETHUSD_PERP",
6740
+ // "id": 701907838,
6741
+ // "orderId": 71548909034,
6742
+ // "pair": "ETHUSD",
6743
+ // "side": "SELL",
6744
+ // "price": "2498.15",
6745
+ // "qty": "1",
6746
+ // "realizedPnl": "0.00012517",
6747
+ // "marginAsset": "ETH",
6748
+ // "baseQty": "0.00400296",
6749
+ // "commission": "0.00000160",
6750
+ // "commissionAsset": "ETH",
6751
+ // "time": 1707530317519,
6752
+ // "positionSide": "LONG",
6753
+ // "buyer": false,
6754
+ // "maker": false
6755
+ // }
6756
+ // ]
6757
+ //
6758
+ // spot margin portfolio margin
6759
+ //
6760
+ // [
6761
+ // {
6762
+ // "symbol": "ADAUSDT",
6763
+ // "id": 470227543,
6764
+ // "orderId": 4421170947,
6765
+ // "price": "0.53880000",
6766
+ // "qty": "10.00000000",
6767
+ // "quoteQty": "5.38800000",
6768
+ // "commission": "0.00538800",
6769
+ // "commissionAsset": "USDT",
6770
+ // "time": 1707545780522,
6771
+ // "isBuyer": false,
6772
+ // "isMaker": false,
6773
+ // "isBestMatch": true
6774
+ // }
6775
+ // ]
6776
+ //
6641
6777
  return this.parseTrades(response, market, since, limit);
6642
6778
  }
6643
6779
  async fetchMyDustTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
@@ -6700,11 +6836,11 @@ class binance extends binance$1 {
6700
6836
  // },
6701
6837
  // ]
6702
6838
  // }
6703
- const results = this.safeValue(response, 'userAssetDribblets', []);
6839
+ const results = this.safeList(response, 'userAssetDribblets', []);
6704
6840
  const rows = this.safeInteger(response, 'total', 0);
6705
6841
  const data = [];
6706
6842
  for (let i = 0; i < rows; i++) {
6707
- const logs = this.safeValue(results[i], 'userAssetDribbletDetails', []);
6843
+ const logs = this.safeList(results[i], 'userAssetDribbletDetails', []);
6708
6844
  for (let j = 0; j < logs.length; j++) {
6709
6845
  logs[j]['isDustTrade'] = true;
6710
6846
  data.push(logs[j]);
@@ -6811,7 +6947,7 @@ class binance extends binance$1 {
6811
6947
  let currency = undefined;
6812
6948
  let response = undefined;
6813
6949
  const request = {};
6814
- const legalMoney = this.safeValue(this.options, 'legalMoney', {});
6950
+ const legalMoney = this.safeDict(this.options, 'legalMoney', {});
6815
6951
  const fiatOnly = this.safeBool(params, 'fiat', false);
6816
6952
  params = this.omit(params, 'fiatOnly');
6817
6953
  const until = this.safeInteger(params, 'until');
@@ -6923,7 +7059,7 @@ class binance extends binance$1 {
6923
7059
  if (paginate) {
6924
7060
  return await this.fetchPaginatedCallDynamic('fetchWithdrawals', code, since, limit, params);
6925
7061
  }
6926
- const legalMoney = this.safeValue(this.options, 'legalMoney', {});
7062
+ const legalMoney = this.safeDict(this.options, 'legalMoney', {});
6927
7063
  const fiatOnly = this.safeBool(params, 'fiat', false);
6928
7064
  params = this.omit(params, 'fiatOnly');
6929
7065
  const request = {};
@@ -7067,7 +7203,7 @@ class binance extends binance$1 {
7067
7203
  'Refund Failed': 'failed',
7068
7204
  },
7069
7205
  };
7070
- const statuses = this.safeValue(statusesByType, type, {});
7206
+ const statuses = this.safeDict(statusesByType, type, {});
7071
7207
  return this.safeString(statuses, status, status);
7072
7208
  }
7073
7209
  parseTransaction(transaction, currency = undefined) {
@@ -7232,7 +7368,7 @@ class binance extends binance$1 {
7232
7368
  const type = this.safeString(transfer, 'type');
7233
7369
  let fromAccount = undefined;
7234
7370
  let toAccount = undefined;
7235
- const accountsById = this.safeValue(this.options, 'accountsById', {});
7371
+ const accountsById = this.safeDict(this.options, 'accountsById', {});
7236
7372
  if (type !== undefined) {
7237
7373
  const parts = type.split('_');
7238
7374
  fromAccount = this.safeValue(parts, 0);
@@ -7268,20 +7404,16 @@ class binance extends binance$1 {
7268
7404
  // }
7269
7405
  //
7270
7406
  const marketId = this.safeString(income, 'symbol');
7271
- const symbol = this.safeSymbol(marketId, market, undefined, 'swap');
7272
- const amount = this.safeNumber(income, 'income');
7273
7407
  const currencyId = this.safeString(income, 'asset');
7274
- const code = this.safeCurrencyCode(currencyId);
7275
- const id = this.safeString(income, 'tranId');
7276
7408
  const timestamp = this.safeInteger(income, 'time');
7277
7409
  return {
7278
7410
  'info': income,
7279
- 'symbol': symbol,
7280
- 'code': code,
7411
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'swap'),
7412
+ 'code': this.safeCurrencyCode(currencyId),
7281
7413
  'timestamp': timestamp,
7282
7414
  'datetime': this.iso8601(timestamp),
7283
- 'id': id,
7284
- 'amount': amount,
7415
+ 'id': this.safeString(income, 'tranId'),
7416
+ 'amount': this.safeNumber(income, 'income'),
7285
7417
  };
7286
7418
  }
7287
7419
  async transfer(code, amount, fromAccount, toAccount, params = {}) {
@@ -7330,7 +7462,7 @@ class binance extends binance$1 {
7330
7462
  throw new errors.ArgumentsRequired(this.id + ' transfer () requires params["symbol"] when toAccount is ' + toAccount);
7331
7463
  }
7332
7464
  }
7333
- const accountsById = this.safeValue(this.options, 'accountsById', {});
7465
+ const accountsById = this.safeDict(this.options, 'accountsById', {});
7334
7466
  const fromIsolated = !(fromId in accountsById);
7335
7467
  const toIsolated = !(toId in accountsById);
7336
7468
  if (fromIsolated && (market === undefined)) {
@@ -7420,7 +7552,7 @@ class binance extends binance$1 {
7420
7552
  const defaultTo = (fromAccount === 'future') ? 'spot' : 'future';
7421
7553
  const toAccount = this.safeString(params, 'toAccount', defaultTo);
7422
7554
  let type = this.safeString(params, 'type');
7423
- const accountsByType = this.safeValue(this.options, 'accountsByType', {});
7555
+ const accountsByType = this.safeDict(this.options, 'accountsByType', {});
7424
7556
  const fromId = this.safeString(accountsByType, fromAccount);
7425
7557
  const toId = this.safeString(accountsByType, toAccount);
7426
7558
  if (type === undefined) {
@@ -7464,7 +7596,7 @@ class binance extends binance$1 {
7464
7596
  // ]
7465
7597
  // }
7466
7598
  //
7467
- const rows = this.safeValue(response, 'rows', []);
7599
+ const rows = this.safeList(response, 'rows', []);
7468
7600
  return this.parseTransfers(rows, currency, since, limit);
7469
7601
  }
7470
7602
  async fetchDepositAddress(code, params = {}) {
@@ -7483,7 +7615,7 @@ class binance extends binance$1 {
7483
7615
  'coin': currency['id'],
7484
7616
  // 'network': 'ETH', // 'BSC', 'XMR', you can get network and isDefault in networkList in the response of sapiGetCapitalConfigDetail
7485
7617
  };
7486
- const networks = this.safeValue(this.options, 'networks', {});
7618
+ const networks = this.safeDict(this.options, 'networks', {});
7487
7619
  let network = this.safeStringUpper(params, 'network'); // this line allows the user to specify either ERC20 or ETH
7488
7620
  network = this.safeString(networks, network, network); // handle ERC20>ETH alias
7489
7621
  if (network !== undefined) {
@@ -7510,7 +7642,7 @@ class binance extends binance$1 {
7510
7642
  const url = this.safeString(response, 'url');
7511
7643
  let impliedNetwork = undefined;
7512
7644
  if (url !== undefined) {
7513
- const reverseNetworks = this.safeValue(this.options, 'reverseNetworks', {});
7645
+ const reverseNetworks = this.safeDict(this.options, 'reverseNetworks', {});
7514
7646
  const parts = url.split('/');
7515
7647
  let topLevel = this.safeString(parts, 2);
7516
7648
  if ((topLevel === 'blockchair.com') || (topLevel === 'viewblock.io')) {
@@ -7525,7 +7657,7 @@ class binance extends binance$1 {
7525
7657
  'TRX': { 'TRC20': 'TRX' },
7526
7658
  });
7527
7659
  if (code in impliedNetworks) {
7528
- const conversion = this.safeValue(impliedNetworks, code, {});
7660
+ const conversion = this.safeDict(impliedNetworks, code, {});
7529
7661
  impliedNetwork = this.safeString(conversion, impliedNetwork, impliedNetwork);
7530
7662
  }
7531
7663
  }
@@ -7641,7 +7773,7 @@ class binance extends binance$1 {
7641
7773
  const entry = response[i];
7642
7774
  const currencyId = this.safeString(entry, 'coin');
7643
7775
  const code = this.safeCurrencyCode(currencyId);
7644
- const networkList = this.safeValue(entry, 'networkList', []);
7776
+ const networkList = this.safeList(entry, 'networkList', []);
7645
7777
  withdrawFees[code] = {};
7646
7778
  for (let j = 0; j < networkList.length; j++) {
7647
7779
  const networkEntry = networkList[j];
@@ -7754,14 +7886,14 @@ class binance extends binance$1 {
7754
7886
  // ]
7755
7887
  // }
7756
7888
  //
7757
- const networkList = this.safeValue(fee, 'networkList', []);
7889
+ const networkList = this.safeList(fee, 'networkList', []);
7758
7890
  const result = this.depositWithdrawFee(fee);
7759
7891
  for (let j = 0; j < networkList.length; j++) {
7760
7892
  const networkEntry = networkList[j];
7761
7893
  const networkId = this.safeString(networkEntry, 'network');
7762
7894
  const networkCode = this.networkIdToCode(networkId);
7763
7895
  const withdrawFee = this.safeNumber(networkEntry, 'withdrawFee');
7764
- const isDefault = this.safeValue(networkEntry, 'isDefault');
7896
+ const isDefault = this.safeBool(networkEntry, 'isDefault');
7765
7897
  if (isDefault === true) {
7766
7898
  result['withdraw'] = {
7767
7899
  'fee': withdrawFee,
@@ -7809,7 +7941,7 @@ class binance extends binance$1 {
7809
7941
  if (tag !== undefined) {
7810
7942
  request['addressTag'] = tag;
7811
7943
  }
7812
- const networks = this.safeValue(this.options, 'networks', {});
7944
+ const networks = this.safeDict(this.options, 'networks', {});
7813
7945
  let network = this.safeStringUpper(params, 'network'); // this line allows the user to specify either ERC20 or ETH
7814
7946
  network = this.safeString(networks, network, network); // handle ERC20>ETH alias
7815
7947
  if (network !== undefined) {
@@ -7901,7 +8033,7 @@ class binance extends binance$1 {
7901
8033
  //
7902
8034
  let data = response;
7903
8035
  if (Array.isArray(data)) {
7904
- data = this.safeValue(data, 0, {});
8036
+ data = this.safeDict(data, 0, {});
7905
8037
  }
7906
8038
  return this.parseTradingFee(data);
7907
8039
  }
@@ -8315,8 +8447,8 @@ class binance extends binance$1 {
8315
8447
  };
8316
8448
  }
8317
8449
  parseAccountPositions(account) {
8318
- const positions = this.safeValue(account, 'positions');
8319
- const assets = this.safeValue(account, 'assets', []);
8450
+ const positions = this.safeList(account, 'positions');
8451
+ const assets = this.safeList(account, 'assets', []);
8320
8452
  const balances = {};
8321
8453
  for (let i = 0; i < assets.length; i++) {
8322
8454
  const entry = assets[i];
@@ -8335,13 +8467,17 @@ class binance extends binance$1 {
8335
8467
  const marketId = this.safeString(position, 'symbol');
8336
8468
  const market = this.safeMarket(marketId, undefined, undefined, 'contract');
8337
8469
  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);
8470
+ const maintenanceMargin = this.safeString(position, 'maintMargin');
8471
+ // check for maintenance margin so empty positions are not returned
8472
+ if ((maintenanceMargin !== '0') && (maintenanceMargin !== '0.00000000')) {
8473
+ // sometimes not all the codes are correctly returned...
8474
+ if (code in balances) {
8475
+ const parsed = this.parseAccountPosition(this.extend(position, {
8476
+ 'crossMargin': balances[code]['crossMargin'],
8477
+ 'crossWalletBalance': balances[code]['crossWalletBalance'],
8478
+ }), market);
8479
+ result.push(parsed);
8480
+ }
8345
8481
  }
8346
8482
  }
8347
8483
  return result;
@@ -8349,6 +8485,7 @@ class binance extends binance$1 {
8349
8485
  parseAccountPosition(position, market = undefined) {
8350
8486
  //
8351
8487
  // usdm
8488
+ //
8352
8489
  // {
8353
8490
  // "symbol": "BTCBUSD",
8354
8491
  // "initialMargin": "0",
@@ -8369,6 +8506,7 @@ class binance extends binance$1 {
8369
8506
  // }
8370
8507
  //
8371
8508
  // coinm
8509
+ //
8372
8510
  // {
8373
8511
  // "symbol": "BTCUSD_210625",
8374
8512
  // "initialMargin": "0.00024393",
@@ -8387,6 +8525,46 @@ class binance extends binance$1 {
8387
8525
  // "crossWalletBalance": "34",
8388
8526
  // }
8389
8527
  //
8528
+ // linear portfolio margin
8529
+ //
8530
+ // {
8531
+ // "symbol": "CTSIUSDT",
8532
+ // "initialMargin": "0",
8533
+ // "maintMargin": "0",
8534
+ // "unrealizedProfit": "0.00000000",
8535
+ // "positionInitialMargin": "0",
8536
+ // "openOrderInitialMargin": "0",
8537
+ // "leverage": "20",
8538
+ // "entryPrice": "0.0",
8539
+ // "maxNotional": "25000",
8540
+ // "bidNotional": "0",
8541
+ // "askNotional": "0",
8542
+ // "positionSide": "SHORT",
8543
+ // "positionAmt": "0",
8544
+ // "updateTime": 0,
8545
+ // "notional": "0",
8546
+ // "breakEvenPrice": "0.0"
8547
+ // }
8548
+ //
8549
+ // inverse portoflio margin
8550
+ //
8551
+ // {
8552
+ // "symbol": "TRXUSD_PERP",
8553
+ // "initialMargin": "0",
8554
+ // "maintMargin": "0",
8555
+ // "unrealizedProfit": "0.00000000",
8556
+ // "positionInitialMargin": "0",
8557
+ // "openOrderInitialMargin": "0",
8558
+ // "leverage": "20",
8559
+ // "entryPrice": "0.00000000",
8560
+ // "positionSide": "SHORT",
8561
+ // "positionAmt": "0",
8562
+ // "maxQty": "5000000",
8563
+ // "updateTime": 0,
8564
+ // "notionalValue": "0",
8565
+ // "breakEvenPrice": "0.00000000"
8566
+ // }
8567
+ //
8390
8568
  const marketId = this.safeString(position, 'symbol');
8391
8569
  market = this.safeMarket(marketId, market, undefined, 'contract');
8392
8570
  const symbol = this.safeString(market, 'symbol');
@@ -8417,8 +8595,8 @@ class binance extends binance$1 {
8417
8595
  contractsStringAbs = Precise["default"].stringDiv(Precise["default"].stringAdd(contractsString, '0.5'), '1', 0);
8418
8596
  }
8419
8597
  const contracts = this.parseNumber(contractsStringAbs);
8420
- const leverageBrackets = this.safeValue(this.options, 'leverageBrackets', {});
8421
- const leverageBracket = this.safeValue(leverageBrackets, symbol, []);
8598
+ const leverageBrackets = this.safeDict(this.options, 'leverageBrackets', {});
8599
+ const leverageBracket = this.safeList(leverageBrackets, symbol, []);
8422
8600
  let maintenanceMarginPercentageString = undefined;
8423
8601
  for (let i = 0; i < leverageBracket.length; i++) {
8424
8602
  const bracket = leverageBracket[i];
@@ -8434,7 +8612,7 @@ class binance extends binance$1 {
8434
8612
  if (timestamp === 0) {
8435
8613
  timestamp = undefined;
8436
8614
  }
8437
- const isolated = this.safeValue(position, 'isolated');
8615
+ const isolated = this.safeBool(position, 'isolated');
8438
8616
  let marginMode = undefined;
8439
8617
  let collateralString = undefined;
8440
8618
  let walletBalance = undefined;
@@ -8587,11 +8765,45 @@ class binance extends binance$1 {
8587
8765
  // "isolatedWallet": "0.00268058"
8588
8766
  // }
8589
8767
  //
8768
+ // inverse portfolio margin
8769
+ //
8770
+ // {
8771
+ // "symbol": "ETHUSD_PERP",
8772
+ // "positionAmt": "1",
8773
+ // "entryPrice": "2422.400000007",
8774
+ // "markPrice": "2424.51267823",
8775
+ // "unRealizedProfit": "0.0000036",
8776
+ // "liquidationPrice": "293.57678898",
8777
+ // "leverage": "100",
8778
+ // "positionSide": "LONG",
8779
+ // "updateTime": 1707371941861,
8780
+ // "maxQty": "15",
8781
+ // "notionalValue": "0.00412454",
8782
+ // "breakEvenPrice": "2423.368960034"
8783
+ // }
8784
+ //
8785
+ // linear portfolio margin
8786
+ //
8787
+ // {
8788
+ // "symbol": "BTCUSDT",
8789
+ // "positionAmt": "0.01",
8790
+ // "entryPrice": "44525.0",
8791
+ // "markPrice": "45464.1735922",
8792
+ // "unRealizedProfit": "9.39173592",
8793
+ // "liquidationPrice": "38007.16308568",
8794
+ // "leverage": "100",
8795
+ // "positionSide": "LONG",
8796
+ // "updateTime": 1707371879042,
8797
+ // "maxNotionalValue": "500000.0",
8798
+ // "notional": "454.64173592",
8799
+ // "breakEvenPrice": "44542.81"
8800
+ // }
8801
+ //
8590
8802
  const marketId = this.safeString(position, 'symbol');
8591
8803
  market = this.safeMarket(marketId, market, undefined, 'contract');
8592
8804
  const symbol = this.safeString(market, 'symbol');
8593
- const leverageBrackets = this.safeValue(this.options, 'leverageBrackets', {});
8594
- const leverageBracket = this.safeValue(leverageBrackets, symbol, []);
8805
+ const leverageBrackets = this.safeDict(this.options, 'leverageBrackets', {});
8806
+ const leverageBracket = this.safeList(leverageBrackets, symbol, []);
8595
8807
  const notionalString = this.safeString2(position, 'notional', 'notionalValue');
8596
8808
  const notionalStringAbs = Precise["default"].stringAbs(notionalString);
8597
8809
  let maintenanceMarginPercentageString = undefined;
@@ -8628,7 +8840,7 @@ class binance extends binance$1 {
8628
8840
  const linear = ('notional' in position);
8629
8841
  if (marginMode === 'cross') {
8630
8842
  // calculate collateral
8631
- const precision = this.safeValue(market, 'precision', {});
8843
+ const precision = this.safeDict(market, 'precision', {});
8632
8844
  if (linear) {
8633
8845
  // walletBalance = (liquidationPrice * (±1 + mmp) ± entryPrice) * contracts
8634
8846
  let onePlusMaintenanceMarginPercentageString = undefined;
@@ -8735,12 +8947,24 @@ class binance extends binance$1 {
8735
8947
  const query = this.omit(params, 'type');
8736
8948
  let subType = undefined;
8737
8949
  [subType, params] = this.handleSubTypeAndParams('loadLeverageBrackets', undefined, params, 'linear');
8950
+ let isPortfolioMargin = undefined;
8951
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'loadLeverageBrackets', 'papi', 'portfolioMargin', false);
8738
8952
  let response = undefined;
8739
8953
  if (this.isLinear(type, subType)) {
8740
- response = await this.fapiPrivateGetLeverageBracket(query);
8954
+ if (isPortfolioMargin) {
8955
+ response = await this.papiGetUmLeverageBracket(query);
8956
+ }
8957
+ else {
8958
+ response = await this.fapiPrivateGetLeverageBracket(query);
8959
+ }
8741
8960
  }
8742
8961
  else if (this.isInverse(type, subType)) {
8743
- response = await this.dapiPrivateV2GetLeverageBracket(query);
8962
+ if (isPortfolioMargin) {
8963
+ response = await this.papiGetCmLeverageBracket(query);
8964
+ }
8965
+ else {
8966
+ response = await this.dapiPrivateV2GetLeverageBracket(query);
8967
+ }
8744
8968
  }
8745
8969
  else {
8746
8970
  throw new errors.NotSupported(this.id + ' loadLeverageBrackets() supports linear and inverse contracts only');
@@ -8750,7 +8974,7 @@ class binance extends binance$1 {
8750
8974
  const entry = response[i];
8751
8975
  const marketId = this.safeString(entry, 'symbol');
8752
8976
  const symbol = this.safeSymbol(marketId, undefined, undefined, 'contract');
8753
- const brackets = this.safeValue(entry, 'brackets', []);
8977
+ const brackets = this.safeList(entry, 'brackets', []);
8754
8978
  const result = [];
8755
8979
  for (let j = 0; j < brackets.length; j++) {
8756
8980
  const bracket = brackets[j];
@@ -8770,8 +8994,11 @@ class binance extends binance$1 {
8770
8994
  * @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
8771
8995
  * @see https://binance-docs.github.io/apidocs/futures/en/#notional-and-leverage-brackets-user_data
8772
8996
  * @see https://binance-docs.github.io/apidocs/delivery/en/#notional-bracket-for-symbol-user_data
8997
+ * @see https://binance-docs.github.io/apidocs/pm/en/#um-notional-and-leverage-brackets-user_data
8998
+ * @see https://binance-docs.github.io/apidocs/pm/en/#cm-notional-and-leverage-brackets-user_data
8773
8999
  * @param {string[]|undefined} symbols list of unified market symbols
8774
9000
  * @param {object} [params] extra parameters specific to the exchange API endpoint
9001
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the leverage tiers for a portfolio margin account
8775
9002
  * @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}, indexed by market symbols
8776
9003
  */
8777
9004
  await this.loadMarkets();
@@ -8779,12 +9006,24 @@ class binance extends binance$1 {
8779
9006
  [type, params] = this.handleMarketTypeAndParams('fetchLeverageTiers', undefined, params);
8780
9007
  let subType = undefined;
8781
9008
  [subType, params] = this.handleSubTypeAndParams('fetchLeverageTiers', undefined, params, 'linear');
9009
+ let isPortfolioMargin = undefined;
9010
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchLeverageTiers', 'papi', 'portfolioMargin', false);
8782
9011
  let response = undefined;
8783
9012
  if (this.isLinear(type, subType)) {
8784
- response = await this.fapiPrivateGetLeverageBracket(params);
9013
+ if (isPortfolioMargin) {
9014
+ response = await this.papiGetUmLeverageBracket(params);
9015
+ }
9016
+ else {
9017
+ response = await this.fapiPrivateGetLeverageBracket(params);
9018
+ }
8785
9019
  }
8786
9020
  else if (this.isInverse(type, subType)) {
8787
- response = await this.dapiPrivateV2GetLeverageBracket(params);
9021
+ if (isPortfolioMargin) {
9022
+ response = await this.papiGetCmLeverageBracket(params);
9023
+ }
9024
+ else {
9025
+ response = await this.dapiPrivateV2GetLeverageBracket(params);
9026
+ }
8788
9027
  }
8789
9028
  else {
8790
9029
  throw new errors.NotSupported(this.id + ' fetchLeverageTiers() supports linear and inverse contracts only');
@@ -8854,7 +9093,7 @@ class binance extends binance$1 {
8854
9093
  //
8855
9094
  const marketId = this.safeString(info, 'symbol');
8856
9095
  market = this.safeMarket(marketId, market, undefined, 'contract');
8857
- const brackets = this.safeValue(info, 'brackets', []);
9096
+ const brackets = this.safeList(info, 'brackets', []);
8858
9097
  const tiers = [];
8859
9098
  for (let j = 0; j < brackets.length; j++) {
8860
9099
  const bracket = brackets[j];
@@ -9069,8 +9308,11 @@ class binance extends binance$1 {
9069
9308
  * @description fetch account positions
9070
9309
  * @see https://binance-docs.github.io/apidocs/futures/en/#account-information-v2-user_data
9071
9310
  * @see https://binance-docs.github.io/apidocs/delivery/en/#account-information-user_data
9311
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-um-account-detail-user_data
9312
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-cm-account-detail-user_data
9072
9313
  * @param {string[]|undefined} symbols list of unified market symbols
9073
9314
  * @param {object} [params] extra parameters specific to the exchange API endpoint
9315
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch positions in a portfolio margin account
9074
9316
  * @returns {object} data on account positions
9075
9317
  */
9076
9318
  if (symbols !== undefined) {
@@ -9082,15 +9324,27 @@ class binance extends binance$1 {
9082
9324
  await this.loadLeverageBrackets(false, params);
9083
9325
  const defaultType = this.safeString(this.options, 'defaultType', 'future');
9084
9326
  const type = this.safeString(params, 'type', defaultType);
9085
- let query = this.omit(params, 'type');
9327
+ params = this.omit(params, 'type');
9086
9328
  let subType = undefined;
9087
- [subType, query] = this.handleSubTypeAndParams('fetchAccountPositions', undefined, params, 'linear');
9329
+ [subType, params] = this.handleSubTypeAndParams('fetchAccountPositions', undefined, params, 'linear');
9330
+ let isPortfolioMargin = undefined;
9331
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchAccountPositions', 'papi', 'portfolioMargin', false);
9088
9332
  let response = undefined;
9089
9333
  if (this.isLinear(type, subType)) {
9090
- response = await this.fapiPrivateV2GetAccount(query);
9334
+ if (isPortfolioMargin) {
9335
+ response = await this.papiGetUmAccount(params);
9336
+ }
9337
+ else {
9338
+ response = await this.fapiPrivateV2GetAccount(params);
9339
+ }
9091
9340
  }
9092
9341
  else if (this.isInverse(type, subType)) {
9093
- response = await this.dapiPrivateGetAccount(query);
9342
+ if (isPortfolioMargin) {
9343
+ response = await this.papiGetCmAccount(params);
9344
+ }
9345
+ else {
9346
+ response = await this.dapiPrivateGetAccount(params);
9347
+ }
9094
9348
  }
9095
9349
  else {
9096
9350
  throw new errors.NotSupported(this.id + ' fetchPositions() supports linear and inverse contracts only');
@@ -9107,8 +9361,11 @@ class binance extends binance$1 {
9107
9361
  * @description fetch positions risk
9108
9362
  * @see https://binance-docs.github.io/apidocs/futures/en/#position-information-v2-user_data
9109
9363
  * @see https://binance-docs.github.io/apidocs/delivery/en/#position-information-user_data
9364
+ * @see https://binance-docs.github.io/apidocs/pm/en/#query-um-position-information-user_data
9365
+ * @see https://binance-docs.github.io/apidocs/pm/en/#query-cm-position-information-user_data
9110
9366
  * @param {string[]|undefined} symbols list of unified market symbols
9111
9367
  * @param {object} [params] extra parameters specific to the exchange API endpoint
9368
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch positions for a portfolio margin account
9112
9369
  * @returns {object} data on the positions risk
9113
9370
  */
9114
9371
  if (symbols !== undefined) {
@@ -9124,71 +9381,124 @@ class binance extends binance$1 {
9124
9381
  const type = this.safeString(params, 'type', defaultType);
9125
9382
  let subType = undefined;
9126
9383
  [subType, params] = this.handleSubTypeAndParams('fetchPositionsRisk', undefined, params, 'linear');
9384
+ let isPortfolioMargin = undefined;
9385
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchPositionsRisk', 'papi', 'portfolioMargin', false);
9127
9386
  params = this.omit(params, 'type');
9128
9387
  let response = undefined;
9129
9388
  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
- // ]
9389
+ if (isPortfolioMargin) {
9390
+ response = await this.papiGetUmPositionRisk(this.extend(request, params));
9391
+ }
9392
+ else {
9393
+ response = await this.fapiPrivateV2GetPositionRisk(this.extend(request, params));
9394
+ }
9185
9395
  }
9186
9396
  else if (this.isInverse(type, subType)) {
9187
- response = await this.dapiPrivateGetPositionRisk(this.extend(request, params));
9397
+ if (isPortfolioMargin) {
9398
+ response = await this.papiGetCmPositionRisk(this.extend(request, params));
9399
+ }
9400
+ else {
9401
+ response = await this.dapiPrivateGetPositionRisk(this.extend(request, params));
9402
+ }
9188
9403
  }
9189
9404
  else {
9190
9405
  throw new errors.NotSupported(this.id + ' fetchPositionsRisk() supports linear and inverse contracts only');
9191
9406
  }
9407
+ // ### Response examples ###
9408
+ //
9409
+ // For One-way position mode:
9410
+ //
9411
+ // [
9412
+ // {
9413
+ // "entryPrice": "0.00000",
9414
+ // "marginType": "isolated",
9415
+ // "isAutoAddMargin": "false",
9416
+ // "isolatedMargin": "0.00000000",
9417
+ // "leverage": "10",
9418
+ // "liquidationPrice": "0",
9419
+ // "markPrice": "6679.50671178",
9420
+ // "maxNotionalValue": "20000000",
9421
+ // "positionAmt": "0.000",
9422
+ // "symbol": "BTCUSDT",
9423
+ // "unRealizedProfit": "0.00000000",
9424
+ // "positionSide": "BOTH",
9425
+ // "updateTime": 0
9426
+ // }
9427
+ // ]
9428
+ //
9429
+ // For Hedge position mode:
9430
+ //
9431
+ // [
9432
+ // {
9433
+ // "entryPrice": "6563.66500",
9434
+ // "marginType": "isolated",
9435
+ // "isAutoAddMargin": "false",
9436
+ // "isolatedMargin": "15517.54150468",
9437
+ // "leverage": "10",
9438
+ // "liquidationPrice": "5930.78",
9439
+ // "markPrice": "6679.50671178",
9440
+ // "maxNotionalValue": "20000000",
9441
+ // "positionAmt": "20.000",
9442
+ // "symbol": "BTCUSDT",
9443
+ // "unRealizedProfit": "2316.83423560"
9444
+ // "positionSide": "LONG",
9445
+ // "updateTime": 1625474304765
9446
+ // },
9447
+ // {
9448
+ // "entryPrice": "0.00000",
9449
+ // "marginType": "isolated",
9450
+ // "isAutoAddMargin": "false",
9451
+ // "isolatedMargin": "5413.95799991",
9452
+ // "leverage": "10",
9453
+ // "liquidationPrice": "7189.95",
9454
+ // "markPrice": "6679.50671178",
9455
+ // "maxNotionalValue": "20000000",
9456
+ // "positionAmt": "-10.000",
9457
+ // "symbol": "BTCUSDT",
9458
+ // "unRealizedProfit": "-1156.46711780",
9459
+ // "positionSide": "SHORT",
9460
+ // "updateTime": 0
9461
+ // }
9462
+ // ]
9463
+ //
9464
+ // inverse portfolio margin:
9465
+ //
9466
+ // [
9467
+ // {
9468
+ // "symbol": "ETHUSD_PERP",
9469
+ // "positionAmt": "1",
9470
+ // "entryPrice": "2422.400000007",
9471
+ // "markPrice": "2424.51267823",
9472
+ // "unRealizedProfit": "0.0000036",
9473
+ // "liquidationPrice": "293.57678898",
9474
+ // "leverage": "100",
9475
+ // "positionSide": "LONG",
9476
+ // "updateTime": 1707371941861,
9477
+ // "maxQty": "15",
9478
+ // "notionalValue": "0.00412454",
9479
+ // "breakEvenPrice": "2423.368960034"
9480
+ // }
9481
+ // ]
9482
+ //
9483
+ // linear portfolio margin:
9484
+ //
9485
+ // [
9486
+ // {
9487
+ // "symbol": "BTCUSDT",
9488
+ // "positionAmt": "0.01",
9489
+ // "entryPrice": "44525.0",
9490
+ // "markPrice": "45464.1735922",
9491
+ // "unRealizedProfit": "9.39173592",
9492
+ // "liquidationPrice": "38007.16308568",
9493
+ // "leverage": "100",
9494
+ // "positionSide": "LONG",
9495
+ // "updateTime": 1707371879042,
9496
+ // "maxNotionalValue": "500000.0",
9497
+ // "notional": "454.64173592",
9498
+ // "breakEvenPrice": "44542.81"
9499
+ // }
9500
+ // ]
9501
+ //
9192
9502
  const result = [];
9193
9503
  for (let i = 0; i < response.length; i++) {
9194
9504
  const parsed = this.parsePositionRisk(response[i]);
@@ -9204,15 +9514,19 @@ class binance extends binance$1 {
9204
9514
  * @description fetch the history of funding payments paid and received on this account
9205
9515
  * @see https://binance-docs.github.io/apidocs/futures/en/#get-income-history-user_data
9206
9516
  * @see https://binance-docs.github.io/apidocs/delivery/en/#get-income-history-user_data
9517
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-um-income-history-user_data
9518
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-cm-income-history-user_data
9207
9519
  * @param {string} symbol unified market symbol
9208
9520
  * @param {int} [since] the earliest time in ms to fetch funding history for
9209
9521
  * @param {int} [limit] the maximum number of funding history structures to retrieve
9210
9522
  * @param {object} [params] extra parameters specific to the exchange API endpoint
9523
+ * @param {int} [params.until] timestamp in ms of the latest funding history entry
9524
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the funding history for a portfolio margin account
9211
9525
  * @returns {object} a [funding history structure]{@link https://docs.ccxt.com/#/?id=funding-history-structure}
9212
9526
  */
9213
9527
  await this.loadMarkets();
9214
9528
  let market = undefined;
9215
- const request = {
9529
+ let request = {
9216
9530
  'incomeType': 'FUNDING_FEE', // "TRANSFER","WELCOME_BONUS", "REALIZED_PNL","FUNDING_FEE", "COMMISSION" and "INSURANCE_CLEAR"
9217
9531
  };
9218
9532
  if (symbol !== undefined) {
@@ -9224,6 +9538,9 @@ class binance extends binance$1 {
9224
9538
  }
9225
9539
  let subType = undefined;
9226
9540
  [subType, params] = this.handleSubTypeAndParams('fetchFundingHistory', market, params, 'linear');
9541
+ let isPortfolioMargin = undefined;
9542
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchFundingHistory', 'papi', 'portfolioMargin', false);
9543
+ [request, params] = this.handleUntilOption('endTime', request, params);
9227
9544
  if (since !== undefined) {
9228
9545
  request['startTime'] = since;
9229
9546
  }
@@ -9235,10 +9552,20 @@ class binance extends binance$1 {
9235
9552
  params = this.omit(params, 'type');
9236
9553
  let response = undefined;
9237
9554
  if (this.isLinear(type, subType)) {
9238
- response = await this.fapiPrivateGetIncome(this.extend(request, params));
9555
+ if (isPortfolioMargin) {
9556
+ response = await this.papiGetUmIncome(this.extend(request, params));
9557
+ }
9558
+ else {
9559
+ response = await this.fapiPrivateGetIncome(this.extend(request, params));
9560
+ }
9239
9561
  }
9240
9562
  else if (this.isInverse(type, subType)) {
9241
- response = await this.dapiPrivateGetIncome(this.extend(request, params));
9563
+ if (isPortfolioMargin) {
9564
+ response = await this.papiGetCmIncome(this.extend(request, params));
9565
+ }
9566
+ else {
9567
+ response = await this.dapiPrivateGetIncome(this.extend(request, params));
9568
+ }
9242
9569
  }
9243
9570
  else {
9244
9571
  throw new errors.NotSupported(this.id + ' fetchFundingHistory() supports linear and inverse contracts only');
@@ -9613,12 +9940,15 @@ class binance extends binance$1 {
9613
9940
  * @see https://binance-docs.github.io/apidocs/voptions/en/#account-funding-flow-user_data
9614
9941
  * @see https://binance-docs.github.io/apidocs/futures/en/#get-income-history-user_data
9615
9942
  * @see https://binance-docs.github.io/apidocs/delivery/en/#get-income-history-user_data
9943
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-um-income-history-user_data
9944
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-cm-income-history-user_data
9616
9945
  * @param {string} code unified currency code
9617
9946
  * @param {int} [since] timestamp in ms of the earliest ledger entry
9618
9947
  * @param {int} [limit] max number of ledger entrys to return
9619
9948
  * @param {object} [params] extra parameters specific to the exchange API endpoint
9620
9949
  * @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)
9950
+ * @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)
9951
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the ledger for a portfolio margin account
9622
9952
  * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
9623
9953
  */
9624
9954
  await this.loadMarkets();
@@ -9647,6 +9977,8 @@ class binance extends binance$1 {
9647
9977
  params = this.omit(params, 'until');
9648
9978
  request['endTime'] = until;
9649
9979
  }
9980
+ let isPortfolioMargin = undefined;
9981
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchLedger', 'papi', 'portfolioMargin', false);
9650
9982
  let response = undefined;
9651
9983
  if (type === 'option') {
9652
9984
  this.checkRequiredArgument('fetchLedger', code, 'code');
@@ -9654,10 +9986,20 @@ class binance extends binance$1 {
9654
9986
  response = await this.eapiPrivateGetBill(this.extend(request, params));
9655
9987
  }
9656
9988
  else if (this.isLinear(type, subType)) {
9657
- response = await this.fapiPrivateGetIncome(this.extend(request, params));
9989
+ if (isPortfolioMargin) {
9990
+ response = await this.papiGetUmIncome(this.extend(request, params));
9991
+ }
9992
+ else {
9993
+ response = await this.fapiPrivateGetIncome(this.extend(request, params));
9994
+ }
9658
9995
  }
9659
9996
  else if (this.isInverse(type, subType)) {
9660
- response = await this.dapiPrivateGetIncome(this.extend(request, params));
9997
+ if (isPortfolioMargin) {
9998
+ response = await this.papiGetCmIncome(this.extend(request, params));
9999
+ }
10000
+ else {
10001
+ response = await this.dapiPrivateGetIncome(this.extend(request, params));
10002
+ }
9661
10003
  }
9662
10004
  else {
9663
10005
  throw new errors.NotSupported(this.id + ' fetchLedger() supports contract wallets only');
@@ -9675,7 +10017,7 @@ class binance extends binance$1 {
9675
10017
  // }
9676
10018
  // ]
9677
10019
  //
9678
- // futures (fapi, dapi)
10020
+ // futures (fapi, dapi, papi)
9679
10021
  //
9680
10022
  // [
9681
10023
  // {
@@ -9704,7 +10046,7 @@ class binance extends binance$1 {
9704
10046
  // "createDate": 1676621042489
9705
10047
  // }
9706
10048
  //
9707
- // futures (fapi, dapi)
10049
+ // futures (fapi, dapi, papi)
9708
10050
  //
9709
10051
  // {
9710
10052
  // "symbol": "",
@@ -9813,7 +10155,7 @@ class binance extends binance$1 {
9813
10155
  const isSpotOrMargin = (api.indexOf('sapi') > -1 || api === 'private');
9814
10156
  const marketType = isSpotOrMargin ? 'spot' : 'future';
9815
10157
  const defaultId = (!isSpotOrMargin) ? 'x-xcKtGhcu' : 'x-R4BD3S82';
9816
- const broker = this.safeValue(this.options, 'broker', {});
10158
+ const broker = this.safeDict(this.options, 'broker', {});
9817
10159
  const brokerId = this.safeString(broker, marketType, defaultId);
9818
10160
  params['newClientOrderId'] = brokerId + this.uuid22();
9819
10161
  }
@@ -9841,8 +10183,8 @@ class binance extends binance$1 {
9841
10183
  }
9842
10184
  else if ((path === 'batchOrders') || (path.indexOf('sub-account') >= 0) || (path === 'capital/withdraw/apply') || (path.indexOf('staking') >= 0)) {
9843
10185
  if ((method === 'DELETE') && (path === 'batchOrders')) {
9844
- const orderidlist = this.safeValue(extendedParams, 'orderidlist', []);
9845
- const origclientorderidlist = this.safeValue(extendedParams, 'origclientorderidlist', []);
10186
+ const orderidlist = this.safeList(extendedParams, 'orderidlist', []);
10187
+ const origclientorderidlist = this.safeList(extendedParams, 'origclientorderidlist', []);
9846
10188
  extendedParams = this.omit(extendedParams, ['orderidlist', 'origclientorderidlist']);
9847
10189
  query = this.rawencode(extendedParams);
9848
10190
  const orderidlistLength = orderidlist.length;
@@ -9911,8 +10253,8 @@ class binance extends binance$1 {
9911
10253
  marketType = 'portfoliomargin';
9912
10254
  }
9913
10255
  if (marketType !== undefined) {
9914
- const exceptionsForMarketType = this.safeValue(this.exceptions, marketType, {});
9915
- return this.safeValue(exceptionsForMarketType, exactOrBroad, {});
10256
+ const exceptionsForMarketType = this.safeDict(this.exceptions, marketType, {});
10257
+ return this.safeDict(exceptionsForMarketType, exactOrBroad, {});
9916
10258
  }
9917
10259
  return {};
9918
10260
  }
@@ -10146,7 +10488,7 @@ class binance extends binance$1 {
10146
10488
  // },
10147
10489
  // ]
10148
10490
  //
10149
- const rate = this.safeValue(response, 0);
10491
+ const rate = this.safeDict(response, 0);
10150
10492
  return this.parseBorrowRate(rate);
10151
10493
  }
10152
10494
  async fetchBorrowRateHistory(code, since = undefined, limit = undefined, params = {}) {
@@ -10250,7 +10592,7 @@ class binance extends binance$1 {
10250
10592
  // "success": true
10251
10593
  // }
10252
10594
  //
10253
- const data = this.safeValue(response, 'data');
10595
+ const data = this.safeDict(response, 'data');
10254
10596
  const giftcardCode = this.safeString(data, 'code');
10255
10597
  const id = this.safeString(data, 'referenceNo');
10256
10598
  return {
@@ -10318,15 +10660,19 @@ class binance extends binance$1 {
10318
10660
  * @name binance#fetchBorrowInterest
10319
10661
  * @description fetch the interest owed by the user for borrowing currency for margin trading
10320
10662
  * @see https://binance-docs.github.io/apidocs/spot/en/#get-interest-history-user_data
10321
- * @param {string} code unified currency code
10322
- * @param {string} symbol unified market symbol when fetch interest in isolated markets
10663
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-margin-borrow-loan-interest-history-user_data
10664
+ * @param {string} [code] unified currency code
10665
+ * @param {string} [symbol] unified market symbol when fetch interest in isolated markets
10323
10666
  * @param {int} [since] the earliest time in ms to fetch borrrow interest for
10324
10667
  * @param {int} [limit] the maximum number of structures to retrieve
10325
10668
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10669
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the borrow interest in a portfolio margin account
10326
10670
  * @returns {object[]} a list of [borrow interest structures]{@link https://docs.ccxt.com/#/?id=borrow-interest-structure}
10327
10671
  */
10328
10672
  await this.loadMarkets();
10329
- const request = {};
10673
+ let isPortfolioMargin = undefined;
10674
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchBorrowInterest', 'papi', 'portfolioMargin', false);
10675
+ let request = {};
10330
10676
  let market = undefined;
10331
10677
  if (code !== undefined) {
10332
10678
  const currency = this.currency(code);
@@ -10338,11 +10684,20 @@ class binance extends binance$1 {
10338
10684
  if (limit !== undefined) {
10339
10685
  request['size'] = limit;
10340
10686
  }
10341
- if (symbol !== undefined) { // Isolated
10342
- market = this.market(symbol);
10343
- request['isolatedSymbol'] = market['id'];
10687
+ [request, params] = this.handleUntilOption('endTime', request, params);
10688
+ let response = undefined;
10689
+ if (isPortfolioMargin) {
10690
+ response = await this.papiGetMarginMarginInterestHistory(this.extend(request, params));
10691
+ }
10692
+ else {
10693
+ if (symbol !== undefined) {
10694
+ market = this.market(symbol);
10695
+ request['isolatedSymbol'] = market['id'];
10696
+ }
10697
+ response = await this.sapiGetMarginInterestHistory(this.extend(request, params));
10344
10698
  }
10345
- const response = await this.sapiGetMarginInterestHistory(this.extend(request, params));
10699
+ //
10700
+ // spot margin
10346
10701
  //
10347
10702
  // {
10348
10703
  // "rows":[
@@ -10359,13 +10714,31 @@ class binance extends binance$1 {
10359
10714
  // "total": 1
10360
10715
  // }
10361
10716
  //
10362
- const rows = this.safeValue(response, 'rows');
10717
+ // spot margin portfolio margin
10718
+ //
10719
+ // {
10720
+ // "total": 49,
10721
+ // "rows": [
10722
+ // {
10723
+ // "txId": 1656187724899910076,
10724
+ // "interestAccuredTime": 1707541200000,
10725
+ // "asset": "USDT",
10726
+ // "rawAsset": "USDT",
10727
+ // "principal": "0.00011146",
10728
+ // "interest": "0.00000001",
10729
+ // "interestRate": "0.00089489",
10730
+ // "type": "PERIODIC"
10731
+ // },
10732
+ // ]
10733
+ // }
10734
+ //
10735
+ const rows = this.safeList(response, 'rows');
10363
10736
  const interest = this.parseBorrowInterests(rows, market);
10364
10737
  return this.filterByCurrencySinceLimit(interest, code, since, limit);
10365
10738
  }
10366
10739
  parseBorrowInterest(info, market = undefined) {
10367
10740
  const symbol = this.safeString(info, 'isolatedSymbol');
10368
- const timestamp = this.safeNumber(info, 'interestAccuredTime');
10741
+ const timestamp = this.safeInteger(info, 'interestAccuredTime');
10369
10742
  const marginMode = (symbol === undefined) ? 'cross' : 'isolated';
10370
10743
  return {
10371
10744
  'account': (symbol === undefined) ? 'cross' : symbol,
@@ -10386,9 +10759,11 @@ class binance extends binance$1 {
10386
10759
  * @name binance#repayCrossMargin
10387
10760
  * @description repay borrowed margin and interest
10388
10761
  * @see https://binance-docs.github.io/apidocs/spot/en/#margin-account-borrow-repay-margin
10762
+ * @see https://binance-docs.github.io/apidocs/pm/en/#margin-account-repay-margin
10389
10763
  * @param {string} code unified currency code of the currency to repay
10390
10764
  * @param {float} amount the amount to repay
10391
10765
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10766
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to repay margin in a portfolio margin account
10392
10767
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
10393
10768
  */
10394
10769
  await this.loadMarkets();
@@ -10396,10 +10771,18 @@ class binance extends binance$1 {
10396
10771
  const request = {
10397
10772
  'asset': currency['id'],
10398
10773
  'amount': this.currencyToPrecision(code, amount),
10399
- 'isIsolated': 'FALSE',
10400
- 'type': 'REPAY',
10401
10774
  };
10402
- const response = await this.sapiPostMarginBorrowRepay(this.extend(request, params));
10775
+ let response = undefined;
10776
+ let isPortfolioMargin = undefined;
10777
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'repayCrossMargin', 'papi', 'portfolioMargin', false);
10778
+ if (isPortfolioMargin) {
10779
+ response = await this.papiPostRepayLoan(this.extend(request, params));
10780
+ }
10781
+ else {
10782
+ request['isIsolated'] = 'FALSE';
10783
+ request['type'] = 'REPAY';
10784
+ response = await this.sapiPostMarginBorrowRepay(this.extend(request, params));
10785
+ }
10403
10786
  //
10404
10787
  // {
10405
10788
  // "tranId": 108988250265,
@@ -10445,9 +10828,11 @@ class binance extends binance$1 {
10445
10828
  * @name binance#borrowCrossMargin
10446
10829
  * @description create a loan to borrow margin
10447
10830
  * @see https://binance-docs.github.io/apidocs/spot/en/#margin-account-borrow-repay-margin
10831
+ * @see https://binance-docs.github.io/apidocs/pm/en/#margin-account-borrow-margin
10448
10832
  * @param {string} code unified currency code of the currency to borrow
10449
10833
  * @param {float} amount the amount to borrow
10450
10834
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10835
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to borrow margin in a portfolio margin account
10451
10836
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
10452
10837
  */
10453
10838
  await this.loadMarkets();
@@ -10455,10 +10840,18 @@ class binance extends binance$1 {
10455
10840
  const request = {
10456
10841
  'asset': currency['id'],
10457
10842
  'amount': this.currencyToPrecision(code, amount),
10458
- 'isIsolated': 'FALSE',
10459
- 'type': 'BORROW',
10460
10843
  };
10461
- const response = await this.sapiPostMarginBorrowRepay(this.extend(request, params));
10844
+ let response = undefined;
10845
+ let isPortfolioMargin = undefined;
10846
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'borrowCrossMargin', 'papi', 'portfolioMargin', false);
10847
+ if (isPortfolioMargin) {
10848
+ response = await this.papiPostMarginLoan(this.extend(request, params));
10849
+ }
10850
+ else {
10851
+ request['isIsolated'] = 'FALSE';
10852
+ request['type'] = 'BORROW';
10853
+ response = await this.sapiPostMarginBorrowRepay(this.extend(request, params));
10854
+ }
10462
10855
  //
10463
10856
  // {
10464
10857
  // "tranId": 108988250265,