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/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
  }
@@ -7839,23 +7861,22 @@ export default class binance extends Exchange {
7839
7861
  }
7840
7862
  await this.loadMarkets();
7841
7863
  await this.loadLeverageBrackets(false, params);
7842
- let method = undefined;
7843
7864
  const defaultType = this.safeString(this.options, 'defaultType', 'future');
7844
7865
  const type = this.safeString(params, 'type', defaultType);
7845
7866
  let query = this.omit(params, 'type');
7846
7867
  let subType = undefined;
7847
7868
  [subType, query] = this.handleSubTypeAndParams('fetchAccountPositions', undefined, params, 'linear');
7869
+ let response = undefined;
7848
7870
  if (this.isLinear(type, subType)) {
7849
- method = 'fapiPrivateV2GetAccount';
7871
+ response = await this.fapiPrivateV2GetAccount(query);
7850
7872
  }
7851
7873
  else if (this.isInverse(type, subType)) {
7852
- method = 'dapiPrivateGetAccount';
7874
+ response = await this.dapiPrivateGetAccount(query);
7853
7875
  }
7854
7876
  else {
7855
7877
  throw new NotSupported(this.id + ' fetchPositions() supports linear and inverse contracts only');
7856
7878
  }
7857
- const account = await this[method](query);
7858
- const result = this.parseAccountPositions(account);
7879
+ const result = this.parseAccountPositions(response);
7859
7880
  symbols = this.marketSymbols(symbols);
7860
7881
  return this.filterByArrayPositions(result, 'symbol', symbols, false);
7861
7882
  }
