ccxt 4.3.67 → 4.3.69

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 (63) hide show
  1. package/README.md +5 -5
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/base/Exchange.js +364 -356
  5. package/dist/cjs/src/base/functions/type.js +2 -2
  6. package/dist/cjs/src/bingx.js +463 -217
  7. package/dist/cjs/src/bitget.js +4 -2
  8. package/dist/cjs/src/btcbox.js +2 -1
  9. package/dist/cjs/src/coinbaseinternational.js +79 -1
  10. package/dist/cjs/src/hyperliquid.js +0 -3
  11. package/dist/cjs/src/kucoin.js +12 -5
  12. package/dist/cjs/src/oxfun.js +2 -2
  13. package/dist/cjs/src/poloniex.js +33 -33
  14. package/dist/cjs/src/poloniexfutures.js +26 -26
  15. package/dist/cjs/src/pro/krakenfutures.js +7 -6
  16. package/dist/cjs/src/pro/poloniex.js +13 -13
  17. package/dist/cjs/src/pro/poloniexfutures.js +5 -5
  18. package/js/ccxt.d.ts +3 -3
  19. package/js/ccxt.js +1 -1
  20. package/js/src/base/Exchange.d.ts +107 -82
  21. package/js/src/base/Exchange.js +364 -356
  22. package/js/src/base/functions/type.js +2 -2
  23. package/js/src/base/types.d.ts +0 -2
  24. package/js/src/binance.d.ts +2 -2
  25. package/js/src/bingx.d.ts +4 -2
  26. package/js/src/bingx.js +463 -217
  27. package/js/src/bitget.d.ts +2 -2
  28. package/js/src/bitget.js +4 -2
  29. package/js/src/bitmart.d.ts +2 -2
  30. package/js/src/bitrue.d.ts +2 -2
  31. package/js/src/btcbox.js +2 -1
  32. package/js/src/bybit.d.ts +2 -2
  33. package/js/src/coinbaseinternational.d.ts +11 -0
  34. package/js/src/coinbaseinternational.js +79 -1
  35. package/js/src/coinex.d.ts +2 -2
  36. package/js/src/coinlist.d.ts +2 -2
  37. package/js/src/deribit.d.ts +2 -2
  38. package/js/src/digifinex.d.ts +2 -2
  39. package/js/src/hyperliquid.js +0 -3
  40. package/js/src/kucoin.js +12 -5
  41. package/js/src/latoken.d.ts +2 -2
  42. package/js/src/mexc.d.ts +2 -2
  43. package/js/src/okx.d.ts +2 -2
  44. package/js/src/oxfun.d.ts +1 -1
  45. package/js/src/oxfun.js +2 -2
  46. package/js/src/phemex.d.ts +2 -2
  47. package/js/src/poloniex.js +33 -33
  48. package/js/src/poloniexfutures.js +26 -26
  49. package/js/src/pro/krakenfutures.js +7 -6
  50. package/js/src/pro/poloniex.js +13 -13
  51. package/js/src/pro/poloniexfutures.js +5 -5
  52. package/js/src/woo.d.ts +2 -2
  53. package/package.json +1 -1
  54. package/js/src/coinbaseprime.d.ts +0 -4
  55. package/js/src/coinbaseprime.js +0 -32
  56. package/js/src/pro/coinbaseprime.d.ts +0 -4
  57. package/js/src/pro/coinbaseprime.js +0 -33
  58. package/js/src/pro/huobipro.d.ts +0 -4
  59. package/js/src/pro/huobipro.js +0 -17
  60. package/js/src/pro/mexc3.d.ts +0 -4
  61. package/js/src/pro/mexc3.js +0 -17
  62. package/js/src/pro/okex.d.ts +0 -4
  63. package/js/src/pro/okex.js +0 -17
