ccxt 4.1.98 → 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.
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.98';
171
+ const version = '4.1.99';
172
172
  Exchange["default"].ccxtVersion = version;
173
173
  const exchanges = {
174
174
  'ace': ace,
@@ -373,7 +373,9 @@ class Exchange {
373
373
  'createOrderWs': undefined,
374
374
  'editOrderWs': undefined,
375
375
  'fetchOpenOrdersWs': undefined,
376
+ 'fetchClosedOrdersWs': undefined,
376
377
  'fetchOrderWs': undefined,
378
+ 'fetchOrdersWs': undefined,
377
379
  'cancelOrderWs': undefined,
378
380
  'cancelOrdersWs': undefined,
379
381
  'cancelAllOrdersWs': undefined,
@@ -2287,6 +2289,11 @@ class Exchange {
2287
2289
  if ('rate' in tradeFee) {
2288
2290
  tradeFee['rate'] = this.safeNumber(tradeFee, 'rate');
2289
2291
  }
2292
+ const entryFees = this.safeValue(entry, 'fees', []);
2293
+ for (let j = 0; j < entryFees.length; j++) {
2294
+ entryFees[j]['cost'] = this.safeNumber(entryFees[j], 'cost');
2295
+ }
2296
+ entry['fees'] = entryFees;
2290
2297
  entry['fee'] = tradeFee;
2291
2298
  }
2292
2299
  let timeInForce = this.safeString(order, 'timeInForce');
@@ -3760,6 +3767,9 @@ class Exchange {
3760
3767
  async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3761
3768
  throw new errors.NotSupported(this.id + ' fetchOrders() is not supported yet');
3762
3769
  }
3770
+ async fetchOrdersWs(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3771
+ throw new errors.NotSupported(this.id + ' fetchOrdersWs() is not supported yet');
3772
+ }
3763
3773
  async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
3764
3774
  throw new errors.NotSupported(this.id + ' fetchOrderTrades() is not supported yet');
3765
3775
  }
@@ -3767,14 +3777,33 @@ class Exchange {
3767
3777
  throw new errors.NotSupported(this.id + ' watchOrders() is not supported yet');
3768
3778
  }
3769
3779
  async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3780
+ if (this.has['fetchOrders']) {
3781
+ const orders = await this.fetchOrders(symbol, since, limit, params);
3782
+ return this.filterBy(orders, 'status', 'open');
3783
+ }
3770
3784
  throw new errors.NotSupported(this.id + ' fetchOpenOrders() is not supported yet');
3771
3785
  }
3772
3786
  async fetchOpenOrdersWs(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3787
+ if (this.has['fetchOrdersWs']) {
3788
+ const orders = await this.fetchOrdersWs(symbol, since, limit, params);
3789
+ return this.filterBy(orders, 'status', 'open');
3790
+ }
3773
3791
  throw new errors.NotSupported(this.id + ' fetchOpenOrdersWs() is not supported yet');
3774
3792
  }
3775
3793
  async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3794
+ if (this.has['fetchOrders']) {
3795
+ const orders = await this.fetchOrders(symbol, since, limit, params);
3796
+ return this.filterBy(orders, 'status', 'closed');
3797
+ }
3776
3798
  throw new errors.NotSupported(this.id + ' fetchClosedOrders() is not supported yet');
3777
3799
  }
3800
+ async fetchClosedOrdersWs(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3801
+ if (this.has['fetchOrdersWs']) {
3802
+ const orders = await this.fetchOrdersWs(symbol, since, limit, params);
3803
+ return this.filterBy(orders, 'status', 'closed');
3804
+ }
3805
+ throw new errors.NotSupported(this.id + ' fetchClosedOrdersWs() is not supported yet');
3806
+ }
3778
3807
  async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3779
3808
  throw new errors.NotSupported(this.id + ' fetchMyTrades() is not supported yet');
3780
3809
  }
