ccxt 4.3.66__py2.py3-none-any.whl → 4.3.68__py2.py3-none-any.whl

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.
@@ -63,6 +63,7 @@ class bingx(Exchange, ImplicitAPI):
63
63
  'createTrailingPercentOrder': True,
64
64
  'createTriggerOrder': True,
65
65
  'fetchBalance': True,
66
+ 'fetchCanceledOrders': True,
66
67
  'fetchClosedOrders': True,
67
68
  'fetchCurrencies': True,
68
69
  'fetchDepositAddress': True,
@@ -298,6 +299,10 @@ class bingx(Exchange, ImplicitAPI):
298
299
  'trade/leverage': 2,
299
300
  'trade/forceOrders': 2,
300
301
  'trade/allFillOrders': 2,
302
+ 'trade/openOrders': 2,
303
+ 'trade/orderDetail': 2,
304
+ 'trade/orderHistory': 2,
305
+ 'trade/marginType': 2,
301
306
  'user/commissionRate': 2,
302
307
  'user/positions': 2,
303
308
  'user/balance': 2,
@@ -306,9 +311,12 @@ class bingx(Exchange, ImplicitAPI):
306
311
  'trade/order': 2,
307
312
  'trade/leverage': 2,
308
313
  'trade/closeAllPositions': 2,
314
+ 'trade/marginType': 2,
315
+ 'trade/positionMargin': 2,
309
316
  },
310
317
  'delete': {
311
318
  'trade/allOpenOrders': 2,
319
+ 'trade/cancelOrder': 2,
312
320
  },
313
321
  },
314
322
  },
@@ -2835,7 +2843,7 @@ class bingx(Exchange, ImplicitAPI):
2835
2843
  # "clientOrderID": ""
2836
2844
  # }
2837
2845
  #
2838
- # inverse swap cancelAllOrders
2846
+ # inverse swap cancelAllOrders, cancelOrder, fetchOrder, fetchOpenOrders, fetchClosedOrders, fetchCanceledOrders
2839
2847
  #
2840
2848
  # {
2841
2849
  # "symbol": "SOL-USD",
@@ -2893,7 +2901,7 @@ class bingx(Exchange, ImplicitAPI):
2893
2901
  side = self.safe_string_lower_2(order, 'side', 'S')
2894
2902
  timestamp = self.safe_integer_n(order, ['time', 'transactTime', 'E'])
2895
2903
  lastTradeTimestamp = self.safe_integer_2(order, 'updateTime', 'T')
2896
- statusId = self.safe_string_2(order, 'status', 'X')
2904
+ statusId = self.safe_string_upper_2(order, 'status', 'X')
2897
2905
  feeCurrencyCode = self.safe_string_2(order, 'feeAsset', 'N')
2898
2906
  feeCost = self.safe_string_n(order, ['fee', 'commission', 'n'])
2899
2907
  if (feeCurrencyCode is None):
@@ -2979,13 +2987,14 @@ class bingx(Exchange, ImplicitAPI):
2979
2987
  async def cancel_order(self, id: str, symbol: Str = None, params={}):
2980
2988
  """
2981
2989
  cancels an open order
2982
- :see: https://bingx-api.github.io/docs/#/spot/trade-api.html#Cancel%20an%20Order
2983
- :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Cancel%20an%20Order
2990
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Cancel%20Order
2991
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Cancel%20Order
2992
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Cancel%20an%20Order
2984
2993
  :param str id: order id
2985
2994
  :param str symbol: unified symbol of the market the order was made in
2986
2995
  :param dict [params]: extra parameters specific to the exchange API endpoint
2987
2996
  :param str [params.clientOrderId]: a unique id for the order
2988
- :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2997
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2989
2998
  """
2990
2999
  if symbol is None:
2991
3000
  raise ArgumentsRequired(self.id + ' cancelOrder() requires a symbol argument')
@@ -3001,11 +3010,17 @@ class bingx(Exchange, ImplicitAPI):
3001
3010
  else:
3002
3011
  request['orderId'] = id
3003
3012
  response = None
