ccxt 4.3.58__py2.py3-none-any.whl → 4.3.60__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.

Potentially problematic release.


This version of ccxt might be problematic. Click here for more details.

Files changed (84) hide show
  1. ccxt/__init__.py +5 -5
  2. ccxt/abstract/bingx.py +1 -1
  3. ccxt/abstract/bitmart.py +1 -0
  4. ccxt/abstract/btcbox.py +1 -0
  5. ccxt/abstract/upbit.py +3 -0
  6. ccxt/abstract/xt.py +1 -0
  7. ccxt/async_support/__init__.py +5 -5
  8. ccxt/async_support/base/exchange.py +1 -1
  9. ccxt/async_support/binance.py +91 -2
  10. ccxt/async_support/bingx.py +448 -123
  11. ccxt/async_support/bitfinex.py +38 -4
  12. ccxt/async_support/bitget.py +1 -1
  13. ccxt/async_support/bitmart.py +1 -0
  14. ccxt/async_support/bitso.py +4 -1
  15. ccxt/async_support/btcbox.py +145 -8
  16. ccxt/async_support/bybit.py +3 -5
  17. ccxt/async_support/cex.py +1 -1
  18. ccxt/async_support/coinsph.py +1 -1
  19. ccxt/async_support/cryptocom.py +11 -5
  20. ccxt/async_support/deribit.py +15 -1
  21. ccxt/async_support/digifinex.py +30 -7
  22. ccxt/async_support/gate.py +17 -18
  23. ccxt/async_support/htx.py +7 -7
  24. ccxt/async_support/hyperliquid.py +107 -3
  25. ccxt/async_support/kraken.py +2 -2
  26. ccxt/async_support/mexc.py +11 -11
  27. ccxt/async_support/novadax.py +1 -1
  28. ccxt/async_support/okcoin.py +1 -1
  29. ccxt/async_support/okx.py +11 -2
  30. ccxt/async_support/phemex.py +1 -1
  31. ccxt/async_support/probit.py +1 -1
  32. ccxt/async_support/timex.py +16 -2
  33. ccxt/async_support/tokocrypto.py +1 -1
  34. ccxt/async_support/upbit.py +139 -45
  35. ccxt/async_support/xt.py +71 -8
  36. ccxt/base/errors.py +23 -23
  37. ccxt/base/exchange.py +9 -9
  38. ccxt/binance.py +91 -2
  39. ccxt/bingx.py +448 -123
  40. ccxt/bitfinex.py +38 -4
  41. ccxt/bitget.py +1 -1
  42. ccxt/bitmart.py +1 -0
  43. ccxt/bitso.py +4 -1
  44. ccxt/btcbox.py +145 -8
  45. ccxt/bybit.py +3 -5
  46. ccxt/cex.py +1 -1
  47. ccxt/coinsph.py +1 -1
  48. ccxt/cryptocom.py +11 -5
  49. ccxt/deribit.py +15 -1
  50. ccxt/digifinex.py +30 -7
  51. ccxt/gate.py +17 -18
  52. ccxt/htx.py +7 -7
  53. ccxt/hyperliquid.py +107 -3
  54. ccxt/kraken.py +2 -2
  55. ccxt/mexc.py +11 -11
  56. ccxt/novadax.py +1 -1
  57. ccxt/okcoin.py +1 -1
  58. ccxt/okx.py +11 -2
  59. ccxt/phemex.py +1 -1
  60. ccxt/pro/__init__.py +3 -1
  61. ccxt/pro/binance.py +11 -13
  62. ccxt/pro/bingx.py +11 -8
  63. ccxt/pro/bitmart.py +2 -2
  64. ccxt/pro/bitopro.py +1 -1
  65. ccxt/pro/cex.py +1 -1
  66. ccxt/pro/coincheck.py +1 -1
  67. ccxt/pro/coinone.py +1 -1
  68. ccxt/pro/hyperliquid.py +1 -1
  69. ccxt/pro/kucoin.py +35 -3
  70. ccxt/pro/phemex.py +1 -1
  71. ccxt/pro/xt.py +1046 -0
  72. ccxt/probit.py +1 -1
  73. ccxt/test/tests_async.py +2 -2
  74. ccxt/test/tests_helpers.py +1 -1
  75. ccxt/test/tests_sync.py +2 -2
  76. ccxt/timex.py +16 -2
  77. ccxt/tokocrypto.py +1 -1
  78. ccxt/upbit.py +139 -45
  79. ccxt/xt.py +71 -8
  80. {ccxt-4.3.58.dist-info → ccxt-4.3.60.dist-info}/METADATA +5 -5
  81. {ccxt-4.3.58.dist-info → ccxt-4.3.60.dist-info}/RECORD +84 -83
  82. {ccxt-4.3.58.dist-info → ccxt-4.3.60.dist-info}/LICENSE.txt +0 -0
  83. {ccxt-4.3.58.dist-info → ccxt-4.3.60.dist-info}/WHEEL +0 -0
  84. {ccxt-4.3.58.dist-info → ccxt-4.3.60.dist-info}/top_level.txt +0 -0