@@ -48,6 +48,7 @@ class bingx extends bingx$1 {
48
48
  'createTrailingPercentOrder': true,
49
49
  'createTriggerOrder': true,
50
50
  'fetchBalance': true,
51
+ 'fetchCanceledOrders': true,
51
52
  'fetchClosedOrders': true,
52
53
  'fetchCurrencies': true,
53
54
  'fetchDepositAddress': true,
@@ -1131,7 +1132,27 @@ class bingx extends bingx$1 {
1131
1132
  // "s": "BTC-USDT"
1132
1133
  // }
1133
1134
  //
1134
- let time = this.safeIntegerN(trade, ['time', 'filledTm', 'T']);
1135
+ // inverse swap fetchMyTrades
1136
+ //
1137
+ // {
1138
+ // "orderId": "1817441228670648320",
1139
+ // "symbol": "SOL-USD",
1140
+ // "type": "MARKET",
1141
+ // "side": "BUY",
1142
+ // "positionSide": "LONG",
1143
+ // "tradeId": "97244554",
1144
+ // "volume": "2",
1145
+ // "tradePrice": "182.652",
1146
+ // "amount": "20.00000000",
1147
+ // "realizedPnl": "0.00000000",
1148
+ // "commission": "-0.00005475",
1149
+ // "currency": "SOL",
1150
+ // "buyer": true,
1151
+ // "maker": false,
1152
+ // "tradeTime": 1722146730000
1153
+ // }
1154
+ //
1155
+ let time = this.safeIntegerN(trade, ['time', 'filledTm', 'T', 'tradeTime']);
1135
1156
  const datetimeId = this.safeString(trade, 'filledTm');
1136
1157
  if (datetimeId !== undefined) {
1137
1158
  time = this.parse8601(datetimeId);
@@ -1144,8 +1165,8 @@ class bingx extends bingx$1 {
1144
1165
  const currencyId = this.safeStringN(trade, ['currency', 'N', 'commissionAsset']);
1145
1166
  const currencyCode = this.safeCurrencyCode(currencyId);
1146
1167
  const m = this.safeBool(trade, 'm');
1147
- const marketId = this.safeString(trade, 's');
1148
- const isBuyerMaker = this.safeBool2(trade, 'buyerMaker', 'isBuyerMaker');
1168
+ const marketId = this.safeString2(trade, 's', 'symbol');
1169
+ const isBuyerMaker = this.safeBoolN(trade, ['buyerMaker', 'isBuyerMaker', 'maker']);
1149
1170
  let takeOrMaker = undefined;
1150
1171
  if ((isBuyerMaker !== undefined) || (m !== undefined)) {
1151
1172
  takeOrMaker = (isBuyerMaker || m) ? 'maker' : 'taker';
@@ -1182,7 +1203,7 @@ class bingx extends bingx$1 {
1182
1203
  'type': this.safeStringLower(trade, 'o'),
1183
1204
  'side': this.parseOrderSide(side),
1184
1205
  'takerOrMaker': takeOrMaker,
1185
- 'price': this.safeString2(trade, 'price', 'p'),
1206
+ 'price': this.safeStringN(trade, ['price', 'p', 'tradePrice']),
1186
1207
  'amount': amount,
1187
1208
  'cost': cost,
1188
1209
  'fee': {
@@ -3011,8 +3032,7 @@ class bingx extends bingx$1 {
3011
3032
  // "clientOrderID": ""
3012
3033
  // }
3013
3034
  //
3014
- // inverse swap cancelAllOrders, cancelOrder
3015
- // inverse swap cancelAllOrders, cancelOrder, fetchOpenOrders
3035
+ // inverse swap cancelAllOrders, cancelOrder, fetchOrder, fetchOpenOrders, fetchClosedOrders, fetchCanceledOrders
3016
3036
  //
3017
3037
  // {
3018
3038
  // "symbol": "SOL-USD",
@@ -3072,7 +3092,7 @@ class bingx extends bingx$1 {
3072
3092
  const side = this.safeStringLower2(order, 'side', 'S');
3073
3093
  const timestamp = this.safeIntegerN(order, ['time', 'transactTime', 'E']);
3074
3094
  const lastTradeTimestamp = this.safeInteger2(order, 'updateTime', 'T');
3075
- const statusId = this.safeString2(order, 'status', 'X');
3095
+ const statusId = this.safeStringUpper2(order, 'status', 'X');
3076
3096
  let feeCurrencyCode = this.safeString2(order, 'feeAsset', 'N');
3077
3097
  const feeCost = this.safeStringN(order, ['fee', 'commission', 'n']);
3078
3098
  if ((feeCurrencyCode === undefined)) {
@@ -3618,11 +3638,12 @@ class bingx extends bingx$1 {
3618
3638
  * @method
3619
3639
  * @name bingx#fetchOrder
3620
3640
  * @description fetches information on an order made by the user
3621
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Orders
3622
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20Order
3641
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20details
3642
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20details
3643
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Order
3623
3644
  * @param {string} symbol unified symbol of the market the order was made in
3624
3645
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3625
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3646
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3626
3647
  */
3627
3648
  if (symbol === undefined) {
3628
3649
  throw new errors.ArgumentsRequired(this.id + ' fetchOrder() requires a symbol argument');
@@ -3633,68 +3654,124 @@ class bingx extends bingx$1 {
3633
3654
  'symbol': market['id'],
3634
3655
  'orderId': id,
3635
3656
  };
3657
+ let type = undefined;
3658
+ let subType = undefined;
3636
3659
  let response = undefined;
3637
- const [marketType, query] = this.handleMarketTypeAndParams('fetchOrder', market, params);
3638
- if (marketType === 'spot') {
3639
- response = await this.spotV1PrivateGetTradeQuery(this.extend(request, query));
3660
+ [type, params] = this.handleMarketTypeAndParams('fetchOrder', market, params);
3661
+ [subType, params] = this.handleSubTypeAndParams('fetchOrder', market, params);
3662
+ if (type === 'spot') {
3663
+ response = await this.spotV1PrivateGetTradeQuery(this.extend(request, params));
3664
+ //
3665
+ // {
3666
+ // "code": 0,
3667
+ // "msg": "",
3668
+ // "data": {
3669
+ // "symbol": "XRP-USDT",
3670
+ // "orderId": 1514087361158316032,
3671
+ // "price": "0.5",
3672
+ // "origQty": "10",
3673
+ // "executedQty": "0",
3674
+ // "cummulativeQuoteQty": "0",
3675
+ // "status": "CANCELED",
3676
+ // "type": "LIMIT",
3677
+ // "side": "BUY",
3678
+ // "time": 1649821532000,
3679
+ // "updateTime": 1649821543000,
3680
+ // "origQuoteOrderQty": "0",
3681
+ // "fee": "0",
3682
+ // "feeAsset": "XRP"
3683
+ // }
3684
+ // }
3685
+ //
3640
3686
  }
3641
3687
  else {
3642
- response = await this.swapV2PrivateGetTradeOrder(this.extend(request, query));
3688
+ if (subType === 'inverse') {
3689
+ response = await this.cswapV1PrivateGetTradeOrderDetail(this.extend(request, params));
3690
+ //
3691
+ // {
3692
+ // "code": 0,
3693
+ // "msg": "",
3694
+ // "data": {
3695
+ // "order": {
3696
+ // "symbol": "SOL-USD",
3697
+ // "orderId": "1816342420721254400",
3698
+ // "side": "BUY",
3699
+ // "positionSide": "Long",
3700
+ // "type": "LIMIT",
3701
+ // "quantity": 1,
3702
+ // "origQty": "",
3703
+ // "price": "150",
3704
+ // "executedQty": "0",
3705
+ // "avgPrice": "0.000",
3706
+ // "cumQuote": "",
3707
+ // "stopPrice": "",
3708
+ // "profit": "0.0000",
3709
+ // "commission": "0.0000",
3710
+ // "status": "Pending",
3711
+ // "time": 1721884753767,
3712
+ // "updateTime": 1721884753786,
3713
+ // "clientOrderId": "",
3714
+ // "leverage": "",
3715
+ // "takeProfit": {
3716
+ // "type": "TAKE_PROFIT",
3717
+ // "quantity": 0,
3718
+ // "stopPrice": 0,
3719
+ // "price": 0,
3720
+ // "workingType": "MARK_PRICE",
3721
+ // "stopGuaranteed": ""
3722
+ // },
3723
+ // "stopLoss": {
3724
+ // "type": "STOP",
3725
+ // "quantity": 0,
3726
+ // "stopPrice": 0,
3727
+ // "price": 0,
3728
+ // "workingType": "MARK_PRICE",
3729
+ // "stopGuaranteed": ""
3730
+ // },
3731
+ // "advanceAttr": 0,
3732
+ // "positionID": 0,
3733
+ // "takeProfitEntrustPrice": 0,
3734
+ // "stopLossEntrustPrice": 0,
3735
+ // "orderType": "",
3736
+ // "workingType": "MARK_PRICE"
3737
+ // }
3738
+ // }
3739
+ // }
3740
+ //
3741
+ }
3742
+ else {
3743
+ response = await this.swapV2PrivateGetTradeOrder(this.extend(request, params));
3744
+ //
3745
+ // {
3746
+ // "code": 0,
3747
+ // "msg": "",
3748
+ // "data": {
3749
+ // "order": {
3750
+ // "symbol": "BTC-USDT",
3751
+ // "orderId": 1597597642269917184,
3752
+ // "side": "SELL",
3753
+ // "positionSide": "LONG",
3754
+ // "type": "TAKE_PROFIT_MARKET",
3755
+ // "origQty": "1.0000",
3756
+ // "price": "0.0",
3757
+ // "executedQty": "0.0000",
3758
+ // "avgPrice": "0.0",
3759
+ // "cumQuote": "",
3760
+ // "stopPrice": "16494.0",
3761
+ // "profit": "",
3762
+ // "commission": "",
3763
+ // "status": "FILLED",
3764
+ // "time": 1669731935000,
3765
+ // "updateTime": 1669752524000
3766
+ // }
3767
+ // }
3768
+ // }
3769
+ //
3770
+ }
3643
3771
  }
3644
- //
3645
- // spot
3646
- //
3647
- // {
3648
- // "code": 0,
3649
- // "msg": "",
3650
- // "data": {
3651
- // "symbol": "XRP-USDT",
3652
- // "orderId": 1514087361158316032,
3653
- // "price": "0.5",
3654
- // "origQty": "10",
3655
- // "executedQty": "0",
3656
- // "cummulativeQuoteQty": "0",
3657
- // "status": "CANCELED",
3658
- // "type": "LIMIT",
3659
- // "side": "BUY",
3660
- // "time": 1649821532000,
3661
- // "updateTime": 1649821543000,
3662
- // "origQuoteOrderQty": "0",
3663
- // "fee": "0",
3664
- // "feeAsset": "XRP"
3665
- // }
3666
- // }
3667
- //
3668
- // swap
3669
- //
3670
- // {
3671
- // "code": 0,
3672
- // "msg": "",
3673
- // "data": {
3674
- // "order": {
3675
- // "symbol": "BTC-USDT",
3676
- // "orderId": 1597597642269917184,
3677
- // "side": "SELL",
3678
- // "positionSide": "LONG",
3679
- // "type": "TAKE_PROFIT_MARKET",
3680
- // "origQty": "1.0000",
3681
- // "price": "0.0",
3682
- // "executedQty": "0.0000",
3683
- // "avgPrice": "0.0",
3684
- // "cumQuote": "",
3685
- // "stopPrice": "16494.0",
3686
- // "profit": "",
3687
- // "commission": "",
3688
- // "status": "FILLED",
3689
- // "time": 1669731935000,
3690
- // "updateTime": 1669752524000
3691
- // }
3692
- // }
3693
- // }
3694
- //
3695
- const data = this.safeValue(response, 'data');
3696
- const first = this.safeDict(data, 'order', data);
3697
- return this.parseOrder(first, market);
3772
+ const data = this.safeDict(response, 'data', {});
3773
+ const order = this.safeDict(data, 'order', data);
3774
+ return this.parseOrder(order, market);
3698
3775
  }
3699
3776
  async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3700
3777
  /**
@@ -3946,8 +4023,51 @@ class bingx extends bingx$1 {
3946
4023
  * @method
3947
4024
  * @name bingx#fetchClosedOrders
3948
4025
  * @description fetches information on multiple closed orders made by the user
3949
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Order%20History
3950
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#User's%20Force%20Orders
4026
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
4027
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
4028
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
4029
+ * @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
4030
+ * @param {string} symbol unified market symbol of the closed orders
4031
+ * @param {int} [since] timestamp in ms of the earliest order
4032
+ * @param {int} [limit] the max number of closed orders to return
4033
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4034
+ * @param {int} [params.until] the latest time in ms to fetch orders for
4035
+ * @param {boolean} [params.standard] whether to fetch standard contract orders
4036
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
4037
+ */
4038
+ await this.loadMarkets();
4039
+ const orders = await this.fetchCanceledAndClosedOrders(symbol, since, limit, params);
4040
+ return this.filterBy(orders, 'status', 'closed');
4041
+ }
4042
+ async fetchCanceledOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
4043
+ /**
4044
+ * @method
4045
+ * @name bingx#fetchCanceledOrders
4046
+ * @description fetches information on multiple canceled orders made by the user
4047
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
4048
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
4049
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
4050
+ * @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
4051
+ * @param {string} symbol unified market symbol of the canceled orders
4052
+ * @param {int} [since] timestamp in ms of the earliest order
4053
+ * @param {int} [limit] the max number of canceled orders to return
4054
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4055
+ * @param {int} [params.until] the latest time in ms to fetch orders for
4056
+ * @param {boolean} [params.standard] whether to fetch standard contract orders
4057
+ * @returns {object} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
4058
+ */
4059
+ await this.loadMarkets();
4060
+ const orders = await this.fetchCanceledAndClosedOrders(symbol, since, limit, params);
4061
+ return this.filterBy(orders, 'status', 'canceled');
4062
+ }
4063
+ async fetchCanceledAndClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
4064
+ /**
4065
+ * @method
4066
+ * @name bingx#fetchCanceledAndClosedOrders
4067
+ * @description fetches information on multiple closed orders made by the user
4068
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
4069
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
4070
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
3951
4071
  * @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
3952
4072
  * @param {string} [symbol] unified market symbol of the market orders were made in
3953
4073
  * @param {int} [since] the earliest time in ms to fetch orders for
@@ -3965,75 +4085,133 @@ class bingx extends bingx$1 {
3965
4085
  const request = {
3966
4086
  'symbol': market['id'],
3967
4087
  };
3968
- let response = undefined;
4088
+ let type = undefined;
4089
+ let subType = undefined;
3969
4090
  let standard = undefined;
4091
+ let response = undefined;
4092
+ [type, params] = this.handleMarketTypeAndParams('fetchClosedOrders', market, params);
4093
+ [subType, params] = this.handleSubTypeAndParams('fetchClosedOrders', market, params);
3970
4094
  [standard, params] = this.handleOptionAndParams(params, 'fetchClosedOrders', 'standard', false);
3971
- const [marketType, query] = this.handleMarketTypeAndParams('fetchClosedOrders', market, params);
3972
4095
  if (standard) {
3973
- response = await this.contractV1PrivateGetAllOrders(this.extend(request, query));
4096
+ response = await this.contractV1PrivateGetAllOrders(this.extend(request, params));
3974
4097
  }
3975
- else if (marketType === 'spot') {
3976
- response = await this.spotV1PrivateGetTradeHistoryOrders(this.extend(request, query));
4098
+ else if (type === 'spot') {
4099
+ response = await this.spotV1PrivateGetTradeHistoryOrders(this.extend(request, params));
4100
+ //
4101
+ // {
4102
+ // "code": 0,
4103
+ // "msg": "",
4104
+ // "data": {
4105
+ // "orders": [
4106
+ // {
4107
+ // "symbol": "XRP-USDT",
4108
+ // "orderId": 1514073325788200960,
4109
+ // "price": "0.5",
4110
+ // "origQty": "20",
4111
+ // "executedQty": "0",
4112
+ // "cummulativeQuoteQty": "0",
4113
+ // "status": "PENDING",
4114
+ // "type": "LIMIT",
4115
+ // "side": "BUY",
4116
+ // "time": 1649818185647,
4117
+ // "updateTime": 1649818185647,
4118
+ // "origQuoteOrderQty": "0"
4119
+ // }
4120
+ // ]
4121
+ // }
4122
+ // }
4123
+ //
3977
4124
  }
3978
4125
  else {
3979
- response = await this.swapV2PrivateGetTradeAllOrders(this.extend(request, query));
4126
+ if (subType === 'inverse') {
4127
+ response = await this.cswapV1PrivateGetTradeOrderHistory(this.extend(request, params));
4128
+ //
4129
+ // {
4130
+ // "code": 0,
4131
+ // "msg": "",
4132
+ // "data": {
4133
+ // "orders": [
4134
+ // {
4135
+ // "symbol": "SOL-USD",
4136
+ // "orderId": "1816002957423951872",
4137
+ // "side": "BUY",
4138
+ // "positionSide": "LONG",
4139
+ // "type": "LIMIT",
4140
+ // "quantity": 1,
4141
+ // "origQty": "10.00000000",
4142
+ // "price": "150.000",
4143
+ // "executedQty": "0.00000000",
4144
+ // "avgPrice": "0.000",
4145
+ // "cumQuote": "",
4146
+ // "stopPrice": "0.000",
4147
+ // "profit": "0.0000",
4148
+ // "commission": "0.000000",
4149
+ // "status": "Filled",
4150
+ // "time": 1721803819000,
4151
+ // "updateTime": 1721803856000,
4152
+ // "clientOrderId": "",
4153
+ // "leverage": "",
4154
+ // "takeProfit": {
4155
+ // "type": "",
4156
+ // "quantity": 0,
4157
+ // "stopPrice": 0,
4158
+ // "price": 0,
4159
+ // "workingType": "",
4160
+ // "stopGuaranteed": ""
4161
+ // },
4162
+ // "stopLoss": {
4163
+ // "type": "",
4164
+ // "quantity": 0,
4165
+ // "stopPrice": 0,
4166
+ // "price": 0,
4167
+ // "workingType": "",
4168
+ // "stopGuaranteed": ""
4169
+ // },
4170
+ // "advanceAttr": 0,
4171
+ // "positionID": 0,
4172
+ // "takeProfitEntrustPrice": 0,
4173
+ // "stopLossEntrustPrice": 0,
4174
+ // "orderType": "",
4175
+ // "workingType": "MARK_PRICE"
4176
+ // },
4177
+ // ]
4178
+ // }
4179
+ // }
4180
+ //
4181
+ }
4182
+ else {
4183
+ response = await this.swapV2PrivateGetTradeAllOrders(this.extend(request, params));
4184
+ //
4185
+ // {
4186
+ // "code": 0,
4187
+ // "msg": "",
4188
+ // "data": {
4189
+ // "orders": [
4190
+ // {
4191
+ // "symbol": "LINK-USDT",
4192
+ // "orderId": 1585839271162413056,
4193
+ // "side": "BUY",
4194
+ // "positionSide": "LONG",
4195
+ // "type": "TRIGGER_MARKET",
4196
+ // "origQty": "5.0",
4197
+ // "price": "9",
4198
+ // "executedQty": "0.0",
4199
+ // "avgPrice": "0",
4200
+ // "cumQuote": "0",
4201
+ // "stopPrice": "5",
4202
+ // "profit": "0.0000",
4203
+ // "commission": "0.000000",
4204
+ // "status": "CANCELLED",
4205
+ // "time": 1667631605000,
4206
+ // "updateTime": 1667631605000
4207
+ // },
4208
+ // ]
4209
+ // }
4210
+ // }
4211
+ //
4212
+ }
3980
4213
  }
3981
- //
3982
- // spot
3983
- //
3984
- // {
3985
- // "code": 0,
3986
- // "msg": "",
3987
- // "data": {
3988
- // "orders": [
3989
- // {
3990
- // "symbol": "XRP-USDT",
3991
- // "orderId": 1514073325788200960,
3992
- // "price": "0.5",
3993
- // "origQty": "20",
3994
- // "executedQty": "0",
3995
- // "cummulativeQuoteQty": "0",
3996
- // "status": "PENDING",
3997
- // "type": "LIMIT",
3998
- // "side": "BUY",
3999
- // "time": 1649818185647,
4000
- // "updateTime": 1649818185647,
4001
- // "origQuoteOrderQty": "0"
4002
- // }
4003
- // ]
4004
- // }
4005
- // }
4006
- //
4007
- // swap
4008
- //
4009
- // {
4010
- // "code": 0,
4011
- // "msg": "",
4012
- // "data": {
4013
- // "orders": [
4014
- // {
4015
- // "symbol": "LINK-USDT",
4016
- // "orderId": 1585839271162413056,
4017
- // "side": "BUY",
4018
- // "positionSide": "LONG",
4019
- // "type": "TRIGGER_MARKET",
4020
- // "origQty": "5.0",
4021
- // "price": "9",
4022
- // "executedQty": "0.0",
4023
- // "avgPrice": "0",
4024
- // "cumQuote": "0",
4025
- // "stopPrice": "5",
4026
- // "profit": "0.0000",
4027
- // "commission": "0.000000",
4028
- // "status": "CANCELLED",
4029
- // "time": 1667631605000,
4030
- // "updateTime": 1667631605000
4031
- // },
4032
- // ]
4033
- // }
4034
- // }
4035
- //
4036
- const data = this.safeValue(response, 'data', []);
4214
+ const data = this.safeDict(response, 'data', {});
4037
4215
  const orders = this.safeList(data, 'orders', []);
4038
4216
  return this.parseOrders(orders, market, since, limit);
4039
4217
  }
@@ -4465,7 +4643,8 @@ class bingx extends bingx$1 {
4465
4643
  * @method
4466
4644
  * @name bingx#setMarginMode
4467
4645
  * @description set margin mode to 'cross' or 'isolated'
4468
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Switch%20Margin%20Mode
4646
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Change%20Margin%20Type
4647
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Set%20Margin%20Type
4469
4648
  * @param {string} marginMode 'cross' or 'isolated'
4470
4649
  * @param {string} symbol unified market symbol
4471
4650
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -4490,7 +4669,14 @@ class bingx extends bingx$1 {
4490
4669
  'symbol': market['id'],
4491
4670
  'marginType': marginMode,
4492
4671
  };
4493
- return await this.swapV2PrivatePostTradeMarginType(this.extend(request, params));
4672
+ let subType = undefined;
4673
+ [subType, params] = this.handleSubTypeAndParams('setMarginMode', market, params);
4674
+ if (subType === 'inverse') {
4675
+ return await this.cswapV1PrivatePostTradeMarginType(this.extend(request, params));
4676
+ }
4677
+ else {
4678
+ return await this.swapV2PrivatePostTradeMarginType(this.extend(request, params));
4679
+ }
4494
4680
  }
4495
4681
  async addMargin(symbol, amount, params = {}) {
4496
4682
  const request = {
@@ -4730,14 +4916,16 @@ class bingx extends bingx$1 {
4730
4916
  * @method
4731
4917
  * @name bingx#fetchMyTrades
4732
4918
  * @description fetch all trades made by the user
4733
- * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20History
4734
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20historical%20transaction%20orders
4919
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20transaction%20details
4920
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20historical%20transaction%20orders
4921
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Order%20Trade%20Detail
4735
4922
  * @param {string} [symbol] unified market symbol
4736
4923
  * @param {int} [since] the earliest time in ms to fetch trades for
4737
4924
  * @param {int} [limit] the maximum number of trades structures to retrieve
4738
4925
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4739
4926
  * @param {int} [params.until] timestamp in ms for the ending date filter, default is undefined
4740
4927
  * @param {string} params.trandingUnit COIN (directly represent assets such as BTC and ETH) or CONT (represents the number of contract sheets)
4928
+ * @param {string} params.orderId the order id required for inverse swap
4741
4929
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
4742
4930
  */
4743
4931
  if (symbol === undefined) {
@@ -4745,84 +4933,121 @@ class bingx extends bingx$1 {
4745
4933
  }
4746
4934
  await this.loadMarkets();
4747
4935
  const market = this.market(symbol);
4748
- const now = this.milliseconds();
4749
- let response = undefined;
4750
- const request = {
4751
- 'symbol': market['id'],
4752
- };
4753
- if (since !== undefined) {
4754
- const startTimeReq = market['spot'] ? 'startTime' : 'startTs';
4755
- request[startTimeReq] = since;
4756
- }
4757
- else if (market['swap']) {
4758
- request['startTs'] = now - 7776000000; // 90 days
4759
- }
4760
- const until = this.safeInteger(params, 'until');
4761
- params = this.omit(params, 'until');
4762
- if (until !== undefined) {
4763
- const endTimeReq = market['spot'] ? 'endTime' : 'endTs';
4764
- request[endTimeReq] = until;
4765
- }
4766
- else if (market['swap']) {
4767
- request['endTs'] = now;
4768
- }
4936
+ const request = {};
4769
4937
  let fills = undefined;
4770
- if (market['spot']) {
4771
- response = await this.spotV1PrivateGetTradeMyTrades(this.extend(request, params));
4772
- const data = this.safeDict(response, 'data', {});
4773
- fills = this.safeList(data, 'fills', []);
4938
+ let response = undefined;
4939
+ let subType = undefined;
4940
+ [subType, params] = this.handleSubTypeAndParams('fetchMyTrades', market, params);
4941
+ if (subType === 'inverse') {
4942
+ const orderId = this.safeString(params, 'orderId');
4943
+ if (orderId === undefined) {
4944
+ throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires an orderId argument for inverse swap trades');
4945
+ }
4946
+ response = await this.cswapV1PrivateGetTradeAllFillOrders(this.extend(request, params));
4947
+ fills = this.safeList(response, 'data', []);
4774
4948
  //
4775
4949
  // {
4776
4950
  // "code": 0,
4777
4951
  // "msg": "",
4778
- // "debugMsg": "",
4779
- // "data": {
4780
- // "fills": [
4781
- // {
4782
- // "symbol": "LTC-USDT",
4783
- // "id": 36237072,
4784
- // "orderId": 1674069326895775744,
4785
- // "price": "85.891",
4786
- // "qty": "0.0582",
4787
- // "quoteQty": "4.9988562000000005",
4788
- // "commission": -0.00005820000000000001,
4789
- // "commissionAsset": "LTC",
4790
- // "time": 1687964205000,
4791
- // "isBuyer": true,
4792
- // "isMaker": false
4793
- // }
4794
- // ]
4795
- // }
4952
+ // "timestamp": 1722147756019,
4953
+ // "data": [
4954
+ // {
4955
+ // "orderId": "1817441228670648320",
4956
+ // "symbol": "SOL-USD",
4957
+ // "type": "MARKET",
4958
+ // "side": "BUY",
4959
+ // "positionSide": "LONG",
4960
+ // "tradeId": "97244554",
4961
+ // "volume": "2",
4962
+ // "tradePrice": "182.652",
4963
+ // "amount": "20.00000000",
4964
+ // "realizedPnl": "0.00000000",
4965
+ // "commission": "-0.00005475",
4966
+ // "currency": "SOL",
4967
+ // "buyer": true,
4968
+ // "maker": false,
4969
+ // "tradeTime": 1722146730000
4970
+ // }
4971
+ // ]
4796
4972
  // }
4797
4973
  //
4798
4974
  }
4799
4975
  else {
4800
- const tradingUnit = this.safeStringUpper(params, 'tradingUnit', 'CONT');
4801
- params = this.omit(params, 'tradingUnit');
4802
- request['tradingUnit'] = tradingUnit;
4803
- response = await this.swapV2PrivateGetTradeAllFillOrders(this.extend(request, params));
4804
- const data = this.safeDict(response, 'data', {});
4805
- fills = this.safeList(data, 'fill_orders', []);
4806
- //
4807
- // {
4808
- // "code": "0",
4809
- // "msg": '',
4810
- // "data": { fill_orders: [
4811
- // {
4812
- // "volume": "0.1",
4813
- // "price": "106.75",
4814
- // "amount": "10.6750",
4815
- // "commission": "-0.0053",
4816
- // "currency": "USDT",
4817
- // "orderId": "1676213270274379776",
4818
- // "liquidatedPrice": "0.00",
4819
- // "liquidatedMarginRatio": "0.00",
4820
- // "filledTime": "2023-07-04T20:56:01.000+0800"
4821
- // }
4822
- // ]
4823
- // }
4824
- // }
4825
- //
4976
+ request['symbol'] = market['id'];
4977
+ const now = this.milliseconds();
4978
+ if (since !== undefined) {
4979
+ const startTimeReq = market['spot'] ? 'startTime' : 'startTs';
4980
+ request[startTimeReq] = since;
4981
+ }
4982
+ else if (market['swap']) {
4983
+ request['startTs'] = now - 7776000000; // 90 days
4984
+ }
4985
+ const until = this.safeInteger(params, 'until');
4986
+ params = this.omit(params, 'until');
4987
+ if (until !== undefined) {
4988
+ const endTimeReq = market['spot'] ? 'endTime' : 'endTs';
4989
+ request[endTimeReq] = until;
4990
+ }
4991
+ else if (market['swap']) {
4992
+ request['endTs'] = now;
4993
+ }
4994
+ if (market['spot']) {
4995
+ response = await this.spotV1PrivateGetTradeMyTrades(this.extend(request, params));
4996
+ const data = this.safeDict(response, 'data', {});
4997
+ fills = this.safeList(data, 'fills', []);
4998
+ //
4999
+ // {
5000
+ // "code": 0,
5001
+ // "msg": "",
5002
+ // "debugMsg": "",
5003
+ // "data": {
5004
+ // "fills": [
5005
+ // {
5006
+ // "symbol": "LTC-USDT",
5007
+ // "id": 36237072,
5008
+ // "orderId": 1674069326895775744,
5009
+ // "price": "85.891",
5010
+ // "qty": "0.0582",
5011
+ // "quoteQty": "4.9988562000000005",
5012
+ // "commission": -0.00005820000000000001,
5013
+ // "commissionAsset": "LTC",
5014
+ // "time": 1687964205000,
5015
+ // "isBuyer": true,
5016
+ // "isMaker": false
5017
+ // }
5018
+ // ]
5019
+ // }
5020
+ // }
5021
+ //
5022
+ }
5023
+ else {
5024
+ const tradingUnit = this.safeStringUpper(params, 'tradingUnit', 'CONT');
5025
+ params = this.omit(params, 'tradingUnit');
5026
+ request['tradingUnit'] = tradingUnit;
5027
+ response = await this.swapV2PrivateGetTradeAllFillOrders(this.extend(request, params));
5028
+ const data = this.safeDict(response, 'data', {});
5029
+ fills = this.safeList(data, 'fill_orders', []);
5030
+ //
5031
+ // {
5032
+ // "code": "0",
5033
+ // "msg": '',
5034
+ // "data": { fill_orders: [
5035
+ // {
5036
+ // "volume": "0.1",
5037
+ // "price": "106.75",
5038
+ // "amount": "10.6750",
5039
+ // "commission": "-0.0053",
5040
+ // "currency": "USDT",
5041
+ // "orderId": "1676213270274379776",
5042
+ // "liquidatedPrice": "0.00",
5043
+ // "liquidatedMarginRatio": "0.00",
5044
+ // "filledTime": "2023-07-04T20:56:01.000+0800"
5045
+ // }
5046
+ // ]
5047
+ // }
5048
+ // }
5049
+ //
5050
+ }
4826
5051
  }
4827
5052
  return this.parseTrades(fills, market, since, limit, params);
4828
5053
  }
@@ -5449,7 +5674,8 @@ class bingx extends bingx$1 {
5449
5674
  * @method
5450
5675
  * @name bingx#fetchMarginMode
5451
5676
  * @description fetches the margin mode of the trading pair
5452
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Margin%20Mode
5677
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Margin%20Type
5678
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Margin%20Type
5453
5679
  * @param {string} symbol unified symbol of the market to fetch the margin mode for
5454
5680
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5455
5681
  * @returns {object} a [margin mode structure]{@link https://docs.ccxt.com/#/?id=margin-mode-structure}
@@ -5459,25 +5685,45 @@ class bingx extends bingx$1 {
5459
5685
  const request = {
5460
5686
  'symbol': market['id'],
5461
5687
  };
5462
- const response = await this.swapV2PrivateGetTradeMarginType(this.extend(request, params));
5463
- //
5464
- // {
5465
- // "code": 0,
5466
- // "msg": "",
5467
- // "data": {
5468
- // "marginType": "CROSSED"
5469
- // }
5470
- // }
5471
- //
5688
+ let subType = undefined;
5689
+ let response = undefined;
5690
+ [subType, params] = this.handleSubTypeAndParams('fetchMarginMode', market, params);
5691
+ if (subType === 'inverse') {
5692
+ response = await this.cswapV1PrivateGetTradeMarginType(this.extend(request, params));
5693
+ //
5694
+ // {
5695
+ // "code": 0,
5696
+ // "msg": "",
5697
+ // "timestamp": 1721966069132,
5698
+ // "data": {
5699
+ // "symbol": "SOL-USD",
5700
+ // "marginType": "CROSSED"
5701
+ // }
5702
+ // }
5703
+ //
5704
+ }
5705
+ else {
5706
+ response = await this.swapV2PrivateGetTradeMarginType(this.extend(request, params));
5707
+ //
5708
+ // {
5709
+ // "code": 0,
5710
+ // "msg": "",
5711
+ // "data": {
5712
+ // "marginType": "CROSSED"
5713
+ // }
5714
+ // }
5715
+ //
5716
+ }
5472
5717
  const data = this.safeDict(response, 'data', {});
5473
5718
  return this.parseMarginMode(data, market);
5474
5719
  }
5475
5720
  parseMarginMode(marginMode, market = undefined) {
5721
+ const marketId = this.safeString(marginMode, 'symbol');
5476
5722
  let marginType = this.safeStringLower(marginMode, 'marginType');
5477
5723
  marginType = (marginType === 'crossed') ? 'cross' : marginType;
5478
5724
  return {
5479
5725
  'info': marginMode,
5480
- 'symbol': market['symbol'],
5726
+ 'symbol': this.safeSymbol(marketId, market, '-', 'swap'),
5481
5727
  'marginMode': marginType,
5482
5728
  };
5483
5729
  }