3004
- marketType, query = self.handle_market_type_and_params('cancelOrder', market, params)
3005
- if marketType == 'spot':
3006
- response = await self.spotV1PrivatePostTradeCancel(self.extend(request, query))
3013
+ type = None
3014
+ subType = None
3015
+ type, params = self.handle_market_type_and_params('cancelOrder', market, params)
3016
+ subType, params = self.handle_sub_type_and_params('cancelOrder', market, params)
3017
+ if type == 'spot':
3018
+ response = await self.spotV1PrivatePostTradeCancel(self.extend(request, params))
3007
3019
  else:
3008
- response = await self.swapV2PrivateDeleteTradeOrder(self.extend(request, query))
3020
+ if subType == 'inverse':
3021
+ response = await self.cswapV1PrivateDeleteTradeCancelOrder(self.extend(request, params))
3022
+ else:
3023
+ response = await self.swapV2PrivateDeleteTradeOrder(self.extend(request, params))
3009
3024
  #
3010
3025
  # spot
3011
3026
  #
@@ -3025,7 +3040,59 @@ class bingx(Exchange, ImplicitAPI):
3025
3040
  # }
3026
3041
  # }
3027
3042
  #
3028
- # swap
3043
+ # inverse swap
3044
+ #
3045
+ # {
3046
+ # "code": 0,
3047
+ # "msg": "",
3048
+ # "data": {
3049
+ # "order": {
3050
+ # "symbol": "SOL-USD",
3051
+ # "orderId": "1816002957423951872",
3052
+ # "side": "BUY",
3053
+ # "positionSide": "Long",
3054
+ # "type": "Pending",
3055
+ # "quantity": 0,
3056
+ # "origQty": "0",
3057
+ # "price": "150",
3058
+ # "executedQty": "0",
3059
+ # "avgPrice": "0",
3060
+ # "cumQuote": "0",
3061
+ # "stopPrice": "",
3062
+ # "profit": "0.0000",
3063
+ # "commission": "0.000000",
3064
+ # "status": "CANCELLED",
3065
+ # "time": 1721803819410,
3066
+ # "updateTime": 1721803819427,
3067
+ # "clientOrderId": "",
3068
+ # "leverage": "",
3069
+ # "takeProfit": {
3070
+ # "type": "",
3071
+ # "quantity": 0,
3072
+ # "stopPrice": 0,
3073
+ # "price": 0,
3074
+ # "workingType": "",
3075
+ # "stopGuaranteed": ""
3076
+ # },
3077
+ # "stopLoss": {
3078
+ # "type": "",
3079
+ # "quantity": 0,
3080
+ # "stopPrice": 0,
3081
+ # "price": 0,
3082
+ # "workingType": "",
3083
+ # "stopGuaranteed": ""
3084
+ # },
3085
+ # "advanceAttr": 0,
3086
+ # "positionID": 0,
3087
+ # "takeProfitEntrustPrice": 0,
3088
+ # "stopLossEntrustPrice": 0,
3089
+ # "orderType": "",
3090
+ # "workingType": ""
3091
+ # }
3092
+ # }
3093
+ # }
3094
+ #
3095
+ # linear swap
3029
3096
  #
3030
3097
  # {
3031
3098
  # "code": 0,
@@ -3052,9 +3119,9 @@ class bingx(Exchange, ImplicitAPI):
3052
3119
  # }
3053
3120
  # }
3054
3121
  #
3055
- data = self.safe_value(response, 'data')
3056
- first = self.safe_dict(data, 'order', data)
3057
- return self.parse_order(first, market)
3122
+ data = self.safe_dict(response, 'data', {})
3123
+ order = self.safe_dict(data, 'order', data)
3124
+ return self.parse_order(order, market)
3058
3125
 
3059
3126
  async def cancel_all_orders(self, symbol: Str = None, params={}):
3060
3127
  """
@@ -3333,11 +3400,12 @@ class bingx(Exchange, ImplicitAPI):
3333
3400
  async def fetch_order(self, id: str, symbol: Str = None, params={}):
3334
3401
  """
3335
3402
  fetches information on an order made by the user
3336
- :see: https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Orders
3337
- :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20Order
3403
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20details
3404
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20details
3405
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Order
3338
3406
  :param str symbol: unified symbol of the market the order was made in
3339
3407
  :param dict [params]: extra parameters specific to the exchange API endpoint