ccxt/bingx.py CHANGED
@@ -302,9 +302,11 @@ class bingx(Exchange, ImplicitAPI):
302
302
  'post': {
303
303
  'trade/order': 2,
304
304
  'trade/leverage': 2,
305
- 'trade/allOpenOrders': 2,
306
305
  'trade/closeAllPositions': 2,
307
306
  },
307
+ 'delete': {
308
+ 'trade/allOpenOrders': 2,
309
+ },
308
310
  },
309
311
  },
310
312
  },
@@ -1477,8 +1479,9 @@ class bingx(Exchange, ImplicitAPI):
1477
1479
  def fetch_ticker(self, symbol: str, params={}) -> Ticker:
1478
1480
  """
1479
1481
  fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
1480
- :see: https://bingx-api.github.io/docs/#/swapV2/market-api.html#Get%20Ticker
1481
- :see: https://bingx-api.github.io/docs/#/spot/market-api.html#24%E5%B0%8F%E6%97%B6%E4%BB%B7%E6%A0%BC%E5%8F%98%E5%8A%A8%E6%83%85%E5%86%B5
1482
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/market-api.html#Get%20Ticker
1483
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/market-api.html#24-hour%20price%20changes
1484
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/market-api.html#Query%2024-Hour%20Price%20Change
1482
1485
  :param str symbol: unified symbol of the market to fetch the ticker for
1483
1486
  :param dict [params]: extra parameters specific to the exchange API endpoint
1484
1487
  :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
@@ -1492,7 +1495,38 @@ class bingx(Exchange, ImplicitAPI):
1492
1495
  if market['spot']:
1493
1496
  response = self.spotV1PublicGetTicker24hr(self.extend(request, params))
1494
1497
  else:
1495
- response = self.swapV2PublicGetQuoteTicker(self.extend(request, params))
1498
+ if market['inverse']:
1499
+ response = self.cswapV1PublicGetMarketTicker(self.extend(request, params))
1500
+ else:
1501
+ response = self.swapV2PublicGetQuoteTicker(self.extend(request, params))
1502
+ #
1503
+ # spot and swap
1504
+ #
1505
+ # {
1506
+ # "code": 0,
1507
+ # "msg": "",
1508
+ # "timestamp": 1720647285296,
1509
+ # "data": [
1510
+ # {
1511
+ # "symbol": "SOL-USD",
1512
+ # "priceChange": "-2.418",
1513
+ # "priceChangePercent": "-1.6900%",
1514
+ # "lastPrice": "140.574",
1515
+ # "lastQty": "1",
1516
+ # "highPrice": "146.190",
1517
+ # "lowPrice": "138.586",
1518
+ # "volume": "1464648.00",
1519
+ # "quoteVolume": "102928.12",
1520
+ # "openPrice": "142.994",
1521
+ # "closeTime": "1720647284976",
1522
+ # "bidPrice": "140.573",
1523
+ # "bidQty": "372",
1524
+ # "askPrice": "140.577",
1525
+ # "askQty": "58"
1526
+ # }
1527
+ # ]
1528
+ # }
1529
+ #
1496
1530
  data = self.safe_list(response, 'data')
1497
1531
  if data is not None:
1498
1532
  first = self.safe_dict(data, 0, {})
@@ -1503,7 +1537,9 @@ class bingx(Exchange, ImplicitAPI):
1503
1537
  def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
1504
1538
  """
1505
1539
  fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1506
- :see: https://bingx-api.github.io/docs/#/swapV2/market-api.html#Get%20Ticker
1540
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/market-api.html#Get%20Ticker
1541
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/market-api.html#24-hour%20price%20changes
1542
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/market-api.html#Query%2024-Hour%20Price%20Change
1507
1543
  :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1508
1544
  :param dict [params]: extra parameters specific to the exchange API endpoint
1509
1545
  :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
@@ -1517,11 +1553,45 @@ class bingx(Exchange, ImplicitAPI):
1517
1553
  market = self.market(firstSymbol)
1518
1554
  type = None
1519
1555
  type, params = self.handle_market_type_and_params('fetchTickers', market, params)
1556
+ subType = None
1557
+ subType, params = self.handle_sub_type_and_params('fetchTickers', market, params)
1520
1558
  response = None
