ccxt 4.2.53 → 4.2.54

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.
@@ -71,8 +71,6 @@ interface binance {
71
71
  sapiGetLoanFlexibleBorrowHistory(params?: {}): Promise<implicitReturnType>;
72
72
  sapiGetLoanFlexibleRepayHistory(params?: {}): Promise<implicitReturnType>;
73
73
  sapiGetLoanFlexibleLtvAdjustmentHistory(params?: {}): Promise<implicitReturnType>;
74
- sapiGetLoanFlexibleLoanableData(params?: {}): Promise<implicitReturnType>;
75
- sapiGetLoanFlexibleCollateralData(params?: {}): Promise<implicitReturnType>;
76
74
  sapiGetLoanVipOngoingOrders(params?: {}): Promise<implicitReturnType>;
77
75
  sapiGetLoanVipRepayHistory(params?: {}): Promise<implicitReturnType>;
78
76
  sapiGetLoanVipCollateralAccount(params?: {}): Promise<implicitReturnType>;
@@ -336,7 +334,6 @@ interface binance {
336
334
  sapiPostLoanRepay(params?: {}): Promise<implicitReturnType>;
337
335
  sapiPostLoanAdjustLtv(params?: {}): Promise<implicitReturnType>;
338
336
  sapiPostLoanCustomizeMarginCall(params?: {}): Promise<implicitReturnType>;
339
- sapiPostLoanFlexibleBorrow(params?: {}): Promise<implicitReturnType>;
340
337
  sapiPostLoanFlexibleRepay(params?: {}): Promise<implicitReturnType>;
341
338
  sapiPostLoanFlexibleAdjustLtv(params?: {}): Promise<implicitReturnType>;
342
339
  sapiPostLoanVipRepay(params?: {}): Promise<implicitReturnType>;
@@ -379,8 +376,17 @@ interface binance {
379
376
  sapiV2GetSubAccountFuturesAccount(params?: {}): Promise<implicitReturnType>;
380
377
  sapiV2GetSubAccountFuturesAccountSummary(params?: {}): Promise<implicitReturnType>;
381
378
  sapiV2GetSubAccountFuturesPositionRisk(params?: {}): Promise<implicitReturnType>;
379
+ sapiV2GetLoanFlexibleOngoingOrders(params?: {}): Promise<implicitReturnType>;
380
+ sapiV2GetLoanFlexibleBorrowHistory(params?: {}): Promise<implicitReturnType>;
381
+ sapiV2GetLoanFlexibleRepayHistory(params?: {}): Promise<implicitReturnType>;
382
+ sapiV2GetLoanFlexibleLtvAdjustmentHistory(params?: {}): Promise<implicitReturnType>;
383
+ sapiV2GetLoanFlexibleLoanableData(params?: {}): Promise<implicitReturnType>;
384
+ sapiV2GetLoanFlexibleCollateralData(params?: {}): Promise<implicitReturnType>;
382
385
  sapiV2PostEthStakingEthStake(params?: {}): Promise<implicitReturnType>;
383
386
  sapiV2PostSubAccountSubAccountApiIpRestriction(params?: {}): Promise<implicitReturnType>;
387
+ sapiV2PostLoanFlexibleBorrow(params?: {}): Promise<implicitReturnType>;
388
+ sapiV2PostLoanFlexibleRepay(params?: {}): Promise<implicitReturnType>;
389
+ sapiV2PostLoanFlexibleAdjustLtv(params?: {}): Promise<implicitReturnType>;
384
390
  sapiV3GetSubAccountAssets(params?: {}): Promise<implicitReturnType>;
385
391
  sapiV3PostAssetGetUserAsset(params?: {}): Promise<implicitReturnType>;
386
392
  sapiV4GetSubAccountAssets(params?: {}): Promise<implicitReturnType>;
@@ -264,6 +264,7 @@ export default class binance extends Exchange {
264
264
  setLeverage(leverage: Int, symbol?: Str, params?: {}): Promise<any>;
265
265
  setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<any>;
266
266
  setPositionMode(hedged: boolean, symbol?: Str, params?: {}): Promise<any>;
267
+ fetchLeverage(symbol: string, params?: {}): Promise<any>;
267
268
  fetchSettlementHistory(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<any>;
268
269
  fetchMySettlementHistory(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<any>;
269
270
  parseSettlement(settlement: any, market: any): {
@@ -274,6 +275,7 @@ export default class binance extends Exchange {
274
275
  datetime: string;
275
276
  };
276
277
  parseSettlements(settlements: any, market: any): any[];
278
+ fetchLedgerEntry(id: string, code?: Str, params?: {}): Promise<any>;
277
279
  fetchLedger(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<any>;
278
280
  parseLedgerEntry(item: any, currency?: Currency): {
279
281
  id: string;
package/js/src/binance.js CHANGED
@@ -96,7 +96,8 @@ export default class binance extends Exchange {
96
96
  'fetchL3OrderBook': false,
97
97
  'fetchLastPrices': true,
98
98
  'fetchLedger': true,
99
- 'fetchLeverage': false,
99
+ 'fetchLedgerEntry': true,
100
+ 'fetchLeverage': true,
100
101
  'fetchLeverageTiers': true,
101
102
  'fetchLiquidations': false,
102
103
  'fetchMarketLeverageTiers': 'emulated',
@@ -296,8 +297,6 @@ export default class binance extends Exchange {
296
297
  'loan/flexible/borrow/history': 40,
297
298
  'loan/flexible/repay/history': 40,
298
299
  'loan/flexible/ltv/adjustment/history': 40,
299
- 'loan/flexible/loanable/data': 40,
300
- 'loan/flexible/collateral/data': 40,
301
300
  'loan/vip/ongoing/orders': 40,
302
301
  'loan/vip/repay/history': 40,
303
302
  'loan/vip/collateral/account': 600,
@@ -589,7 +588,6 @@ export default class binance extends Exchange {
589
588
  'loan/repay': 40.002,
590
589
  'loan/adjust/ltv': 40.002,
591
590
  'loan/customize/margin_call': 40.002,
592
- 'loan/flexible/borrow': 40.002,
593
591
  'loan/flexible/repay': 40.002,
594
592
  'loan/flexible/adjust/ltv': 40.002,
595
593
  'loan/vip/repay': 40.002,
@@ -644,10 +642,19 @@ export default class binance extends Exchange {
644
642
  'sub-account/futures/account': 0.1,
645
643
  'sub-account/futures/accountSummary': 1,
646
644
  'sub-account/futures/positionRisk': 0.1,
645
+ 'loan/flexible/ongoing/orders': 30,
646
+ 'loan/flexible/borrow/history': 40,
647
+ 'loan/flexible/repay/history': 40,
648
+ 'loan/flexible/ltv/adjustment/history': 40,
649
+ 'loan/flexible/loanable/data': 40,
650
+ 'loan/flexible/collateral/data': 40, // Weight(IP): 400 => cost = 0.1 * 400 = 40
647
651
  },
648
652
  'post': {
649
653
  'eth-staking/eth/stake': 15,
650
- 'sub-account/subAccountApi/ipRestriction': 20.001, // Weight(UID): 3000 => cost = 0.006667 * 3000 = 20.001
654
+ 'sub-account/subAccountApi/ipRestriction': 20.001,
655
+ 'loan/flexible/borrow': 40.002,
656
+ 'loan/flexible/repay': 40.002,
657
+ 'loan/flexible/adjust/ltv': 40.002, // Weight(UID): 6000 => cost = 0.006667 * 6000 = 40.002
651
658
  },
652
659
  },
653
660
  'sapiV3': {
@@ -10382,6 +10389,67 @@ export default class binance extends Exchange {
10382
10389
  //
10383
10390
  return response;
10384
10391
  }
10392
+ async fetchLeverage(symbol, params = {}) {
10393
+ /**
10394
+ * @method
10395
+ * @name binance#fetchLeverage
10396
+ * @description fetch the set leverage for a market
10397
+ * @see https://binance-docs.github.io/apidocs/futures/en/#account-information-v2-user_data
10398
+ * @see https://binance-docs.github.io/apidocs/delivery/en/#account-information-user_data
10399
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-um-account-detail-user_data
10400
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-cm-account-detail-user_data
10401
+ * @param {string} symbol unified market symbol
10402
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
10403
+ * @returns {object} a [leverage structure]{@link https://docs.ccxt.com/#/?id=leverage-structure}
10404
+ */
10405
+ await this.loadMarkets();
10406
+ await this.loadLeverageBrackets(false, params);
10407
+ const market = this.market(symbol);
10408
+ if (!market['contract']) {
10409
+ throw new NotSupported(this.id + ' fetchLeverage() supports linear and inverse contracts only');
10410
+ }
10411
+ let type = undefined;
10412
+ [type, params] = this.handleMarketTypeAndParams('fetchLeverage', market, params);
10413
+ let subType = undefined;
10414
+ [subType, params] = this.handleSubTypeAndParams('fetchLeverage', market, params, 'linear');
10415
+ let isPortfolioMargin = undefined;
10416
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchLeverage', 'papi', 'portfolioMargin', false);
10417
+ let response = undefined;
10418
+ if (this.isLinear(type, subType)) {
10419
+ if (isPortfolioMargin) {
10420
+ response = await this.papiGetUmAccount(params);
10421
+ }
10422
+ else {
10423
+ response = await this.fapiPrivateV2GetAccount(params);
10424
+ }
10425
+ }
10426
+ else if (this.isInverse(type, subType)) {
10427
+ if (isPortfolioMargin) {
10428
+ response = await this.papiGetCmAccount(params);
10429
+ }
10430
+ else {
10431
+ response = await this.dapiPrivateGetAccount(params);
10432
+ }
10433
+ }
10434
+ else {
10435
+ throw new NotSupported(this.id + ' fetchPositions() supports linear and inverse contracts only');
10436
+ }
10437
+ const positions = this.safeList(response, 'positions', []);
10438
+ for (let i = 0; i < positions.length; i++) {
10439
+ const position = positions[i];
10440
+ const innerSymbol = this.safeString(position, 'symbol');
10441
+ if (innerSymbol === market['id']) {
10442
+ const isolated = this.safeBool(position, 'isolated');
10443
+ const marginMode = isolated ? 'isolated' : 'cross';
10444
+ return {
10445
+ 'info': position,
10446
+ 'marginMode': marginMode,
10447
+ 'leverage': this.safeInteger(position, 'leverage'),
10448
+ };
10449
+ }
10450
+ }
10451
+ return response;
10452
+ }
10385
10453
  async fetchSettlementHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
10386
10454
  /**
10387
10455
  * @method
@@ -10564,6 +10632,19 @@ export default class binance extends Exchange {
10564
10632
  }
10565
10633
  return result;
10566
10634
  }
10635
+ async fetchLedgerEntry(id, code = undefined, params = {}) {
10636
+ await this.loadMarkets();
10637
+ let type = undefined;
10638
+ [type, params] = this.handleMarketTypeAndParams('fetchLedgerEntry', undefined, params);
10639
+ const query = {
10640
+ 'recordId': id,
10641
+ 'type': type,
10642
+ };
10643
+ if (type !== 'option') {
10644
+ throw new BadRequest(this.id + ' fetchLedgerEntry () can only be used for type option');
10645
+ }
10646
+ return await this.fetchLedger(code, undefined, undefined, this.extend(query, params));
10647
+ }
10567
10648
  async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
10568
10649
  /**
10569
10650
  * @method
package/js/src/bybit.d.ts CHANGED
@@ -126,6 +126,11 @@ export default class bybit extends Exchange {
126
126
  fetchUsdcPositions(symbols?: Strings, params?: {}): Promise<import("./base/types.js").Position[]>;
127
127
  fetchPositions(symbols?: Strings, params?: {}): Promise<import("./base/types.js").Position[]>;
128
128
  parsePosition(position: any, market?: Market): import("./base/types.js").Position;
129
+ fetchLeverage(symbol: string, params?: {}): Promise<{
130
+ info: import("./base/types.js").Position;
131
+ leverage: number;
132
+ marginMode: number;
133
+ }>;
129
134
  setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<any>;
130
135
  setLeverage(leverage: Int, symbol?: Str, params?: {}): Promise<any>;
131
136
  setPositionMode(hedged: boolean, symbol?: Str, params?: {}): Promise<any>;
package/js/src/bybit.js CHANGED
@@ -111,6 +111,7 @@ export default class bybit extends Exchange {
111
111
  'fetchUnderlyingAssets': false,
112
112
  'fetchVolatilityHistory': true,
113
113
  'fetchWithdrawals': true,
114
+ 'fetchLeverage': true,
114
115
  'repayCrossMargin': true,
115
116
  'setLeverage': true,
116
117
  'setMarginMode': true,
@@ -6347,6 +6348,24 @@ export default class bybit extends Exchange {
6347
6348
  'takeProfitPrice': this.safeNumber2(position, 'take_profit', 'takeProfit'),
6348
6349
  });
6349
6350
  }
6351
+ async fetchLeverage(symbol, params = {}) {
6352
+ /**
6353
+ * @method
6354
+ * @name bybit#fetchLeverage
6355
+ * @description fetch the set leverage for a market
6356
+ * @see https://bybit-exchange.github.io/docs/v5/position
6357
+ * @param {string} symbol unified market symbol
6358
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
6359
+ * @returns {object} a [leverage structure]{@link https://docs.ccxt.com/#/?id=leverage-structure}
6360
+ */
6361
+ await this.loadMarkets();
6362
+ const position = await this.fetchPosition(symbol, params);
6363
+ return {
6364
+ 'info': position,
6365
+ 'leverage': this.safeInteger(position, 'leverage'),
6366
+ 'marginMode': this.safeNumber(position, 'marginMode'),
6367
+ };
6368
+ }
6350
6369
  async setMarginMode(marginMode, symbol = undefined, params = {}) {
6351
6370
  /**
6352
6371
  * @method
@@ -30,8 +30,8 @@ export default class binance extends binanceRest {
30
30
  signParams(params?: {}): any;
31
31
  authenticate(params?: {}): Promise<void>;
32
32
  keepAliveListenKey(params?: {}): Promise<void>;
33
- setBalanceCache(client: Client, type: any): void;
34
- loadBalanceSnapshot(client: any, messageHash: any, type: any): Promise<void>;
33
+ setBalanceCache(client: Client, type: any, isPortfolioMargin?: boolean): void;
34
+ loadBalanceSnapshot(client: any, messageHash: any, type: any, isPortfolioMargin: any): Promise<void>;
35
35
  fetchBalanceWs(params?: {}): Promise<Balances>;
36
36
  handleBalanceWs(client: Client, message: any): void;
37
37
  watchBalance(params?: {}): Promise<Balances>;
@@ -52,8 +52,8 @@ export default class binance extends binanceRest {
52
52
  parseWsOrder(order: any, market?: any): Order;
53
53
  handleOrderUpdate(client: Client, message: any): void;
54
54
  watchPositions(symbols?: Strings, since?: Int, limit?: Int, params?: {}): Promise<Position[]>;
55
- setPositionsCache(client: Client, type: any, symbols?: Strings): void;
56
- loadPositionsSnapshot(client: any, messageHash: any, type: any): Promise<void>;
55
+ setPositionsCache(client: Client, type: any, symbols?: Strings, isPortfolioMargin?: boolean): void;
56
+ loadPositionsSnapshot(client: any, messageHash: any, type: any, isPortfolioMargin: any): Promise<void>;
57
57
  handlePositions(client: any, message: any): void;
58
58
  parseWsPosition(position: any, market?: any): Position;
59
59
  fetchMyTradesWs(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
@@ -66,6 +66,7 @@ export default class binance extends binanceRest {
66
66
  'future': 'wss://fstream.binance.com/ws',
67
67
  'delivery': 'wss://dstream.binance.com/ws',
68
68
  'ws': 'wss://ws-api.binance.com:443/ws-api/v3',
69
+ 'papi': 'wss://fstream.binance.com/pm/ws',
69
70
  },
70
71
  },
71
72
  },
@@ -1241,11 +1242,12 @@ export default class binance extends binanceRest {
1241
1242
  }
1242
1243
  async authenticate(params = {}) {
1243
1244
  const time = this.milliseconds();
1244
- let query = undefined;
1245
1245
  let type = undefined;
1246
- [type, query] = this.handleMarketTypeAndParams('authenticate', undefined, params);
1246
+ [type, params] = this.handleMarketTypeAndParams('authenticate', undefined, params);
1247
1247
  let subType = undefined;
1248
- [subType, query] = this.handleSubTypeAndParams('authenticate', undefined, query);
1248
+ [subType, params] = this.handleSubTypeAndParams('authenticate', undefined, params);
1249
+ let isPortfolioMargin = undefined;
1250
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'authenticate', 'papi', 'portfolioMargin', false);
1249
1251
  if (this.isLinear(type, subType)) {
1250
1252
  type = 'future';
1251
1253
  }
@@ -1253,36 +1255,39 @@ export default class binance extends binanceRest {
1253
1255
  type = 'delivery';
1254
1256
  }
1255
1257
  let marginMode = undefined;
1256
- [marginMode, query] = this.handleMarginModeAndParams('authenticate', query);
1258
+ [marginMode, params] = this.handleMarginModeAndParams('authenticate', params);
1257
1259
  const isIsolatedMargin = (marginMode === 'isolated');
1258
1260
  const isCrossMargin = (marginMode === 'cross') || (marginMode === undefined);
1259
- const symbol = this.safeString(query, 'symbol');
1260
- query = this.omit(query, 'symbol');
1261
+ const symbol = this.safeString(params, 'symbol');
1262
+ params = this.omit(params, 'symbol');
1261
1263
  const options = this.safeValue(this.options, type, {});
1262
1264
  const lastAuthenticatedTime = this.safeInteger(options, 'lastAuthenticatedTime', 0);
1263
1265
  const listenKeyRefreshRate = this.safeInteger(this.options, 'listenKeyRefreshRate', 1200000);
1264
1266
  const delay = this.sum(listenKeyRefreshRate, 10000);
1265
1267
  if (time - lastAuthenticatedTime > delay) {
1266
1268
  let response = undefined;
1267
- if (type === 'future') {
1268
- response = await this.fapiPrivatePostListenKey(query);
1269
+ if (isPortfolioMargin) {
1270
+ response = await this.papiPostListenKey(params);
1271
+ }
1272
+ else if (type === 'future') {
1273
+ response = await this.fapiPrivatePostListenKey(params);
1269
1274
  }
1270
1275
  else if (type === 'delivery') {
1271
- response = await this.dapiPrivatePostListenKey(query);
1276
+ response = await this.dapiPrivatePostListenKey(params);
1272
1277
  }
1273
1278
  else if (type === 'margin' && isCrossMargin) {
1274
- response = await this.sapiPostUserDataStream(query);
1279
+ response = await this.sapiPostUserDataStream(params);
1275
1280
  }
1276
1281
  else if (isIsolatedMargin) {
1277
1282
  if (symbol === undefined) {
1278
1283
  throw new ArgumentsRequired(this.id + ' authenticate() requires a symbol argument for isolated margin mode');
1279
1284
  }
1280
1285
  const marketId = this.marketId(symbol);
1281
- query = this.extend(query, { 'symbol': marketId });
1282
- response = await this.sapiPostUserDataStreamIsolated(query);
1286
+ params = this.extend(params, { 'symbol': marketId });
1287
+ response = await this.sapiPostUserDataStreamIsolated(params);
1283
1288
  }
1284
1289
  else {
1285
- response = await this.publicPostUserDataStream(query);
1290
+ response = await this.publicPostUserDataStream(params);
1286
1291
  }
1287
1292
  this.options[type] = this.extend(options, {
1288
1293
  'listenKey': this.safeString(response, 'listenKey'),
@@ -1295,6 +1300,8 @@ export default class binance extends binanceRest {
1295
1300
  // https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot
1296
1301
  let type = this.safeString2(this.options, 'defaultType', 'authenticate', 'spot');
1297
1302
  type = this.safeString(params, 'type', type);
1303
+ let isPortfolioMargin = undefined;
1304
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'keepAliveListenKey', 'papi', 'portfolioMargin', false);
1298
1305
  const subTypeInfo = this.handleSubTypeAndParams('keepAliveListenKey', undefined, params);
1299
1306
  const subType = subTypeInfo[0];
1300
1307
  if (this.isLinear(type, subType)) {
@@ -1311,28 +1318,35 @@ export default class binance extends binanceRest {
1311
1318
  }
1312
1319
  const request = {};
1313
1320
  const symbol = this.safeString(params, 'symbol');
1314
- const sendParams = this.omit(params, ['type', 'symbol']);
1321
+ params = this.omit(params, ['type', 'symbol']);
1315
1322
  const time = this.milliseconds();
1316
1323
  try {
1317
- if (type === 'future') {
1318
- await this.fapiPrivatePutListenKey(this.extend(request, sendParams));
1324
+ if (isPortfolioMargin) {
1325
+ await this.papiPutListenKey(this.extend(request, params));
1326
+ }
1327
+ else if (type === 'future') {
1328
+ await this.fapiPrivatePutListenKey(this.extend(request, params));
1319
1329
  }
1320
1330
  else if (type === 'delivery') {
1321
- await this.dapiPrivatePutListenKey(this.extend(request, sendParams));
1331
+ await this.dapiPrivatePutListenKey(this.extend(request, params));
1322
1332
  }
1323
1333
  else {
1324
1334
  request['listenKey'] = listenKey;
1325
1335
  if (type === 'margin') {
1326
1336
  request['symbol'] = symbol;
1327
- await this.sapiPutUserDataStream(this.extend(request, sendParams));
1337
+ await this.sapiPutUserDataStream(this.extend(request, params));
1328
1338
  }
1329
1339
  else {
1330
- await this.publicPutUserDataStream(this.extend(request, sendParams));
1340
+ await this.publicPutUserDataStream(this.extend(request, params));
1331
1341
  }
1332
1342
  }
1333
1343
  }
1334
1344
  catch (error) {
1335
- const url = this.urls['api']['ws'][type] + '/' + this.options[type]['listenKey'];
1345
+ let urlType = type;
1346
+ if (isPortfolioMargin) {
1347
+ urlType = 'papi';
1348
+ }
1349
+ const url = this.urls['api']['ws'][urlType] + '/' + this.options[type]['listenKey'];
1336
1350
  const client = this.client(url);
1337
1351
  const messageHashes = Object.keys(client.futures);
1338
1352
  for (let i = 0; i < messageHashes.length; i++) {
@@ -1364,7 +1378,7 @@ export default class binance extends binanceRest {
1364
1378
  }
1365
1379
  }
1366
1380
  }
1367
- setBalanceCache(client, type) {
1381
+ setBalanceCache(client, type, isPortfolioMargin = false) {
1368
1382
  if (type in client.subscriptions) {
1369
1383
  return;
1370
1384
  }
@@ -1374,15 +1388,21 @@ export default class binance extends binanceRest {
1374
1388
  const messageHash = type + ':fetchBalanceSnapshot';
1375
1389
  if (!(messageHash in client.futures)) {
1376
1390
  client.future(messageHash);
1377
- this.spawn(this.loadBalanceSnapshot, client, messageHash, type);
1391
+ this.spawn(this.loadBalanceSnapshot, client, messageHash, type, isPortfolioMargin);
1378
1392
  }
1379
1393
  }
1380
1394
  else {
1381
1395
  this.balance[type] = {};
1382
1396
  }
1383
1397
  }
1384
- async loadBalanceSnapshot(client, messageHash, type) {
1385
- const response = await this.fetchBalance({ 'type': type });
1398
+ async loadBalanceSnapshot(client, messageHash, type, isPortfolioMargin) {
1399
+ const params = {
1400
+ 'type': type,
1401
+ };
1402
+ if (isPortfolioMargin) {
1403
+ params['portfolioMargin'] = true;
1404
+ }
1405
+ const response = await this.fetchBalance(params);
1386
1406
  this.balance[type] = this.extend(response, this.safeValue(this.balance, type, {}));
1387
1407
  // don't remove the future from the .futures cache
1388
1408
  const future = client.futures[messageHash];
@@ -1476,6 +1496,7 @@ export default class binance extends binanceRest {
1476
1496
  * @name binance#watchBalance
1477
1497
  * @description watch balance and get the amount of funds available for trading or funds locked in orders
1478
1498
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1499
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to watch the balance of a portfolio margin account
1479
1500
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1480
1501
  */
1481
1502
  await this.loadMarkets();
@@ -1484,16 +1505,22 @@ export default class binance extends binanceRest {
1484
1505
  let type = this.safeString(params, 'type', defaultType);
1485
1506
  let subType = undefined;
1486
1507
  [subType, params] = this.handleSubTypeAndParams('watchBalance', undefined, params);
1508
+ let isPortfolioMargin = undefined;
1509
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'watchBalance', 'papi', 'portfolioMargin', false);
1510
+ let urlType = type;
1511
+ if (isPortfolioMargin) {
1512
+ urlType = 'papi';
1513
+ }
1487
1514
  if (this.isLinear(type, subType)) {
1488
1515
  type = 'future';
1489
1516
  }
1490
1517
  else if (this.isInverse(type, subType)) {
1491
1518
  type = 'delivery';
1492
1519
  }
1493
- const url = this.urls['api']['ws'][type] + '/' + this.options[type]['listenKey'];
1520
+ const url = this.urls['api']['ws'][urlType] + '/' + this.options[type]['listenKey'];
1494
1521
  const client = this.client(url);
1495
- this.setBalanceCache(client, type);
1496
- this.setPositionsCache(client, type);
1522
+ this.setBalanceCache(client, type, isPortfolioMargin);
1523
+ this.setPositionsCache(client, type, undefined, isPortfolioMargin);
1497
1524
  const options = this.safeValue(this.options, 'watchBalance');
1498
1525
  const fetchBalanceSnapshot = this.safeBool(options, 'fetchBalanceSnapshot', false);
1499
1526
  const awaitBalanceSnapshot = this.safeBool(options, 'awaitBalanceSnapshot', true);
@@ -2100,11 +2127,14 @@ export default class binance extends binanceRest {
2100
2127
  * @name binance#watchOrders
2101
2128
  * @description watches information on multiple orders made by the user
2102
2129
  * @see https://binance-docs.github.io/apidocs/spot/en/#payload-order-update
2130
+ * @see https://binance-docs.github.io/apidocs/pm/en/#event-futures-order-update
2131
+ * @see https://binance-docs.github.io/apidocs/pm/en/#event-margin-order-update
2103
2132
  * @param {string} symbol unified market symbol of the market the orders were made in
2104
2133
  * @param {int} [since] the earliest time in ms to fetch orders for
2105
2134
  * @param {int} [limit] the maximum number of order structures to retrieve
2106
2135
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2107
2136
  * @param {string|undefined} [params.marginMode] 'cross' or 'isolated', for spot margin
2137
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to watch portfolio margin account orders
2108
2138
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2109
2139
  */
2110
2140
  await this.loadMarkets();
@@ -2133,10 +2163,15 @@ export default class binance extends binanceRest {
2133
2163
  if ((type === 'margin') || ((type === 'spot') && (marginMode !== undefined))) {
2134
2164
  urlType = 'spot'; // spot-margin shares the same stream as regular spot
2135
2165
  }
2166
+ let isPortfolioMargin = undefined;
2167
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'watchOrders', 'papi', 'portfolioMargin', false);
2168
+ if (isPortfolioMargin) {
2169
+ urlType = 'papi';
2170
+ }
2136
2171
  const url = this.urls['api']['ws'][urlType] + '/' + this.options[type]['listenKey'];
2137
2172
  const client = this.client(url);
2138
- this.setBalanceCache(client, type);
2139
- this.setPositionsCache(client, type);
2173
+ this.setBalanceCache(client, type, isPortfolioMargin);
2174
+ this.setPositionsCache(client, type, undefined, isPortfolioMargin);
2140
2175
  const message = undefined;
2141
2176
  const orders = await this.watch(url, messageHash, message, type);
2142
2177
  if (this.newUpdates) {
@@ -2391,6 +2426,7 @@ export default class binance extends binanceRest {
2391
2426
  * @description watch all open positions
2392
2427
  * @param {string[]|undefined} symbols list of unified market symbols
2393
2428
  * @param {object} params extra parameters specific to the exchange API endpoint
2429
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to watch positions in a portfolio margin account
2394
2430
  * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
2395
2431
  */
2396
2432
  await this.loadMarkets();
@@ -2421,10 +2457,16 @@ export default class binance extends binanceRest {
2421
2457
  type = 'delivery';
2422
2458
  }
2423
2459
  messageHash = type + ':positions' + messageHash;
2424
- const url = this.urls['api']['ws'][type] + '/' + this.options[type]['listenKey'];
2460
+ let isPortfolioMargin = undefined;
2461
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'watchPositions', 'papi', 'portfolioMargin', false);
2462
+ let urlType = type;
2463
+ if (isPortfolioMargin) {
2464
+ urlType = 'papi';
2465
+ }
2466
+ const url = this.urls['api']['ws'][urlType] + '/' + this.options[type]['listenKey'];
2425
2467
  const client = this.client(url);
2426
- this.setBalanceCache(client, type);
2427
- this.setPositionsCache(client, type, symbols);
2468
+ this.setBalanceCache(client, type, isPortfolioMargin);
2469
+ this.setPositionsCache(client, type, symbols, isPortfolioMargin);
2428
2470
  const fetchPositionsSnapshot = this.handleOption('watchPositions', 'fetchPositionsSnapshot', true);
2429
2471
  const awaitPositionsSnapshot = this.safeValue('watchPositions', 'awaitPositionsSnapshot', true);
2430
2472
  const cache = this.safeValue(this.positions, type);
@@ -2438,7 +2480,7 @@ export default class binance extends binanceRest {
2438
2480
  }
2439
2481
  return this.filterBySymbolsSinceLimit(cache, symbols, since, limit, true);
2440
2482
  }
2441
- setPositionsCache(client, type, symbols = undefined) {
2483
+ setPositionsCache(client, type, symbols = undefined, isPortfolioMargin = false) {
2442
2484
  if (type === 'spot') {
2443
2485
  return;
2444
2486
  }
@@ -2453,15 +2495,21 @@ export default class binance extends binanceRest {
2453
2495
  const messageHash = type + ':fetchPositionsSnapshot';
2454
2496
  if (!(messageHash in client.futures)) {
2455
2497
  client.future(messageHash);
2456
- this.spawn(this.loadPositionsSnapshot, client, messageHash, type);
2498
+ this.spawn(this.loadPositionsSnapshot, client, messageHash, type, isPortfolioMargin);
2457
2499
  }
2458
2500
  }
2459
2501
  else {
2460
2502
  this.positions[type] = new ArrayCacheBySymbolBySide();
2461
2503
  }
2462
2504
  }
2463
- async loadPositionsSnapshot(client, messageHash, type) {
2464
- const positions = await this.fetchPositions(undefined, { 'type': type });
2505
+ async loadPositionsSnapshot(client, messageHash, type, isPortfolioMargin) {
2506
+ const params = {
2507
+ 'type': type,
2508
+ };
2509
+ if (isPortfolioMargin) {
2510
+ params['portfolioMargin'] = true;
2511
+ }
2512
+ const positions = await this.fetchPositions(undefined, params);
2465
2513
  this.positions[type] = new ArrayCacheBySymbolBySide();
2466
2514
  const cache = this.positions[type];
2467
2515
  for (let i = 0; i < positions.length; i++) {
@@ -2734,6 +2782,7 @@ export default class binance extends binanceRest {
2734
2782
  * @param {int} [since] the earliest time in ms to fetch orders for
2735
2783
  * @param {int} [limit] the maximum number of order structures to retrieve
2736
2784
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2785
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to watch trades in a portfolio margin account
2737
2786
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure
2738
2787
  */
2739
2788
  await this.loadMarkets();
@@ -2763,10 +2812,15 @@ export default class binance extends binanceRest {
2763
2812
  if (type === 'margin') {
2764
2813
  urlType = 'spot'; // spot-margin shares the same stream as regular spot
2765
2814
  }
2815
+ let isPortfolioMargin = undefined;
2816
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'watchMyTrades', 'papi', 'portfolioMargin', false);
2817
+ if (isPortfolioMargin) {
2818
+ urlType = 'papi';
2819
+ }
2766
2820
  const url = this.urls['api']['ws'][urlType] + '/' + this.options[type]['listenKey'];
2767
2821
  const client = this.client(url);
2768
- this.setBalanceCache(client, type);
2769
- this.setPositionsCache(client, type);
2822
+ this.setBalanceCache(client, type, isPortfolioMargin);
2823
+ this.setPositionsCache(client, type, undefined, isPortfolioMargin);
2770
2824
  const message = undefined;
2771
2825
  const trades = await this.watch(url, messageHash, message, type);
2772
2826
  if (this.newUpdates) {
@@ -230,6 +230,7 @@ export default class whitebit extends Exchange {
230
230
  'account': 'spot',
231
231
  },
232
232
  'accountsByType': {
233
+ 'funding': 'main',
233
234
  'main': 'main',
234
235
  'spot': 'spot',
235
236
  'margin': 'collateral',
@@ -1323,9 +1324,9 @@ export default class whitebit extends Exchange {
1323
1324
  else {
1324
1325
  const options = this.safeValue(this.options, 'fetchBalance', {});
1325
1326
  const defaultAccount = this.safeString(options, 'account');
1326
- const account = this.safeString(params, 'account', defaultAccount);
1327
- params = this.omit(params, 'account');
1328
- if (account === 'main') {
1327
+ const account = this.safeString2(params, 'account', 'type', defaultAccount);
1328
+ params = this.omit(params, ['account', 'type']);
1329
+ if (account === 'main' || account === 'funding') {
1329
1330
  response = await this.v4PrivatePostMainAccountBalance(params);
1330
1331
  }
1331
1332
  else {
package/jsdoc2md.js CHANGED
@@ -108,10 +108,11 @@ const sidebar =
108
108
  - [Supported Exchanges](Exchange-Markets.md)
109
109
  - [Exchanges By Country](Exchange-Markets-By-Country.md)
110
110
  - [API Spec By Method](baseSpec.md)
111
- - API Spec by Exchange
112
- ${exchangeLinks.join('\n')}
111
+ - [FAQ](FAQ.md)
113
112
  - [Changelog](CHANGELOG.md)
114
113
  - [Awesome](Awesome.md)
114
+ - API Spec by Exchange
115
+ ${exchangeLinks.join('\n')}
115
116
  `
116
117
  fs.writeFileSync('./wiki/_sidebar.md', sidebar);
117
118
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.53",
3
+ "version": "4.2.54",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",
package/skip-tests.json CHANGED
@@ -379,7 +379,7 @@
379
379
  },
380
380
  "onetrading": {
381
381
  "skip": true,
382
- "until": "2024-02-28",
382
+ "until": "2024-03-28",
383
383
  "skipWs": true,
384
384
  "skipMethods": {
385
385
  "fetchOrderBook": "some bid might be lower than next bid",