3340
- :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
3408
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
3341
3409
  """
3342
3410
  if symbol is None:
3343
3411
  raise ArgumentsRequired(self.id + ' fetchOrder() requires a symbol argument')
@@ -3347,66 +3415,120 @@ class bingx(Exchange, ImplicitAPI):
3347
3415
  'symbol': market['id'],
3348
3416
  'orderId': id,
3349
3417
  }
3418
+ type = None
3419
+ subType = None
3350
3420
  response = None
3351
- marketType, query = self.handle_market_type_and_params('fetchOrder', market, params)
3352
- if marketType == 'spot':
3353
- response = await self.spotV1PrivateGetTradeQuery(self.extend(request, query))
3421
+ type, params = self.handle_market_type_and_params('fetchOrder', market, params)
3422
+ subType, params = self.handle_sub_type_and_params('fetchOrder', market, params)
3423
+ if type == 'spot':
3424
+ response = await self.spotV1PrivateGetTradeQuery(self.extend(request, params))
3425
+ #
3426
+ # {
3427
+ # "code": 0,
3428
+ # "msg": "",
3429
+ # "data": {
3430
+ # "symbol": "XRP-USDT",
3431
+ # "orderId": 1514087361158316032,
3432
+ # "price": "0.5",
3433
+ # "origQty": "10",
3434
+ # "executedQty": "0",
3435
+ # "cummulativeQuoteQty": "0",
3436
+ # "status": "CANCELED",
3437
+ # "type": "LIMIT",
3438
+ # "side": "BUY",
3439
+ # "time": 1649821532000,
3440
+ # "updateTime": 1649821543000,
3441
+ # "origQuoteOrderQty": "0",
3442
+ # "fee": "0",
3443
+ # "feeAsset": "XRP"
3444
+ # }
3445
+ # }
3446
+ #
3354
3447
  else:
3355
- response = await self.swapV2PrivateGetTradeOrder(self.extend(request, query))
3356
- #
3357
- # spot
3358
- #
3359
- # {
3360
- # "code": 0,
3361
- # "msg": "",
3362
- # "data": {
3363
- # "symbol": "XRP-USDT",
3364
- # "orderId": 1514087361158316032,
3365
- # "price": "0.5",
3366
- # "origQty": "10",
3367
- # "executedQty": "0",
3368
- # "cummulativeQuoteQty": "0",
3369
- # "status": "CANCELED",
3370
- # "type": "LIMIT",
3371
- # "side": "BUY",
3372
- # "time": 1649821532000,
3373
- # "updateTime": 1649821543000,
3374
- # "origQuoteOrderQty": "0",
3375
- # "fee": "0",
3376
- # "feeAsset": "XRP"
3377
- # }
3378
- # }
3379
- #
3380
- # swap
3381
- #
3382
- # {
3383
- # "code": 0,
3384
- # "msg": "",
3385
- # "data": {
3386
- # "order": {
3387
- # "symbol": "BTC-USDT",
3388
- # "orderId": 1597597642269917184,
3389
- # "side": "SELL",
3390
- # "positionSide": "LONG",
3391
- # "type": "TAKE_PROFIT_MARKET",
3392
- # "origQty": "1.0000",
3393
- # "price": "0.0",
3394
- # "executedQty": "0.0000",
3395
- # "avgPrice": "0.0",
3396
- # "cumQuote": "",
3397
- # "stopPrice": "16494.0",
3398
- # "profit": "",
3399
- # "commission": "",
3400
- # "status": "FILLED",
3401
- # "time": 1669731935000,
3402
- # "updateTime": 1669752524000
3403
- # }
3404
- # }
3405
- # }
3406
- #
3407
- data = self.safe_value(response, 'data')
3408
- first = self.safe_dict(data, 'order', data)
3409
- return self.parse_order(first, market)
3448
+ if subType == 'inverse':
3449
+ response = await self.cswapV1PrivateGetTradeOrderDetail(self.extend(request, params))
3450
+ #
3451
+ # {
3452
+ # "code": 0,
3453
+ # "msg": "",
3454
+ # "data": {
3455
+ # "order": {
3456
+ # "symbol": "SOL-USD",
3457
+ # "orderId": "1816342420721254400",
3458
+ # "side": "BUY",
3459
+ # "positionSide": "Long",
3460
+ # "type": "LIMIT",
3461
+ # "quantity": 1,
3462
+ # "origQty": "",
3463
+ # "price": "150",
3464
+ # "executedQty": "0",
3465
+ # "avgPrice": "0.000",
3466
+ # "cumQuote": "",
3467
+ # "stopPrice": "",
3468
+ # "profit": "0.0000",
3469
+ # "commission": "0.0000",
3470
+ # "status": "Pending",
3471
+ # "time": 1721884753767,
3472
+ # "updateTime": 1721884753786,
3473
+ # "clientOrderId": "",
3474
+ # "leverage": "",
3475
+ # "takeProfit": {
3476
+ # "type": "TAKE_PROFIT",
3477
+ # "quantity": 0,
3478
+ # "stopPrice": 0,
3479
+ # "price": 0,
3480
+ # "workingType": "MARK_PRICE",
3481
+ # "stopGuaranteed": ""
3482
+ # },
3483
+ # "stopLoss": {
3484
+ # "type": "STOP",
3485
+ # "quantity": 0,
3486
+ # "stopPrice": 0,
3487
+ # "price": 0,
3488
+ # "workingType": "MARK_PRICE",
3489
+ # "stopGuaranteed": ""
3490
+ # },
3491
+ # "advanceAttr": 0,
3492
+ # "positionID": 0,
3493
+ # "takeProfitEntrustPrice": 0,
3494
+ # "stopLossEntrustPrice": 0,
3495
+ # "orderType": "",
3496
+ # "workingType": "MARK_PRICE"
3497
+ # }
3498
+ # }
3499
+ # }
3500
+ #
3501
+ else:
3502
+ response = await self.swapV2PrivateGetTradeOrder(self.extend(request, params))
3503
+ #
3504
+ # {
3505
+ # "code": 0,
3506
+ # "msg": "",
3507
+ # "data": {
3508
+ # "order": {
3509
+ # "symbol": "BTC-USDT",
3510
+ # "orderId": 1597597642269917184,
3511
+ # "side": "SELL",
3512
+ # "positionSide": "LONG",
3513
+ # "type": "TAKE_PROFIT_MARKET",
3514
+ # "origQty": "1.0000",
3515
+ # "price": "0.0",
3516
+ # "executedQty": "0.0000",
3517
+ # "avgPrice": "0.0",
3518
+ # "cumQuote": "",
3519
+ # "stopPrice": "16494.0",
3520
+ # "profit": "",
3521
+ # "commission": "",
3522
+ # "status": "FILLED",
3523
+ # "time": 1669731935000,
3524
+ # "updateTime": 1669752524000
3525
+ # }
3526
+ # }
3527
+ # }
3528
+ #
3529
+ data = self.safe_dict(response, 'data', {})
3530
+ order = self.safe_dict(data, 'order', data)
3531
+ return self.parse_order(order, market)
3410
3532
 
3411
3533
  async def fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
3412
3534
  """
