ccxt 4.3.66 → 4.3.68

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 (55) hide show
  1. package/README.md +3 -3
  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 +6 -4
  5. package/dist/cjs/src/base/functions/type.js +2 -2
  6. package/dist/cjs/src/bingx.js +478 -159
  7. package/dist/cjs/src/bitget.js +4 -2
  8. package/dist/cjs/src/bithumb.js +61 -17
  9. package/dist/cjs/src/pro/krakenfutures.js +7 -6
  10. package/dist/cjs/src/pro/okx.js +17 -4
  11. package/js/ccxt.d.ts +1 -1
  12. package/js/ccxt.js +1 -1
  13. package/js/src/abstract/bingx.d.ts +7 -0
  14. package/js/src/base/Exchange.d.ts +14 -13
  15. package/js/src/base/Exchange.js +6 -4
  16. package/js/src/base/functions/type.js +2 -2
  17. package/js/src/bingx.d.ts +2 -0
  18. package/js/src/bingx.js +478 -159
  19. package/js/src/bitget.js +4 -2
  20. package/js/src/bithumb.js +61 -17
  21. package/js/src/pro/bitget.d.ts +1 -1
  22. package/js/src/pro/bybit.d.ts +1 -1
  23. package/js/src/pro/coinone.d.ts +1 -1
  24. package/js/src/pro/currencycom.d.ts +1 -1
  25. package/js/src/pro/hollaex.d.ts +1 -1
  26. package/js/src/pro/hyperliquid.d.ts +1 -1
  27. package/js/src/pro/krakenfutures.js +7 -6
  28. package/js/src/pro/kucoin.d.ts +1 -1
  29. package/js/src/pro/kucoinfutures.d.ts +1 -1
  30. package/js/src/pro/mexc.d.ts +1 -1
  31. package/js/src/pro/okcoin.d.ts +1 -1
  32. package/js/src/pro/okx.d.ts +2 -2
  33. package/js/src/pro/okx.js +18 -5
  34. package/js/src/pro/oxfun.d.ts +1 -1
  35. package/js/src/pro/p2b.d.ts +1 -1
  36. package/js/src/pro/poloniex.d.ts +1 -1
  37. package/js/src/pro/whitebit.d.ts +1 -1
  38. package/package.json +1 -1
  39. package/dist/cjs/src/abstract/bittrex.js +0 -9
  40. package/dist/cjs/src/bittrex.js +0 -2308
  41. package/dist/cjs/src/pro/bittrex.js +0 -959
  42. package/js/src/bittrex.d.ts +0 -97
  43. package/js/src/bittrex.js +0 -2309
  44. package/js/src/coinbaseprime.d.ts +0 -4
  45. package/js/src/coinbaseprime.js +0 -32
  46. package/js/src/pro/bittrex.d.ts +0 -69
  47. package/js/src/pro/bittrex.js +0 -960
  48. package/js/src/pro/coinbaseprime.d.ts +0 -4
  49. package/js/src/pro/coinbaseprime.js +0 -33
  50. package/js/src/pro/huobipro.d.ts +0 -4
  51. package/js/src/pro/huobipro.js +0 -17
  52. package/js/src/pro/mexc3.d.ts +0 -4
  53. package/js/src/pro/mexc3.js +0 -17
  54. package/js/src/pro/okex.d.ts +0 -4
  55. 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,
@@ -286,6 +287,10 @@ export default class bingx extends Exchange {
286
287
  'trade/leverage': 2,
287
288
  'trade/forceOrders': 2,
288
289
  'trade/allFillOrders': 2,
290
+ 'trade/openOrders': 2,
291
+ 'trade/orderDetail': 2,
292
+ 'trade/orderHistory': 2,
293
+ 'trade/marginType': 2,
289
294
  'user/commissionRate': 2,
290
295
  'user/positions': 2,
291
296
  'user/balance': 2,
@@ -294,9 +299,12 @@ export default class bingx extends Exchange {
294
299
  'trade/order': 2,
295
300
  'trade/leverage': 2,
296
301
  'trade/closeAllPositions': 2,
302
+ 'trade/marginType': 2,
303
+ 'trade/positionMargin': 2,
297
304
  },
298
305
  'delete': {
299
306
  'trade/allOpenOrders': 2,
307
+ 'trade/cancelOrder': 2,
300
308
  },
301
309
  },
302
310
  },