1521
1559
  if type == 'spot':
1522
1560
  response = self.spotV1PublicGetTicker24hr(params)
1523
1561
  else:
1524
- response = self.swapV2PublicGetQuoteTicker(params)
1562
+ if subType == 'inverse':
1563
+ response = self.cswapV1PublicGetMarketTicker(params)
1564
+ else:
1565
+ response = self.swapV2PublicGetQuoteTicker(params)
1566
+ #
1567
+ # spot and swap
1568
+ #
1569
+ # {
1570
+ # "code": 0,
1571
+ # "msg": "",
1572
+ # "timestamp": 1720647285296,
1573
+ # "data": [
1574
+ # {
1575
+ # "symbol": "SOL-USD",
1576
+ # "priceChange": "-2.418",
1577
+ # "priceChangePercent": "-1.6900%",
1578
+ # "lastPrice": "140.574",
1579
+ # "lastQty": "1",
1580
+ # "highPrice": "146.190",
1581
+ # "lowPrice": "138.586",
1582
+ # "volume": "1464648.00",
1583
+ # "quoteVolume": "102928.12",
1584
+ # "openPrice": "142.994",
1585
+ # "closeTime": "1720647284976",
1586
+ # "bidPrice": "140.573",
1587
+ # "bidQty": "372",
1588
+ # "askPrice": "140.577",
1589
+ # "askQty": "58"
1590
+ # },
1591
+ # ...
1592
+ # ]
1593
+ # }
1594
+ #
1525
1595
  tickers = self.safe_list(response, 'data')
1526
1596
  return self.parse_tickers(tickers, symbols)
1527
1597
 
@@ -1919,7 +1989,7 @@ class bingx(Exchange, ImplicitAPI):
1919
1989
  elif timeInForce == 'GTC':
1920
1990
  request['timeInForce'] = 'GTC'
1921
1991
  if isSpot:
1922
- cost = self.safe_number_2(params, 'cost', 'quoteOrderQty')
1992
+ cost = self.safe_string_2(params, 'cost', 'quoteOrderQty')
1923
1993
  params = self.omit(params, 'cost')
1924
1994
  if cost is not None:
1925
1995
  request['quoteOrderQty'] = self.parse_to_numeric(self.cost_to_precision(symbol, cost))
@@ -2029,7 +2099,7 @@ class bingx(Exchange, ImplicitAPI):
2029
2099
  else:
2030
2100
  positionSide = 'LONG' if (side == 'buy') else 'SHORT'
2031
2101
  request['positionSide'] = positionSide
2032
- request['quantity'] = self.parse_to_numeric(self.amount_to_precision(symbol, amount))
2102
+ request['quantity'] = amount if (market['inverse']) else self.parse_to_numeric(self.amount_to_precision(symbol, amount)) # precision not available for inverse contracts
2033
2103
  params = self.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'trailingAmount', 'trailingPercent', 'trailingType', 'takeProfit', 'stopLoss', 'clientOrderId'])
2034
2104
  return self.extend(request, params)
2035
2105
 
@@ -2038,6 +2108,7 @@ class bingx(Exchange, ImplicitAPI):
2038
2108
  create a trade order
2039
2109
  :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Trade%20order
2040
2110
  :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Create%20an%20Order
2111
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Trade%20order
2041
2112
  :param str symbol: unified symbol of the market to create an order in
2042
2113
  :param str type: 'market' or 'limit'
2043
2114
  :param str side: 'buy' or 'sell'
@@ -2070,6 +2141,8 @@ class bingx(Exchange, ImplicitAPI):
2070
2141
  if market['swap']:
2071
2142
  if test:
2072
2143
  response = self.swapV2PrivatePostTradeOrderTest(request)
2144
+ elif market['inverse']:
2145
+ response = self.cswapV1PrivatePostTradeOrder(request)
2073
2146
  else:
2074
2147
  response = self.swapV2PrivatePostTradeOrder(request)
2075
2148
  else:
@@ -2094,7 +2167,7 @@ class bingx(Exchange, ImplicitAPI):
2094
2167
  # }
2095
2168
  # }
2096
2169
  #
2097
- # swap
2170
+ # linear swap
2098
2171
  #
2099
2172
  # {
2100
2173
  # "code": 0,
@@ -2112,15 +2185,37 @@ class bingx(Exchange, ImplicitAPI):
2112
2185
  # }
2113
2186
  # }
2114
2187
  #