@@ -3498,9 +3620,10 @@ class bingx(Exchange, ImplicitAPI):
3498
3620
 
3499
3621
  async def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
3500
3622
  """
3501
- :see: https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Open%20Orders
3502
- :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20all%20current%20pending%20orders
3503
3623
  fetch all unfilled currently open orders
3624
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Current%20Open%20Orders
3625
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Current%20All%20Open%20Orders
3626
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20all%20current%20pending%20orders
3504
3627
  :param str symbol: unified market symbol
3505
3628
  :param int [since]: the earliest time in ms to fetch open orders for
3506
3629
  :param int [limit]: the maximum number of open order structures to retrieve
@@ -3513,12 +3636,18 @@ class bingx(Exchange, ImplicitAPI):
3513
3636
  if symbol is not None:
3514
3637
  market = self.market(symbol)
3515
3638
  request['symbol'] = market['id']
3639
+ type = None
3640
+ subType = None
3516
3641
  response = None
3517
- marketType, query = self.handle_market_type_and_params('fetchOpenOrders', market, params)
3518
- if marketType == 'spot':
3519
- response = await self.spotV1PrivateGetTradeOpenOrders(self.extend(request, query))
3642
+ type, params = self.handle_market_type_and_params('fetchOpenOrders', market, params)
3643
+ subType, params = self.handle_sub_type_and_params('fetchOpenOrders', market, params)
3644
+ if type == 'spot':
3645
+ response = await self.spotV1PrivateGetTradeOpenOrders(self.extend(request, params))
3520
3646
  else:
3521
- response = await self.swapV2PrivateGetTradeOpenOrders(self.extend(request, query))
3647
+ if subType == 'inverse':
3648
+ response = await self.cswapV1PrivateGetTradeOpenOrders(self.extend(request, params))
3649
+ else:
3650
+ response = await self.swapV2PrivateGetTradeOpenOrders(self.extend(request, params))
3522
3651
  #
3523
3652
  # spot
3524
3653
  #
@@ -3545,7 +3674,61 @@ class bingx(Exchange, ImplicitAPI):
3545
3674
  # }
3546
3675
  # }
3547
3676
  #
3548
- # swap
3677
+ # inverse swap
3678
+ #
3679
+ # {
3680
+ # "code": 0,
3681
+ # "msg": "",
3682
+ # "data": {
3683
+ # "orders": [
3684
+ # {
3685
+ # "symbol": "SOL-USD",
3686
+ # "orderId": "1816013900044320768",
3687
+ # "side": "BUY",
3688
+ # "positionSide": "Long",
3689
+ # "type": "LIMIT",
3690
+ # "quantity": 1,
3691
+ # "origQty": "",
3692
+ # "price": "150",
3693
+ # "executedQty": "0",
3694
+ # "avgPrice": "0.000",
3695
+ # "cumQuote": "",
3696
+ # "stopPrice": "",
3697
+ # "profit": "0.0000",
3698
+ # "commission": "0.0000",
3699
+ # "status": "Pending",
3700
+ # "time": 1721806428334,
3701
+ # "updateTime": 1721806428352,
3702
+ # "clientOrderId": "",
3703
+ # "leverage": "",
3704
+ # "takeProfit": {
3705
+ # "type": "TAKE_PROFIT",
3706
+ # "quantity": 0,
3707
+ # "stopPrice": 0,
3708
+ # "price": 0,
3709
+ # "workingType": "MARK_PRICE",
3710
+ # "stopGuaranteed": ""
3711
+ # },
3712
+ # "stopLoss": {
3713
+ # "type": "STOP",
3714
+ # "quantity": 0,
3715
+ # "stopPrice": 0,
3716
+ # "price": 0,
3717
+ # "workingType": "MARK_PRICE",
3718
+ # "stopGuaranteed": ""
3719
+ # },
3720
+ # "advanceAttr": 0,
3721
+ # "positionID": 0,
3722
+ # "takeProfitEntrustPrice": 0,
3723
+ # "stopLossEntrustPrice": 0,
3724
+ # "orderType": "",
3725
+ # "workingType": "MARK_PRICE"
3726
+ # }
3727
+ # ]
3728
+ # }
3729
+ # }
3730
+ #
3731
+ # linear swap
3549
3732
  #
3550
3733
  # {
3551
3734
  # "code": 0,
@@ -3581,8 +3764,47 @@ class bingx(Exchange, ImplicitAPI):
3581
3764
  async def fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
3582
3765
  """
