ccxt 4.1.97 → 4.1.99

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 (46) hide show
  1. package/README.md +3 -3
  2. package/build.sh +1 -1
  3. package/dist/ccxt.browser.js +524 -230
  4. package/dist/ccxt.browser.min.js +2 -2
  5. package/dist/cjs/ccxt.js +1 -1
  6. package/dist/cjs/src/base/Exchange.js +29 -0
  7. package/dist/cjs/src/binance.js +113 -91
  8. package/dist/cjs/src/bingx.js +58 -9
  9. package/dist/cjs/src/bitget.js +108 -51
  10. package/dist/cjs/src/bitmart.js +71 -17
  11. package/dist/cjs/src/bitvavo.js +52 -14
  12. package/dist/cjs/src/coinex.js +58 -21
  13. package/dist/cjs/src/kraken.js +21 -16
  14. package/dist/cjs/src/phemex.js +3 -3
  15. package/dist/cjs/src/pro/binance.js +1 -1
  16. package/dist/cjs/src/pro/bingx.js +6 -3
  17. package/dist/cjs/src/pro/bitget.js +1 -1
  18. package/dist/cjs/src/pro/bitmart.js +1 -1
  19. package/dist/cjs/src/pro/bybit.js +1 -1
  20. package/js/ccxt.d.ts +1 -1
  21. package/js/ccxt.js +1 -1
  22. package/js/src/abstract/binance.d.ts +16 -0
  23. package/js/src/abstract/binancecoinm.d.ts +16 -0
  24. package/js/src/abstract/binanceus.d.ts +16 -0
  25. package/js/src/abstract/binanceusdm.d.ts +16 -0
  26. package/js/src/abstract/coinex.d.ts +14 -1
  27. package/js/src/base/Exchange.d.ts +4 -0
  28. package/js/src/base/Exchange.js +29 -0
  29. package/js/src/binance.js +113 -91
  30. package/js/src/bingx.d.ts +1 -0
  31. package/js/src/bingx.js +58 -9
  32. package/js/src/bitget.js +108 -51
  33. package/js/src/bitmart.js +71 -17
  34. package/js/src/bitvavo.js +52 -14
  35. package/js/src/coinex.js +58 -21
  36. package/js/src/kraken.js +21 -16
  37. package/js/src/phemex.js +3 -3
  38. package/js/src/pro/binance.js +1 -1
  39. package/js/src/pro/bingx.js +6 -3
  40. package/js/src/pro/bitget.js +1 -1
  41. package/js/src/pro/bitmart.js +1 -1
  42. package/js/src/pro/bybit.js +1 -1
  43. package/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.d.ts +1 -1
  44. package/package.json +13 -13
  45. package/skip-tests.json +119 -71
  46. package/run-tests-ws.js +0 -290
