ccxt 4.3.62__py2.py3-none-any.whl → 4.3.64__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 (74) hide show
  1. ccxt/__init__.py +2 -1
  2. ccxt/abstract/binance.py +5 -5
  3. ccxt/abstract/binancecoinm.py +5 -5
  4. ccxt/abstract/binanceus.py +5 -5
  5. ccxt/abstract/binanceusdm.py +5 -5
  6. ccxt/abstract/cryptocom.py +11 -0
  7. ccxt/abstract/kucoin.py +1 -0
  8. ccxt/abstract/kucoinfutures.py +1 -0
  9. ccxt/abstract/woo.py +3 -0
  10. ccxt/ace.py +33 -15
  11. ccxt/alpaca.py +1 -0
  12. ccxt/async_support/__init__.py +2 -1
  13. ccxt/async_support/ace.py +33 -15
  14. ccxt/async_support/alpaca.py +1 -0
  15. ccxt/async_support/base/exchange.py +4 -4
  16. ccxt/async_support/binance.py +6 -9
  17. ccxt/async_support/bingx.py +534 -152
  18. ccxt/async_support/bitfinex.py +1 -1
  19. ccxt/async_support/bitfinex2.py +1 -1
  20. ccxt/async_support/coinbaseinternational.py +1 -1
  21. ccxt/async_support/cryptocom.py +17 -2
  22. ccxt/async_support/independentreserve.py +103 -1
  23. ccxt/async_support/kucoin.py +2 -0
  24. ccxt/async_support/mercado.py +5 -1
  25. ccxt/async_support/whitebit.py +1 -1
  26. ccxt/async_support/woo.py +321 -81
  27. ccxt/async_support/xt.py +3 -3
  28. ccxt/async_support/yobit.py +1 -1
  29. ccxt/async_support/zonda.py +1 -1
  30. ccxt/base/errors.py +8 -1
  31. ccxt/base/exchange.py +11 -5
  32. ccxt/binance.py +6 -9
  33. ccxt/bingx.py +534 -152
  34. ccxt/bitfinex.py +1 -1
  35. ccxt/bitfinex2.py +1 -1
  36. ccxt/coinbaseinternational.py +1 -1
  37. ccxt/cryptocom.py +17 -2
  38. ccxt/independentreserve.py +103 -1
  39. ccxt/kucoin.py +2 -0
  40. ccxt/mercado.py +5 -1
  41. ccxt/pro/__init__.py +1 -1
  42. ccxt/pro/binance.py +56 -35
  43. ccxt/pro/bitfinex2.py +6 -4
  44. ccxt/pro/bitget.py +5 -2
  45. ccxt/pro/bitmart.py +3 -3
  46. ccxt/pro/bitvavo.py +1 -1
  47. ccxt/pro/bybit.py +41 -18
  48. ccxt/pro/cryptocom.py +7 -2
  49. ccxt/pro/gate.py +7 -4
  50. ccxt/pro/gemini.py +4 -2
  51. ccxt/pro/htx.py +5 -1
  52. ccxt/pro/independentreserve.py +6 -4
  53. ccxt/pro/kraken.py +79 -6
  54. ccxt/pro/okx.py +5 -5
  55. ccxt/pro/onetrading.py +3 -2
  56. ccxt/pro/oxfun.py +1 -1
  57. ccxt/pro/poloniexfutures.py +5 -2
  58. ccxt/pro/vertex.py +3 -2
  59. ccxt/pro/woo.py +2 -1
  60. ccxt/pro/woofipro.py +3 -2
  61. ccxt/test/tests_async.py +3 -3
  62. ccxt/test/tests_helpers.py +1 -1
  63. ccxt/test/tests_init.py +3 -3
  64. ccxt/test/tests_sync.py +3 -3
  65. ccxt/whitebit.py +1 -1
  66. ccxt/woo.py +321 -81
  67. ccxt/xt.py +3 -3
  68. ccxt/yobit.py +1 -1
  69. ccxt/zonda.py +1 -1
  70. {ccxt-4.3.62.dist-info → ccxt-4.3.64.dist-info}/METADATA +4 -4
  71. {ccxt-4.3.62.dist-info → ccxt-4.3.64.dist-info}/RECORD +74 -74
  72. {ccxt-4.3.62.dist-info → ccxt-4.3.64.dist-info}/LICENSE.txt +0 -0
  73. {ccxt-4.3.62.dist-info → ccxt-4.3.64.dist-info}/WHEEL +0 -0
  74. {ccxt-4.3.62.dist-info → ccxt-4.3.64.dist-info}/top_level.txt +0 -0
@@ -8,7 +8,7 @@ from ccxt.abstract.bingx import ImplicitAPI
8
8
  import asyncio
9
9
  import hashlib