2188
+ # inverse swap
2189
+ #
2190
+ # {
2191
+ # "orderId": 1809841379603398656,
2192
+ # "symbol": "SOL-USD",
2193
+ # "positionSide": "LONG",
2194
+ # "side": "BUY",
2195
+ # "type": "LIMIT",
2196
+ # "price": 100,
2197
+ # "quantity": 1,
2198
+ # "stopPrice": 0,
2199
+ # "workingType": "",
2200
+ # "timeInForce": ""
2201
+ # }
2202
+ #
2115
2203
  if isinstance(response, str):
2116
2204
  # broken api engine : order-ids are too long numbers(i.e. 1742930526912864656)
2117
2205
  # and json.loadscan not handle them in JS, so we have to use .parseJson
2118
2206
  # however, when order has an attached SL/TP, their value types need extra parsing
2119
2207
  response = self.fix_stringified_json_members(response)
2120
2208
  response = self.parse_json(response)
2121
- data = self.safe_value(response, 'data', {})
2122
- order = self.safe_dict(data, 'order', data)
2123
- return self.parse_order(order, market)
2209
+ data = self.safe_dict(response, 'data', {})
2210
+ result: dict = {}
2211
+ if market['swap']:
2212
+ if market['inverse']:
2213
+ result = response
2214
+ else:
2215
+ result = self.safe_dict(data, 'order', {})
2216
+ else:
2217
+ result = data
2218
+ return self.parse_order(result, market)
2124
2219
 
2125
2220
  def create_orders(self, orders: List[OrderRequest], params={}):
