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