10
10
  import numbers
11
- from ccxt.base.types import Balances, Currencies, Currency, Int, Leverage, MarginMode, MarginModification, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry, TransferEntries
11
+ from ccxt.base.types import Balances, Currencies, Currency, Int, Leverage, MarginMode, MarginModification, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, Transaction, TransferEntry, TransferEntries
12
12
  from typing import List
13
13
  from ccxt.base.errors import ExchangeError
14
14
  from ccxt.base.errors import AuthenticationError
@@ -86,6 +86,7 @@ class bingx(Exchange, ImplicitAPI):
86
86
  'fetchOrder': True,
87
87
  'fetchOrderBook': True,
88
88
  'fetchOrders': True,
89
+ 'fetchPosition': True,
89
90
  'fetchPositionHistory': False,
90
91
  'fetchPositionMode': True,
91
92
  'fetchPositions': True,
@@ -94,6 +95,7 @@ class bingx(Exchange, ImplicitAPI):
94
95
  'fetchTickers': True,
95
96
  'fetchTime': True,
96
97
  'fetchTrades': True,
98
+ 'fetchTradingFee': True,
97
99
  'fetchTransfers': True,
98
100
  'fetchWithdrawals': True,
99
101
  'reduceMargin': True,
@@ -1699,6 +1701,7 @@ class bingx(Exchange, ImplicitAPI):
1699
1701
  :see: https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Assets
1700
1702
  :see: https://bingx-api.github.io/docs/#/swapV2/account-api.html#Get%20Perpetual%20Swap%20Account%20Asset%20Information
1701
1703
  :see: https://bingx-api.github.io/docs/#/standard/contract-interface.html#Query%20standard%20contract%20balance
1704
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Account%20Assets
1702
1705
  :param dict [params]: extra parameters specific to the exchange API endpoint
1703
1706
  :param boolean [params.standard]: whether to fetch standard contract balances
1704
1707
  :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
@@ -1707,111 +1710,220 @@ class bingx(Exchange, ImplicitAPI):
1707
1710
  response = None
1708
1711
  standard = None
1709
1712
  standard, params = self.handle_option_and_params(params, 'fetchBalance', 'standard', False)
1713
+ subType = None
1714
+ subType, params = self.handle_sub_type_and_params('fetchBalance', None, params)
1710
1715
  marketType, marketTypeQuery = self.handle_market_type_and_params('fetchBalance', None, params)
1711
1716
  if standard:
1712
1717
  response = await self.contractV1PrivateGetBalance(marketTypeQuery)
1718
+ #
1719
+ # {
1720
+ # "code": 0,
1721
+ # "timestamp": 1721192833454,
1722
+ # "data": [
1723
+ # {
1724
+ # "asset": "USDT",
1725
+ # "balance": "4.72644300000000000000",
1726
+ # "crossWalletBalance": "4.72644300000000000000",
1727
+ # "crossUnPnl": "0",
1728
+ # "availableBalance": "4.72644300000000000000",
1729
+ # "maxWithdrawAmount": "4.72644300000000000000",
1730
+ # "marginAvailable": False,
1731
+ # "updateTime": 1721192833443
1732
+ # },
1733
+ # ]
1734
+ # }
1735
+ #
1713
1736
  elif marketType == 'spot':
1714
1737
  response = await self.spotV1PrivateGetAccountBalance(marketTypeQuery)
1738
+ #
1739
+ # {
1740
+ # "code": 0,
1741
+ # "msg": "",
1742
+ # "debugMsg": "",
1743
+ # "data": {
1744
+ # "balances": [
1745
+ # {
1746
+ # "asset": "USDT",
1747
+ # "free": "45.733046995800514",
1748
+ # "locked": "0"
1749
+ # },
1750
+ # ]
1751
+ # }
1752
+ # }
1753
+ #
1715
1754
  else:
1716
- response = await self.swapV2PrivateGetUserBalance(marketTypeQuery)
1755
+ if subType == 'inverse':
1756
+ response = await self.cswapV1PrivateGetUserBalance(marketTypeQuery)
1757
+ #
1758
+ # {
1759
+ # "code": 0,
1760
+ # "msg": "",
1761
+ # "timestamp": 1721191833813,
1762
+ # "data": [
1763
+ # {
1764
+ # "asset": "SOL",
1765
+ # "balance": "0.35707951",
1766
+ # "equity": "0.35791051",
1767
+ # "unrealizedProfit": "0.00083099",
1768
+ # "availableMargin": "0.35160653",
1769
+ # "usedMargin": "0.00630397",
1770
+ # "freezedMargin": "0",
1771
+ # "shortUid": "12851936"
1772
+ # }
1773
+ # ]
1774
+ # }
1775
+ #
1776
+ else:
1777
+ response = await self.swapV2PrivateGetUserBalance(marketTypeQuery)
1778
+ #
1779
+ # {
1780
+ # "code": 0,
1781
+ # "msg": "",
1782
+ # "data": {
1783
+ # "balance": {
1784
+ # "userId": "1177064765068660742",
1785
+ # "asset": "USDT",
1786
+ # "balance": "51.5198",
1787
+ # "equity": "50.5349",
1788
+ # "unrealizedProfit": "-0.9849",
1789
+ # "realisedProfit": "-0.2134",
1790
+ # "availableMargin": "49.1428",
1791
+ # "usedMargin": "1.3922",
1792
+ # "freezedMargin": "0.0000",
1793
+ # "shortUid": "12851936"
1794
+ # }
1795
+ # }
1796
+ # }
1797
+ #
1798
+ return self.parse_balance(response)
1799
+
1800
+ def parse_balance(self, response) -> Balances:
1801
+ #
1802
+ # standard
1803
+ #
1804
+ # {
1805
+ # "code": 0,
1806
+ # "timestamp": 1721192833454,
1807
+ # "data": [
1808
+ # {
1809
+ # "asset": "USDT",
1810
+ # "balance": "4.72644300000000000000",
1811
+ # "crossWalletBalance": "4.72644300000000000000",
1812
+ # "crossUnPnl": "0",
1813
+ # "availableBalance": "4.72644300000000000000",
1814
+ # "maxWithdrawAmount": "4.72644300000000000000",
1815
+ # "marginAvailable": False,
1816
+ # "updateTime": 1721192833443
1817
+ # },
1818
+ # ]
1819
+ # }
1717
1820
  #
1718
1821
  # spot
1719
1822
  #
1720
- # {
1721
- # "code": 0,
1722
- # "msg": "",
1723
- # "ttl": 1,
1724
- # "data": {
1725
- # "balances": [
1726
- # {
1727
- # "asset": "USDT",
1728
- # "free": "16.73971130673954",
1729
- # "locked": "0"
1730
- # }
1731
- # ]
1732
- # }
1733
- # }
1823
+ # {
1824
+ # "code": 0,
1825
+ # "msg": "",
1826
+ # "debugMsg": "",
1827
+ # "data": {
1828
+ # "balances": [
1829
+ # {
1830
+ # "asset": "USDT",
1831
+ # "free": "45.733046995800514",
1832
+ # "locked": "0"
1833
+ # },
1834
+ # ]
1835
+ # }
1836
+ # }
1734
1837
  #
1735
- # swap
1838
+ # inverse swap
1736
1839
  #
1737
- # {
1738
- # "code": 0,
1739
- # "msg": "",
1740
- # "data": {
1741
- # "balance": {
1742
- # "asset": "USDT",
1743
- # "balance": "15.6128",
1744
- # "equity": "15.6128",
1745
- # "unrealizedProfit": "0.0000",
1746
- # "realisedProfit": "0.0000",
1747
- # "availableMargin": "15.6128",
1748
- # "usedMargin": "0.0000",
1749
- # "freezedMargin": "0.0000"
1750
- # }
1751
- # }
1752
- # }
1753
- # standard futures
1754
- # {
1755
- # "code":"0",
1756
- # "timestamp":"1691148990942",
1757
- # "data":[
1758
- # {
1759
- # "asset":"VST",
1760
- # "balance":"100000.00000000000000000000",
1761
- # "crossWalletBalance":"100000.00000000000000000000",
1762
- # "crossUnPnl":"0",
1763
- # "availableBalance":"100000.00000000000000000000",
1764
- # "maxWithdrawAmount":"100000.00000000000000000000",
1765
- # "marginAvailable":false,
1766
- # "updateTime":"1691148990902"
1767
- # },
1768
- # {
1769
- # "asset":"USDT",
1770
- # "balance":"0",
1771
- # "crossWalletBalance":"0",
1772
- # "crossUnPnl":"0",
1773
- # "availableBalance":"0",
1774
- # "maxWithdrawAmount":"0",
1775
- # "marginAvailable":false,
1776
- # "updateTime":"1691148990902"
1777
- # },
1778
- # ]
1840
+ # {
1841
+ # "code": 0,
1842
+ # "msg": "",
1843
+ # "timestamp": 1721191833813,
1844
+ # "data": [
1845
+ # {
1846
+ # "asset": "SOL",
1847
+ # "balance": "0.35707951",
1848
+ # "equity": "0.35791051",
1849
+ # "unrealizedProfit": "0.00083099",
1850
+ # "availableMargin": "0.35160653",
1851
+ # "usedMargin": "0.00630397",
1852
+ # "freezedMargin": "0",
1853
+ # "shortUid": "12851936"
1854
+ # }
1855
+ # ]
1856
+ # }
1857
+ #
1858
+ # linear swap
1859
+ #
1860
+ # {
1861
+ # "code": 0,
1862
+ # "msg": "",
1863
+ # "data": {
1864
+ # "balance": {
1865
+ # "userId": "1177064765068660742",
1866
+ # "asset": "USDT",
1867
+ # "balance": "51.5198",
1868
+ # "equity": "50.5349",
1869
+ # "unrealizedProfit": "-0.9849",
1870
+ # "realisedProfit": "-0.2134",
1871
+ # "availableMargin": "49.1428",
1872
+ # "usedMargin": "1.3922",
1873
+ # "freezedMargin": "0.0000",
1874
+ # "shortUid": "12851936"
1875
+ # }
1876
+ # }
1779
1877
  # }