2126
2221
  """
@@ -2286,7 +2381,7 @@ class bingx(Exchange, ImplicitAPI):
2286
2381
  # }
2287
2382
  #
2288
2383
  #
2289
- # swap
2384
+ # linear swap
2290
2385
  # createOrder, createOrders
2291
2386
  #
2292
2387
  # {
@@ -2297,6 +2392,21 @@ class bingx(Exchange, ImplicitAPI):
2297
2392
  # "type": "LIMIT"
2298
2393
  # }
2299
2394
  #
2395
+ # inverse swap createOrder
2396
+ #
2397
+ # {
2398
+ # "orderId": 1809841379603398656,
2399
+ # "symbol": "SOL-USD",
2400
+ # "positionSide": "LONG",
2401
+ # "side": "BUY",
2402
+ # "type": "LIMIT",
2403
+ # "price": 100,
2404
+ # "quantity": 1,
2405
+ # "stopPrice": 0,
2406
+ # "workingType": "",
2407
+ # "timeInForce": ""
2408
+ # }
2409
+ #
2300
2410
  # fetchOrder, fetchOpenOrders, fetchClosedOrders
2301
2411
  #
2302
2412
  # {
@@ -2429,7 +2539,9 @@ class bingx(Exchange, ImplicitAPI):
2429
2539
  # side: 'SELL'
2430
2540
  # }
2431
2541
  # }
2542
+ #
2432
2543
  # stop loss order
2544
+ #
2433
2545
  # {
2434
2546
  # "symbol": "ETH-USDT",
2435
2547
  # "orderId": "1792461744476422144",
@@ -2449,6 +2561,52 @@ class bingx(Exchange, ImplicitAPI):
2449
2561
  # "clientOrderID": ""
2450
2562
  # }
2451
2563
  #
2564
+ # inverse swap cancelAllOrders
2565
+ #
2566
+ # {
2567
+ # "symbol": "SOL-USD",
2568
+ # "orderId": "1809845251327672320",
2569
+ # "side": "BUY",
2570
+ # "positionSide": "LONG",
2571
+ # "type": "LIMIT",
2572
+ # "quantity": 1,
2573
+ # "origQty": "0",
2574
+ # "price": "90",
2575
+ # "executedQty": "0",
2576
+ # "avgPrice": "0",
2577
+ # "cumQuote": "0",
2578
+ # "stopPrice": "",
2579
+ # "profit": "0.0000",
2580
+ # "commission": "0.000000",
2581
+ # "status": "CANCELLED",
2582
+ # "time": 1720335707872,
2583
+ # "updateTime": 1720335707912,
2584
+ # "clientOrderId": "",
2585
+ # "leverage": "",
2586
+ # "takeProfit": {
2587
+ # "type": "",
2588
+ # "quantity": 0,
2589
+ # "stopPrice": 0,
2590
+ # "price": 0,
2591
+ # "workingType": "",
2592
+ # "stopGuaranteed": ""
2593
+ # },
2594
+ # "stopLoss": {
2595
+ # "type": "",
2596
+ # "quantity": 0,
2597
+ # "stopPrice": 0,
2598
+ # "price": 0,
2599
+ # "workingType": "",
2600
+ # "stopGuaranteed": ""
2601
+ # },
2602
+ # "advanceAttr": 0,
2603
+ # "positionID": 0,
2604
+ # "takeProfitEntrustPrice": 0,
2605
+ # "stopLossEntrustPrice": 0,
2606
+ # "orderType": "",
2607
+ # "workingType": ""
2608
+ # }
2609
+ #
2452
2610
  info = order
2453
2611
  newOrder = self.safe_dict_2(order, 'newOrderResponse', 'orderOpenResponse')
2454
2612
  if newOrder is not None:
@@ -2629,6 +2787,7 @@ class bingx(Exchange, ImplicitAPI):
2629
2787
  cancel all open orders
2630
2788
  :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Cancel%20orders%20by%20symbol
2631
2789
  :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Cancel%20All%20Orders
2790
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Cancel%20all%20orders
2632
2791
  :param str [symbol]: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
2633
2792
  :param dict [params]: extra parameters specific to the exchange API endpoint
2634
2793
  :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
@@ -2666,36 +2825,94 @@ class bingx(Exchange, ImplicitAPI):
2666
2825
  # }
2667
2826
  #
2668
2827
  elif market['swap']:
2669
- response = self.swapV2PrivateDeleteTradeAllOpenOrders(self.extend(request, params))
2670
- #
2671
- # {
2672
- # "code": 0,
2673
- # "msg": "",
2674
- # "data": {
2675
- # "success": [
2676
- # {
2677
- # "symbol": "LINK-USDT",
2678
- # "orderId": 1597783835095859200,
2679
- # "side": "BUY",
2680
- # "positionSide": "LONG",
2681
- # "type": "TRIGGER_LIMIT",
2682
- # "origQty": "5.0",
2683
- # "price": "9.0000",
2684
- # "executedQty": "0.0",
2685
- # "avgPrice": "0.0000",
2686
- # "cumQuote": "0",
2687
- # "stopPrice": "9.5000",
2688
- # "profit": "",
2689
- # "commission": "",
2690
- # "status": "NEW",
2691
- # "time": 1669776326000,
2692
- # "updateTime": 1669776326000
2693
- # }
2694
- # ],
2695
- # "failed": null
2696
- # }
2697
- # }
2698
- #
2828
+ if market['inverse']:
2829
+ response = self.cswapV1PrivateDeleteTradeAllOpenOrders(self.extend(request, params))
2830
+ #
2831
+ # {
2832
+ # "code": 0,
2833
+ # "msg": "",
2834
+ # "timestamp": 1720501468364,
2835
+ # "data": {
2836
+ # "success": [
2837
+ # {
2838
+ # "symbol": "SOL-USD",
2839
+ # "orderId": "1809845251327672320",
2840
+ # "side": "BUY",
2841
+ # "positionSide": "LONG",
2842
+ # "type": "LIMIT",
2843
+ # "quantity": 1,
2844
+ # "origQty": "0",
2845
+ # "price": "90",
2846
+ # "executedQty": "0",
2847
+ # "avgPrice": "0",
2848
+ # "cumQuote": "0",
2849
+ # "stopPrice": "",
2850
+ # "profit": "0.0000",
2851
+ # "commission": "0.000000",
2852
+ # "status": "CANCELLED",
2853
+ # "time": 1720335707872,
2854
+ # "updateTime": 1720335707912,
2855
+ # "clientOrderId": "",
2856
+ # "leverage": "",
2857
+ # "takeProfit": {
2858
+ # "type": "",
2859
+ # "quantity": 0,
2860
+ # "stopPrice": 0,
2861
+ # "price": 0,
2862
+ # "workingType": "",
2863
+ # "stopGuaranteed": ""
2864
+ # },
2865
+ # "stopLoss": {
2866
+ # "type": "",
2867
+ # "quantity": 0,
2868
+ # "stopPrice": 0,
2869
+ # "price": 0,
2870
+ # "workingType": "",
2871
+ # "stopGuaranteed": ""
2872
+ # },
2873
+ # "advanceAttr": 0,
2874
+ # "positionID": 0,
2875
+ # "takeProfitEntrustPrice": 0,
2876
+ # "stopLossEntrustPrice": 0,
2877
+ # "orderType": "",
2878
+ # "workingType": ""
2879
+ # }
2880
+ # ],
2881
+ # "failed": null
2882
+ # }
2883
+ # }
2884
+ #
2885
+ else:
2886
+ response = self.swapV2PrivateDeleteTradeAllOpenOrders(self.extend(request, params))
2887
+ #
2888
+ # {
2889
+ # "code": 0,
2890
+ # "msg": "",
2891
+ # "data": {
2892
+ # "success": [
2893
+ # {
2894
+ # "symbol": "LINK-USDT",
2895
+ # "orderId": 1597783835095859200,
2896
+ # "side": "BUY",
2897
+ # "positionSide": "LONG",
2898
+ # "type": "TRIGGER_LIMIT",
2899
+ # "origQty": "5.0",
2900
+ # "price": "9.0000",
2901
+ # "executedQty": "0.0",
2902
+ # "avgPrice": "0.0000",
2903
+ # "cumQuote": "0",
2904
+ # "stopPrice": "9.5000",
2905
+ # "profit": "",
2906
+ # "commission": "",
2907
+ # "status": "NEW",
2908
+ # "time": 1669776326000,
2909
+ # "updateTime": 1669776326000
2910
+ # }
2911
+ # ],
2912
+ # "failed": null
2913
+ # }
2914
+ # }
2915
+ #
2699
2916
  else:
2700
2917
  raise BadRequest(self.id + ' cancelAllOrders is only supported for spot and swap markets.')
2701
2918
  data = self.safe_dict(response, 'data', {})
@@ -3670,6 +3887,7 @@ class bingx(Exchange, ImplicitAPI):
3670
3887
  """