@@ -7879,15 +7900,15 @@ export default class binance extends Exchange {
7879
7900
  await this.loadMarkets();
7880
7901
  await this.loadLeverageBrackets(false, params);
7881
7902
  const request = {};
7882
- let method = undefined;
7883
7903
  let defaultType = 'future';
7884
7904
  defaultType = this.safeString(this.options, 'defaultType', defaultType);
7885
7905
  const type = this.safeString(params, 'type', defaultType);
7886
7906
  let subType = undefined;
7887
7907
  [subType, params] = this.handleSubTypeAndParams('fetchPositionsRisk', undefined, params, 'linear');
7888
7908
  params = this.omit(params, 'type');
7909
+ let response = undefined;
7889
7910
  if (this.isLinear(type, subType)) {
7890
- method = 'fapiPrivateV2GetPositionRisk';
7911
+ response = await this.fapiPrivateV2GetPositionRisk(this.extend(request, params));
7891
7912
  // ### Response examples ###
7892
7913
  //
7893
7914
  // For One-way position mode:
@@ -7944,12 +7965,11 @@ export default class binance extends Exchange {
7944
7965
  // ]
7945
7966
  }
7946
7967
  else if (this.isInverse(type, subType)) {
7947
- method = 'dapiPrivateGetPositionRisk';
7968
+ response = await this.dapiPrivateGetPositionRisk(this.extend(request, params));
7948
7969
  }
7949
7970
  else {
7950
7971
  throw new NotSupported(this.id + ' fetchPositionsRisk() supports linear and inverse contracts only');
7951
7972
  }
7952
- const response = await this[method](this.extend(request, params));
7953
7973
  const result = [];
7954
7974
  for (let i = 0; i < response.length; i++) {
7955
7975
  const parsed = this.parsePositionRisk(response[i]);
@@ -8127,6 +8147,8 @@ export default class binance extends Exchange {
8127
8147
  const defaultType = this.safeString(this.options, 'defaultType', 'future');
8128
8148
  const type = this.safeString(params, 'type', defaultType);
8129
8149
  params = this.omit(params, ['type']);
8150
+ let subType = undefined;
8151
+ [subType, params] = this.handleSubTypeAndParams('setPositionMode', undefined, params);
8130
8152
  let dualSidePosition = undefined;
8131
8153
  if (hedged) {
8132
8154
  dualSidePosition = 'true';
@@ -8137,13 +8159,13 @@ export default class binance extends Exchange {
8137
8159
  const request = {
8138
8160
  'dualSidePosition': dualSidePosition,
8139
8161
  };
8140
- let method = undefined;
8141
- if (this.isInverse(type)) {
8142
- method = 'dapiPrivatePostPositionSideDual';
8162
+ let response = undefined;
8163
+ if (this.isInverse(type, subType)) {
8164
+ response = await this.dapiPrivatePostPositionSideDual(this.extend(request, params));
8143
8165
  }
8144
8166
  else {
8145
8167
  // default to future
8146
- method = 'fapiPrivatePostPositionSideDual';
8168
+ response = await this.fapiPrivatePostPositionSideDual(this.extend(request, params));
8147
8169
  }
8148
8170
  //
8149
8171
  // {
@@ -8151,7 +8173,7 @@ export default class binance extends Exchange {
8151
8173
  // "msg": "success"
8152
8174
  // }
8153
8175
  //
8154
- return await this[method](this.extend(request, params));
8176
+ return response;
8155
8177
  }
8156
8178
  async fetchSettlementHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
8157
8179
  /**
@@ -8363,24 +8385,9 @@ export default class binance extends Exchange {
8363
8385
  if (code !== undefined) {
8364
8386
  currency = this.currency(code);
8365
8387
  }
8366
- let method = undefined;
8367
8388
  const request = {};
8368
8389
  [type, params] = this.handleMarketTypeAndParams('fetchLedger', undefined, params);
8369
8390
  [subType, params] = this.handleSubTypeAndParams('fetchLedger', undefined, params);
8370
- if (type === 'option') {
8371
- this.checkRequiredArgument('fetchLedger', code, 'code');
8372
- request['currency'] = currency['id'];
8373
- method = 'eapiPrivateGetBill';
8374
- }
8375
- else if (this.isLinear(type, subType)) {
8376
- method = 'fapiPrivateGetIncome';
8377
- }
8378
- else if (this.isInverse(type, subType)) {
8379
- method = 'dapiPrivateGetIncome';
8380
- }
8381
- else {
8382
- throw new NotSupported(this.id + ' fetchLedger() supports contract wallets only');
8383
- }
8384
8391
  if (since !== undefined) {
8385
8392
  request['startTime'] = since;
8386
8393
  }
@@ -8392,7 +8399,21 @@ export default class binance extends Exchange {
8392
8399
  params = this.omit(params, 'until');
8393
8400
  request['endTime'] = until;
8394
8401
  }
8395
- 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
+ }
8396
8417
  //
8397
8418
  // options (eapi)
8398
8419
  //
@@ -9266,11 +9287,13 @@ export default class binance extends Exchange {
9266
9287
  const duration = this.parseTimeframe(timeframe);
9267
9288
  request['endTime'] = this.sum(since, duration * limit * 1000);
9268
9289
  }
9269
- let method = 'fapiDataGetOpenInterestHist';
9290
+ let response = undefined;
9270
9291
  if (market['inverse']) {
9271
- method = 'dapiDataGetOpenInterestHist';
9292
+ response = await this.dapiDataGetOpenInterestHist(this.extend(request, params));
9293
+ }
9294
+ else {
9295
+ response = await this.fapiDataGetOpenInterestHist(this.extend(request, params));
9272
9296
  }
9273
- const response = await this[method](this.extend(request, params));
9274
9297
  //
9275
9298
  // [
9276
9299
  // {
@@ -9306,14 +9329,16 @@ export default class binance extends Exchange {
9306
9329
  else {
9307
9330
  request['symbol'] = market['id'];
9308
9331
  }
9309
- let method = 'fapiPublicGetOpenInterest';
9332
+ let response = undefined;
9310
9333
  if (market['option']) {
9311
- method = 'eapiPublicGetOpenInterest';
9334
+ response = await this.eapiPublicGetOpenInterest(this.extend(request, params));
9312
9335
  }
9313
9336
  else if (market['inverse']) {
9314
- method = 'dapiPublicGetOpenInterest';
9337
+ response = await this.dapiPublicGetOpenInterest(this.extend(request, params));
9338
+ }
9339
+ else {
9340
+ response = await this.fapiPublicGetOpenInterest(this.extend(request, params));
9315
9341
  }
9316
- const response = await this[method](this.extend(request, params));
9317
9342
  //
9318
9343
  // futures (fapi)
9319
9344
  //
package/js/src/bingx.js CHANGED
@@ -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();