1780
1878
  #
1781
- return self.parse_balance(response)
1782
-
1783
- def parse_balance(self, response) -> Balances:
1784
- data = self.safe_value(response, 'data')
1785
- balances = self.safe_value_2(data, 'balance', 'balances', data)
1786
1879
  result: dict = {'info': response}
1787
- if isinstance(balances, list):
1788
- for i in range(0, len(balances)):
1789
- balance = balances[i]
1880
+ standardAndInverseBalances = self.safe_list(response, 'data')
1881
+ firstStandardOrInverse = self.safe_dict(standardAndInverseBalances, 0)
1882
+ isStandardOrInverse = firstStandardOrInverse is not None
1883
+ spotData = self.safe_dict(response, 'data', {})
1884
+ spotBalances = self.safe_list(spotData, 'balances')
1885
+ firstSpot = self.safe_dict(spotBalances, 0)
1886
+ isSpot = firstSpot is not None
1887
+ if isStandardOrInverse:
1888
+ for i in range(0, len(standardAndInverseBalances)):
1889
+ balance = standardAndInverseBalances[i]
1890
+ currencyId = self.safe_string(balance, 'asset')
1891
+ code = self.safe_currency_code(currencyId)
1892
+ account = self.account()
1893
+ account['free'] = self.safe_string_2(balance, 'availableMargin', 'availableBalance')
1894
+ account['used'] = self.safe_string(balance, 'usedMargin')
1895
+ account['total'] = self.safe_string(balance, 'maxWithdrawAmount')
1896
+ result[code] = account
1897
+ elif isSpot:
1898
+ for i in range(0, len(spotBalances)):
1899
+ balance = spotBalances[i]
1790
1900
  currencyId = self.safe_string(balance, 'asset')
1791
1901
  code = self.safe_currency_code(currencyId)
1792
1902
  account = self.account()
1793
- account['free'] = self.safe_string_2(balance, 'free', 'availableBalance')
1903
+ account['free'] = self.safe_string(balance, 'free')
1794
1904
  account['used'] = self.safe_string(balance, 'locked')
1795
- account['total'] = self.safe_string(balance, 'balance')
1796
1905
  result[code] = account
1797
1906
  else:
1798
- currencyId = self.safe_string(balances, 'asset')
1907
+ linearSwapData = self.safe_dict(response, 'data', {})
1908
+ linearSwapBalance = self.safe_dict(linearSwapData, 'balance')
1909
+ currencyId = self.safe_string(linearSwapBalance, 'asset')
1799
1910
  code = self.safe_currency_code(currencyId)
1800
1911
  account = self.account()
1801
- account['free'] = self.safe_string(balances, 'availableMargin')
1802
- account['used'] = self.safe_string(balances, 'usedMargin')
1912
+ account['free'] = self.safe_string(linearSwapBalance, 'availableMargin')
1913
+ account['used'] = self.safe_string(linearSwapBalance, 'usedMargin')
1803
1914
  result[code] = account
1804
1915
  return self.safe_balance(result)
1805
1916
 
1806
1917
  async def fetch_positions(self, symbols: Strings = None, params={}):
1807
1918
  """
1808
1919
  fetch all open positions
1809
- :see: https://bingx-api.github.io/docs/#/swapV2/account-api.html#Perpetual%20Swap%20Positions
1810
- :see: https://bingx-api.github.io/docs/#/standard/contract-interface.html#Query%20standard%20contract%20balance
1920
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/account-api.html#Query%20position%20data
1921
+ :see: https://bingx-api.github.io/docs/#/en-us/standard/contract-interface.html#position
1922
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20warehouse
1811
1923
  :param str[]|None symbols: list of unified market symbols
1812
1924
  :param dict [params]: extra parameters specific to the exchange API endpoint
1813
1925
  :param boolean [params.standard]: whether to fetch standard contract positions
1814
- :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
1926
+ :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
1815
1927
  """
1816
1928
  await self.load_markets()
