ccxt 4.4.34__py2.py3-none-any.whl → 4.4.36__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.
Files changed (67) hide show
  1. ccxt/__init__.py +3 -1
  2. ccxt/abstract/bingx.py +1 -0
  3. ccxt/abstract/bitopro.py +1 -0
  4. ccxt/abstract/bitpanda.py +0 -12
  5. ccxt/abstract/bitrue.py +3 -3
  6. ccxt/abstract/bybit.py +15 -0
  7. ccxt/abstract/defx.py +69 -0
  8. ccxt/abstract/deribit.py +1 -0
  9. ccxt/abstract/gate.py +14 -0
  10. ccxt/abstract/gateio.py +14 -0
  11. ccxt/abstract/okx.py +1 -0
  12. ccxt/abstract/onetrading.py +0 -12
  13. ccxt/abstract/xt.py +5 -5
  14. ccxt/async_support/__init__.py +3 -1
  15. ccxt/async_support/base/exchange.py +1 -1
  16. ccxt/async_support/bingx.py +324 -138
  17. ccxt/async_support/bitfinex2.py +18 -13
  18. ccxt/async_support/bitmex.py +104 -2
  19. ccxt/async_support/bitopro.py +21 -4
  20. ccxt/async_support/bitrue.py +2 -2
  21. ccxt/async_support/bitso.py +2 -1
  22. ccxt/async_support/btcmarkets.py +3 -3
  23. ccxt/async_support/btcturk.py +19 -19
  24. ccxt/async_support/bybit.py +21 -1
  25. ccxt/async_support/defx.py +1981 -0
  26. ccxt/async_support/deribit.py +27 -12
  27. ccxt/async_support/gate.py +156 -39
  28. ccxt/async_support/htx.py +11 -2
  29. ccxt/async_support/hyperliquid.py +68 -11
  30. ccxt/async_support/idex.py +3 -4
  31. ccxt/async_support/kraken.py +97 -90
  32. ccxt/async_support/kucoin.py +1 -1
  33. ccxt/async_support/okx.py +1 -0
  34. ccxt/async_support/onetrading.py +47 -369
  35. ccxt/async_support/xt.py +10 -10
  36. ccxt/base/exchange.py +2 -1
  37. ccxt/bingx.py +324 -138
  38. ccxt/bitfinex2.py +18 -13
  39. ccxt/bitmex.py +104 -2
  40. ccxt/bitopro.py +21 -4
  41. ccxt/bitrue.py +2 -2
  42. ccxt/bitso.py +2 -1
  43. ccxt/btcmarkets.py +3 -3
  44. ccxt/btcturk.py +19 -19
  45. ccxt/bybit.py +21 -1
  46. ccxt/defx.py +1980 -0
  47. ccxt/deribit.py +27 -12
  48. ccxt/gate.py +156 -39
  49. ccxt/htx.py +11 -2
  50. ccxt/hyperliquid.py +68 -11
  51. ccxt/idex.py +3 -4
  52. ccxt/kraken.py +97 -90
  53. ccxt/kucoin.py +1 -1
  54. ccxt/okx.py +1 -0
  55. ccxt/onetrading.py +47 -369
  56. ccxt/pro/__init__.py +3 -1
  57. ccxt/pro/bitrue.py +13 -11
  58. ccxt/pro/defx.py +832 -0
  59. ccxt/pro/probit.py +54 -66
  60. ccxt/test/tests_async.py +44 -3
  61. ccxt/test/tests_sync.py +44 -3
  62. ccxt/xt.py +10 -10
  63. {ccxt-4.4.34.dist-info → ccxt-4.4.36.dist-info}/METADATA +7 -6
  64. {ccxt-4.4.34.dist-info → ccxt-4.4.36.dist-info}/RECORD +67 -63
  65. {ccxt-4.4.34.dist-info → ccxt-4.4.36.dist-info}/LICENSE.txt +0 -0
  66. {ccxt-4.4.34.dist-info → ccxt-4.4.36.dist-info}/WHEEL +0 -0
  67. {ccxt-4.4.34.dist-info → ccxt-4.4.36.dist-info}/top_level.txt +0 -0
ccxt/bingx.py CHANGED
@@ -380,6 +380,7 @@ class bingx(Exchange, ImplicitAPI):
380
380
  'get': {
381
381
  'list': 10,
382
382
  'assets': 2,
383
+ 'allAccountBalance': 2,
383
384
  },
