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