1817
1929
  symbols = self.market_symbols(symbols)
@@ -1821,54 +1933,207 @@ class bingx(Exchange, ImplicitAPI):
1821
1933
  if standard:
1822
1934
  response = await self.contractV1PrivateGetAllPosition(params)
1823
1935
  else:
1824
- response = await self.swapV2PrivateGetUserPositions(params)
1825
- #
1826
- # {
1827
- # "code": 0,
1828
- # "msg": "",
1829
- # "data": [
1830
- # {
1831
- # "symbol": "BTC-USDT",
1832
- # "positionId": "12345678",
1833
- # "positionSide": "LONG",
1834
- # "isolated": True,
1835
- # "positionAmt": "123.33",
1836
- # "availableAmt": "128.99",
1837
- # "unrealizedProfit": "1.22",
1838
- # "realisedProfit": "8.1",
1839
- # "initialMargin": "123.33",
1840
- # "avgPrice": "2.2",
1841
- # "leverage": 10,
1842
- # }
1843
- # ]
1844
- # }
1845
- #
1936
+ market = None
1937
+ if symbols is not None:
1938
+ symbols = self.market_symbols(symbols)
1939
+ firstSymbol = self.safe_string(symbols, 0)
1940
+ if firstSymbol is not None:
1941
+ market = self.market(firstSymbol)
1942
+ subType = None
1943
+ subType, params = self.handle_sub_type_and_params('fetchPositions', market, params)
1944
+ if subType == 'inverse':
1945
+ response = await self.cswapV1PrivateGetUserPositions(params)
1946
+ #
1947
+ # {
1948
+ # "code": 0,
1949
+ # "msg": "",
1950
+ # "timestamp": 0,
1951
+ # "data": [
1952
+ # {
1953
+ # "symbol": "SOL-USD",
1954
+ # "positionId": "1813080351385337856",
1955
+ # "positionSide": "LONG",
1956
+ # "isolated": False,
1957
+ # "positionAmt": "1",
1958
+ # "availableAmt": "1",
1959
+ # "unrealizedProfit": "-0.00009074",
1960
+ # "initialMargin": "0.00630398",
1961
+ # "liquidationPrice": 23.968303426677032,
1962
+ # "avgPrice": "158.63",
1963
+ # "leverage": 10,
1964
+ # "markPrice": "158.402",
1965
+ # "riskRate": "0.00123783",
1966
+ # "maxMarginReduction": "0",
1967
+ # "updateTime": 1721107015848
1968
+ # }
1969
+ # ]
1970
+ # }
1971
+ #
1972
+ else:
1973
+ response = await self.swapV2PrivateGetUserPositions(params)
1974
+ #
1975
+ # {
1976
+ # "code": 0,
1977
+ # "msg": "",
1978
+ # "data": [
1979
+ # {
1980
+ # "positionId": "1792480725958881280",
1981
+ # "symbol": "LTC-USDT",
1982
+ # "currency": "USDT",
1983
+ # "positionAmt": "0.1",
1984
+ # "availableAmt": "0.1",
1985
+ # "positionSide": "LONG",
1986
+ # "isolated": False,
1987
+ # "avgPrice": "83.53",
1988
+ # "initialMargin": "1.3922",
1989
+ # "margin": "0.3528",
1990
+ # "leverage": 6,
1991
+ # "unrealizedProfit": "-1.0393",
1992
+ # "realisedProfit": "-0.2119",
1993
+ # "liquidationPrice": 0,
1994
+ # "pnlRatio": "-0.7465",
1995
+ # "maxMarginReduction": "0.0000",
1996
+ # "riskRate": "0.0008",
1997
+ # "markPrice": "73.14",
1998
+ # "positionValue": "7.3136",
1999
+ # "onlyOnePosition": True,
2000
+ # "updateTime": 1721088016688
2001
+ # }
2002
+ # ]
2003
+ # }
2004
+ #
1846
2005
  positions = self.safe_list(response, 'data', [])
1847
2006
  return self.parse_positions(positions, symbols)
1848
2007
 