384
385
  'post': {
385
386
  'create': 10,
@@ -2597,6 +2598,9 @@ class bingx(Exchange, ImplicitAPI):
2597
2598
  }
2598
2599
  isMarketOrder = type == 'MARKET'
2599
2600
  isSpot = marketType == 'spot'
2601
+ isTwapOrder = type == 'TWAP'
2602
+ if isTwapOrder and isSpot:
2603
+ raise BadSymbol(self.id + ' createOrder() twap order supports swap contracts only')
2600
2604
  stopLossPrice = self.safe_string(params, 'stopLossPrice')
2601
2605
  takeProfitPrice = self.safe_string(params, 'takeProfitPrice')
2602
2606
  triggerPrice = self.safe_string_2(params, 'stopPrice', 'triggerPrice')
@@ -2645,6 +2649,26 @@ class bingx(Exchange, ImplicitAPI):
2645
2649
  request['type'] = 'TAKE_STOP_MARKET'
2646
2650
  request['stopPrice'] = self.parse_to_numeric(self.price_to_precision(symbol, stopTakePrice))
2647
2651
  else:
2652
+ if isTwapOrder:
2653
+ twapRequest: dict = {
2654
+ 'symbol': request['symbol'],
2655
+ 'side': request['side'],
2656
+ 'positionSide': 'LONG' if (side == 'buy') else 'SHORT',
2657
+ 'triggerPrice': self.parse_to_numeric(self.price_to_precision(symbol, triggerPrice)),
2658
+ 'totalAmount': self.parse_to_numeric(self.amount_to_precision(symbol, amount)),
2659
+ }
2660
+ # {
2661
+ # "symbol": "LTC-USDT",
2662
+ # "side": "BUY",
2663
+ # "positionSide": "LONG",
2664
+ # "priceType": "constant",
2665
+ # "priceVariance": "10",
2666
+ # "triggerPrice": "120",
2667
+ # "interval": 8,
2668
+ # "amountPerOrder": "0.5",
2669
+ # "totalAmount": "1"
2670
+ # }
2671
+ return self.extend(twapRequest, params)
2648
2672
  if timeInForce == 'FOK':
2649
2673
  request['timeInForce'] = 'FOK'
2650
2674
  trailingAmount = self.safe_string(params, 'trailingAmount')
@@ -2742,6 +2766,7 @@ class bingx(Exchange, ImplicitAPI):
2742
2766
  https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Trade%20order
2743
2767
  https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Create%20an%20Order
2744
2768
  https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Trade%20order
2769
+ https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Place%20TWAP%20Order
2745
2770
 
2746
2771
  :param str symbol: unified symbol of the market to create an order in
2747
2772
  :param str type: 'market' or 'limit'
@@ -2779,6 +2804,8 @@ class bingx(Exchange, ImplicitAPI):
2779
2804
  response = self.swapV2PrivatePostTradeOrderTest(request)
2780
2805
  elif market['inverse']:
2781
2806
  response = self.cswapV1PrivatePostTradeOrder(request)
2807
+ elif type == 'twap':
2808
+ response = self.swapV1PrivatePostTwapOrder(request)
2782
2809
  else:
2783
2810
  response = self.swapV2PrivatePostTradeOrder(request)
2784
2811
  else:
@@ -2836,6 +2863,17 @@ class bingx(Exchange, ImplicitAPI):
2836
2863
  # "timeInForce": ""
2837
2864
  # }
2838
2865
  #
2866
+ # twap order
2867
+ #
2868
+ # {
2869
+ # "code": 0,
2870
+ # "msg": "",
2871
+ # "timestamp": 1732693774386,
2872
+ # "data": {
2873
+ # "mainOrderId": "4633860139993029715"
2874
+ # }
2875
+ # }
2876
+ #
2839
2877
  if isinstance(response, str):
2840
2878
  # broken api engine : order-ids are too long numbers(i.e. 1742930526912864656)
2841
2879
  # and json.loadscan not handle them in JS, so we have to use .parseJson
@@ -2848,7 +2886,7 @@ class bingx(Exchange, ImplicitAPI):
2848
2886
  if market['inverse']:
2849
2887
  result = response
2850
2888
  else:
2851
- result = self.safe_dict(data, 'order', {})
2889
+ result = self.safe_dict(data, 'order', data)
2852
2890
  else:
2853
2891
  result = data
2854
2892
  return self.parse_order(result, market)
@@ -3265,9 +3303,9 @@ class bingx(Exchange, ImplicitAPI):
3265
3303
  if market is None:
3266
3304
  market = self.safe_market(marketId, None, None, marketType)
3267
3305
  side = self.safe_string_lower_2(order, 'side', 'S')
3268
- timestamp = self.safe_integer_n(order, ['time', 'transactTime', 'E'])
3306
+ timestamp = self.safe_integer_n(order, ['time', 'transactTime', 'E', 'createdTime'])
3269
3307
  lastTradeTimestamp = self.safe_integer_2(order, 'updateTime', 'T')
3270
- statusId = self.safe_string_upper_2(order, 'status', 'X')
3308
+ statusId = self.safe_string_upper_n(order, ['status', 'X', 'orderStatus'])
3271
3309
  feeCurrencyCode = self.safe_string_2(order, 'feeAsset', 'N')
3272
3310
  feeCost = self.safe_string_n(order, ['fee', 'commission', 'n'])
3273
3311
  if (feeCurrencyCode is None):
@@ -3308,7 +3346,7 @@ class bingx(Exchange, ImplicitAPI):
3308
3346
  triggerPrice = None
3309
3347
  return self.safe_order({
3310
3348
  'info': info,
3311
- 'id': self.safe_string_2(order, 'orderId', 'i'),
3349
+ 'id': self.safe_string_n(order, ['orderId', 'i', 'mainOrderId']),
3312
3350
  'clientOrderId': self.safe_string_n(order, ['clientOrderID', 'clientOrderId', 'origClientOrderId', 'c']),
3313
3351
  'symbol': self.safe_symbol(marketId, market, '-', marketType),
3314
3352
  'timestamp': timestamp,
@@ -3326,7 +3364,7 @@ class bingx(Exchange, ImplicitAPI):
3326
3364
  'takeProfitPrice': takeProfitPrice,
3327
3365
  'average': self.safe_string_2(order, 'avgPrice', 'ap'),
3328
3366
  'cost': self.safe_string(order, 'cummulativeQuoteQty'),
3329
- 'amount': self.safe_string_n(order, ['origQty', 'q', 'quantity']),
3367
+ 'amount': self.safe_string_n(order, ['origQty', 'q', 'quantity', 'totalAmount']),
3330
3368
  'filled': self.safe_string_2(order, 'executedQty', 'z'),
3331
3369
  'remaining': None,
3332
3370
  'status': self.parse_order_status(statusId),
@@ -3343,6 +3381,7 @@ class bingx(Exchange, ImplicitAPI):
3343
3381
  'NEW': 'open',
3344
3382
  'PENDING': 'open',
3345
3383
  'PARTIALLY_FILLED': 'open',
3384
+ 'RUNNING': 'open',
3346
3385
  'FILLED': 'closed',
3347
3386
  'CANCELED': 'canceled',
3348
3387
  'CANCELLED': 'canceled',
@@ -3357,6 +3396,7 @@ class bingx(Exchange, ImplicitAPI):
3357
3396
  https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Cancel%20Order
3358
3397
  https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Cancel%20Order
3359
3398
  https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Cancel%20an%20Order
3399
+ https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Cancel%20TWAP%20Order
3360
3400
 
3361
3401
  :param str id: order id
3362
3402
  :param str symbol: unified symbol of the market the order was made in
@@ -3364,31 +3404,64 @@ class bingx(Exchange, ImplicitAPI):
3364
3404
  :param str [params.clientOrderId]: a unique id for the order
3365
3405
  :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
3366
3406
  """
3367
- if symbol is None:
3368
- raise ArgumentsRequired(self.id + ' cancelOrder() requires a symbol argument')
3369
3407
  self.load_markets()
3370
- market = self.market(symbol)
3371
- request: dict = {
3372
- 'symbol': market['id'],
3373
- }
3374
- clientOrderId = self.safe_string_2(params, 'clientOrderId', 'clientOrderID')
3375
- params = self.omit(params, ['clientOrderId'])
3376
- if clientOrderId is not None:
3377
- request['clientOrderID'] = clientOrderId
3378
- else:
3379
- request['orderId'] = id
3408
+ isTwapOrder = self.safe_bool(params, 'twap', False)
3409
+ params = self.omit(params, 'twap')
3380
3410
  response = None
3381
- type = None
3382
- subType = None
3383
- type, params = self.handle_market_type_and_params('cancelOrder', market, params)
3384
- subType, params = self.handle_sub_type_and_params('cancelOrder', market, params)
3385
- if type == 'spot':
3386
- response = self.spotV1PrivatePostTradeCancel(self.extend(request, params))
3411
+ market = None
3412
+ if isTwapOrder:
3413
+ twapRequest: dict = {
3414
+ 'mainOrderId': id,
3415
+ }
3416
+ response = self.swapV1PrivatePostTwapCancelOrder(self.extend(twapRequest, params))
3417
+ #
3418
+ # {
3419
+ # "code": 0,
3420
+ # "msg": "",
3421
+ # "timestamp": 1702731661854,
3422
+ # "data": {
3423
+ # "symbol": "BNB-USDT",
3424
+ # "side": "BUY",
3425
+ # "positionSide": "LONG",
3426
+ # "priceType": "constant",
3427
+ # "priceVariance": "2000",
3428
+ # "triggerPrice": "68000",
3429
+ # "interval": 8,
3430
+ # "amountPerOrder": "0.111",
3431
+ # "totalAmount": "0.511",
3432
+ # "orderStatus": "Running",
3433
+ # "executedQty": "0.1",
3434
+ # "duration": 800,
3435
+ # "maxDuration": 9000,
3436
+ # "createdTime": 1702731661854,
3437
+ # "updateTime": 1702731661854
3438
+ # }
3439
+ # }
3440
+ #
3387
3441
  else:
3388
- if subType == 'inverse':
3389
- response = self.cswapV1PrivateDeleteTradeCancelOrder(self.extend(request, params))
3442
+ if symbol is None:
3443
+ raise ArgumentsRequired(self.id + ' cancelOrder() requires a symbol argument')
3444
+ market = self.market(symbol)
3445
+ request: dict = {
3446
+ 'symbol': market['id'],
3447
+ }
3448
+ clientOrderId = self.safe_string_2(params, 'clientOrderId', 'clientOrderID')
3449
+ params = self.omit(params, ['clientOrderId'])
3450
+ if clientOrderId is not None:
3451
+ request['clientOrderID'] = clientOrderId
3452
+ else:
3453
+ request['orderId'] = id
3454
+ type = None
3455
+ subType = None
3456
+ type, params = self.handle_market_type_and_params('cancelOrder', market, params)
3457
+ subType, params = self.handle_sub_type_and_params('cancelOrder', market, params)
3458
+ if type == 'spot':
3459
+ response = self.spotV1PrivatePostTradeCancel(self.extend(request, params))
3390
3460
  else:
3391
- response = self.swapV2PrivateDeleteTradeOrder(self.extend(request, params))
3461
+ if subType == 'inverse':
3462
+ response = self.cswapV1PrivateDeleteTradeCancelOrder(self.extend(request, params))
3463
+ else:
3464
+ response = self.swapV2PrivateDeleteTradeOrder(self.extend(request, params))
3392
3465
  #
3393
3466
  # spot
3394
3467
  #
@@ -3778,131 +3851,167 @@ class bingx(Exchange, ImplicitAPI):
3778
3851
  https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20details
3779
3852
  https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20details
3780
3853
  https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Order
3854
+ https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#TWAP%20Order%20Details
3781
3855
 
3782
3856
  :param str id: the order id
3783
3857
  :param str symbol: unified symbol of the market the order was made in
3784
3858
  :param dict [params]: extra parameters specific to the exchange API endpoint
3859
+ :param boolean [params.twap]: if fetching twap order
3785
3860
  :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
3786
3861
  """
3787
- if symbol is None:
3788
- raise ArgumentsRequired(self.id + ' fetchOrder() requires a symbol argument')
3789
3862
  self.load_markets()
3790
- market = self.market(symbol)
3791
- request: dict = {
3792
- 'symbol': market['id'],
3793
- 'orderId': id,
3794
- }
3795
- type = None
3796
- subType = None
3863
+ isTwapOrder = self.safe_bool(params, 'twap', False)
3864
+ params = self.omit(params, 'twap')
3797
3865
  response = None
3798
- type, params = self.handle_market_type_and_params('fetchOrder', market, params)
3799
- subType, params = self.handle_sub_type_and_params('fetchOrder', market, params)
3800
- if type == 'spot':
3801
- response = self.spotV1PrivateGetTradeQuery(self.extend(request, params))
3866
+ market = None
3867
+ if isTwapOrder:
3868
+ twapRequest: dict = {
3869
+ 'mainOrderId': id,
3870
+ }
3871
+ response = self.swapV1PrivateGetTwapOrderDetail(self.extend(twapRequest, params))
3802
3872
  #
3803
3873
  # {
3804
3874
  # "code": 0,
3805
- # "msg": "",
3875
+ # "msg": "success cancel order",
3876
+ # "timestamp": 1732760856617,
3806
3877
  # "data": {
3807
- # "symbol": "XRP-USDT",
3808
- # "orderId": 1514087361158316032,
3809
- # "price": "0.5",
3810
- # "origQty": "10",
3811
- # "executedQty": "0",
3812
- # "cummulativeQuoteQty": "0",
3813
- # "status": "CANCELED",
3814
- # "type": "LIMIT",
3878
+ # "symbol": "LTC-USDT",
3879
+ # "mainOrderId": "5596903086063901779",
3815
3880
  # "side": "BUY",
3816
- # "time": 1649821532000,
3817
- # "updateTime": 1649821543000,
3818
- # "origQuoteOrderQty": "0",
3819
- # "fee": "0",
3820
- # "feeAsset": "XRP"
3881
+ # "positionSide": "LONG",
3882
+ # "priceType": "constant",
3883
+ # "priceVariance": "10.00",
3884
+ # "triggerPrice": "120.00",
3885
+ # "interval": 8,
3886
+ # "amountPerOrder": "0.5",
3887
+ # "totalAmount": "1.0",
3888
+ # "orderStatus": "Filled",
3889
+ # "executedQty": "1.0",
3890
+ # "duration": 16,
3891
+ # "maxDuration": 86400,
3892
+ # "createdTime": 1732693017000,
3893
+ # "updateTime": 1732693033000
3821
3894
  # }
3822
3895
  # }
3823
3896
  #
3824
3897
  else:
3825
- if subType == 'inverse':
3826
- response = self.cswapV1PrivateGetTradeOrderDetail(self.extend(request, params))
3898
+ if symbol is None:
3899
+ raise ArgumentsRequired(self.id + ' fetchOrder() requires a symbol argument')
3900
+ market = self.market(symbol)
3901
+ request: dict = {
3902
+ 'symbol': market['id'],
3903
+ 'orderId': id,
3904
+ }
3905
+ type = None
3906
+ subType = None
3907
+ type, params = self.handle_market_type_and_params('fetchOrder', market, params)
3908
+ subType, params = self.handle_sub_type_and_params('fetchOrder', market, params)
3909
+ if type == 'spot':
3910
+ response = self.spotV1PrivateGetTradeQuery(self.extend(request, params))
3827
3911
  #
3828
3912
  # {
3829
3913
  # "code": 0,
3830
3914
  # "msg": "",
3831
3915
  # "data": {
3832
- # "order": {
3833
- # "symbol": "SOL-USD",
3834
- # "orderId": "1816342420721254400",
3835
- # "side": "BUY",
3836
- # "positionSide": "Long",
3837
- # "type": "LIMIT",
3838
- # "quantity": 1,
3839
- # "origQty": "",
3840
- # "price": "150",
3841
- # "executedQty": "0",
3842
- # "avgPrice": "0.000",
3843
- # "cumQuote": "",
3844
- # "stopPrice": "",
3845
- # "profit": "0.0000",
3846
- # "commission": "0.0000",
3847
- # "status": "Pending",
3848
- # "time": 1721884753767,
3849
- # "updateTime": 1721884753786,
3850
- # "clientOrderId": "",
3851
- # "leverage": "",
3852
- # "takeProfit": {
3853
- # "type": "TAKE_PROFIT",
3854
- # "quantity": 0,
3855
- # "stopPrice": 0,
3856
- # "price": 0,
3857
- # "workingType": "MARK_PRICE",
3858
- # "stopGuaranteed": ""
3859
- # },
3860
- # "stopLoss": {
3861
- # "type": "STOP",
3862
- # "quantity": 0,
3863
- # "stopPrice": 0,
3864
- # "price": 0,
3865
- # "workingType": "MARK_PRICE",
3866
- # "stopGuaranteed": ""
3867
- # },
3868
- # "advanceAttr": 0,
3869
- # "positionID": 0,
3870
- # "takeProfitEntrustPrice": 0,
3871
- # "stopLossEntrustPrice": 0,
3872
- # "orderType": "",
3873
- # "workingType": "MARK_PRICE"
3874
- # }
3916
+ # "symbol": "XRP-USDT",
3917
+ # "orderId": 1514087361158316032,
3918
+ # "price": "0.5",
3919
+ # "origQty": "10",
3920
+ # "executedQty": "0",
3921
+ # "cummulativeQuoteQty": "0",
3922
+ # "status": "CANCELED",
3923
+ # "type": "LIMIT",
3924
+ # "side": "BUY",
3925
+ # "time": 1649821532000,
3926
+ # "updateTime": 1649821543000,
3927
+ # "origQuoteOrderQty": "0",
3928
+ # "fee": "0",
3929
+ # "feeAsset": "XRP"
3875
3930
  # }
3876
3931
  # }
3877
3932
  #
3878
3933
  else:
3879
- response = self.swapV2PrivateGetTradeOrder(self.extend(request, params))
3880
- #
3881
- # {
3882
- # "code": 0,
3883
- # "msg": "",
3884
- # "data": {
3885
- # "order": {
3886
- # "symbol": "BTC-USDT",
3887
- # "orderId": 1597597642269917184,
3888
- # "side": "SELL",
3889
- # "positionSide": "LONG",
3890
- # "type": "TAKE_PROFIT_MARKET",
3891
- # "origQty": "1.0000",
3892
- # "price": "0.0",
3893
- # "executedQty": "0.0000",
3894
- # "avgPrice": "0.0",
3895
- # "cumQuote": "",
3896
- # "stopPrice": "16494.0",
3897
- # "profit": "",
3898
- # "commission": "",
3899
- # "status": "FILLED",
3900
- # "time": 1669731935000,
3901
- # "updateTime": 1669752524000
3902
- # }
3903
- # }
3904
- # }
3905
- #
3934
+ if subType == 'inverse':
3935
+ response = self.cswapV1PrivateGetTradeOrderDetail(self.extend(request, params))
3936
+ #
3937
+ # {
3938
+ # "code": 0,
3939
+ # "msg": "",
3940
+ # "data": {
3941
+ # "order": {
3942
+ # "symbol": "SOL-USD",
3943
+ # "orderId": "1816342420721254400",
3944
+ # "side": "BUY",
3945
+ # "positionSide": "Long",
3946
+ # "type": "LIMIT",
3947
+ # "quantity": 1,
3948
+ # "origQty": "",
3949
+ # "price": "150",
3950
+ # "executedQty": "0",
3951
+ # "avgPrice": "0.000",
3952
+ # "cumQuote": "",
3953
+ # "stopPrice": "",
3954
+ # "profit": "0.0000",
3955
+ # "commission": "0.0000",
3956
+ # "status": "Pending",
3957
+ # "time": 1721884753767,
3958
+ # "updateTime": 1721884753786,
3959
+ # "clientOrderId": "",
3960
+ # "leverage": "",
3961
+ # "takeProfit": {
3962
+ # "type": "TAKE_PROFIT",
3963
+ # "quantity": 0,
3964
+ # "stopPrice": 0,
3965
+ # "price": 0,
3966
+ # "workingType": "MARK_PRICE",
3967
+ # "stopGuaranteed": ""
3968
+ # },
3969
+ # "stopLoss": {
3970
+ # "type": "STOP",
3971
+ # "quantity": 0,
3972
+ # "stopPrice": 0,
3973
+ # "price": 0,
3974
+ # "workingType": "MARK_PRICE",
3975
+ # "stopGuaranteed": ""
3976
+ # },
3977
+ # "advanceAttr": 0,
3978
+ # "positionID": 0,
3979
+ # "takeProfitEntrustPrice": 0,
3980
+ # "stopLossEntrustPrice": 0,
3981
+ # "orderType": "",
3982
+ # "workingType": "MARK_PRICE"
3983
+ # }
3984
+ # }
3985
+ # }
3986
+ #
3987
+ else:
3988
+ response = self.swapV2PrivateGetTradeOrder(self.extend(request, params))
3989
+ #
3990
+ # {
3991
+ # "code": 0,
3992
+ # "msg": "",
3993
+ # "data": {
3994
+ # "order": {
3995
+ # "symbol": "BTC-USDT",
3996
+ # "orderId": 1597597642269917184,
3997
+ # "side": "SELL",
3998
+ # "positionSide": "LONG",
3999
+ # "type": "TAKE_PROFIT_MARKET",
4000
+ # "origQty": "1.0000",
4001
+ # "price": "0.0",
4002
+ # "executedQty": "0.0000",
4003
+ # "avgPrice": "0.0",
4004
+ # "cumQuote": "",
4005
+ # "stopPrice": "16494.0",
4006
+ # "profit": "",
4007
+ # "commission": "",
4008
+ # "status": "FILLED",
4009
+ # "time": 1669731935000,
4010
+ # "updateTime": 1669752524000
4011
+ # }
4012
+ # }
4013
+ # }
4014
+ #
3906
4015
  data = self.safe_dict(response, 'data', {})
3907
4016
  order = self.safe_dict(data, 'order', data)
3908
4017
  return self.parse_order(order, market)
@@ -4001,11 +4110,13 @@ class bingx(Exchange, ImplicitAPI):
4001
4110
  https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Current%20Open%20Orders
4002
4111
  https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Current%20All%20Open%20Orders
4003
4112
  https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20all%20current%20pending%20orders
4113
+ https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20TWAP%20Entrusted%20Order
4004
4114
 
4005
4115
  :param str symbol: unified market symbol
4006
4116
  :param int [since]: the earliest time in ms to fetch open orders for
4007
4117
  :param int [limit]: the maximum number of open order structures to retrieve
4008
4118
  :param dict [params]: extra parameters specific to the exchange API endpoint
4119
+ :param boolean [params.twap]: if fetching twap open orders
4009
4120
  :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
4010
4121
  """
4011
4122
  self.load_markets()
@@ -4022,7 +4133,11 @@ class bingx(Exchange, ImplicitAPI):
4022
4133
  if type == 'spot':
4023
4134
  response = self.spotV1PrivateGetTradeOpenOrders(self.extend(request, params))
4024
4135
  else:
4025
- if subType == 'inverse':
4136
+ isTwapOrder = self.safe_bool(params, 'twap', False)
4137
+ params = self.omit(params, 'twap')
4138
+ if isTwapOrder:
4139
+ response = self.swapV1PrivateGetTwapOpenOrders(self.extend(request, params))
4140
+ elif subType == 'inverse':
4026
4141
  response = self.cswapV1PrivateGetTradeOpenOrders(self.extend(request, params))
4027
4142
  else:
4028
4143
  response = self.swapV2PrivateGetTradeOpenOrders(self.extend(request, params))
@@ -4135,8 +4250,38 @@ class bingx(Exchange, ImplicitAPI):
4135
4250
  # }
4136
4251
  # }
4137
4252
  #
4253
+ # twap
4254
+ #
4255
+ # {
4256
+ # "code": 0,
4257
+ # "msg": "",
4258
+ # "timestamp": 1702731661854,
4259
+ # "data": {
4260
+ # "list": [
4261
+ # {
4262
+ # "symbol": "BNB-USDT",
4263
+ # "side": "BUY",
4264
+ # "positionSide": "LONG",
4265
+ # "priceType": "constant",
4266
+ # "priceVariance": "2000",
4267
+ # "triggerPrice": "68000",
4268
+ # "interval": 8,
4269
+ # "amountPerOrder": "0.111",
4270
+ # "totalAmount": "0.511",
4271
+ # "orderStatus": "Running",
4272
+ # "executedQty": "0.1",
4273
+ # "duration": 800,
4274
+ # "maxDuration": 9000,
4275
+ # "createdTime": 1702731661854,
4276
+ # "updateTime": 1702731661854
4277
+ # }
4278
+ # ],
4279
+ # "total": 1
4280
+ # }
4281
+ # }
4282
+ #
4138
4283
  data = self.safe_dict(response, 'data', {})
4139
- orders = self.safe_list(data, 'orders', [])
4284
+ orders = self.safe_list_2(data, 'orders', 'list', [])
4140
4285
  return self.parse_orders(orders, market, since, limit)
4141
4286
 
4142
4287
  def fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
@@ -4189,6 +4334,7 @@ class bingx(Exchange, ImplicitAPI):
4189
4334
  https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
4190
4335
  https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
4191
4336
  https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
4337
+ https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20TWAP%20Historical%20Orders
4192
4338
 
4193
4339
  :param str [symbol]: unified market symbol of the market orders were made in
4194
4340
  :param int [since]: the earliest time in ms to fetch orders for
@@ -4196,6 +4342,7 @@ class bingx(Exchange, ImplicitAPI):
4196
4342
  :param dict [params]: extra parameters specific to the exchange API endpoint
4197
4343
  :param int [params.until]: the latest time in ms to fetch orders for
4198
4344
  :param boolean [params.standard]: whether to fetch standard contract orders
4345
+ :param boolean [params.twap]: if fetching twap orders
4199
4346
  :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
4200
4347
  """
4201
4348
  if symbol is None:
@@ -4243,7 +4390,46 @@ class bingx(Exchange, ImplicitAPI):
4243
4390
  # }
4244
4391
  #
4245
4392
  else:
4246
- if subType == 'inverse':
4393
+ isTwapOrder = self.safe_bool(params, 'twap', False)
4394
+ params = self.omit(params, 'twap')
4395
+ if isTwapOrder:
4396
+ request['pageIndex'] = 1
4397
+ request['pageSize'] = 100 if (limit is None) else limit
4398
+ request['startTime'] = 1 if (since is None) else since
4399
+ until = self.safe_integer(params, 'until', self.milliseconds())
4400
+ params = self.omit(params, 'until')
4401
+ request['endTime'] = until
4402
+ response = self.swapV1PrivateGetTwapHistoryOrders(self.extend(request, params))
4403
+ #
4404
+ # {
4405
+ # "code": 0,
4406
+ # "msg": "",
4407
+ # "timestamp": 1702731661854,
4408
+ # "data": {
4409
+ # "list": [
4410
+ # {
4411
+ # "symbol": "BNB-USDT",
4412
+ # "side": "BUY",
4413
+ # "positionSide": "LONG",
4414
+ # "priceType": "constant",
4415
+ # "priceVariance": "2000",
4416
+ # "triggerPrice": "68000",
4417
+ # "interval": 8,
4418
+ # "amountPerOrder": "0.111",
4419
+ # "totalAmount": "0.511",
4420
+ # "orderStatus": "Running",
4421
+ # "executedQty": "0.1",
4422
+ # "duration": 800,
4423
+ # "maxDuration": 9000,
4424
+ # "createdTime": 1702731661854,
4425
+ # "updateTime": 1702731661854
4426
+ # }
4427
+ # ],
4428
+ # "total": 1
4429
+ # }
4430
+ # }
4431
+ #
4432
+ elif subType == 'inverse':
4247
4433
  response = self.cswapV1PrivateGetTradeOrderHistory(self.extend(request, params))
4248
4434
  #
4249
4435
  # {
@@ -4329,7 +4515,7 @@ class bingx(Exchange, ImplicitAPI):
4329
4515
  # }
4330
4516
  #
4331
4517
  data = self.safe_dict(response, 'data', {})
4332
- orders = self.safe_list(data, 'orders', [])
4518
+ orders = self.safe_list_2(data, 'orders', 'list', [])
4333
4519
  return self.parse_orders(orders, market, since, limit)
4334
4520
 
4335
4521
  def transfer(self, code: str, amount: float, fromAccount: str, toAccount: str, params={}) -> TransferEntry:
@@ -5882,27 +6068,27 @@ class bingx(Exchange, ImplicitAPI):
5882
6068
  path = self.implode_params(path, params)
5883
6069
  url += path
5884
6070
  params = self.omit(params, self.extract_params(path))
6071
+ params['timestamp'] = self.nonce()
5885
6072
  params = self.keysort(params)
5886
6073
  if access == 'public':
5887
- params['timestamp'] = self.nonce()
5888
6074
  if params:
5889
6075
  url += '?' + self.urlencode(params)
5890
6076
  elif access == 'private':
5891
6077
  self.check_required_credentials()
5892
- params['timestamp'] = self.nonce()
6078
+ isJsonContentType = ((type == 'subAccount') and (method == 'POST'))
5893
6079
  parsedParams = self.parse_params(params)
5894
- query = self.urlencode(parsedParams)
5895
6080
  signature = self.hmac(self.encode(self.rawencode(parsedParams)), self.encode(self.secret), hashlib.sha256)
5896
- if params:
5897
- query = '?' + query + '&'
5898
- else:
5899
- query += '?'
5900
- query += 'signature=' + signature
5901
6081
  headers = {
5902
6082
  'X-BX-APIKEY': self.apiKey,
5903
6083
  'X-SOURCE-KEY': self.safe_string(self.options, 'broker', 'CCXT'),
5904
6084
  }
5905
- url += query
6085
+ if isJsonContentType:
6086
+ headers['Content-Type'] = 'application/json'
6087
+ parsedParams['signature'] = signature
6088
+ body = self.json(parsedParams)
6089
+ else:
6090
+ query = self.urlencode(parsedParams)
6091
+ url += '?' + query + '&signature=' + signature
5906
6092
  return {'url': url, 'method': method, 'body': body, 'headers': headers}
5907
6093
 
5908
6094
  def nonce(self):