3671
3888
  fetch the set leverage for a market
3672
3889
  :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20Leverage
3890
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Leverage
3673
3891
  :param str symbol: unified market symbol
3674
3892
  :param dict [params]: extra parameters specific to the exchange API endpoint
3675
3893
  :returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
@@ -3679,21 +3897,77 @@ class bingx(Exchange, ImplicitAPI):
3679
3897
  request: dict = {
3680
3898
  'symbol': market['id'],
3681
3899
  }
3682
- response = self.swapV2PrivateGetTradeLeverage(self.extend(request, params))
3683
- #
3684
- # {
3685
- # "code": 0,
3686
- # "msg": "",
3687
- # "data": {
3688
- # "longLeverage": 6,
3689
- # "shortLeverage": 6
3690
- # }
3691
- # }
3692
- #
3900
+ response = None
3901
+ if market['inverse']:
3902
+ response = self.cswapV1PrivateGetTradeLeverage(self.extend(request, params))
3903
+ #
3904
+ # {
3905
+ # "code": 0,
3906
+ # "msg": "",
3907
+ # "timestamp": 1720683803391,
3908
+ # "data": {
3909
+ # "symbol": "SOL-USD",
3910
+ # "longLeverage": 5,
3911
+ # "shortLeverage": 5,
3912
+ # "maxLongLeverage": 50,
3913
+ # "maxShortLeverage": 50,
3914
+ # "availableLongVol": "4000000",
3915
+ # "availableShortVol": "4000000"
3916
+ # }
3917
+ # }
3918
+ #
3919
+ else:
3920
+ response = self.swapV2PrivateGetTradeLeverage(self.extend(request, params))
3921
+ #
3922
+ # {
3923
+ # "code": 0,
3924
+ # "msg": "",
3925
+ # "data": {
3926
+ # "longLeverage": 5,
3927
+ # "shortLeverage": 5,
3928
+ # "maxLongLeverage": 125,
3929
+ # "maxShortLeverage": 125,
3930
+ # "availableLongVol": "0.0000",
3931
+ # "availableShortVol": "0.0000",
3932
+ # "availableLongVal": "0.0",
3933
+ # "availableShortVal": "0.0",
3934
+ # "maxPositionLongVal": "0.0",
3935
+ # "maxPositionShortVal": "0.0"
3936
+ # }
3937
+ # }
3938
+ #
3693
3939
  data = self.safe_dict(response, 'data', {})
3694
3940
  return self.parse_leverage(data, market)
3695
3941
 
3696
3942
  def parse_leverage(self, leverage: dict, market: Market = None) -> Leverage:
3943
+ #
3944
+ # linear swap
3945
+ #
3946
+ # {
3947
+ # "longLeverage": 5,
3948
+ # "shortLeverage": 5,
3949
+ # "maxLongLeverage": 125,
3950
+ # "maxShortLeverage": 125,
3951
+ # "availableLongVol": "0.0000",
3952
+ # "availableShortVol": "0.0000",
3953
+ # "availableLongVal": "0.0",
3954
+ # "availableShortVal": "0.0",
3955
+ # "maxPositionLongVal": "0.0",
3956
+ # "maxPositionShortVal": "0.0"
3957
+ # }
3958
+ #
3959
+ # inverse swap
3960
+ #
3961
+ # {
3962
+ # "symbol": "SOL-USD",
3963
+ # "longLeverage": 5,
3964
+ # "shortLeverage": 5,
3965
+ # "maxLongLeverage": 50,
3966
+ # "maxShortLeverage": 50,
3967
+ # "availableLongVol": "4000000",
3968
+ # "availableShortVol": "4000000"
3969
+ # }
3970
+ #
3697
3971
  marketId = self.safe_string(leverage, 'symbol')