2008
+ async def fetch_position(self, symbol: str, params={}):
2009
+ """
2010
+ fetch data on a single open contract trade position
2011
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/account-api.html#Query%20position%20data
2012
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20warehouse
2013
+ :param str symbol: unified market symbol of the market the position is held in
2014
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2015
+ :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
2016
+ """
2017
+ await self.load_markets()
2018
+ market = self.market(symbol)
2019
+ if not market['swap']:
2020
+ raise BadRequest(self.id + ' fetchPosition() supports swap markets only')
2021
+ request: dict = {
2022
+ 'symbol': market['id'],
2023
+ }
2024
+ response = None
2025
+ if market['inverse']:
2026
+ response = await self.cswapV1PrivateGetUserPositions(self.extend(request, params))
2027
+ #
2028
+ # {
2029
+ # "code": 0,
2030
+ # "msg": "",
2031
+ # "timestamp": 0,
2032
+ # "data": [
2033
+ # {
2034
+ # "symbol": "SOL-USD",
2035
+ # "positionId": "1813080351385337856",
2036
+ # "positionSide": "LONG",
2037
+ # "isolated": False,
2038
+ # "positionAmt": "1",
2039
+ # "availableAmt": "1",
2040
+ # "unrealizedProfit": "-0.00009074",
2041
+ # "initialMargin": "0.00630398",
2042
+ # "liquidationPrice": 23.968303426677032,
2043
+ # "avgPrice": "158.63",
2044
+ # "leverage": 10,
2045
+ # "markPrice": "158.402",
2046
+ # "riskRate": "0.00123783",
2047
+ # "maxMarginReduction": "0",
2048
+ # "updateTime": 1721107015848
2049
+ # }
2050
+ # ]
2051
+ # }
2052
+ #
2053
+ else:
2054
+ response = await self.swapV2PrivateGetUserPositions(self.extend(request, params))
2055
+ #
2056
+ # {
2057
+ # "code": 0,
2058
+ # "msg": "",
2059
+ # "data": [
2060
+ # {
2061
+ # "positionId": "1792480725958881280",
2062
+ # "symbol": "LTC-USDT",
2063
+ # "currency": "USDT",
2064
+ # "positionAmt": "0.1",
2065
+ # "availableAmt": "0.1",
2066
+ # "positionSide": "LONG",
2067
+ # "isolated": False,
2068
+ # "avgPrice": "83.53",
2069
+ # "initialMargin": "1.3922",
2070
+ # "margin": "0.3528",
2071
+ # "leverage": 6,
2072
+ # "unrealizedProfit": "-1.0393",
2073
+ # "realisedProfit": "-0.2119",
2074
+ # "liquidationPrice": 0,
2075
+ # "pnlRatio": "-0.7465",
2076
+ # "maxMarginReduction": "0.0000",
2077
+ # "riskRate": "0.0008",
2078
+ # "markPrice": "73.14",
2079
+ # "positionValue": "7.3136",
2080
+ # "onlyOnePosition": True,
2081
+ # "updateTime": 1721088016688
2082
+ # }
2083
+ # ]
2084
+ # }
2085
+ #
2086
+ data = self.safe_list(response, 'data', [])
2087
+ first = self.safe_dict(data, 0, {})
2088
+ return self.parse_position(first, market)
2089
+
1849
2090
  def parse_position(self, position: dict, market: Market = None):
1850
2091
  #
1851
- # {
1852
- # "positionId":"1773122376147623936",
1853
- # "symbol":"XRP-USDT",
1854
- # "currency":"USDT",
1855
- # "positionAmt":"3",
1856
- # "availableAmt":"3",
1857
- # "positionSide":"LONG",
1858
- # "isolated":false,
1859
- # "avgPrice":"0.6139",
1860
- # "initialMargin":"0.0897",
1861
- # "leverage":20,
1862
- # "unrealizedProfit":"-0.0023",
1863
- # "realisedProfit":"-0.0009",
1864
- # "liquidationPrice":0,
1865
- # "pnlRatio":"-0.0260",
1866
- # "maxMarginReduction":"",
1867
- # "riskRate":"",
1868
- # "markPrice":"",
1869
- # "positionValue":"",
1870
- # "onlyOnePosition":false
1871
- # }
2092
+ # inverse swap
2093
+ #
2094
+ # {
2095
+ # "symbol": "SOL-USD",
2096
+ # "positionId": "1813080351385337856",
2097
+ # "positionSide": "LONG",
2098
+ # "isolated": False,
2099
+ # "positionAmt": "1",
2100
+ # "availableAmt": "1",
2101
+ # "unrealizedProfit": "-0.00009074",
2102
+ # "initialMargin": "0.00630398",
2103
+ # "liquidationPrice": 23.968303426677032,
2104
+ # "avgPrice": "158.63",
2105
+ # "leverage": 10,
2106
+ # "markPrice": "158.402",
2107
+ # "riskRate": "0.00123783",
2108
+ # "maxMarginReduction": "0",
2109
+ # "updateTime": 1721107015848
2110
+ # }
2111
+ #
2112
+ # linear swap
2113
+ #
2114
+ # {
2115
+ # "positionId": "1792480725958881280",
2116
+ # "symbol": "LTC-USDT",
2117
+ # "currency": "USDT",
2118
+ # "positionAmt": "0.1",
2119
+ # "availableAmt": "0.1",
2120
+ # "positionSide": "LONG",
2121
+ # "isolated": False,
2122
+ # "avgPrice": "83.53",
2123
+ # "initialMargin": "1.3922",
2124
+ # "margin": "0.3528",
2125
+ # "leverage": 6,
2126
+ # "unrealizedProfit": "-1.0393",
2127
+ # "realisedProfit": "-0.2119",
2128
+ # "liquidationPrice": 0,
2129
+ # "pnlRatio": "-0.7465",
2130
+ # "maxMarginReduction": "0.0000",
2131
+ # "riskRate": "0.0008",
2132
+ # "markPrice": "73.14",
2133
+ # "positionValue": "7.3136",
2134
+ # "onlyOnePosition": True,
2135
+ # "updateTime": 1721088016688
2136
+ # }
1872
2137
  #