@@ -340,6 +340,16 @@ class binance extends binance$1 {
340
340
  'lending/union/interestHistory': 0.1,
341
341
  'lending/project/list': 0.1,
342
342
  'lending/project/position/list': 0.1,
343
+ // eth-staking
344
+ 'eth-staking/eth/history/stakingHistory': 15,
345
+ 'eth-staking/eth/history/redemptionHistory': 15,
346
+ 'eth-staking/eth/history/rewardsHistory': 15,
347
+ 'eth-staking/eth/quota': 15,
348
+ 'eth-staking/eth/history/rateHistory': 15,
349
+ 'eth-staking/account': 15,
350
+ 'eth-staking/wbeth/history/wrapHistory': 15,
351
+ 'eth-staking/wbeth/history/unwrapHistory': 15,
352
+ 'eth-staking/eth/history/wbethRewardsHistory': 15,
343
353
  // mining endpoints
344
354
  'mining/pub/algoList': 0.1,
345
355
  'mining/pub/coinList': 0.1,
@@ -541,6 +551,13 @@ class binance extends binance$1 {
541
551
  'staking/purchase': 0.1,
542
552
  'staking/redeem': 0.1,
543
553
  'staking/setAutoStaking': 0.1,
554
+ // eth-staking
555
+ 'eth-staking/eth/stake': 15,
556
+ 'eth-staking/eth/redeem': 15,
557
+ 'eth-staking/wbeth/wrap': 15,
558
+ // mining endpoints
559
+ 'mining/hash-transfer/config': 0.5,
560
+ 'mining/hash-transfer/config/cancel': 0.5,
544
561
  'portfolio/repay': 20.001,
545
562
  'loan/vip/renew': 40.002,
546
563
  'loan/vip/borrow': 40.002,
@@ -594,11 +611,13 @@ class binance extends binance$1 {
594
611
  },
595
612
  'sapiV2': {
596
613
  'get': {
614
+ 'eth-staking/account': 15,
597
615
  'sub-account/futures/account': 0.1,
598
616
  'sub-account/futures/accountSummary': 1,
599
617
  'sub-account/futures/positionRisk': 0.1,
600
618
  },
601
619
  'post': {
620
+ 'eth-staking/eth/stake': 15,
602
621
  'sub-account/subAccountApi/ipRestriction': 20.001, // Weight(UID): 3000 => cost = 0.006667 * 3000 = 20.001
603
622
  },
604
623
  },
@@ -3620,22 +3639,6 @@ class binance extends binance$1 {
3620
3639
  // 'endTime': 789, // Timestamp in ms to get aggregate trades until INCLUSIVE.
3621
3640
  // 'limit': 500, // default = 500, maximum = 1000
3622
3641
  };
3623
- let method = this.safeString(this.options, 'fetchTradesMethod');
3624
- method = this.safeString2(params, 'fetchTradesMethod', 'method', method);
3625
- if (method === undefined) {
3626
- if (market['option']) {
3627
- method = 'eapiPublicGetTrades';
3628
- }
3629
- else if (market['linear']) {
3630
- method = 'fapiPublicGetAggTrades';
3631
- }
3632
- else if (market['inverse']) {
3633
- method = 'dapiPublicGetAggTrades';
3634
- }
3635
- else {
3636
- method = 'publicGetAggTrades';
3637
- }
3638
- }
3639
3642
  if (!market['option']) {
3640
3643
  if (since !== undefined) {
3641
3644
  request['startTime'] = since;
@@ -3652,7 +3655,22 @@ class binance extends binance$1 {
3652
3655
  const isFutureOrSwap = (market['swap'] || market['future']);
3653
3656
  request['limit'] = isFutureOrSwap ? Math.min(limit, 1000) : limit; // default = 500, maximum = 1000
3654
3657
  }
3658
+ let method = this.safeString(this.options, 'fetchTradesMethod');
3659
+ method = this.safeString2(params, 'fetchTradesMethod', 'method', method);
3655
3660
  params = this.omit(params, ['until', 'fetchTradesMethod']);
3661
+ let response = undefined;
3662
+ if (market['option'] || method === 'eapiPublicGetTrades') {
3663
+ response = await this.eapiPublicGetTrades(this.extend(request, params));
3664
+ }
3665
+ else if (market['linear'] || method === 'fapiPublicGetAggTrades') {
3666
+ response = await this.fapiPublicGetAggTrades(this.extend(request, params));
3667
+ }
3668
+ else if (market['inverse'] || method === 'dapiPublicGetAggTrades') {
3669
+ response = await this.dapiPublicGetAggTrades(this.extend(request, params));
3670
+ }
3671
+ else {
3672
+ response = await this.publicGetAggTrades(this.extend(request, params));
3673
+ }
3656
3674
  //
3657
3675
  // Caveats:
3658
3676
  // - default limit (500) applies only if no other parameters set, trades up
@@ -3662,7 +3680,6 @@ class binance extends binance$1 {
3662
3680
  // - "tradeId" accepted and returned by this method is "aggregate" trade id
3663
3681
  // which is different from actual trade id
3664
3682
  // - setting both fromId and time window results in error
3665
- const response = await this[method](this.extend(request, params));
3666
3683
  //
3667
3684
  // aggregate trades
3668
3685
  //
@@ -4261,6 +4278,15 @@ class binance extends binance$1 {
4261
4278
  }
4262
4279
  const stopPriceString = this.safeString(order, 'stopPrice');
4263
4280
  const stopPrice = this.parseNumber(this.omitZero(stopPriceString));
4281
+ const feeCost = this.safeNumber(order, 'fee');
4282
+ let fee = undefined;
4283
+ if (feeCost !== undefined) {
4284
+ fee = {
4285
+ 'currency': this.safeString(order, 'quoteAsset'),
4286
+ 'cost': feeCost,
4287
+ 'rate': undefined,
4288
+ };
4289
+ }
4264
4290
  return this.safeOrder({
4265
4291
  'info': order,
4266
4292
  'id': id,
@@ -4283,11 +4309,7 @@ class binance extends binance$1 {
4283
4309
  'filled': filled,
4284
4310
  'remaining': undefined,
4285
4311
  'status': status,
4286
- 'fee': {
4287
- 'currency': this.safeString(order, 'quoteAsset'),
4288
- 'cost': this.safeNumber(order, 'fee'),
4289
- 'rate': undefined,
4290
- },
4312
+ 'fee': fee,
4291
4313
  'trades': fills,
4292
4314
  }, market);
4293
4315
  }
@@ -7836,23 +7858,22 @@ class binance extends binance$1 {
7836
7858
  }
7837
7859
  await this.loadMarkets();
7838
7860
  await this.loadLeverageBrackets(false, params);
7839
- let method = undefined;
7840
7861
  const defaultType = this.safeString(this.options, 'defaultType', 'future');
7841
7862
  const type = this.safeString(params, 'type', defaultType);
7842
7863
  let query = this.omit(params, 'type');
7843
7864
  let subType = undefined;
7844
7865
  [subType, query] = this.handleSubTypeAndParams('fetchAccountPositions', undefined, params, 'linear');
7866
+ let response = undefined;
7845
7867
  if (this.isLinear(type, subType)) {
7846
- method = 'fapiPrivateV2GetAccount';
7868
+ response = await this.fapiPrivateV2GetAccount(query);
7847
7869
  }
7848
7870
  else if (this.isInverse(type, subType)) {
7849
- method = 'dapiPrivateGetAccount';
7871
+ response = await this.dapiPrivateGetAccount(query);
7850
7872
  }
7851
7873
  else {
7852
7874
  throw new errors.NotSupported(this.id + ' fetchPositions() supports linear and inverse contracts only');
7853
7875
  }
7854
- const account = await this[method](query);
7855
- const result = this.parseAccountPositions(account);
7876
+ const result = this.parseAccountPositions(response);
7856
7877
  symbols = this.marketSymbols(symbols);
7857
7878
  return this.filterByArrayPositions(result, 'symbol', symbols, false);
7858
7879
  }
@@ -7876,15 +7897,15 @@ class binance extends binance$1 {
7876
7897
  await this.loadMarkets();
7877
7898
  await this.loadLeverageBrackets(false, params);
7878
7899
  const request = {};
7879
- let method = undefined;
7880
7900
  let defaultType = 'future';
7881
7901
  defaultType = this.safeString(this.options, 'defaultType', defaultType);
7882
7902
  const type = this.safeString(params, 'type', defaultType);
7883
7903
  let subType = undefined;
7884
7904
  [subType, params] = this.handleSubTypeAndParams('fetchPositionsRisk', undefined, params, 'linear');
7885
7905
  params = this.omit(params, 'type');
7906
+ let response = undefined;
7886
7907
  if (this.isLinear(type, subType)) {
7887
- method = 'fapiPrivateV2GetPositionRisk';
7908
+ response = await this.fapiPrivateV2GetPositionRisk(this.extend(request, params));
7888
7909
  // ### Response examples ###
7889
7910
  //
7890
7911
  // For One-way position mode:
@@ -7941,12 +7962,11 @@ class binance extends binance$1 {
7941
7962
  // ]
7942
7963
  }
7943
7964
  else if (this.isInverse(type, subType)) {
7944
- method = 'dapiPrivateGetPositionRisk';
7965
+ response = await this.dapiPrivateGetPositionRisk(this.extend(request, params));
7945
7966
  }
7946
7967
  else {
7947
7968
  throw new errors.NotSupported(this.id + ' fetchPositionsRisk() supports linear and inverse contracts only');
7948
7969
  }
7949
- const response = await this[method](this.extend(request, params));
7950
7970
  const result = [];
7951
7971
  for (let i = 0; i < response.length; i++) {
7952
7972
  const parsed = this.parsePositionRisk(response[i]);
@@ -8124,6 +8144,8 @@ class binance extends binance$1 {
8124
8144
  const defaultType = this.safeString(this.options, 'defaultType', 'future');
8125
8145
  const type = this.safeString(params, 'type', defaultType);
8126
8146
  params = this.omit(params, ['type']);
8147
+ let subType = undefined;
8148
+ [subType, params] = this.handleSubTypeAndParams('setPositionMode', undefined, params);
8127
8149
  let dualSidePosition = undefined;
8128
8150
  if (hedged) {
8129
8151
  dualSidePosition = 'true';
@@ -8134,13 +8156,13 @@ class binance extends binance$1 {
8134
8156
  const request = {
8135
8157
  'dualSidePosition': dualSidePosition,
8136
8158
  };
8137
- let method = undefined;
8138
- if (this.isInverse(type)) {
8139
- method = 'dapiPrivatePostPositionSideDual';
8159
+ let response = undefined;
8160
+ if (this.isInverse(type, subType)) {
8161
+ response = await this.dapiPrivatePostPositionSideDual(this.extend(request, params));
8140
8162
  }
8141
8163
  else {
8142
8164
  // default to future
8143
- method = 'fapiPrivatePostPositionSideDual';
8165
+ response = await this.fapiPrivatePostPositionSideDual(this.extend(request, params));
8144
8166
  }
8145
8167
  //
8146
8168
  // {
@@ -8148,7 +8170,7 @@ class binance extends binance$1 {
8148
8170
  // "msg": "success"
8149
8171
  // }
8150
8172
  //
8151
- return await this[method](this.extend(request, params));
8173
+ return response;
8152
8174
  }
8153
8175
  async fetchSettlementHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
8154
8176
  /**
@@ -8360,24 +8382,9 @@ class binance extends binance$1 {
8360
8382
  if (code !== undefined) {
8361
8383
  currency = this.currency(code);
8362
8384
  }
8363
- let method = undefined;
8364
8385
  const request = {};
8365
8386
  [type, params] = this.handleMarketTypeAndParams('fetchLedger', undefined, params);
8366
8387
  [subType, params] = this.handleSubTypeAndParams('fetchLedger', undefined, params);
8367
- if (type === 'option') {
8368
- this.checkRequiredArgument('fetchLedger', code, 'code');
8369
- request['currency'] = currency['id'];
8370
- method = 'eapiPrivateGetBill';
8371
- }
8372
- else if (this.isLinear(type, subType)) {
8373
- method = 'fapiPrivateGetIncome';
8374
- }
8375
- else if (this.isInverse(type, subType)) {
8376
- method = 'dapiPrivateGetIncome';
8377
- }
8378
- else {
8379
- throw new errors.NotSupported(this.id + ' fetchLedger() supports contract wallets only');
8380
- }
8381
8388
  if (since !== undefined) {
8382
8389
  request['startTime'] = since;
8383
8390
  }
@@ -8389,7 +8396,21 @@ class binance extends binance$1 {
8389
8396
  params = this.omit(params, 'until');
8390
8397
  request['endTime'] = until;
8391
8398
  }
8392
- const response = await this[method](this.extend(request, params));
8399
+ let response = undefined;
8400
+ if (type === 'option') {
8401
+ this.checkRequiredArgument('fetchLedger', code, 'code');
8402
+ request['currency'] = currency['id'];
8403
+ response = await this.eapiPrivateGetBill(this.extend(request, params));
8404
+ }
8405
+ else if (this.isLinear(type, subType)) {
8406
+ response = await this.fapiPrivateGetIncome(this.extend(request, params));
8407
+ }
8408
+ else if (this.isInverse(type, subType)) {
8409
+ response = await this.dapiPrivateGetIncome(this.extend(request, params));
8410
+ }
8411
+ else {
8412
+ throw new errors.NotSupported(this.id + ' fetchLedger() supports contract wallets only');
8413
+ }
8393
8414
  //
8394
8415
  // options (eapi)
8395
8416
  //
@@ -9263,11 +9284,13 @@ class binance extends binance$1 {
9263
9284
  const duration = this.parseTimeframe(timeframe);
9264
9285
  request['endTime'] = this.sum(since, duration * limit * 1000);
9265
9286
  }
9266
- let method = 'fapiDataGetOpenInterestHist';
9287
+ let response = undefined;
9267
9288
  if (market['inverse']) {
9268
- method = 'dapiDataGetOpenInterestHist';
9289
+ response = await this.dapiDataGetOpenInterestHist(this.extend(request, params));
9290
+ }
9291
+ else {
9292
+ response = await this.fapiDataGetOpenInterestHist(this.extend(request, params));
9269
9293
  }
9270
- const response = await this[method](this.extend(request, params));
9271
9294
  //
9272
9295
  // [
9273
9296
  // {
@@ -9303,14 +9326,16 @@ class binance extends binance$1 {
9303
9326
  else {
9304
9327
  request['symbol'] = market['id'];
9305
9328
  }
9306
- let method = 'fapiPublicGetOpenInterest';
9329
+ let response = undefined;
9307
9330
  if (market['option']) {
9308
- method = 'eapiPublicGetOpenInterest';
9331
+ response = await this.eapiPublicGetOpenInterest(this.extend(request, params));
9309
9332
  }
9310
9333
  else if (market['inverse']) {
9311
- method = 'dapiPublicGetOpenInterest';
9334
+ response = await this.dapiPublicGetOpenInterest(this.extend(request, params));
9335
+ }
9336
+ else {
9337
+ response = await this.fapiPublicGetOpenInterest(this.extend(request, params));
9312
9338
  }
9313
- const response = await this[method](this.extend(request, params));
9314
9339
  //
9315
9340
  // futures (fapi)
9316
9341
  //
@@ -1697,15 +1697,20 @@ class bingx extends bingx$1 {
1697
1697
  else if (timeInForce === 'FOK') {
1698
1698
  request['timeInForce'] = 'FOK';
1699
1699
  }
1700
- if ((type === 'LIMIT') || (type === 'TRIGGER_LIMIT') || (type === 'STOP') || (type === 'TAKE_PROFIT')) {
1701
- request['price'] = this.parseToNumeric(this.priceToPrecision(symbol, price));
1702
- }
1703
- const triggerPrice = this.safeNumber2(params, 'stopPrice', 'triggerPrice');
1704
- const stopLossPrice = this.safeNumber(params, 'stopLossPrice');
1705
- const takeProfitPrice = this.safeNumber(params, 'takeProfitPrice');
1700
+ const triggerPrice = this.safeString2(params, 'stopPrice', 'triggerPrice');
1701
+ const stopLossPrice = this.safeString(params, 'stopLossPrice');
1702
+ const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
1703
+ const trailingAmount = this.safeString(params, 'trailingAmount');
1704
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'priceRate');
1706
1705
  const isTriggerOrder = triggerPrice !== undefined;
1707
1706
  const isStopLossPriceOrder = stopLossPrice !== undefined;
1708
1707
  const isTakeProfitPriceOrder = takeProfitPrice !== undefined;
1708
+ const isTrailingAmountOrder = trailingAmount !== undefined;
1709
+ const isTrailingPercentOrder = trailingPercent !== undefined;
1710
+ const isTrailing = isTrailingAmountOrder || isTrailingPercentOrder;
1711
+ if (((type === 'LIMIT') || (type === 'TRIGGER_LIMIT') || (type === 'STOP') || (type === 'TAKE_PROFIT')) && !isTrailing) {
1712
+ request['price'] = this.parseToNumeric(this.priceToPrecision(symbol, price));
1713
+ }
1709
1714
  let reduceOnly = this.safeValue(params, 'reduceOnly', false);
1710
1715
  if (isTriggerOrder) {
1711
1716
  request['stopPrice'] = this.parseToNumeric(this.priceToPrecision(symbol, triggerPrice));
@@ -1738,6 +1743,16 @@ class bingx extends bingx$1 {
1738
1743
  }
1739
1744
  }
1740
1745
  }
1746
+ else if (isTrailing) {
1747
+ request['type'] = 'TRAILING_STOP_MARKET';
1748
+ if (isTrailingAmountOrder) {
1749
+ request['price'] = this.parseToNumeric(trailingAmount);
1750
+ }
1751
+ else if (isTrailingPercentOrder) {
1752
+ const requestTrailingPercent = Precise["default"].stringDiv(trailingPercent, '100');
1753
+ request['priceRate'] = this.parseToNumeric(requestTrailingPercent);
1754
+ }
1755
+ }
1741
1756
  let positionSide = undefined;
1742
1757
  if (reduceOnly) {
1743
1758
  positionSide = (side === 'buy') ? 'SHORT' : 'LONG';
@@ -1747,7 +1762,7 @@ class bingx extends bingx$1 {
1747
1762
  }
1748
1763
  request['positionSide'] = positionSide;
1749
1764
  request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
1750
- params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice']);
1765
+ params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'trailingAmount', 'trailingPercent']);
1751
1766
  }
1752
1767
  return this.extend(request, params);
1753
1768
  }
@@ -1770,6 +1785,8 @@ class bingx extends bingx$1 {
1770
1785
  * @param {float} [params.stopLossPrice] *swap only* stop loss trigger price
1771
1786
  * @param {float} [params.takeProfitPrice] *swap only* take profit trigger price
1772
1787
  * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount
1788
+ * @param {float} [params.trailingAmount] *swap only* the quote amount to trail away from the current market price
1789
+ * @param {float} [params.trailingPercent] *swap only* the percent to trail away from the current market price
1773
1790
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1774
1791
  */
1775
1792
  await this.loadMarkets();