package/js/src/binance.js CHANGED
@@ -343,6 +343,16 @@ export default class binance extends Exchange {
343
343
  'lending/union/interestHistory': 0.1,
344
344
  'lending/project/list': 0.1,
345
345
  'lending/project/position/list': 0.1,
346
+ // eth-staking
347
+ 'eth-staking/eth/history/stakingHistory': 15,
348
+ 'eth-staking/eth/history/redemptionHistory': 15,
349
+ 'eth-staking/eth/history/rewardsHistory': 15,
350
+ 'eth-staking/eth/quota': 15,
351
+ 'eth-staking/eth/history/rateHistory': 15,
352
+ 'eth-staking/account': 15,
353
+ 'eth-staking/wbeth/history/wrapHistory': 15,
354
+ 'eth-staking/wbeth/history/unwrapHistory': 15,
355
+ 'eth-staking/eth/history/wbethRewardsHistory': 15,
346
356
  // mining endpoints
347
357
  'mining/pub/algoList': 0.1,
348
358
  'mining/pub/coinList': 0.1,
@@ -544,6 +554,13 @@ export default class binance extends Exchange {
544
554
  'staking/purchase': 0.1,
545
555
  'staking/redeem': 0.1,
546
556
  'staking/setAutoStaking': 0.1,
557
+ // eth-staking
558
+ 'eth-staking/eth/stake': 15,
559
+ 'eth-staking/eth/redeem': 15,
560
+ 'eth-staking/wbeth/wrap': 15,
561
+ // mining endpoints
562
+ 'mining/hash-transfer/config': 0.5,
563
+ 'mining/hash-transfer/config/cancel': 0.5,
547
564
  'portfolio/repay': 20.001,
548
565
  'loan/vip/renew': 40.002,
549
566
  'loan/vip/borrow': 40.002,
@@ -597,11 +614,13 @@ export default class binance extends Exchange {
597
614
  },
598
615
  'sapiV2': {
599
616
  'get': {
617
+ 'eth-staking/account': 15,
600
618
  'sub-account/futures/account': 0.1,
601
619
  'sub-account/futures/accountSummary': 1,
602
620
  'sub-account/futures/positionRisk': 0.1,
603
621
  },
604
622
  'post': {
623
+ 'eth-staking/eth/stake': 15,
605
624
  'sub-account/subAccountApi/ipRestriction': 20.001, // Weight(UID): 3000 => cost = 0.006667 * 3000 = 20.001
606
625
  },
607
626
  },
@@ -3623,22 +3642,6 @@ export default class binance extends Exchange {
3623
3642
  // 'endTime': 789, // Timestamp in ms to get aggregate trades until INCLUSIVE.
3624
3643
  // 'limit': 500, // default = 500, maximum = 1000
3625
3644
  };
3626
- let method = this.safeString(this.options, 'fetchTradesMethod');
3627
- method = this.safeString2(params, 'fetchTradesMethod', 'method', method);
3628
- if (method === undefined) {
3629
- if (market['option']) {
3630
- method = 'eapiPublicGetTrades';
3631
- }
3632
- else if (market['linear']) {
3633
- method = 'fapiPublicGetAggTrades';
3634
- }
3635
- else if (market['inverse']) {
3636
- method = 'dapiPublicGetAggTrades';
3637
- }
3638
- else {
3639
- method = 'publicGetAggTrades';
3640
- }
3641
- }
3642
3645
  if (!market['option']) {
3643
3646
  if (since !== undefined) {
3644
3647
  request['startTime'] = since;
@@ -3655,7 +3658,22 @@ export default class binance extends Exchange {
3655
3658
  const isFutureOrSwap = (market['swap'] || market['future']);
3656
3659
  request['limit'] = isFutureOrSwap ? Math.min(limit, 1000) : limit; // default = 500, maximum = 1000
3657
3660
  }
3661
+ let method = this.safeString(this.options, 'fetchTradesMethod');
3662
+ method = this.safeString2(params, 'fetchTradesMethod', 'method', method);
3658
3663
  params = this.omit(params, ['until', 'fetchTradesMethod']);
3664
+ let response = undefined;
3665
+ if (market['option'] || method === 'eapiPublicGetTrades') {
3666
+ response = await this.eapiPublicGetTrades(this.extend(request, params));
3667
+ }
3668
+ else if (market['linear'] || method === 'fapiPublicGetAggTrades') {
3669
+ response = await this.fapiPublicGetAggTrades(this.extend(request, params));
3670
+ }
3671
+ else if (market['inverse'] || method === 'dapiPublicGetAggTrades') {
3672
+ response = await this.dapiPublicGetAggTrades(this.extend(request, params));
3673
+ }
3674
+ else {
3675
+ response = await this.publicGetAggTrades(this.extend(request, params));
3676
+ }
3659
3677
  //
3660
3678
  // Caveats:
3661
3679
  // - default limit (500) applies only if no other parameters set, trades up
@@ -3665,7 +3683,6 @@ export default class binance extends Exchange {
3665
3683
  // - "tradeId" accepted and returned by this method is "aggregate" trade id
3666
3684
  // which is different from actual trade id
3667
3685
  // - setting both fromId and time window results in error
3668
- const response = await this[method](this.extend(request, params));
3669
3686
  //
3670
3687
  // aggregate trades
3671
3688
  //
@@ -4264,6 +4281,15 @@ export default class binance extends Exchange {
4264
4281
  }
4265
4282
  const stopPriceString = this.safeString(order, 'stopPrice');
4266
4283
  const stopPrice = this.parseNumber(this.omitZero(stopPriceString));
4284
+ const feeCost = this.safeNumber(order, 'fee');
4285
+ let fee = undefined;
4286
+ if (feeCost !== undefined) {
4287
+ fee = {
4288
+ 'currency': this.safeString(order, 'quoteAsset'),
4289
+ 'cost': feeCost,
4290
+ 'rate': undefined,
4291
+ };
4292
+ }
4267
4293
  return this.safeOrder({
4268
4294
  'info': order,
4269
4295
  'id': id,
@@ -4286,11 +4312,7 @@ export default class binance extends Exchange {
4286
4312
  'filled': filled,
4287
4313
  'remaining': undefined,
4288
4314
  'status': status,
4289
- 'fee': {
4290
- 'currency': this.safeString(order, 'quoteAsset'),
4291
- 'cost': this.safeNumber(order, 'fee'),
4292
- 'rate': undefined,
4293
- },
4315
+ 'fee': fee,
4294
4316
  'trades': fills,
4295
4317
  }, market);
4296
4318
  }
@@ -6079,7 +6101,8 @@ export default class binance extends Exchange {
6079
6101
  'amount': this.currencyToPrecision(code, amount),
6080
6102
  };
6081
6103
  request['type'] = this.safeString(params, 'type');
6082
- let method = 'sapiPostAssetTransfer';
6104
+ params = this.omit(params, 'type');
6105
+ let response = undefined;
6083
6106
  if (request['type'] === undefined) {
6084
6107
  const symbol = this.safeString(params, 'symbol');
6085
6108
  if (symbol !== undefined) {
@@ -6119,16 +6142,16 @@ export default class binance extends Exchange {
6119
6142
  throw new BadRequest(this.id + ' transfer () does not allow transfers between ' + fromAccount + ' and ' + toAccount);
6120
6143
  }
6121
6144
  else if (toSpot && fromIsolated) {
6122
- method = 'sapiPostMarginIsolatedTransfer';
6123
6145
  request['transFrom'] = 'ISOLATED_MARGIN';
6124
6146
  request['transTo'] = 'SPOT';
6125
6147
  request['symbol'] = fromId;
6148
+ response = await this.sapiPostMarginIsolatedTransfer(this.extend(request, params));
6126
6149
  }
6127
6150
  else if (fromSpot && toIsolated) {
6128
- method = 'sapiPostMarginIsolatedTransfer';
6129
6151
  request['transFrom'] = 'SPOT';
6130
6152
  request['transTo'] = 'ISOLATED_MARGIN';
6131
6153
  request['symbol'] = toId;
6154
+ response = await this.sapiPostMarginIsolatedTransfer(this.extend(request, params));
6132
6155
  }
6133
6156
  else {
6134
6157
  if (fromIsolated) {
@@ -6146,8 +6169,9 @@ export default class binance extends Exchange {
6146
6169
  request['type'] = fromId + '_' + toId;
6147
6170
  }
6148
6171
  }
6149
- params = this.omit(params, 'type');
6150
- const response = await this[method](this.extend(request, params));
6172
+ if (response === undefined) {
6173
+ response = await this.sapiPostAssetTransfer(this.extend(request, params));
6174
+ }
6151
6175
  //
6152
6176
  // {
6153
6177
  // "tranId":13526853623
@@ -6940,7 +6964,6 @@ export default class binance extends Exchange {
6940
6964
  */
6941
6965
  await this.loadMarkets();
6942
6966
  const request = {};
6943
- let method = undefined;
6944
6967
  let paginate = false;
6945
6968
  [paginate, params] = this.handleOptionAndParams(params, 'fetchFundingRateHistory', 'paginate');
6946
6969
  if (paginate) {
@@ -6957,15 +6980,6 @@ export default class binance extends Exchange {
6957
6980
  let subType = undefined;
6958
6981
  [subType, params] = this.handleSubTypeAndParams('fetchFundingRateHistory', market, params, 'linear');
6959
6982
  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
6983
  if (since !== undefined) {
6970
6984
  request['startTime'] = since;
6971
6985
  }
@@ -6978,7 +6992,16 @@ export default class binance extends Exchange {
6978
6992
  if (limit !== undefined) {
6979
6993
  request['limit'] = limit;
6980
6994
  }
6981
- const response = await this[method](this.extend(request, params));
6995
+ let response = undefined;
6996
+ if (this.isLinear(type, subType)) {
6997
+ response = await this.fapiPublicGetFundingRate(this.extend(request, params));
6998
+ }
6999
+ else if (this.isInverse(type, subType)) {
7000
+ response = await this.dapiPublicGetFundingRate(this.extend(request, params));
7001
+ }
7002
+ else {
7003
+ throw new NotSupported(this.id + ' fetchFundingRateHistory() is not supported for ' + type + ' markets');
7004
+ }
6982
7005
  //
6983
7006
  // {
6984
7007
  // "symbol": "BTCUSDT",
@@ -7014,22 +7037,21 @@ export default class binance extends Exchange {
7014
7037
  */
7015
7038
  await this.loadMarkets();
7016
7039
  symbols = this.marketSymbols(symbols);
7017
- let method = undefined;
7018
7040
  const defaultType = this.safeString2(this.options, 'fetchFundingRates', 'defaultType', 'future');
7019
7041
  const type = this.safeString(params, 'type', defaultType);
7020
7042
  let subType = undefined;
7021
7043
  [subType, params] = this.handleSubTypeAndParams('fetchFundingRates', undefined, params, 'linear');
7022
7044
  const query = this.omit(params, 'type');
7045
+ let response = undefined;
7023
7046
  if (this.isLinear(type, subType)) {
7024
- method = 'fapiPublicGetPremiumIndex';
7047
+ response = await this.fapiPublicGetPremiumIndex(query);
7025
7048
  }
7026
7049
  else if (this.isInverse(type, subType)) {
7027
- method = 'dapiPublicGetPremiumIndex';
7050
+ response = await this.dapiPublicGetPremiumIndex(query);
7028
7051
  }
7029
7052
  else {
7030
7053
  throw new NotSupported(this.id + ' fetchFundingRates() supports linear and inverse contracts only');
7031
7054
  }
7032
- const response = await this[method](query);
7033
7055
  const result = [];
7034
7056
  for (let i = 0; i < response.length; i++) {
7035
7057
  const entry = response[i];
@@ -7497,22 +7519,21 @@ export default class binance extends Exchange {
7497
7519
  // it contains useful stuff like the maintenance margin and initial margin for positions
7498
7520
  const leverageBrackets = this.safeValue(this.options, 'leverageBrackets');
7499
7521
  if ((leverageBrackets === undefined) || (reload)) {
7500
- let method = undefined;
7501
7522
  const defaultType = this.safeString(this.options, 'defaultType', 'future');
7502
7523
  const type = this.safeString(params, 'type', defaultType);
7503
7524
  const query = this.omit(params, 'type');
7504
7525
  let subType = undefined;
7505
7526
  [subType, params] = this.handleSubTypeAndParams('loadLeverageBrackets', undefined, params, 'linear');
7527
+ let response = undefined;
7506
7528
  if (this.isLinear(type, subType)) {
7507
- method = 'fapiPrivateGetLeverageBracket';
7529
+ response = await this.fapiPrivateGetLeverageBracket(query);
7508
7530
  }
7509
7531
  else if (this.isInverse(type, subType)) {
7510
- method = 'dapiPrivateV2GetLeverageBracket';
7532
+ response = await this.dapiPrivateV2GetLeverageBracket(query);
7511
7533
  }
7512
7534
  else {
7513
7535
  throw new NotSupported(this.id + ' loadLeverageBrackets() supports linear and inverse contracts only');
7514
7536
  }
7515
- const response = await this[method](query);
7516
7537
  this.options['leverageBrackets'] = {};
7517
7538
  for (let i = 0; i < response.length; i++) {
7518
7539
  const entry = response[i];
@@ -7840,23 +7861,22 @@ export default class binance extends Exchange {
7840
7861
  }
7841
7862
  await this.loadMarkets();
7842
7863
  await this.loadLeverageBrackets(false, params);
7843
- let method = undefined;
7844
7864
  const defaultType = this.safeString(this.options, 'defaultType', 'future');
7845
7865
  const type = this.safeString(params, 'type', defaultType);
7846
7866
  let query = this.omit(params, 'type');
7847
7867
  let subType = undefined;
7848
7868
  [subType, query] = this.handleSubTypeAndParams('fetchAccountPositions', undefined, params, 'linear');
7869
+ let response = undefined;
7849
7870
  if (this.isLinear(type, subType)) {
7850
- method = 'fapiPrivateV2GetAccount';
7871
+ response = await this.fapiPrivateV2GetAccount(query);
7851
7872
  }
7852
7873
  else if (this.isInverse(type, subType)) {
7853
- method = 'dapiPrivateGetAccount';
7874
+ response = await this.dapiPrivateGetAccount(query);
7854
7875
  }
7855
7876
  else {
7856
7877
  throw new NotSupported(this.id + ' fetchPositions() supports linear and inverse contracts only');
7857
7878
  }
7858
- const account = await this[method](query);
7859
- const result = this.parseAccountPositions(account);
7879
+ const result = this.parseAccountPositions(response);
7860
7880
  symbols = this.marketSymbols(symbols);
7861
7881
  return this.filterByArrayPositions(result, 'symbol', symbols, false);
7862
7882
  }
@@ -7880,15 +7900,15 @@ export default class binance extends Exchange {
7880
7900
  await this.loadMarkets();
7881
7901
  await this.loadLeverageBrackets(false, params);
7882
7902
  const request = {};
7883
- let method = undefined;
7884
7903
  let defaultType = 'future';
7885
7904
  defaultType = this.safeString(this.options, 'defaultType', defaultType);
7886
7905
  const type = this.safeString(params, 'type', defaultType);
7887
7906
  let subType = undefined;
7888
7907
  [subType, params] = this.handleSubTypeAndParams('fetchPositionsRisk', undefined, params, 'linear');
7889
7908
  params = this.omit(params, 'type');
7909
+ let response = undefined;
7890
7910
  if (this.isLinear(type, subType)) {
7891
- method = 'fapiPrivateV2GetPositionRisk';
7911
+ response = await this.fapiPrivateV2GetPositionRisk(this.extend(request, params));
7892
7912
  // ### Response examples ###
7893
7913
  //
7894
7914
  // For One-way position mode:
@@ -7945,12 +7965,11 @@ export default class binance extends Exchange {
7945
7965
  // ]
7946
7966
  }
7947
7967
  else if (this.isInverse(type, subType)) {
7948
- method = 'dapiPrivateGetPositionRisk';
7968
+ response = await this.dapiPrivateGetPositionRisk(this.extend(request, params));
7949
7969
  }
7950
7970
  else {
7951
7971
  throw new NotSupported(this.id + ' fetchPositionsRisk() supports linear and inverse contracts only');
7952
7972
  }
7953
- const response = await this[method](this.extend(request, params));
7954
7973
  const result = [];
7955
7974
  for (let i = 0; i < response.length; i++) {
7956
7975
  const parsed = this.parsePositionRisk(response[i]);
@@ -7974,7 +7993,6 @@ export default class binance extends Exchange {
7974
7993
  */
7975
7994
  await this.loadMarkets();
7976
7995
  let market = undefined;
7977
- let method = undefined;
7978
7996
  const request = {
7979
7997
  'incomeType': 'FUNDING_FEE', // "TRANSFER","WELCOME_BONUS", "REALIZED_PNL","FUNDING_FEE", "COMMISSION" and "INSURANCE_CLEAR"
7980
7998
  };
@@ -7996,16 +8014,16 @@ export default class binance extends Exchange {
7996
8014
  const defaultType = this.safeString2(this.options, 'fetchFundingHistory', 'defaultType', 'future');
7997
8015
  const type = this.safeString(params, 'type', defaultType);
7998
8016
  params = this.omit(params, 'type');
8017
+ let response = undefined;
7999
8018
  if (this.isLinear(type, subType)) {
8000
- method = 'fapiPrivateGetIncome';
8019
+ response = await this.fapiPrivateGetIncome(this.extend(request, params));
8001
8020
  }
8002
8021
  else if (this.isInverse(type, subType)) {
8003
- method = 'dapiPrivateGetIncome';
8022
+ response = await this.dapiPrivateGetIncome(this.extend(request, params));
8004
8023
  }
8005
8024
  else {
8006
8025
  throw new NotSupported(this.id + ' fetchFundingHistory() supports linear and inverse contracts only');
8007
8026
  }
8008
- const response = await this[method](this.extend(request, params));
8009
8027
  return this.parseIncomes(response, market, since, limit);
8010
8028
  }
8011
8029
  async setLeverage(leverage, symbol = undefined, params = {}) {
@@ -8129,6 +8147,8 @@ export default class binance extends Exchange {
8129
8147
  const defaultType = this.safeString(this.options, 'defaultType', 'future');
8130
8148
  const type = this.safeString(params, 'type', defaultType);
8131
8149
  params = this.omit(params, ['type']);
8150
+ let subType = undefined;
8151
+ [subType, params] = this.handleSubTypeAndParams('setPositionMode', undefined, params);
8132
8152
  let dualSidePosition = undefined;
8133
8153
  if (hedged) {
8134
8154
  dualSidePosition = 'true';
@@ -8139,13 +8159,13 @@ export default class binance extends Exchange {
8139
8159
  const request = {
8140
8160
  'dualSidePosition': dualSidePosition,
8141
8161
  };
8142
- let method = undefined;
8143
- if (this.isInverse(type)) {
8144
- method = 'dapiPrivatePostPositionSideDual';
8162
+ let response = undefined;
8163
+ if (this.isInverse(type, subType)) {
8164
+ response = await this.dapiPrivatePostPositionSideDual(this.extend(request, params));
8145
8165
  }
8146
8166
  else {
8147
8167
  // default to future
8148
- method = 'fapiPrivatePostPositionSideDual';
8168
+ response = await this.fapiPrivatePostPositionSideDual(this.extend(request, params));
8149
8169
  }
8150
8170
  //
8151
8171
  // {
@@ -8153,7 +8173,7 @@ export default class binance extends Exchange {
8153
8173
  // "msg": "success"
8154
8174
  // }
8155
8175
  //
8156
- return await this[method](this.extend(request, params));
8176
+ return response;
8157
8177
  }
8158
8178
  async fetchSettlementHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
8159
8179
  /**
@@ -8365,24 +8385,9 @@ export default class binance extends Exchange {
8365
8385
  if (code !== undefined) {
8366
8386
  currency = this.currency(code);
8367
8387
  }
8368
- let method = undefined;
8369
8388
  const request = {};
8370
8389
  [type, params] = this.handleMarketTypeAndParams('fetchLedger', undefined, params);
8371
8390
  [subType, params] = this.handleSubTypeAndParams('fetchLedger', undefined, params);
8372
- if (type === 'option') {
8373
- this.checkRequiredArgument('fetchLedger', code, 'code');
8374
- request['currency'] = currency['id'];
8375
- method = 'eapiPrivateGetBill';
8376
- }
8377
- else if (this.isLinear(type, subType)) {
8378
- method = 'fapiPrivateGetIncome';
8379
- }
8380
- else if (this.isInverse(type, subType)) {
8381
- method = 'dapiPrivateGetIncome';
8382
- }
8383
- else {
8384
- throw new NotSupported(this.id + ' fetchLedger() supports contract wallets only');
8385
- }
8386
8391
  if (since !== undefined) {
8387
8392
  request['startTime'] = since;
8388
8393
  }
@@ -8394,7 +8399,21 @@ export default class binance extends Exchange {
8394
8399
  params = this.omit(params, 'until');
8395
8400
  request['endTime'] = until;
8396
8401
  }
8397
- const response = await this[method](this.extend(request, params));
8402
+ let response = undefined;
8403
+ if (type === 'option') {
8404
+ this.checkRequiredArgument('fetchLedger', code, 'code');
8405
+ request['currency'] = currency['id'];
8406
+ response = await this.eapiPrivateGetBill(this.extend(request, params));
8407
+ }
8408
+ else if (this.isLinear(type, subType)) {
8409
+ response = await this.fapiPrivateGetIncome(this.extend(request, params));
8410
+ }
8411
+ else if (this.isInverse(type, subType)) {
8412
+ response = await this.dapiPrivateGetIncome(this.extend(request, params));
8413
+ }
8414
+ else {
8415
+ throw new NotSupported(this.id + ' fetchLedger() supports contract wallets only');
8416
+ }
8398
8417
  //
8399
8418
  // options (eapi)
8400
8419
  //
@@ -8759,17 +8778,16 @@ export default class binance extends Exchange {
8759
8778
  'symbol': market['id'],
8760
8779
  'amount': amount,
8761
8780
  };
8762
- let method = undefined;
8781
+ let response = undefined;
8763
8782
  let code = undefined;
8764
8783
  if (market['linear']) {
8765
- method = 'fapiPrivatePostPositionMargin';
8766
8784
  code = market['quote'];
8785
+ response = await this.fapiPrivatePostPositionMargin(this.extend(request, params));
8767
8786
  }
8768
8787
  else {
8769
- method = 'dapiPrivatePostPositionMargin';
8770
8788
  code = market['base'];
8789
+ response = await this.dapiPrivatePostPositionMargin(this.extend(request, params));
8771
8790
  }
8772
- const response = await this[method](this.extend(request, params));
8773
8791
  //
8774
8792
  // {
8775
8793
  // "code": 200,
@@ -9269,11 +9287,13 @@ export default class binance extends Exchange {
9269
9287
  const duration = this.parseTimeframe(timeframe);
9270
9288
  request['endTime'] = this.sum(since, duration * limit * 1000);
9271
9289
  }
9272
- let method = 'fapiDataGetOpenInterestHist';
9290
+ let response = undefined;
9273
9291
  if (market['inverse']) {
9274
- method = 'dapiDataGetOpenInterestHist';
9292
+ response = await this.dapiDataGetOpenInterestHist(this.extend(request, params));
9293
+ }
9294
+ else {
9295
+ response = await this.fapiDataGetOpenInterestHist(this.extend(request, params));
9275
9296
  }
9276
- const response = await this[method](this.extend(request, params));
9277
9297
  //
9278
9298
  // [
9279
9299
  // {
@@ -9309,14 +9329,16 @@ export default class binance extends Exchange {
9309
9329
  else {
9310
9330
  request['symbol'] = market['id'];
9311
9331
  }
9312
- let method = 'fapiPublicGetOpenInterest';
9332
+ let response = undefined;
9313
9333
  if (market['option']) {
9314
- method = 'eapiPublicGetOpenInterest';
9334
+ response = await this.eapiPublicGetOpenInterest(this.extend(request, params));
9315
9335
  }
9316
9336
  else if (market['inverse']) {
9317
- method = 'dapiPublicGetOpenInterest';
9337
+ response = await this.dapiPublicGetOpenInterest(this.extend(request, params));
9338
+ }
9339
+ else {
9340
+ response = await this.fapiPublicGetOpenInterest(this.extend(request, params));
9318
9341
  }
9319
- const response = await this[method](this.extend(request, params));
9320
9342
  //
9321
9343
  // futures (fapi)
9322
9344
  //
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,
@@ -1700,15 +1700,20 @@ export default class bingx extends Exchange {
1700
1700
  else if (timeInForce === 'FOK') {
1701
1701
  request['timeInForce'] = 'FOK';
1702
1702
  }
1703
- if ((type === 'LIMIT') || (type === 'TRIGGER_LIMIT') || (type === 'STOP') || (type === 'TAKE_PROFIT')) {
1704
- request['price'] = this.parseToNumeric(this.priceToPrecision(symbol, price));
1705
- }
1706
- const triggerPrice = this.safeNumber2(params, 'stopPrice', 'triggerPrice');
1707
- const stopLossPrice = this.safeNumber(params, 'stopLossPrice');
1708
- const takeProfitPrice = this.safeNumber(params, 'takeProfitPrice');
1703
+ const triggerPrice = this.safeString2(params, 'stopPrice', 'triggerPrice');
1704
+ const stopLossPrice = this.safeString(params, 'stopLossPrice');
1705
+ const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
1706
+ const trailingAmount = this.safeString(params, 'trailingAmount');
1707
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'priceRate');
1709
1708
  const isTriggerOrder = triggerPrice !== undefined;
1710
1709
  const isStopLossPriceOrder = stopLossPrice !== undefined;
1711
1710
  const isTakeProfitPriceOrder = takeProfitPrice !== undefined;
1711
+ const isTrailingAmountOrder = trailingAmount !== undefined;
1712
+ const isTrailingPercentOrder = trailingPercent !== undefined;
1713
+ const isTrailing = isTrailingAmountOrder || isTrailingPercentOrder;
1714
+ if (((type === 'LIMIT') || (type === 'TRIGGER_LIMIT') || (type === 'STOP') || (type === 'TAKE_PROFIT')) && !isTrailing) {
1715
+ request['price'] = this.parseToNumeric(this.priceToPrecision(symbol, price));
1716
+ }
1712
1717
  let reduceOnly = this.safeValue(params, 'reduceOnly', false);
1713
1718
  if (isTriggerOrder) {
1714
1719
  request['stopPrice'] = this.parseToNumeric(this.priceToPrecision(symbol, triggerPrice));
@@ -1741,6 +1746,16 @@ export default class bingx extends Exchange {
1741
1746
  }
1742
1747
  }
1743
1748
  }
1749
+ else if (isTrailing) {
1750
+ request['type'] = 'TRAILING_STOP_MARKET';
1751
+ if (isTrailingAmountOrder) {
1752
+ request['price'] = this.parseToNumeric(trailingAmount);
1753
+ }
1754
+ else if (isTrailingPercentOrder) {
1755
+ const requestTrailingPercent = Precise.stringDiv(trailingPercent, '100');
1756
+ request['priceRate'] = this.parseToNumeric(requestTrailingPercent);
1757
+ }
1758
+ }
1744
1759
  let positionSide = undefined;
1745
1760
  if (reduceOnly) {
1746
1761
  positionSide = (side === 'buy') ? 'SHORT' : 'LONG';
@@ -1750,7 +1765,7 @@ export default class bingx extends Exchange {
1750
1765
  }
1751
1766
  request['positionSide'] = positionSide;
1752
1767
  request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
1753
- params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice']);
1768
+ params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'trailingAmount', 'trailingPercent']);
1754
1769
  }
1755
1770
  return this.extend(request, params);
1756
1771
  }
@@ -1773,6 +1788,8 @@ export default class bingx extends Exchange {
1773
1788
  * @param {float} [params.stopLossPrice] *swap only* stop loss trigger price
1774
1789
  * @param {float} [params.takeProfitPrice] *swap only* take profit trigger price
1775
1790
  * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount
1791
+ * @param {float} [params.trailingAmount] *swap only* the quote amount to trail away from the current market price
1792
+ * @param {float} [params.trailingPercent] *swap only* the percent to trail away from the current market price
1776
1793
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1777
1794
  */
1778
1795
  await this.loadMarkets();
@@ -3382,12 +3399,44 @@ export default class bingx extends Exchange {
3382
3399
  'datetime': this.iso8601(timestamp),
3383
3400
  });
3384
3401
  }
3402
+ async closePosition(symbol, side = undefined, params = {}) {
3403
+ /**
3404
+ * @method
3405
+ * @name bingx#closePosition
3406
+ * @description closes open positions for a market
3407
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
3408
+ * @param {string} symbol Unified CCXT market symbol
3409
+ * @param {string} [side] not used by bingx
3410
+ * @param {object} [params] extra parameters specific to the bingx api endpoint
3411
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3412
+ */
3413
+ await this.loadMarkets();
3414
+ const market = this.market(symbol);
3415
+ const request = {
3416
+ 'symbol': market['id'],
3417
+ };
3418
+ const response = await this.swapV2PrivatePostTradeCloseAllPositions(this.extend(request, params));
3419
+ //
3420
+ // {
3421
+ // "code": 0,
3422
+ // "msg": "",
3423
+ // "data": {
3424
+ // "success": [
3425
+ // 1727686766700486656,
3426
+ // ],
3427
+ // "failed": null
3428
+ // }
3429
+ // }
3430
+ //
3431
+ const data = this.safeValue(response, 'data');
3432
+ return this.parseOrder(data);
3433
+ }
3385
3434
  async closeAllPositions(params = {}) {
3386
3435
  /**
3387
3436
  * @method
3388
3437
  * @name bitget#closePositions
3389
3438
  * @description closes open positions for a market
3390
- * @see https://bitgetlimited.github.io/apidoc/en/mix/#close-all-position
3439
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
3391
3440
  * @param {object} [params] extra parameters specific to the okx api endpoint
3392
3441
  * @param {string} [params.recvWindow] request valid time window value
3393
3442
  * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}