1873
2138
  # standard position
1874
2139
  #
@@ -1903,13 +2168,13 @@ class bingx(Exchange, ImplicitAPI):
1903
2168
  'percentage': None,
1904
2169
  'contracts': self.safe_number(position, 'positionAmt'),
1905
2170
  'contractSize': None,
1906
- 'markPrice': None,
2171
+ 'markPrice': self.safe_number(position, 'markPrice'),
1907
2172
  'lastPrice': None,
1908
2173
  'side': self.safe_string_lower(position, 'positionSide'),
1909
2174
  'hedged': None,
1910
2175
  'timestamp': None,
1911
2176
  'datetime': None,
1912
- 'lastUpdateTimestamp': None,
2177
+ 'lastUpdateTimestamp': self.safe_integer(position, 'updateTime'),
1913
2178
  'maintenanceMargin': None,
1914
2179
  'maintenanceMarginPercentage': None,
1915
2180
  'collateral': None,
@@ -4270,6 +4535,7 @@ class bingx(Exchange, ImplicitAPI):
4270
4535
  """
4271
4536
  retrieves the users liquidated positions
4272
4537
  :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#User's%20Force%20Orders
4538
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20force%20orders
4273
4539
  :param str [symbol]: unified CCXT market symbol
4274
4540
  :param int [since]: the earliest time in ms to fetch liquidations for
4275
4541
  :param int [limit]: the maximum number of liquidation structures to retrieve
@@ -4290,38 +4556,73 @@ class bingx(Exchange, ImplicitAPI):
4290
4556
  request['startTime'] = since
4291
4557
  if limit is not None:
4292
4558
  request['limit'] = limit
4293
- response = await self.swapV2PrivateGetTradeForceOrders(self.extend(request, params))
4294
- #
4295
- # {
4296
- # "code": 0,
4297
- # "msg": "",
4298
- # "data": {
4299
- # "orders": [
4300
- # {
4301
- # "time": "int64",
4302
- # "symbol": "string",
4303
- # "side": "string",
4304
- # "type": "string",
4305
- # "positionSide": "string",
4306
- # "cumQuote": "string",
4307
- # "status": "string",
4308
- # "stopPrice": "string",
4309
- # "price": "string",
4310
- # "origQty": "string",
4311
- # "avgPrice": "string",
4312
- # "executedQty": "string",
4313
- # "orderId": "int64",
4314
- # "profit": "string",
4315
- # "commission": "string",
4316
- # "workingType": "string",
4317
- # "updateTime": "int64"
4318
- # },
4319
- # ]
4320
- # }
4321
- # }
4322
- #
4323
- data = self.safe_dict(response, 'data', {})
4324
- liquidations = self.safe_list(data, 'orders', [])
4559
+ subType = None
4560
+ subType, params = self.handle_sub_type_and_params('fetchMyLiquidations', market, params)
4561
+ response = None
4562
+ liquidations = None
4563
+ if subType == 'inverse':
4564
+ response = await self.cswapV1PrivateGetTradeForceOrders(self.extend(request, params))
4565
+ #
4566
+ # {
4567
+ # "code": 0,
4568
+ # "msg": "",
4569
+ # "timestamp": 1721280071678,
4570
+ # "data": [
4571
+ # {
4572
+ # "orderId": "string",
4573
+ # "symbol": "string",
4574
+ # "type": "string",
4575
+ # "side": "string",
4576
+ # "positionSide": "string",
4577
+ # "price": "string",
4578
+ # "quantity": "float64",
4579
+ # "stopPrice": "string",
4580
+ # "workingType": "string",
4581
+ # "status": "string",
4582
+ # "time": "int64",
4583
+ # "avgPrice": "string",
4584
+ # "executedQty": "string",
4585
+ # "profit": "string",
4586
+ # "commission": "string",
4587
+ # "updateTime": "string"
4588
+ # }
4589
+ # ]
4590
+ # }
4591
+ #
4592
+ liquidations = self.safe_list(response, 'data', [])
4593
+ else:
4594
+ response = await self.swapV2PrivateGetTradeForceOrders(self.extend(request, params))
4595
+ #
4596
+ # {
4597
+ # "code": 0,
4598
+ # "msg": "",
4599
+ # "data": {
4600
+ # "orders": [
4601
+ # {
4602
+ # "time": "int64",
4603
+ # "symbol": "string",
4604
+ # "side": "string",
4605
+ # "type": "string",
4606
+ # "positionSide": "string",
4607
+ # "cumQuote": "string",
4608
+ # "status": "string",
4609
+ # "stopPrice": "string",
4610
+ # "price": "string",
4611
+ # "origQty": "string",
4612
+ # "avgPrice": "string",
4613
+ # "executedQty": "string",
4614
+ # "orderId": "int64",
4615
+ # "profit": "string",
4616
+ # "commission": "string",
4617
+ # "workingType": "string",
4618
+ # "updateTime": "int64"
4619
+ # },
4620
+ # ]
4621
+ # }
4622
+ # }
4623
+ #
4624
+ data = self.safe_dict(response, 'data', {})
4625
+ liquidations = self.safe_list(data, 'orders', [])
4325
4626
  return self.parse_liquidations(liquidations, market, since, limit)
4326
4627
 
4327
4628
  def parse_liquidation(self, liquidation, market: Market = None):
@@ -4711,6 +5012,87 @@ class bingx(Exchange, ImplicitAPI):
4711
5012
  'marginMode': marginType,
4712
5013
  }
4713
5014
 
5015
+ async def fetch_trading_fee(self, symbol: str, params={}) -> TradingFeeInterface:
5016
+ """
5017
+ fetch the trading fees for a market
5018
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Trading%20Commission%20Rate
5019
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/account-api.html#Query%20Trading%20Commission%20Rate
5020
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Trade%20Commission%20Rate
5021
+ :param str symbol: unified market symbol
5022
+ :param dict [params]: extra parameters specific to the exchange API endpoint
5023
+ :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
5024
+ """
5025
+ await self.load_markets()
5026
+ market = self.market(symbol)
5027
+ request: dict = {
5028
+ 'symbol': market['id'],
5029
+ }
5030
+ response = None
5031
+ commission: dict = {}
5032
+ data = self.safe_dict(response, 'data', {})
5033
+ if market['spot']:
5034
+ response = await self.spotV1PrivateGetUserCommissionRate(self.extend(request, params))
5035
+ #
5036
+ # {
5037
+ # "code": 0,
5038
+ # "msg": "",
5039
+ # "debugMsg": "",
5040
+ # "data": {
5041
+ # "takerCommissionRate": 0.001,
5042
+ # "makerCommissionRate": 0.001
5043
+ # }
5044
+ # }
5045
+ #
5046
+ commission = data
5047
+ else:
5048
+ if market['inverse']:
5049
+ response = await self.cswapV1PrivateGetUserCommissionRate(params)
5050
+ #
5051
+ # {
5052
+ # "code": 0,
5053
+ # "msg": "",
5054
+ # "timestamp": 1721365261438,
5055
+ # "data": {
5056
+ # "takerCommissionRate": "0.0005",
5057
+ # "makerCommissionRate": "0.0002"
5058
+ # }
5059
+ # }
5060
+ #
5061
+ commission = data
5062
+ else:
5063
+ response = await self.swapV2PrivateGetUserCommissionRate(params)
5064
+ #
5065
+ # {
5066
+ # "code": 0,
5067
+ # "msg": "",
5068
+ # "data": {
5069
+ # "commission": {
5070
+ # "takerCommissionRate": 0.0005,
5071
+ # "makerCommissionRate": 0.0002
5072
+ # }
5073
+ # }
5074
+ # }
5075
+ #
5076
+ commission = self.safe_dict(data, 'commission', {})
5077
+ return self.parse_trading_fee(commission, market)
5078
+
5079
+ def parse_trading_fee(self, fee: dict, market: Market = None) -> TradingFeeInterface:
5080
+ #
5081
+ # {
5082
+ # "takerCommissionRate": 0.001,
5083
+ # "makerCommissionRate": 0.001
5084
+ # }
5085
+ #
5086
+ symbol = market['symbol'] if (market is not None) else None
5087
+ return {
5088
+ 'info': fee,
5089
+ 'symbol': symbol,
5090
+ 'maker': self.safe_number(fee, 'makerCommissionRate'),
5091
+ 'taker': self.safe_number(fee, 'takerCommissionRate'),
5092
+ 'percentage': False,
5093
+ 'tierBased': False,
5094
+ }
5095
+
4714
5096
  def sign(self, path, section='public', method='GET', params={}, headers=None, body=None):
4715
5097
  type = section[0]
4716
5098
  version = section[1]