@@ -3007,7 +3015,7 @@ export default class bingx extends Exchange {
3007
3015
  // "clientOrderID": ""
3008
3016
  // }
3009
3017
  //
3010
- // inverse swap cancelAllOrders
3018
+ // inverse swap cancelAllOrders, cancelOrder, fetchOrder, fetchOpenOrders, fetchClosedOrders, fetchCanceledOrders
3011
3019
  //
3012
3020
  // {
3013
3021
  // "symbol": "SOL-USD",
@@ -3067,7 +3075,7 @@ export default class bingx extends Exchange {
3067
3075
  const side = this.safeStringLower2(order, 'side', 'S');
3068
3076
  const timestamp = this.safeIntegerN(order, ['time', 'transactTime', 'E']);
3069
3077
  const lastTradeTimestamp = this.safeInteger2(order, 'updateTime', 'T');
3070
- const statusId = this.safeString2(order, 'status', 'X');
3078
+ const statusId = this.safeStringUpper2(order, 'status', 'X');
3071
3079
  let feeCurrencyCode = this.safeString2(order, 'feeAsset', 'N');
3072
3080
  const feeCost = this.safeStringN(order, ['fee', 'commission', 'n']);
3073
3081
  if ((feeCurrencyCode === undefined)) {
@@ -3169,13 +3177,14 @@ export default class bingx extends Exchange {
3169
3177
  * @method
3170
3178
  * @name bingx#cancelOrder
3171
3179
  * @description cancels an open order
3172
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Cancel%20an%20Order
3173
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Cancel%20an%20Order
3180
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Cancel%20Order
3181
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Cancel%20Order
3182
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Cancel%20an%20Order
3174
3183
  * @param {string} id order id
3175
3184
  * @param {string} symbol unified symbol of the market the order was made in
3176
3185
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3177
3186
  * @param {string} [params.clientOrderId] a unique id for the order
3178
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3187
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3179
3188
  */
3180
3189
  if (symbol === undefined) {
3181
3190
  throw new ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
@@ -3194,12 +3203,20 @@ export default class bingx extends Exchange {
3194
3203
  request['orderId'] = id;
3195
3204
  }
3196
3205
  let response = undefined;
3197
- const [marketType, query] = this.handleMarketTypeAndParams('cancelOrder', market, params);
3198
- if (marketType === 'spot') {
3199
- response = await this.spotV1PrivatePostTradeCancel(this.extend(request, query));
3206
+ let type = undefined;
3207
+ let subType = undefined;
3208
+ [type, params] = this.handleMarketTypeAndParams('cancelOrder', market, params);
3209
+ [subType, params] = this.handleSubTypeAndParams('cancelOrder', market, params);
3210
+ if (type === 'spot') {
3211
+ response = await this.spotV1PrivatePostTradeCancel(this.extend(request, params));
3200
3212
  }
3201
3213
  else {
3202
- response = await this.swapV2PrivateDeleteTradeOrder(this.extend(request, query));
3214
+ if (subType === 'inverse') {
3215
+ response = await this.cswapV1PrivateDeleteTradeCancelOrder(this.extend(request, params));
3216
+ }
3217
+ else {
3218
+ response = await this.swapV2PrivateDeleteTradeOrder(this.extend(request, params));
3219
+ }
3203
3220
  }
3204
3221
  //
3205
3222
  // spot
@@ -3220,7 +3237,59 @@ export default class bingx extends Exchange {
3220
3237
  // }
3221
3238
  // }
3222
3239
  //
3223
- // swap
3240
+ // inverse swap
3241
+ //
3242
+ // {
3243
+ // "code": 0,
3244
+ // "msg": "",
3245
+ // "data": {
3246
+ // "order": {
3247
+ // "symbol": "SOL-USD",
3248
+ // "orderId": "1816002957423951872",
3249
+ // "side": "BUY",
3250
+ // "positionSide": "Long",
3251
+ // "type": "Pending",
3252
+ // "quantity": 0,
3253
+ // "origQty": "0",
3254
+ // "price": "150",
3255
+ // "executedQty": "0",
3256
+ // "avgPrice": "0",
3257
+ // "cumQuote": "0",
3258
+ // "stopPrice": "",
3259
+ // "profit": "0.0000",
3260
+ // "commission": "0.000000",
3261
+ // "status": "CANCELLED",
3262
+ // "time": 1721803819410,
3263
+ // "updateTime": 1721803819427,
3264
+ // "clientOrderId": "",
3265
+ // "leverage": "",
3266
+ // "takeProfit": {
3267
+ // "type": "",
3268
+ // "quantity": 0,
3269
+ // "stopPrice": 0,
3270
+ // "price": 0,
3271
+ // "workingType": "",
3272
+ // "stopGuaranteed": ""
3273
+ // },
3274
+ // "stopLoss": {
3275
+ // "type": "",
3276
+ // "quantity": 0,
3277
+ // "stopPrice": 0,
3278
+ // "price": 0,
3279
+ // "workingType": "",
3280
+ // "stopGuaranteed": ""
3281
+ // },
3282
+ // "advanceAttr": 0,
3283
+ // "positionID": 0,
3284
+ // "takeProfitEntrustPrice": 0,
3285
+ // "stopLossEntrustPrice": 0,
3286
+ // "orderType": "",
3287
+ // "workingType": ""
3288
+ // }
3289
+ // }
3290
+ // }
3291
+ //
3292
+ // linear swap
3224
3293
  //
3225
3294
  // {
3226
3295
  // "code": 0,
@@ -3247,9 +3316,9 @@ export default class bingx extends Exchange {
3247
3316
  // }
3248
3317
  // }
3249
3318
  //
3250
- const data = this.safeValue(response, 'data');
3251
- const first = this.safeDict(data, 'order', data);
3252
- return this.parseOrder(first, market);
3319
+ const data = this.safeDict(response, 'data', {});
3320
+ const order = this.safeDict(data, 'order', data);
3321
+ return this.parseOrder(order, market);
3253
3322
  }
3254
3323
  async cancelAllOrders(symbol = undefined, params = {}) {
3255
3324
  /**
@@ -3552,11 +3621,12 @@ export default class bingx extends Exchange {
3552
3621
  * @method
3553
3622
  * @name bingx#fetchOrder
3554
3623
  * @description fetches information on an order made by the user
3555
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Orders
3556
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20Order
3624
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20details
3625
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20details
3626
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Order
3557
3627
  * @param {string} symbol unified symbol of the market the order was made in
3558
3628
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3559
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3629
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3560
3630
  */
3561
3631
  if (symbol === undefined) {
3562
3632
  throw new ArgumentsRequired(this.id + ' fetchOrder() requires a symbol argument');
@@ -3567,68 +3637,124 @@ export default class bingx extends Exchange {
3567
3637
  'symbol': market['id'],
3568
3638
  'orderId': id,
3569
3639
  };
3640
+ let type = undefined;
3641
+ let subType = undefined;
3570
3642
  let response = undefined;
3571
- const [marketType, query] = this.handleMarketTypeAndParams('fetchOrder', market, params);
3572
- if (marketType === 'spot') {
3573
- response = await this.spotV1PrivateGetTradeQuery(this.extend(request, query));
3643
+ [type, params] = this.handleMarketTypeAndParams('fetchOrder', market, params);
3644
+ [subType, params] = this.handleSubTypeAndParams('fetchOrder', market, params);
3645
+ if (type === 'spot') {
3646
+ response = await this.spotV1PrivateGetTradeQuery(this.extend(request, params));
3647
+ //
3648
+ // {
3649
+ // "code": 0,
3650
+ // "msg": "",
3651
+ // "data": {
3652
+ // "symbol": "XRP-USDT",
3653
+ // "orderId": 1514087361158316032,
3654
+ // "price": "0.5",
3655
+ // "origQty": "10",
3656
+ // "executedQty": "0",
3657
+ // "cummulativeQuoteQty": "0",
3658
+ // "status": "CANCELED",
3659
+ // "type": "LIMIT",
3660
+ // "side": "BUY",
3661
+ // "time": 1649821532000,
3662
+ // "updateTime": 1649821543000,
3663
+ // "origQuoteOrderQty": "0",
3664
+ // "fee": "0",
3665
+ // "feeAsset": "XRP"
3666
+ // }
3667
+ // }
3668
+ //
3574
3669
  }
3575
3670
  else {
3576
- response = await this.swapV2PrivateGetTradeOrder(this.extend(request, query));
3671
+ if (subType === 'inverse') {
3672
+ response = await this.cswapV1PrivateGetTradeOrderDetail(this.extend(request, params));
3673
+ //
3674
+ // {
3675
+ // "code": 0,
3676
+ // "msg": "",
3677
+ // "data": {
3678
+ // "order": {
3679
+ // "symbol": "SOL-USD",
3680
+ // "orderId": "1816342420721254400",
3681
+ // "side": "BUY",
3682
+ // "positionSide": "Long",
3683
+ // "type": "LIMIT",
3684
+ // "quantity": 1,
3685
+ // "origQty": "",
3686
+ // "price": "150",
3687
+ // "executedQty": "0",
3688
+ // "avgPrice": "0.000",
3689
+ // "cumQuote": "",
3690
+ // "stopPrice": "",
3691
+ // "profit": "0.0000",
3692
+ // "commission": "0.0000",
3693
+ // "status": "Pending",
3694
+ // "time": 1721884753767,
3695
+ // "updateTime": 1721884753786,
3696
+ // "clientOrderId": "",
3697
+ // "leverage": "",
3698
+ // "takeProfit": {
3699
+ // "type": "TAKE_PROFIT",
3700
+ // "quantity": 0,
3701
+ // "stopPrice": 0,
3702
+ // "price": 0,
3703
+ // "workingType": "MARK_PRICE",
3704
+ // "stopGuaranteed": ""
3705
+ // },
3706
+ // "stopLoss": {
3707
+ // "type": "STOP",
3708
+ // "quantity": 0,
3709
+ // "stopPrice": 0,
3710
+ // "price": 0,
3711
+ // "workingType": "MARK_PRICE",
3712
+ // "stopGuaranteed": ""
3713
+ // },
3714
+ // "advanceAttr": 0,
3715
+ // "positionID": 0,
3716
+ // "takeProfitEntrustPrice": 0,
3717
+ // "stopLossEntrustPrice": 0,
3718
+ // "orderType": "",
3719
+ // "workingType": "MARK_PRICE"
3720
+ // }
3721
+ // }
3722
+ // }
3723
+ //
3724
+ }
3725
+ else {
3726
+ response = await this.swapV2PrivateGetTradeOrder(this.extend(request, params));
3727
+ //
3728
+ // {
3729
+ // "code": 0,
3730
+ // "msg": "",
3731
+ // "data": {
3732
+ // "order": {
3733
+ // "symbol": "BTC-USDT",
3734
+ // "orderId": 1597597642269917184,
3735
+ // "side": "SELL",
3736
+ // "positionSide": "LONG",
3737
+ // "type": "TAKE_PROFIT_MARKET",
3738
+ // "origQty": "1.0000",
3739
+ // "price": "0.0",
3740
+ // "executedQty": "0.0000",
3741
+ // "avgPrice": "0.0",
3742
+ // "cumQuote": "",
3743
+ // "stopPrice": "16494.0",
3744
+ // "profit": "",
3745
+ // "commission": "",
3746
+ // "status": "FILLED",
3747
+ // "time": 1669731935000,
3748
+ // "updateTime": 1669752524000
3749
+ // }
3750
+ // }
3751
+ // }
3752
+ //
3753
+ }
3577
3754
  }
3578
- //
3579
- // spot
3580
- //
3581
- // {
3582
- // "code": 0,
3583
- // "msg": "",
3584
- // "data": {
3585
- // "symbol": "XRP-USDT",
3586
- // "orderId": 1514087361158316032,
3587
- // "price": "0.5",
3588
- // "origQty": "10",
3589
- // "executedQty": "0",
3590
- // "cummulativeQuoteQty": "0",
3591
- // "status": "CANCELED",
3592
- // "type": "LIMIT",
3593
- // "side": "BUY",
3594
- // "time": 1649821532000,
3595
- // "updateTime": 1649821543000,
3596
- // "origQuoteOrderQty": "0",
3597
- // "fee": "0",
3598
- // "feeAsset": "XRP"
3599
- // }
3600
- // }
3601
- //
3602
- // swap
3603
- //
3604
- // {
3605
- // "code": 0,
3606
- // "msg": "",
3607
- // "data": {
3608
- // "order": {
3609
- // "symbol": "BTC-USDT",
3610
- // "orderId": 1597597642269917184,
3611
- // "side": "SELL",
3612
- // "positionSide": "LONG",
3613
- // "type": "TAKE_PROFIT_MARKET",
3614
- // "origQty": "1.0000",
3615
- // "price": "0.0",
3616
- // "executedQty": "0.0000",
3617
- // "avgPrice": "0.0",
3618
- // "cumQuote": "",
3619
- // "stopPrice": "16494.0",
3620
- // "profit": "",
3621
- // "commission": "",
3622
- // "status": "FILLED",
3623
- // "time": 1669731935000,
3624
- // "updateTime": 1669752524000
3625
- // }
3626
- // }
3627
- // }
3628
- //
3629
- const data = this.safeValue(response, 'data');
3630
- const first = this.safeDict(data, 'order', data);
3631
- return this.parseOrder(first, market);
3755
+ const data = this.safeDict(response, 'data', {});
3756
+ const order = this.safeDict(data, 'order', data);
3757
+ return this.parseOrder(order, market);
3632
3758
  }
3633
3759
  async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3634
3760
  /**
@@ -3729,9 +3855,10 @@ export default class bingx extends Exchange {
3729
3855
  /**
3730
3856
  * @method
3731
3857
  * @name bingx#fetchOpenOrders
3732
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Open%20Orders
3733
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20all%20current%20pending%20orders
3734
3858
  * @description fetch all unfilled currently open orders
3859
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Current%20Open%20Orders
3860
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Current%20All%20Open%20Orders
3861
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20all%20current%20pending%20orders
3735
3862
  * @param {string} symbol unified market symbol
3736
3863
  * @param {int} [since] the earliest time in ms to fetch open orders for
3737
3864
  * @param {int} [limit] the maximum number of open order structures to retrieve
@@ -3745,13 +3872,21 @@ export default class bingx extends Exchange {
3745
3872
  market = this.market(symbol);
3746
3873
  request['symbol'] = market['id'];
3747
3874
  }
3875
+ let type = undefined;
3876
+ let subType = undefined;
3748
3877
  let response = undefined;
3749
- const [marketType, query] = this.handleMarketTypeAndParams('fetchOpenOrders', market, params);
3750
- if (marketType === 'spot') {
3751
- response = await this.spotV1PrivateGetTradeOpenOrders(this.extend(request, query));
3878
+ [type, params] = this.handleMarketTypeAndParams('fetchOpenOrders', market, params);
3879
+ [subType, params] = this.handleSubTypeAndParams('fetchOpenOrders', market, params);
3880
+ if (type === 'spot') {
3881
+ response = await this.spotV1PrivateGetTradeOpenOrders(this.extend(request, params));
3752
3882
  }
3753
3883
  else {
3754
- response = await this.swapV2PrivateGetTradeOpenOrders(this.extend(request, query));
3884
+ if (subType === 'inverse') {
3885
+ response = await this.cswapV1PrivateGetTradeOpenOrders(this.extend(request, params));
3886
+ }
3887
+ else {
3888
+ response = await this.swapV2PrivateGetTradeOpenOrders(this.extend(request, params));
3889
+ }
3755
3890
  }
3756
3891
  //
3757
3892
  // spot
@@ -3779,7 +3914,61 @@ export default class bingx extends Exchange {
3779
3914
  // }
3780
3915
  // }
3781
3916
  //
3782
- // swap
3917
+ // inverse swap
3918
+ //
3919
+ // {
3920
+ // "code": 0,
3921
+ // "msg": "",
3922
+ // "data": {
3923
+ // "orders": [
3924
+ // {
3925
+ // "symbol": "SOL-USD",
3926
+ // "orderId": "1816013900044320768",
3927
+ // "side": "BUY",
3928
+ // "positionSide": "Long",
3929
+ // "type": "LIMIT",
3930
+ // "quantity": 1,
3931
+ // "origQty": "",
3932
+ // "price": "150",
3933
+ // "executedQty": "0",
3934
+ // "avgPrice": "0.000",
3935
+ // "cumQuote": "",
3936
+ // "stopPrice": "",
3937
+ // "profit": "0.0000",
3938
+ // "commission": "0.0000",
3939
+ // "status": "Pending",
3940
+ // "time": 1721806428334,
3941
+ // "updateTime": 1721806428352,
3942
+ // "clientOrderId": "",
3943
+ // "leverage": "",
3944
+ // "takeProfit": {
3945
+ // "type": "TAKE_PROFIT",
3946
+ // "quantity": 0,
3947
+ // "stopPrice": 0,
3948
+ // "price": 0,
3949
+ // "workingType": "MARK_PRICE",
3950
+ // "stopGuaranteed": ""
3951
+ // },
3952
+ // "stopLoss": {
3953
+ // "type": "STOP",
3954
+ // "quantity": 0,
3955
+ // "stopPrice": 0,
3956
+ // "price": 0,
3957
+ // "workingType": "MARK_PRICE",
3958
+ // "stopGuaranteed": ""
3959
+ // },
3960
+ // "advanceAttr": 0,
3961
+ // "positionID": 0,
3962
+ // "takeProfitEntrustPrice": 0,
3963
+ // "stopLossEntrustPrice": 0,
3964
+ // "orderType": "",
3965
+ // "workingType": "MARK_PRICE"
3966
+ // }
3967
+ // ]
3968
+ // }
3969
+ // }
3970
+ //
3971
+ // linear swap
3783
3972
  //
3784
3973
  // {
3785
3974
  // "code": 0,
@@ -3817,8 +4006,51 @@ export default class bingx extends Exchange {
3817
4006
  * @method
3818
4007
  * @name bingx#fetchClosedOrders
3819
4008
  * @description fetches information on multiple closed orders made by the user
3820
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Order%20History
3821
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#User's%20Force%20Orders
4009
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
4010
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
4011
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
4012
+ * @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
4013
+ * @param {string} symbol unified market symbol of the closed orders
4014
+ * @param {int} [since] timestamp in ms of the earliest order
4015
+ * @param {int} [limit] the max number of closed orders to return
4016
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4017
+ * @param {int} [params.until] the latest time in ms to fetch orders for
4018
+ * @param {boolean} [params.standard] whether to fetch standard contract orders
4019
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
4020
+ */
4021
+ await this.loadMarkets();
4022
+ const orders = await this.fetchCanceledAndClosedOrders(symbol, since, limit, params);
4023
+ return this.filterBy(orders, 'status', 'closed');
4024
+ }
4025
+ async fetchCanceledOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
4026
+ /**
4027
+ * @method
4028
+ * @name bingx#fetchCanceledOrders
4029
+ * @description fetches information on multiple canceled orders made by the user
4030
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
4031
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
4032
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
4033
+ * @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
4034
+ * @param {string} symbol unified market symbol of the canceled orders
4035
+ * @param {int} [since] timestamp in ms of the earliest order
4036
+ * @param {int} [limit] the max number of canceled orders to return
4037
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4038
+ * @param {int} [params.until] the latest time in ms to fetch orders for
4039
+ * @param {boolean} [params.standard] whether to fetch standard contract orders
4040
+ * @returns {object} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
4041
+ */
4042
+ await this.loadMarkets();
4043
+ const orders = await this.fetchCanceledAndClosedOrders(symbol, since, limit, params);
4044
+ return this.filterBy(orders, 'status', 'canceled');
4045
+ }
4046
+ async fetchCanceledAndClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
4047
+ /**
4048
+ * @method
4049
+ * @name bingx#fetchCanceledAndClosedOrders
4050
+ * @description fetches information on multiple closed orders made by the user
4051
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
4052
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
4053
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
3822
4054
  * @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
3823
4055
  * @param {string} [symbol] unified market symbol of the market orders were made in
3824
4056
  * @param {int} [since] the earliest time in ms to fetch orders for
@@ -3836,75 +4068,133 @@ export default class bingx extends Exchange {
3836
4068
  const request = {
3837
4069
  'symbol': market['id'],
3838
4070
  };
3839
- let response = undefined;
4071
+ let type = undefined;
4072
+ let subType = undefined;
3840
4073
  let standard = undefined;
4074
+ let response = undefined;
4075
+ [type, params] = this.handleMarketTypeAndParams('fetchClosedOrders', market, params);
4076
+ [subType, params] = this.handleSubTypeAndParams('fetchClosedOrders', market, params);
3841
4077
  [standard, params] = this.handleOptionAndParams(params, 'fetchClosedOrders', 'standard', false);
3842
- const [marketType, query] = this.handleMarketTypeAndParams('fetchClosedOrders', market, params);
3843
4078
  if (standard) {
3844
- response = await this.contractV1PrivateGetAllOrders(this.extend(request, query));
4079
+ response = await this.contractV1PrivateGetAllOrders(this.extend(request, params));
3845
4080
  }
3846
- else if (marketType === 'spot') {
3847
- response = await this.spotV1PrivateGetTradeHistoryOrders(this.extend(request, query));
4081
+ else if (type === 'spot') {
4082
+ response = await this.spotV1PrivateGetTradeHistoryOrders(this.extend(request, params));
4083
+ //
4084
+ // {
4085
+ // "code": 0,
4086
+ // "msg": "",
4087
+ // "data": {
4088
+ // "orders": [
4089
+ // {
4090
+ // "symbol": "XRP-USDT",
4091
+ // "orderId": 1514073325788200960,
4092
+ // "price": "0.5",
4093
+ // "origQty": "20",
4094
+ // "executedQty": "0",
4095
+ // "cummulativeQuoteQty": "0",
4096
+ // "status": "PENDING",
4097
+ // "type": "LIMIT",
4098
+ // "side": "BUY",
4099
+ // "time": 1649818185647,
4100
+ // "updateTime": 1649818185647,
4101
+ // "origQuoteOrderQty": "0"
4102
+ // }
4103
+ // ]
4104
+ // }
4105
+ // }
4106
+ //
3848
4107
  }
3849
4108
  else {
3850
- response = await this.swapV2PrivateGetTradeAllOrders(this.extend(request, query));
4109
+ if (subType === 'inverse') {
4110
+ response = await this.cswapV1PrivateGetTradeOrderHistory(this.extend(request, params));
4111
+ //
4112
+ // {
4113
+ // "code": 0,
4114
+ // "msg": "",
4115
+ // "data": {
4116
+ // "orders": [
4117
+ // {
4118
+ // "symbol": "SOL-USD",
4119
+ // "orderId": "1816002957423951872",
4120
+ // "side": "BUY",
4121
+ // "positionSide": "LONG",
4122
+ // "type": "LIMIT",
4123
+ // "quantity": 1,
4124
+ // "origQty": "10.00000000",
4125
+ // "price": "150.000",
4126
+ // "executedQty": "0.00000000",
4127
+ // "avgPrice": "0.000",
4128
+ // "cumQuote": "",
4129
+ // "stopPrice": "0.000",
4130
+ // "profit": "0.0000",
4131
+ // "commission": "0.000000",
4132
+ // "status": "Filled",
4133
+ // "time": 1721803819000,
4134
+ // "updateTime": 1721803856000,
4135
+ // "clientOrderId": "",
4136
+ // "leverage": "",
4137
+ // "takeProfit": {
4138
+ // "type": "",
4139
+ // "quantity": 0,
4140
+ // "stopPrice": 0,
4141
+ // "price": 0,
4142
+ // "workingType": "",
4143
+ // "stopGuaranteed": ""
4144
+ // },
4145
+ // "stopLoss": {
4146
+ // "type": "",
4147
+ // "quantity": 0,
4148
+ // "stopPrice": 0,
4149
+ // "price": 0,
4150
+ // "workingType": "",
4151
+ // "stopGuaranteed": ""
4152
+ // },
4153
+ // "advanceAttr": 0,
4154
+ // "positionID": 0,
4155
+ // "takeProfitEntrustPrice": 0,
4156
+ // "stopLossEntrustPrice": 0,
4157
+ // "orderType": "",
4158
+ // "workingType": "MARK_PRICE"
4159
+ // },
4160
+ // ]
4161
+ // }
4162
+ // }
4163
+ //
4164
+ }
4165
+ else {
4166
+ response = await this.swapV2PrivateGetTradeAllOrders(this.extend(request, params));
4167
+ //
4168
+ // {
4169
+ // "code": 0,
4170
+ // "msg": "",
4171
+ // "data": {
4172
+ // "orders": [
4173
+ // {
4174
+ // "symbol": "LINK-USDT",
4175
+ // "orderId": 1585839271162413056,
4176
+ // "side": "BUY",
4177
+ // "positionSide": "LONG",
4178
+ // "type": "TRIGGER_MARKET",
4179
+ // "origQty": "5.0",
4180
+ // "price": "9",
4181
+ // "executedQty": "0.0",
4182
+ // "avgPrice": "0",
4183
+ // "cumQuote": "0",
4184
+ // "stopPrice": "5",
4185
+ // "profit": "0.0000",
4186
+ // "commission": "0.000000",
4187
+ // "status": "CANCELLED",
4188
+ // "time": 1667631605000,
4189
+ // "updateTime": 1667631605000
4190
+ // },
4191
+ // ]
4192
+ // }
4193
+ // }
4194
+ //
4195
+ }
3851
4196
  }
3852
- //
3853
- // spot
3854
- //
3855
- // {
3856
- // "code": 0,
3857
- // "msg": "",
3858
- // "data": {
3859
- // "orders": [
3860
- // {
3861
- // "symbol": "XRP-USDT",
3862
- // "orderId": 1514073325788200960,
3863
- // "price": "0.5",
3864
- // "origQty": "20",
3865
- // "executedQty": "0",
3866
- // "cummulativeQuoteQty": "0",
3867
- // "status": "PENDING",
3868
- // "type": "LIMIT",
3869
- // "side": "BUY",
3870
- // "time": 1649818185647,
3871
- // "updateTime": 1649818185647,
3872
- // "origQuoteOrderQty": "0"
3873
- // }
3874
- // ]
3875
- // }
3876
- // }
3877
- //
3878
- // swap
3879
- //
3880
- // {
3881
- // "code": 0,
3882
- // "msg": "",
3883
- // "data": {
3884
- // "orders": [
3885
- // {
3886
- // "symbol": "LINK-USDT",
3887
- // "orderId": 1585839271162413056,
3888
- // "side": "BUY",
3889
- // "positionSide": "LONG",
3890
- // "type": "TRIGGER_MARKET",
3891
- // "origQty": "5.0",
3892
- // "price": "9",
3893
- // "executedQty": "0.0",
3894
- // "avgPrice": "0",
3895
- // "cumQuote": "0",
3896
- // "stopPrice": "5",
3897
- // "profit": "0.0000",
3898
- // "commission": "0.000000",
3899
- // "status": "CANCELLED",
3900
- // "time": 1667631605000,
3901
- // "updateTime": 1667631605000
3902
- // },
3903
- // ]
3904
- // }
3905
- // }
3906
- //
3907
- const data = this.safeValue(response, 'data', []);
4197
+ const data = this.safeDict(response, 'data', {});
3908
4198
  const orders = this.safeList(data, 'orders', []);
3909
4199
  return this.parseOrders(orders, market, since, limit);
3910
4200
  }
@@ -4336,7 +4626,8 @@ export default class bingx extends Exchange {
4336
4626
  * @method
4337
4627
  * @name bingx#setMarginMode
4338
4628
  * @description set margin mode to 'cross' or 'isolated'
4339
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Switch%20Margin%20Mode
4629
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Change%20Margin%20Type
4630
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Set%20Margin%20Type
4340
4631
  * @param {string} marginMode 'cross' or 'isolated'
4341
4632
  * @param {string} symbol unified market symbol
4342
4633
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -4361,7 +4652,14 @@ export default class bingx extends Exchange {
4361
4652
  'symbol': market['id'],
4362
4653
  'marginType': marginMode,
4363
4654
  };
4364
- return await this.swapV2PrivatePostTradeMarginType(this.extend(request, params));
4655
+ let subType = undefined;
4656
+ [subType, params] = this.handleSubTypeAndParams('setMarginMode', market, params);
4657
+ if (subType === 'inverse') {
4658
+ return await this.cswapV1PrivatePostTradeMarginType(this.extend(request, params));
4659
+ }
4660
+ else {
4661
+ return await this.swapV2PrivatePostTradeMarginType(this.extend(request, params));
4662
+ }
4365
4663
  }
4366
4664
  async addMargin(symbol, amount, params = {}) {
4367
4665
  const request = {
@@ -5320,7 +5618,8 @@ export default class bingx extends Exchange {
5320
5618
  * @method
5321
5619
  * @name bingx#fetchMarginMode
5322
5620
  * @description fetches the margin mode of the trading pair
5323
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Margin%20Mode
5621
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Margin%20Type
5622
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Margin%20Type
5324
5623
  * @param {string} symbol unified symbol of the market to fetch the margin mode for
5325
5624
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5326
5625
  * @returns {object} a [margin mode structure]{@link https://docs.ccxt.com/#/?id=margin-mode-structure}
@@ -5330,25 +5629,45 @@ export default class bingx extends Exchange {
5330
5629
  const request = {
5331
5630
  'symbol': market['id'],
5332
5631
  };
5333
- const response = await this.swapV2PrivateGetTradeMarginType(this.extend(request, params));
5334
- //
5335
- // {
5336
- // "code": 0,
5337
- // "msg": "",
5338
- // "data": {
5339
- // "marginType": "CROSSED"
5340
- // }
5341
- // }
5342
- //
5632
+ let subType = undefined;
5633
+ let response = undefined;
5634
+ [subType, params] = this.handleSubTypeAndParams('fetchMarginMode', market, params);
5635
+ if (subType === 'inverse') {
5636
+ response = await this.cswapV1PrivateGetTradeMarginType(this.extend(request, params));
5637
+ //
5638
+ // {
5639
+ // "code": 0,
5640
+ // "msg": "",
5641
+ // "timestamp": 1721966069132,
5642
+ // "data": {
5643
+ // "symbol": "SOL-USD",
5644
+ // "marginType": "CROSSED"
5645
+ // }
5646
+ // }
5647
+ //
5648
+ }
5649
+ else {
5650
+ response = await this.swapV2PrivateGetTradeMarginType(this.extend(request, params));
5651
+ //
5652
+ // {
5653
+ // "code": 0,
5654
+ // "msg": "",
5655
+ // "data": {
5656
+ // "marginType": "CROSSED"
5657
+ // }
5658
+ // }
5659
+ //
5660
+ }
5343
5661
  const data = this.safeDict(response, 'data', {});
5344
5662
  return this.parseMarginMode(data, market);
5345
5663
  }
5346
5664
  parseMarginMode(marginMode, market = undefined) {
5665
+ const marketId = this.safeString(marginMode, 'symbol');
5347
5666
  let marginType = this.safeStringLower(marginMode, 'marginType');
5348
5667
  marginType = (marginType === 'crossed') ? 'cross' : marginType;
5349
5668
  return {
5350
5669
  'info': marginMode,
5351
- 'symbol': market['symbol'],
5670
+ 'symbol': this.safeSymbol(marketId, market, '-', 'swap'),
5352
5671
  'marginMode': marginType,
5353
5672
  };
5354
5673
  }