ccxt 4.1.97 → 4.1.98

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.
package/dist/cjs/ccxt.js CHANGED
@@ -168,7 +168,7 @@ var woo$1 = require('./src/pro/woo.js');
168
168
 
169
169
  //-----------------------------------------------------------------------------
170
170
  // this is updated by vss.js when building
171
- const version = '4.1.97';
171
+ const version = '4.1.98';
172
172
  Exchange["default"].ccxtVersion = version;
173
173
  const exchanges = {
174
174
  'ace': ace,
@@ -6076,7 +6076,8 @@ class binance extends binance$1 {
6076
6076
  'amount': this.currencyToPrecision(code, amount),
6077
6077
  };
6078
6078
  request['type'] = this.safeString(params, 'type');
6079
- let method = 'sapiPostAssetTransfer';
6079
+ params = this.omit(params, 'type');
6080
+ let response = undefined;
6080
6081
  if (request['type'] === undefined) {
6081
6082
  const symbol = this.safeString(params, 'symbol');
6082
6083
  if (symbol !== undefined) {
@@ -6116,16 +6117,16 @@ class binance extends binance$1 {
6116
6117
  throw new errors.BadRequest(this.id + ' transfer () does not allow transfers between ' + fromAccount + ' and ' + toAccount);
6117
6118
  }
6118
6119
  else if (toSpot && fromIsolated) {
6119
- method = 'sapiPostMarginIsolatedTransfer';
6120
6120
  request['transFrom'] = 'ISOLATED_MARGIN';
6121
6121
  request['transTo'] = 'SPOT';
6122
6122
  request['symbol'] = fromId;
6123
+ response = await this.sapiPostMarginIsolatedTransfer(this.extend(request, params));
6123
6124
  }
6124
6125
  else if (fromSpot && toIsolated) {
6125
- method = 'sapiPostMarginIsolatedTransfer';
6126
6126
  request['transFrom'] = 'SPOT';
6127
6127
  request['transTo'] = 'ISOLATED_MARGIN';
6128
6128
  request['symbol'] = toId;
6129
+ response = await this.sapiPostMarginIsolatedTransfer(this.extend(request, params));
6129
6130
  }
6130
6131
  else {
6131
6132
  if (fromIsolated) {
@@ -6143,8 +6144,9 @@ class binance extends binance$1 {
6143
6144
  request['type'] = fromId + '_' + toId;
6144
6145
  }
6145
6146
  }
6146
- params = this.omit(params, 'type');
6147
- const response = await this[method](this.extend(request, params));
6147
+ if (response === undefined) {
6148
+ response = await this.sapiPostAssetTransfer(this.extend(request, params));
6149
+ }
6148
6150
  //
6149
6151
  // {
6150
6152
  // "tranId":13526853623
@@ -6937,7 +6939,6 @@ class binance extends binance$1 {
6937
6939
  */
6938
6940
  await this.loadMarkets();
6939
6941
  const request = {};
6940
- let method = undefined;
6941
6942
  let paginate = false;
6942
6943
  [paginate, params] = this.handleOptionAndParams(params, 'fetchFundingRateHistory', 'paginate');
6943
6944
  if (paginate) {
@@ -6954,15 +6955,6 @@ class binance extends binance$1 {
6954
6955
  let subType = undefined;
6955
6956
  [subType, params] = this.handleSubTypeAndParams('fetchFundingRateHistory', market, params, 'linear');
6956
6957
  params = this.omit(params, 'type');
6957
- if (this.isLinear(type, subType)) {
6958
- method = 'fapiPublicGetFundingRate';
6959
- }
6960
- else if (this.isInverse(type, subType)) {
6961
- method = 'dapiPublicGetFundingRate';
6962
- }
6963
- if (method === undefined) {
6964
- throw new errors.NotSupported(this.id + ' fetchFundingRateHistory() is not supported for ' + type + ' markets');
6965
- }
6966
6958
  if (since !== undefined) {
6967
6959
  request['startTime'] = since;
6968
6960
  }
@@ -6975,7 +6967,16 @@ class binance extends binance$1 {
6975
6967
  if (limit !== undefined) {
6976
6968
  request['limit'] = limit;
6977
6969
  }
6978
- const response = await this[method](this.extend(request, params));
6970
+ let response = undefined;
6971
+ if (this.isLinear(type, subType)) {
6972
+ response = await this.fapiPublicGetFundingRate(this.extend(request, params));
6973
+ }
6974
+ else if (this.isInverse(type, subType)) {
6975
+ response = await this.dapiPublicGetFundingRate(this.extend(request, params));
6976
+ }
6977
+ else {
6978
+ throw new errors.NotSupported(this.id + ' fetchFundingRateHistory() is not supported for ' + type + ' markets');
6979
+ }
6979
6980
  //
6980
6981
  // {
6981
6982
  // "symbol": "BTCUSDT",
@@ -7011,22 +7012,21 @@ class binance extends binance$1 {
7011
7012
  */
7012
7013
  await this.loadMarkets();
7013
7014
  symbols = this.marketSymbols(symbols);
7014
- let method = undefined;
7015
7015
  const defaultType = this.safeString2(this.options, 'fetchFundingRates', 'defaultType', 'future');
7016
7016
  const type = this.safeString(params, 'type', defaultType);
7017
7017
  let subType = undefined;
7018
7018
  [subType, params] = this.handleSubTypeAndParams('fetchFundingRates', undefined, params, 'linear');
7019
7019
  const query = this.omit(params, 'type');
7020
+ let response = undefined;
7020
7021
  if (this.isLinear(type, subType)) {
7021
- method = 'fapiPublicGetPremiumIndex';
7022
+ response = await this.fapiPublicGetPremiumIndex(query);
7022
7023
  }
7023
7024
  else if (this.isInverse(type, subType)) {
7024
- method = 'dapiPublicGetPremiumIndex';
7025
+ response = await this.dapiPublicGetPremiumIndex(query);
7025
7026
  }
7026
7027
  else {
7027
7028
  throw new errors.NotSupported(this.id + ' fetchFundingRates() supports linear and inverse contracts only');
7028
7029
  }
7029
- const response = await this[method](query);
7030
7030
  const result = [];
7031
7031
  for (let i = 0; i < response.length; i++) {
7032
7032
  const entry = response[i];
@@ -7494,22 +7494,21 @@ class binance extends binance$1 {
7494
7494
  // it contains useful stuff like the maintenance margin and initial margin for positions
7495
7495
  const leverageBrackets = this.safeValue(this.options, 'leverageBrackets');
7496
7496
  if ((leverageBrackets === undefined) || (reload)) {
7497
- let method = undefined;
7498
7497
  const defaultType = this.safeString(this.options, 'defaultType', 'future');
7499
7498
  const type = this.safeString(params, 'type', defaultType);
7500
7499
  const query = this.omit(params, 'type');
7501
7500
  let subType = undefined;
7502
7501
  [subType, params] = this.handleSubTypeAndParams('loadLeverageBrackets', undefined, params, 'linear');
7502
+ let response = undefined;
7503
7503
  if (this.isLinear(type, subType)) {
7504
- method = 'fapiPrivateGetLeverageBracket';
7504
+ response = await this.fapiPrivateGetLeverageBracket(query);
7505
7505
  }
7506
7506
  else if (this.isInverse(type, subType)) {
7507
- method = 'dapiPrivateV2GetLeverageBracket';
7507
+ response = await this.dapiPrivateV2GetLeverageBracket(query);
7508
7508
  }
7509
7509
  else {
7510
7510
  throw new errors.NotSupported(this.id + ' loadLeverageBrackets() supports linear and inverse contracts only');
7511
7511
  }
7512
- const response = await this[method](query);
7513
7512
  this.options['leverageBrackets'] = {};
7514
7513
  for (let i = 0; i < response.length; i++) {
7515
7514
  const entry = response[i];
@@ -7971,7 +7970,6 @@ class binance extends binance$1 {
7971
7970
  */
7972
7971
  await this.loadMarkets();
7973
7972
  let market = undefined;
7974
- let method = undefined;
7975
7973
  const request = {
7976
7974
  'incomeType': 'FUNDING_FEE', // "TRANSFER","WELCOME_BONUS", "REALIZED_PNL","FUNDING_FEE", "COMMISSION" and "INSURANCE_CLEAR"
7977
7975
  };
@@ -7993,16 +7991,16 @@ class binance extends binance$1 {
7993
7991
  const defaultType = this.safeString2(this.options, 'fetchFundingHistory', 'defaultType', 'future');
7994
7992
  const type = this.safeString(params, 'type', defaultType);
7995
7993
  params = this.omit(params, 'type');
7994
+ let response = undefined;
7996
7995
  if (this.isLinear(type, subType)) {
7997
- method = 'fapiPrivateGetIncome';
7996
+ response = await this.fapiPrivateGetIncome(this.extend(request, params));
7998
7997
  }
7999
7998
  else if (this.isInverse(type, subType)) {
8000
- method = 'dapiPrivateGetIncome';
7999
+ response = await this.dapiPrivateGetIncome(this.extend(request, params));
8001
8000
  }
8002
8001
  else {
8003
8002
  throw new errors.NotSupported(this.id + ' fetchFundingHistory() supports linear and inverse contracts only');
8004
8003
  }
8005
- const response = await this[method](this.extend(request, params));
8006
8004
  return this.parseIncomes(response, market, since, limit);
8007
8005
  }
8008
8006
  async setLeverage(leverage, symbol = undefined, params = {}) {
@@ -8756,17 +8754,16 @@ class binance extends binance$1 {
8756
8754
  'symbol': market['id'],
8757
8755
  'amount': amount,
8758
8756
  };
8759
- let method = undefined;
8757
+ let response = undefined;
8760
8758
  let code = undefined;
8761
8759
  if (market['linear']) {
8762
- method = 'fapiPrivatePostPositionMargin';
8763
8760
  code = market['quote'];
8761
+ response = await this.fapiPrivatePostPositionMargin(this.extend(request, params));
8764
8762
  }
8765
8763
  else {
8766
- method = 'dapiPrivatePostPositionMargin';
8767
8764
  code = market['base'];
8765
+ response = await this.dapiPrivatePostPositionMargin(this.extend(request, params));
8768
8766
  }
8769
- const response = await this[method](this.extend(request, params));
8770
8767
  //
8771
8768
  // {
8772
8769
  // "code": 200,
@@ -30,7 +30,7 @@ class bingx extends bingx$1 {
30
30
  'cancelOrder': true,
31
31
  'cancelOrders': true,
32
32
  'closeAllPositions': true,
33
- 'closePosition': false,
33
+ 'closePosition': true,
34
34
  'createMarketBuyOrderWithCost': true,
35
35
  'createMarketOrderWithCost': true,
36
36
  'createMarketSellOrderWithCost': true,
@@ -3379,12 +3379,44 @@ class bingx extends bingx$1 {
3379
3379
  'datetime': this.iso8601(timestamp),
3380
3380
  });
3381
3381
  }
3382
+ async closePosition(symbol, side = undefined, params = {}) {
3383
+ /**
3384
+ * @method
3385
+ * @name bingx#closePosition
3386
+ * @description closes open positions for a market
3387
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
3388
+ * @param {string} symbol Unified CCXT market symbol
3389
+ * @param {string} [side] not used by bingx
3390
+ * @param {object} [params] extra parameters specific to the bingx api endpoint
3391
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3392
+ */
3393
+ await this.loadMarkets();
3394
+ const market = this.market(symbol);
3395
+ const request = {
3396
+ 'symbol': market['id'],
3397
+ };
3398
+ const response = await this.swapV2PrivatePostTradeCloseAllPositions(this.extend(request, params));
3399
+ //
3400
+ // {
3401
+ // "code": 0,
3402
+ // "msg": "",
3403
+ // "data": {
3404
+ // "success": [
3405
+ // 1727686766700486656,
3406
+ // ],
3407
+ // "failed": null
3408
+ // }
3409
+ // }
3410
+ //
3411
+ const data = this.safeValue(response, 'data');
3412
+ return this.parseOrder(data);
3413
+ }
3382
3414
  async closeAllPositions(params = {}) {
3383
3415
  /**
3384
3416
  * @method
3385
3417
  * @name bitget#closePositions
3386
3418
  * @description closes open positions for a market
3387
- * @see https://bitgetlimited.github.io/apidoc/en/mix/#close-all-position
3419
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
3388
3420
  * @param {object} [params] extra parameters specific to the okx api endpoint
3389
3421
  * @param {string} [params.recvWindow] request valid time window value
3390
3422
  * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
@@ -1278,12 +1278,12 @@ class bitget extends bitget$1 {
1278
1278
  '30m': '30min',
1279
1279
  '1h': '1h',
1280
1280
  '4h': '4h',
1281
- '6h': '6h',
1282
- '12h': '12h',
1283
- '1d': '1day',
1284
- '3d': '3day',
1285
- '1w': '1week',
1286
- '1M': '1M',
1281
+ '6h': '6Hutc',
1282
+ '12h': '12Hutc',
1283
+ '1d': '1Dutc',
1284
+ '3d': '3Dutc',
1285
+ '1w': '1Wutc',
1286
+ '1M': '1Mutc',
1287
1287
  },
1288
1288
  'swap': {
1289
1289
  '1m': '1m',
@@ -1294,12 +1294,12 @@ class bitget extends bitget$1 {
1294
1294
  '1h': '1H',
1295
1295
  '2h': '2H',
1296
1296
  '4h': '4H',
1297
- '6h': '6H',
1298
- '12h': '12H',
1299
- '1d': '1D',
1300
- '3d': '3D',
1301
- '1w': '1W',
1302
- '1M': '1M',
1297
+ '6h': '6Hutc',
1298
+ '12h': '12Hutc',
1299
+ '1d': '1Dutc',
1300
+ '3d': '3Dutc',
1301
+ '1w': '1Wutc',
1302
+ '1M': '1Mutc',
1303
1303
  },
1304
1304
  },
1305
1305
  'fetchMarkets': [
@@ -2901,7 +2901,7 @@ class bitget extends bitget$1 {
2901
2901
  const currencyCode = this.safeCurrencyCode(this.safeString(feeStructure, 'feeCoin'));
2902
2902
  fee = {
2903
2903
  'currency': currencyCode,
2904
- 'cost': Precise["default"].stringNeg(this.safeString(feeStructure, 'totalFee')),
2904
+ 'cost': Precise["default"].stringAbs(this.safeString(feeStructure, 'totalFee')),
2905
2905
  };
2906
2906
  }
2907
2907
  return this.safeTrade({
@@ -4288,7 +4288,7 @@ class phemex extends phemex$1 {
4288
4288
  * @name phemex#setLeverage
4289
4289
  * @description set the level of leverage for a market
4290
4290
  * @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#set-leverage
4291
- * @param {float} leverage the rate of leverage
4291
+ * @param {float} leverage the rate of leverage, 100 > leverage > -100 excluding numbers between -1 to 1
4292
4292
  * @param {string} symbol unified market symbol
4293
4293
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4294
4294
  * @param {bool} [params.hedged] set to true if hedged position mode is enabled (by default long and short leverage are set to the same value)
@@ -4301,8 +4301,8 @@ class phemex extends phemex$1 {
4301
4301
  if (symbol === undefined) {
4302
4302
  throw new errors.ArgumentsRequired(this.id + ' setLeverage() requires a symbol argument');
4303
4303
  }
4304
- if ((leverage < 1) || (leverage > 100)) {
4305
- throw new errors.BadRequest(this.id + ' setLeverage() leverage should be between 1 and 100');
4304
+ if ((leverage < -100) || (leverage > 100)) {
4305
+ throw new errors.BadRequest(this.id + ' setLeverage() leverage should be between -100 and 100');
4306
4306
  }
4307
4307
  await this.loadMarkets();
4308
4308
  const isHedged = this.safeValue(params, 'hedged', false);
@@ -169,7 +169,8 @@ class bingx extends bingx$1 {
169
169
  const data = this.safeValue(message, 'data', []);
170
170
  const messageHash = this.safeString(message, 'dataType');
171
171
  const marketId = messageHash.split('@')[0];
172
- const marketType = client.url.indexOf('swap') >= 0 ? 'swap' : 'spot';
172
+ const isSwap = client.url.indexOf('swap') >= 0;
173
+ const marketType = isSwap ? 'swap' : 'spot';
173
174
  const market = this.safeMarket(marketId, undefined, undefined, marketType);
174
175
  const symbol = market['symbol'];
175
176
  let trades = undefined;
@@ -284,7 +285,8 @@ class bingx extends bingx$1 {
284
285
  const data = this.safeValue(message, 'data', []);
285
286
  const messageHash = this.safeString(message, 'dataType');
286
287
  const marketId = messageHash.split('@')[0];
287
- const marketType = client.url.indexOf('swap') >= 0 ? 'swap' : 'spot';
288
+ const isSwap = client.url.indexOf('swap') >= 0;
289
+ const marketType = isSwap ? 'swap' : 'spot';
288
290
  const market = this.safeMarket(marketId, undefined, undefined, marketType);
289
291
  const symbol = market['symbol'];
290
292
  let orderbook = this.safeValue(this.orderbooks, symbol);
@@ -376,7 +378,8 @@ class bingx extends bingx$1 {
376
378
  const messageHash = this.safeString(message, 'dataType');
377
379
  const timeframeId = messageHash.split('_')[1];
378
380
  const marketId = messageHash.split('@')[0];
379
- const marketType = client.url.indexOf('swap') >= 0 ? 'swap' : 'spot';
381
+ const isSwap = client.url.indexOf('swap') >= 0;
382
+ const marketType = isSwap ? 'swap' : 'spot';
380
383
  const market = this.safeMarket(marketId, undefined, undefined, marketType);
381
384
  const symbol = market['symbol'];
382
385
  this.ohlcvs[symbol] = this.safeValue(this.ohlcvs, symbol, {});
@@ -435,7 +435,7 @@ class bitmart extends bitmart$1 {
435
435
  const symbolKeys = Object.keys(symbols);
436
436
  for (let i = 0; i < symbolKeys.length; i++) {
437
437
  const symbol = symbolKeys[i];
438
- const symbolSpecificMessageHash = messageHash + ':' + symbol;
438
+ const symbolSpecificMessageHash = messageHash + '::' + symbol;
439
439
  client.resolve(newOrders, symbolSpecificMessageHash);
440
440
  }
441
441
  client.resolve(newOrders, messageHash);
package/js/ccxt.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
5
  import type { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode, Greeks } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
7
- declare const version = "4.1.96";
7
+ declare const version = "4.1.97";
8
8
  import ace from './src/ace.js';
9
9
  import alpaca from './src/alpaca.js';
10
10
  import ascendex from './src/ascendex.js';
package/js/ccxt.js CHANGED
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
38
38
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.1.97';
41
+ const version = '4.1.98';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
package/js/src/binance.js CHANGED
@@ -6079,7 +6079,8 @@ export default class binance extends Exchange {
6079
6079
  'amount': this.currencyToPrecision(code, amount),
6080
6080
  };
6081
6081
  request['type'] = this.safeString(params, 'type');
6082
- let method = 'sapiPostAssetTransfer';
6082
+ params = this.omit(params, 'type');
6083
+ let response = undefined;
6083
6084
  if (request['type'] === undefined) {
6084
6085
  const symbol = this.safeString(params, 'symbol');
6085
6086
  if (symbol !== undefined) {
@@ -6119,16 +6120,16 @@ export default class binance extends Exchange {
6119
6120
  throw new BadRequest(this.id + ' transfer () does not allow transfers between ' + fromAccount + ' and ' + toAccount);
6120
6121
  }
6121
6122
  else if (toSpot && fromIsolated) {
6122
- method = 'sapiPostMarginIsolatedTransfer';
6123
6123
  request['transFrom'] = 'ISOLATED_MARGIN';
6124
6124
  request['transTo'] = 'SPOT';
6125
6125
  request['symbol'] = fromId;
6126
+ response = await this.sapiPostMarginIsolatedTransfer(this.extend(request, params));
6126
6127
  }
6127
6128
  else if (fromSpot && toIsolated) {
6128
- method = 'sapiPostMarginIsolatedTransfer';
6129
6129
  request['transFrom'] = 'SPOT';
6130
6130
  request['transTo'] = 'ISOLATED_MARGIN';
6131
6131
  request['symbol'] = toId;
6132
+ response = await this.sapiPostMarginIsolatedTransfer(this.extend(request, params));
6132
6133
  }
6133
6134
  else {
6134
6135
  if (fromIsolated) {
@@ -6146,8 +6147,9 @@ export default class binance extends Exchange {
6146
6147
  request['type'] = fromId + '_' + toId;
6147
6148
  }
6148
6149
  }
6149
- params = this.omit(params, 'type');
6150
- const response = await this[method](this.extend(request, params));
6150
+ if (response === undefined) {
6151
+ response = await this.sapiPostAssetTransfer(this.extend(request, params));
6152
+ }
6151
6153
  //
6152
6154
  // {
6153
6155
  // "tranId":13526853623
@@ -6940,7 +6942,6 @@ export default class binance extends Exchange {
6940
6942
  */
6941
6943
  await this.loadMarkets();
6942
6944
  const request = {};
6943
- let method = undefined;
6944
6945
  let paginate = false;
6945
6946
  [paginate, params] = this.handleOptionAndParams(params, 'fetchFundingRateHistory', 'paginate');
6946
6947
  if (paginate) {
@@ -6957,15 +6958,6 @@ export default class binance extends Exchange {
6957
6958
  let subType = undefined;
6958
6959
  [subType, params] = this.handleSubTypeAndParams('fetchFundingRateHistory', market, params, 'linear');
6959
6960
  params = this.omit(params, 'type');
6960
- if (this.isLinear(type, subType)) {
6961
- method = 'fapiPublicGetFundingRate';
6962
- }
6963
- else if (this.isInverse(type, subType)) {
6964
- method = 'dapiPublicGetFundingRate';
6965
- }
6966
- if (method === undefined) {
6967
- throw new NotSupported(this.id + ' fetchFundingRateHistory() is not supported for ' + type + ' markets');
6968
- }
6969
6961
  if (since !== undefined) {
6970
6962
  request['startTime'] = since;
6971
6963
  }
@@ -6978,7 +6970,16 @@ export default class binance extends Exchange {
6978
6970
  if (limit !== undefined) {
6979
6971
  request['limit'] = limit;
6980
6972
  }
6981
- const response = await this[method](this.extend(request, params));
6973
+ let response = undefined;
6974
+ if (this.isLinear(type, subType)) {
6975
+ response = await this.fapiPublicGetFundingRate(this.extend(request, params));
6976
+ }
6977
+ else if (this.isInverse(type, subType)) {
6978
+ response = await this.dapiPublicGetFundingRate(this.extend(request, params));
6979
+ }
6980
+ else {
6981
+ throw new NotSupported(this.id + ' fetchFundingRateHistory() is not supported for ' + type + ' markets');
6982
+ }
6982
6983
  //
6983
6984
  // {
6984
6985
  // "symbol": "BTCUSDT",
@@ -7014,22 +7015,21 @@ export default class binance extends Exchange {
7014
7015
  */
7015
7016
  await this.loadMarkets();
7016
7017
  symbols = this.marketSymbols(symbols);
7017
- let method = undefined;
7018
7018
  const defaultType = this.safeString2(this.options, 'fetchFundingRates', 'defaultType', 'future');
7019
7019
  const type = this.safeString(params, 'type', defaultType);
7020
7020
  let subType = undefined;
7021
7021
  [subType, params] = this.handleSubTypeAndParams('fetchFundingRates', undefined, params, 'linear');
7022
7022
  const query = this.omit(params, 'type');
7023
+ let response = undefined;
7023
7024
  if (this.isLinear(type, subType)) {
7024
- method = 'fapiPublicGetPremiumIndex';
7025
+ response = await this.fapiPublicGetPremiumIndex(query);
7025
7026
  }
7026
7027
  else if (this.isInverse(type, subType)) {
7027
- method = 'dapiPublicGetPremiumIndex';
7028
+ response = await this.dapiPublicGetPremiumIndex(query);
7028
7029
  }
7029
7030
  else {
7030
7031
  throw new NotSupported(this.id + ' fetchFundingRates() supports linear and inverse contracts only');
7031
7032
  }
7032
- const response = await this[method](query);
7033
7033
  const result = [];
7034
7034
  for (let i = 0; i < response.length; i++) {
7035
7035
  const entry = response[i];
@@ -7497,22 +7497,21 @@ export default class binance extends Exchange {
7497
7497
  // it contains useful stuff like the maintenance margin and initial margin for positions
7498
7498
  const leverageBrackets = this.safeValue(this.options, 'leverageBrackets');
7499
7499
  if ((leverageBrackets === undefined) || (reload)) {
7500
- let method = undefined;
7501
7500
  const defaultType = this.safeString(this.options, 'defaultType', 'future');
7502
7501
  const type = this.safeString(params, 'type', defaultType);
7503
7502
  const query = this.omit(params, 'type');
7504
7503
  let subType = undefined;
7505
7504
  [subType, params] = this.handleSubTypeAndParams('loadLeverageBrackets', undefined, params, 'linear');
7505
+ let response = undefined;
7506
7506
  if (this.isLinear(type, subType)) {
7507
- method = 'fapiPrivateGetLeverageBracket';
7507
+ response = await this.fapiPrivateGetLeverageBracket(query);
7508
7508
  }
7509
7509
  else if (this.isInverse(type, subType)) {
7510
- method = 'dapiPrivateV2GetLeverageBracket';
7510
+ response = await this.dapiPrivateV2GetLeverageBracket(query);
7511
7511
  }
7512
7512
  else {
7513
7513
  throw new NotSupported(this.id + ' loadLeverageBrackets() supports linear and inverse contracts only');
7514
7514
  }
7515
- const response = await this[method](query);
7516
7515
  this.options['leverageBrackets'] = {};
7517
7516
  for (let i = 0; i < response.length; i++) {
7518
7517
  const entry = response[i];
@@ -7974,7 +7973,6 @@ export default class binance extends Exchange {
7974
7973
  */
7975
7974
  await this.loadMarkets();
7976
7975
  let market = undefined;
7977
- let method = undefined;
7978
7976
  const request = {
7979
7977
  'incomeType': 'FUNDING_FEE', // "TRANSFER","WELCOME_BONUS", "REALIZED_PNL","FUNDING_FEE", "COMMISSION" and "INSURANCE_CLEAR"
7980
7978
  };
@@ -7996,16 +7994,16 @@ export default class binance extends Exchange {
7996
7994
  const defaultType = this.safeString2(this.options, 'fetchFundingHistory', 'defaultType', 'future');
7997
7995
  const type = this.safeString(params, 'type', defaultType);
7998
7996
  params = this.omit(params, 'type');
7997
+ let response = undefined;
7999
7998
  if (this.isLinear(type, subType)) {
8000
- method = 'fapiPrivateGetIncome';
7999
+ response = await this.fapiPrivateGetIncome(this.extend(request, params));
8001
8000
  }
8002
8001
  else if (this.isInverse(type, subType)) {
8003
- method = 'dapiPrivateGetIncome';
8002
+ response = await this.dapiPrivateGetIncome(this.extend(request, params));
8004
8003
  }
8005
8004
  else {
8006
8005
  throw new NotSupported(this.id + ' fetchFundingHistory() supports linear and inverse contracts only');
8007
8006
  }
8008
- const response = await this[method](this.extend(request, params));
8009
8007
  return this.parseIncomes(response, market, since, limit);
8010
8008
  }
8011
8009
  async setLeverage(leverage, symbol = undefined, params = {}) {
@@ -8759,17 +8757,16 @@ export default class binance extends Exchange {
8759
8757
  'symbol': market['id'],
8760
8758
  'amount': amount,
8761
8759
  };
8762
- let method = undefined;
8760
+ let response = undefined;
8763
8761
  let code = undefined;
8764
8762
  if (market['linear']) {
8765
- method = 'fapiPrivatePostPositionMargin';
8766
8763
  code = market['quote'];
8764
+ response = await this.fapiPrivatePostPositionMargin(this.extend(request, params));
8767
8765
  }
8768
8766
  else {
8769
- method = 'dapiPrivatePostPositionMargin';
8770
8767
  code = market['base'];
8768
+ response = await this.dapiPrivatePostPositionMargin(this.extend(request, params));
8771
8769
  }
8772
- const response = await this[method](this.extend(request, params));
8773
8770
  //
8774
8771
  // {
8775
8772
  // "code": 200,
package/js/src/bingx.d.ts CHANGED
@@ -133,6 +133,7 @@ export default class bingx extends Exchange {
133
133
  parseParams(params: any): {};
134
134
  fetchMyLiquidations(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Liquidation[]>;
135
135
  parseLiquidation(liquidation: any, market?: Market): import("./base/types.js").Liquidation;
136
+ closePosition(symbol: string, side?: OrderSide, params?: {}): Promise<Order>;
136
137
  closeAllPositions(params?: {}): Promise<Position[]>;
137
138
  setPositionMode(hedged: any, symbol?: Str, params?: {}): Promise<any>;
138
139
  sign(path: any, section?: string, method?: string, params?: {}, headers?: any, body?: any): {
package/js/src/bingx.js CHANGED
@@ -33,7 +33,7 @@ export default class bingx extends Exchange {
33
33
  'cancelOrder': true,
34
34
  'cancelOrders': true,
35
35
  'closeAllPositions': true,
36
- 'closePosition': false,
36
+ 'closePosition': true,
37
37
  'createMarketBuyOrderWithCost': true,
38
38
  'createMarketOrderWithCost': true,
39
39
  'createMarketSellOrderWithCost': true,
@@ -3382,12 +3382,44 @@ export default class bingx extends Exchange {
3382
3382
  'datetime': this.iso8601(timestamp),
3383
3383
  });
3384
3384
  }
3385
+ async closePosition(symbol, side = undefined, params = {}) {
3386
+ /**
3387
+ * @method
3388
+ * @name bingx#closePosition
3389
+ * @description closes open positions for a market
3390
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
3391
+ * @param {string} symbol Unified CCXT market symbol
3392
+ * @param {string} [side] not used by bingx
3393
+ * @param {object} [params] extra parameters specific to the bingx api endpoint
3394
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3395
+ */
3396
+ await this.loadMarkets();
3397
+ const market = this.market(symbol);
3398
+ const request = {
3399
+ 'symbol': market['id'],
3400
+ };
3401
+ const response = await this.swapV2PrivatePostTradeCloseAllPositions(this.extend(request, params));
3402
+ //
3403
+ // {
3404
+ // "code": 0,
3405
+ // "msg": "",
3406
+ // "data": {
3407
+ // "success": [
3408
+ // 1727686766700486656,
3409
+ // ],
3410
+ // "failed": null
3411
+ // }
3412
+ // }
3413
+ //
3414
+ const data = this.safeValue(response, 'data');
3415
+ return this.parseOrder(data);
3416
+ }
3385
3417
  async closeAllPositions(params = {}) {
3386
3418
  /**
3387
3419
  * @method
3388
3420
  * @name bitget#closePositions
3389
3421
  * @description closes open positions for a market
3390
- * @see https://bitgetlimited.github.io/apidoc/en/mix/#close-all-position
3422
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
3391
3423
  * @param {object} [params] extra parameters specific to the okx api endpoint
3392
3424
  * @param {string} [params.recvWindow] request valid time window value
3393
3425
  * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}