3583
3766
  fetches information on multiple closed orders made by the user
3584
- :see: https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Order%20History
3585
- :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#User's%20Force%20Orders
3767
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
3768
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
3769
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
3770
+ :see: https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
3771
+ :param str symbol: unified market symbol of the closed orders
3772
+ :param int [since]: timestamp in ms of the earliest order
3773
+ :param int [limit]: the max number of closed orders to return
3774
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3775
+ :param int [params.until]: the latest time in ms to fetch orders for
3776
+ :param boolean [params.standard]: whether to fetch standard contract orders
3777
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
3778
+ """
3779
+ await self.load_markets()
3780
+ orders = await self.fetch_canceled_and_closed_orders(symbol, since, limit, params)
3781
+ return self.filter_by(orders, 'status', 'closed')
3782
+
3783
+ async def fetch_canceled_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
3784
+ """
3785
+ fetches information on multiple canceled orders made by the user
3786
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
3787
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
3788
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
3789
+ :see: https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
3790
+ :param str symbol: unified market symbol of the canceled orders
3791
+ :param int [since]: timestamp in ms of the earliest order
3792
+ :param int [limit]: the max number of canceled orders to return
3793
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3794
+ :param int [params.until]: the latest time in ms to fetch orders for
3795
+ :param boolean [params.standard]: whether to fetch standard contract orders
3796
+ :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
3797
+ """
3798
+ await self.load_markets()
3799
+ orders = await self.fetch_canceled_and_closed_orders(symbol, since, limit, params)
3800
+ return self.filter_by(orders, 'status', 'canceled')
3801
+
3802
+ async def fetch_canceled_and_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
3803
+ """
3804
+ fetches information on multiple closed orders made by the user
3805
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
3806
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
3807
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
3586
3808
  :see: https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