3698
3972
  return {
3699
3973
  'info': leverage,
@@ -3707,6 +3981,7 @@ class bingx(Exchange, ImplicitAPI):
3707
3981
  """
3708
3982
  set the level of leverage for a market
3709
3983
  :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Switch%20Leverage
3984
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Modify%20Leverage
3710
3985
  :param float leverage: the rate of leverage
3711
3986
  :param str symbol: unified market symbol
3712
3987
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -3724,17 +3999,42 @@ class bingx(Exchange, ImplicitAPI):
3724
3999
  'side': side,
3725
4000
  'leverage': leverage,
3726
4001
  }
3727
- #
3728
- # {
3729
- # "code": 0,
3730
- # "msg": "",
3731
- # "data": {
3732
- # "leverage": 6,
3733
- # "symbol": "BTC-USDT"
3734
- # }
3735
- # }
3736
- #
3737
- return self.swapV2PrivatePostTradeLeverage(self.extend(request, params))
4002
+ if market['inverse']:
4003
+ return self.cswapV1PrivatePostTradeLeverage(self.extend(request, params))
4004
+ #
4005
+ # {
4006
+ # "code": 0,
4007
+ # "msg": "",
4008
+ # "timestamp": 1720725058059,
4009
+ # "data": {
4010
+ # "symbol": "SOL-USD",
4011
+ # "longLeverage": 10,
4012
+ # "shortLeverage": 5,
4013
+ # "maxLongLeverage": 50,
4014
+ # "maxShortLeverage": 50,
4015
+ # "availableLongVol": "4000000",
4016
+ # "availableShortVol": "4000000"
4017
+ # }
4018
+ # }
4019
+ #
4020
+ else:
4021
+ return self.swapV2PrivatePostTradeLeverage(self.extend(request, params))
4022
+ #
4023
+ # {
4024
+ # "code": 0,
4025
+ # "msg": "",
4026
+ # "data": {
4027
+ # "leverage": 10,
4028
+ # "symbol": "BTC-USDT",
4029
+ # "availableLongVol": "0.0000",
4030
+ # "availableShortVol": "0.0000",
4031
+ # "availableLongVal": "0.0",
4032
+ # "availableShortVal": "0.0",
4033
+ # "maxPositionLongVal": "0.0",
4034
+ # "maxPositionShortVal": "0.0"
4035
+ # }
4036
+ # }
4037
+ #
3738
4038
 
3739
4039
  def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
3740
4040
  """
@@ -4060,93 +4360,118 @@ class bingx(Exchange, ImplicitAPI):
4060
4360
  """
4061
4361
  closes open positions for a market
4062
4362
  :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
4363
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Close%20all%20positions%20in%20bulk
4063
4364
  :param str symbol: Unified CCXT market symbol
4064
4365
  :param str [side]: not used by bingx
4065
4366
  :param dict [params]: extra parameters specific to the bingx api endpoint
4066
- :param str|None [params.positionId]: it is recommended to hasattr(self, fill) parameter when closing a position
4367
+ :param str|None [params.positionId]: the id of the position you would like to close
4067
4368
  :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
4068
4369
  """
4069
4370
  self.load_markets()
4371
+ market = self.market(symbol)
4070
4372
  positionId = self.safe_string(params, 'positionId')
4071
- params = self.omit(params, 'positionId')
4373
+ request: dict = {}
4072
4374
  response = None
4073
4375
  if positionId is not None:
4074
- request: dict = {
4075
- 'positionId': positionId,
4076
- }
4077
4376
  response = self.swapV1PrivatePostTradeClosePosition(self.extend(request, params))
4377
+ #
4378
+ # {
4379
+ # "code": 0,
4380
+ # "msg": "",
4381
+ # "timestamp": 1710992264190,
4382
+ # "data": {
4383
+ # "orderId": 1770656007907930112,
4384
+ # "positionId": "1751667128353910784",
4385
+ # "symbol": "LTC-USDT",
4386
+ # "side": "Ask",
4387
+ # "type": "MARKET",
4388
+ # "positionSide": "Long",
4389
+ # "origQty": "0.2"
4390
+ # }
4391
+ # }
4392
+ #
4078
4393
  else:
4079
- market = self.market(symbol)
4080
- request: dict = {
4081
- 'symbol': market['id'],
4082
- }
4083
- response = self.swapV2PrivatePostTradeCloseAllPositions(self.extend(request, params))
4084
- #
4085
- # swapV1PrivatePostTradeClosePosition
4086
- #
4087
- # {
4088
- # "code": 0,
4089
- # "msg": "",
4090
- # "timestamp": 1710992264190,
4091
- # "data": {
4092
- # "orderId": 1770656007907930112,
4093
- # "positionId": "1751667128353910784",
4094
- # "symbol": "LTC-USDT",
4095
- # "side": "Ask",
4096
- # "type": "MARKET",
4097
- # "positionSide": "Long",
4098
- # "origQty": "0.2"
4099
- # }
4100
- # }
4101
- #
4102
- # swapV2PrivatePostTradeCloseAllPositions
4103
- #
4104
- # {
4105
- # "code": 0,
4106
- # "msg": "",
4107
- # "data": {
4108
- # "success": [
4109
- # 1727686766700486656,
4110
- # ],
4111
- # "failed": null
4112
- # }
4113
- # }
4114
- #
4394
+ request['symbol'] = market['id']
4395
+ if market['inverse']:
4396
+ response = self.cswapV1PrivatePostTradeCloseAllPositions(self.extend(request, params))
4397
+ #
4398
+ # {
4399
+ # "code": 0,
4400
+ # "msg": "",
4401
+ # "timestamp": 1720771601428,
4402
+ # "data": {
4403
+ # "success": ["1811673520637231104"],
4404
+ # "failed": null
4405
+ # }
4406
+ # }
4407
+ #
4408
+ else:
4409
+ response = self.swapV2PrivatePostTradeCloseAllPositions(self.extend(request, params))
4410
+ #
4411
+ # {
4412
+ # "code": 0,
4413
+ # "msg": "",
4414
+ # "data": {
4415
+ # "success": [
4416
+ # 1727686766700486656,
4417
+ # ],
4418
+ # "failed": null
4419
+ # }
4420
+ # }
4421
+ #
4115
4422
  data = self.safe_dict(response, 'data')
4116
- return self.parse_order(data)
4423
+ return self.parse_order(data, market)
4117
4424
 
4118
4425
  def close_all_positions(self, params={}) -> List[Position]:
4119
4426
  """
4120
4427
  closes open positions for a market
4121
4428
  :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
4122
- :param dict [params]: extra parameters specific to the okx api endpoint
4429
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Close%20all%20positions%20in%20bulk
4430
+ :param dict [params]: extra parameters specific to the bingx api endpoint
4123
4431
  :param str [params.recvWindow]: request valid time window value
4124
- :returns dict[]: `A list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
4432
+ :returns dict[]: `a list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
4125
4433
  """
4126
4434
  self.load_markets()
4127
4435
  defaultRecvWindow = self.safe_integer(self.options, 'recvWindow')
4128
4436
  recvWindow = self.safe_integer(self.parse_params, 'recvWindow', defaultRecvWindow)
4129
4437
  marketType = None
4130
4438
  marketType, params = self.handle_market_type_and_params('closeAllPositions', None, params)
4439
+ subType = None
4440
+ subType, params = self.handle_sub_type_and_params('closeAllPositions', None, params)
4131
4441
  if marketType == 'margin':
4132
4442
  raise BadRequest(self.id + ' closePositions() cannot be used for ' + marketType + ' markets')
4133
4443
  request: dict = {
4134
4444
  'recvWindow': recvWindow,
4135
4445
  }
4136
- response = self.swapV2PrivatePostTradeCloseAllPositions(self.extend(request, params))
4137
- #
4138
- # {
4139
- # "code": 0,
4140
- # "msg": "",
4141
- # "data": {
4142
- # "success": [
4143
- # 1727686766700486656,
4144
- # 1727686767048613888
4145
- # ],
4146
- # "failed": null
4147
- # }
4148
- # }
4149
- #
4446
+ response = None
4447
+ if subType == 'inverse':
4448
+ response = self.cswapV1PrivatePostTradeCloseAllPositions(self.extend(request, params))
4449
+ #
4450
+ # {
4451
+ # "code": 0,
4452
+ # "msg": "",
4453
+ # "timestamp": 1720771601428,
4454
+ # "data": {
4455
+ # "success": ["1811673520637231104"],
4456
+ # "failed": null
4457
+ # }
4458
+ # }
4459
+ #
4460
+ else:
4461
+ response = self.swapV2PrivatePostTradeCloseAllPositions(self.extend(request, params))
4462
+ #
4463
+ # {
4464
+ # "code": 0,
4465
+ # "msg": "",
4466
+ # "data": {
4467
+ # "success": [
4468
+ # 1727686766700486656,
4469
+ # 1727686767048613888
4470
+ # ],
4471
+ # "failed": null
4472
+ # }
4473
+ # }
4474
+ #
4150
4475
  data = self.safe_dict(response, 'data', {})
4151
4476
  success = self.safe_list(data, 'success', [])
4152
4477
  positions = []