3587
3809
  :param str [symbol]: unified market symbol of the market orders were made in
3588
3810
  :param int [since]: the earliest time in ms to fetch orders for
@@ -3599,72 +3821,128 @@ class bingx(Exchange, ImplicitAPI):
3599
3821
  request: dict = {
3600
3822
  'symbol': market['id'],
3601
3823
  }
3602
- response = None
3824
+ type = None
3825
+ subType = None
3603
3826
  standard = None
3827
+ response = None
3828
+ type, params = self.handle_market_type_and_params('fetchClosedOrders', market, params)
3829
+ subType, params = self.handle_sub_type_and_params('fetchClosedOrders', market, params)
3604
3830
  standard, params = self.handle_option_and_params(params, 'fetchClosedOrders', 'standard', False)
3605
- marketType, query = self.handle_market_type_and_params('fetchClosedOrders', market, params)
3606
3831
  if standard:
3607
- response = await self.contractV1PrivateGetAllOrders(self.extend(request, query))
3608
- elif marketType == 'spot':
3609
- response = await self.spotV1PrivateGetTradeHistoryOrders(self.extend(request, query))
3832
+ response = await self.contractV1PrivateGetAllOrders(self.extend(request, params))
3833
+ elif type == 'spot':
3834
+ response = await self.spotV1PrivateGetTradeHistoryOrders(self.extend(request, params))
3835
+ #
3836
+ # {
3837
+ # "code": 0,
3838
+ # "msg": "",
3839
+ # "data": {
3840
+ # "orders": [
3841
+ # {
3842
+ # "symbol": "XRP-USDT",
3843
+ # "orderId": 1514073325788200960,
3844
+ # "price": "0.5",
3845
+ # "origQty": "20",
3846
+ # "executedQty": "0",
3847
+ # "cummulativeQuoteQty": "0",
3848
+ # "status": "PENDING",
3849
+ # "type": "LIMIT",
3850
+ # "side": "BUY",
3851
+ # "time": 1649818185647,
3852
+ # "updateTime": 1649818185647,
3853
+ # "origQuoteOrderQty": "0"
3854
+ # }
3855
+ # ]
3856
+ # }
3857
+ # }
3858
+ #
3610
3859
  else:
3611
- response = await self.swapV2PrivateGetTradeAllOrders(self.extend(request, query))
3612
- #
3613
- # spot
3614
- #
3615
- # {
3616
- # "code": 0,
3617
- # "msg": "",
3618
- # "data": {
3619
- # "orders": [
3620
- # {
3621
- # "symbol": "XRP-USDT",
3622
- # "orderId": 1514073325788200960,
3623
- # "price": "0.5",
3624
- # "origQty": "20",
3625
- # "executedQty": "0",
3626
- # "cummulativeQuoteQty": "0",
3627
- # "status": "PENDING",
3628
- # "type": "LIMIT",
3629
- # "side": "BUY",
3630
- # "time": 1649818185647,
3631
- # "updateTime": 1649818185647,
3632
- # "origQuoteOrderQty": "0"
3633
- # }
3634
- # ]
3635
- # }
3636
- # }
3637
- #
3638
- # swap
3639
- #
3640
- # {
3641
- # "code": 0,
3642
- # "msg": "",
3643
- # "data": {
3644
- # "orders": [
3645
- # {
3646
- # "symbol": "LINK-USDT",
3647
- # "orderId": 1585839271162413056,
3648
- # "side": "BUY",
3649
- # "positionSide": "LONG",
3650
- # "type": "TRIGGER_MARKET",
3651
- # "origQty": "5.0",
3652
- # "price": "9",
3653
- # "executedQty": "0.0",
3654
- # "avgPrice": "0",
3655
- # "cumQuote": "0",
3656
- # "stopPrice": "5",
3657
- # "profit": "0.0000",
3658
- # "commission": "0.000000",
3659
- # "status": "CANCELLED",
3660
- # "time": 1667631605000,
3661
- # "updateTime": 1667631605000
3662
- # },
3663
- # ]
3664
- # }
3665
- # }
3666
- #
3667
- data = self.safe_value(response, 'data', [])
3860
+ if subType == 'inverse':
3861
+ response = await self.cswapV1PrivateGetTradeOrderHistory(self.extend(request, params))
3862
+ #
3863
+ # {
3864
+ # "code": 0,
3865
+ # "msg": "",
3866
+ # "data": {
3867
+ # "orders": [
3868
+ # {
3869
+ # "symbol": "SOL-USD",
3870
+ # "orderId": "1816002957423951872",
3871
+ # "side": "BUY",
3872
+ # "positionSide": "LONG",
3873
+ # "type": "LIMIT",
3874
+ # "quantity": 1,
3875
+ # "origQty": "10.00000000",
3876
+ # "price": "150.000",
3877
+ # "executedQty": "0.00000000",
3878
+ # "avgPrice": "0.000",
3879
+ # "cumQuote": "",
3880
+ # "stopPrice": "0.000",
3881
+ # "profit": "0.0000",
3882
+ # "commission": "0.000000",
3883
+ # "status": "Filled",
3884
+ # "time": 1721803819000,
3885
+ # "updateTime": 1721803856000,
3886
+ # "clientOrderId": "",
3887
+ # "leverage": "",
3888
+ # "takeProfit": {
3889
+ # "type": "",
3890
+ # "quantity": 0,
3891
+ # "stopPrice": 0,
3892
+ # "price": 0,
3893
+ # "workingType": "",
3894
+ # "stopGuaranteed": ""
3895
+ # },
3896
+ # "stopLoss": {
3897
+ # "type": "",
3898
+ # "quantity": 0,
3899
+ # "stopPrice": 0,
3900
+ # "price": 0,
3901
+ # "workingType": "",
3902
+ # "stopGuaranteed": ""
3903
+ # },
3904
+ # "advanceAttr": 0,
3905
+ # "positionID": 0,
3906
+ # "takeProfitEntrustPrice": 0,
3907
+ # "stopLossEntrustPrice": 0,
3908
+ # "orderType": "",
3909
+ # "workingType": "MARK_PRICE"
3910
+ # },
3911
+ # ]
3912
+ # }
3913
+ # }
3914
+ #
3915
+ else:
3916
+ response = await self.swapV2PrivateGetTradeAllOrders(self.extend(request, params))
3917
+ #
3918
+ # {
3919
+ # "code": 0,
3920
+ # "msg": "",
3921
+ # "data": {
3922
+ # "orders": [
3923
+ # {
3924
+ # "symbol": "LINK-USDT",
3925
+ # "orderId": 1585839271162413056,
3926
+ # "side": "BUY",
3927
+ # "positionSide": "LONG",
3928
+ # "type": "TRIGGER_MARKET",
3929
+ # "origQty": "5.0",
3930
+ # "price": "9",
3931
+ # "executedQty": "0.0",
3932
+ # "avgPrice": "0",
3933
+ # "cumQuote": "0",
3934
+ # "stopPrice": "5",
3935
+ # "profit": "0.0000",
3936
+ # "commission": "0.000000",
3937
+ # "status": "CANCELLED",
3938
+ # "time": 1667631605000,
3939
+ # "updateTime": 1667631605000
3940
+ # },
3941
+ # ]
3942
+ # }
3943
+ # }
3944
+ #
3945
+ data = self.safe_dict(response, 'data', {})
3668
3946
  orders = self.safe_list(data, 'orders', [])
3669
3947
  return self.parse_orders(orders, market, since, limit)
3670
3948
 
@@ -4067,7 +4345,8 @@ class bingx(Exchange, ImplicitAPI):
4067
4345
  async def set_margin_mode(self, marginMode: str, symbol: Str = None, params={}):
4068
4346
  """
4069
4347
  set margin mode to 'cross' or 'isolated'
4070
- :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Switch%20Margin%20Mode
4348
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Change%20Margin%20Type
4349
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Set%20Margin%20Type
4071
4350
  :param str marginMode: 'cross' or 'isolated'
4072
4351
  :param str symbol: unified market symbol
4073
4352
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -4088,7 +4367,12 @@ class bingx(Exchange, ImplicitAPI):
4088
4367
  'symbol': market['id'],
4089
4368
  'marginType': marginMode,
4090
4369
  }
4091
- return await self.swapV2PrivatePostTradeMarginType(self.extend(request, params))
4370
+ subType = None
4371
+ subType, params = self.handle_sub_type_and_params('setMarginMode', market, params)
4372
+ if subType == 'inverse':
4373
+ return await self.cswapV1PrivatePostTradeMarginType(self.extend(request, params))
4374
+ else:
4375
+ return await self.swapV2PrivatePostTradeMarginType(self.extend(request, params))
4092
4376
 
4093
4377
  async def add_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
4094
4378
  request: dict = {
@@ -4980,7 +5264,8 @@ class bingx(Exchange, ImplicitAPI):
4980
5264
  async def fetch_margin_mode(self, symbol: str, params={}) -> MarginMode:
4981
5265
  """
4982
5266
  fetches the margin mode of the trading pair
4983
- :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Margin%20Mode
5267
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Margin%20Type
5268
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Margin%20Type
4984
5269
  :param str symbol: unified symbol of the market to fetch the margin mode for
4985
5270
  :param dict [params]: extra parameters specific to the exchange API endpoint
4986
5271
  :returns dict: a `margin mode structure <https://docs.ccxt.com/#/?id=margin-mode-structure>`
@@ -4990,25 +5275,43 @@ class bingx(Exchange, ImplicitAPI):
4990
5275
  request: dict = {
4991
5276
  'symbol': market['id'],
4992
5277
  }
4993
- response = await self.swapV2PrivateGetTradeMarginType(self.extend(request, params))
4994
- #
4995
- # {
4996
- # "code": 0,
4997
- # "msg": "",
4998
- # "data": {
4999
- # "marginType": "CROSSED"
5000
- # }
5001
- # }
5002
- #
5278
+ subType = None
5279
+ response = None
5280
+ subType, params = self.handle_sub_type_and_params('fetchMarginMode', market, params)
5281
+ if subType == 'inverse':
5282
+ response = await self.cswapV1PrivateGetTradeMarginType(self.extend(request, params))
5283
+ #
5284
+ # {
5285
+ # "code": 0,
5286
+ # "msg": "",
5287
+ # "timestamp": 1721966069132,
5288
+ # "data": {
5289
+ # "symbol": "SOL-USD",
5290
+ # "marginType": "CROSSED"
5291
+ # }
5292
+ # }
5293
+ #
5294
+ else:
5295
+ response = await self.swapV2PrivateGetTradeMarginType(self.extend(request, params))
5296
+ #
5297
+ # {
5298
+ # "code": 0,
5299
+ # "msg": "",
5300
+ # "data": {
5301
+ # "marginType": "CROSSED"
5302
+ # }
5303
+ # }
5304
+ #
5003
5305
  data = self.safe_dict(response, 'data', {})
5004
5306
  return self.parse_margin_mode(data, market)
5005
5307
 
5006
5308
  def parse_margin_mode(self, marginMode: dict, market=None) -> MarginMode:
5309
+ marketId = self.safe_string(marginMode, 'symbol')
5007
5310
  marginType = self.safe_string_lower(marginMode, 'marginType')
5008
5311
  marginType = 'cross' if (marginType == 'crossed') else marginType
5009
5312
  return {
5010
5313
  'info': marginMode,
5011
- 'symbol': market['symbol'],
5314
+ 'symbol': self.safe_symbol(marketId, market, '-', 'swap'),
5012
5315
  'marginMode': marginType,
5013
5316
  }
5014
5317