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.
- ccxt/__init__.py +2 -1
- ccxt/abstract/binance.py +5 -5
- ccxt/abstract/binancecoinm.py +5 -5
- ccxt/abstract/binanceus.py +5 -5
- ccxt/abstract/binanceusdm.py +5 -5
- ccxt/abstract/cryptocom.py +11 -0
- ccxt/abstract/kucoin.py +1 -0
- ccxt/abstract/kucoinfutures.py +1 -0
- ccxt/abstract/woo.py +3 -0
- ccxt/ace.py +33 -15
- ccxt/alpaca.py +1 -0
- ccxt/async_support/__init__.py +2 -1
- ccxt/async_support/ace.py +33 -15
- ccxt/async_support/alpaca.py +1 -0
- ccxt/async_support/base/exchange.py +4 -4
- ccxt/async_support/binance.py +6 -9
- ccxt/async_support/bingx.py +534 -152
- ccxt/async_support/bitfinex.py +1 -1
- ccxt/async_support/bitfinex2.py +1 -1
- ccxt/async_support/coinbaseinternational.py +1 -1
- ccxt/async_support/cryptocom.py +17 -2
- ccxt/async_support/independentreserve.py +103 -1
- ccxt/async_support/kucoin.py +2 -0
- ccxt/async_support/mercado.py +5 -1
- ccxt/async_support/whitebit.py +1 -1
- ccxt/async_support/woo.py +321 -81
- ccxt/async_support/xt.py +3 -3
- ccxt/async_support/yobit.py +1 -1
- ccxt/async_support/zonda.py +1 -1
- ccxt/base/errors.py +8 -1
- ccxt/base/exchange.py +11 -5
- ccxt/binance.py +6 -9
- ccxt/bingx.py +534 -152
- ccxt/bitfinex.py +1 -1
- ccxt/bitfinex2.py +1 -1
- ccxt/coinbaseinternational.py +1 -1
- ccxt/cryptocom.py +17 -2
- ccxt/independentreserve.py +103 -1
- ccxt/kucoin.py +2 -0
- ccxt/mercado.py +5 -1
- ccxt/pro/__init__.py +1 -1
- ccxt/pro/binance.py +56 -35
- ccxt/pro/bitfinex2.py +6 -4
- ccxt/pro/bitget.py +5 -2
- ccxt/pro/bitmart.py +3 -3
- ccxt/pro/bitvavo.py +1 -1
- ccxt/pro/bybit.py +41 -18
- ccxt/pro/cryptocom.py +7 -2
- ccxt/pro/gate.py +7 -4
- ccxt/pro/gemini.py +4 -2
- ccxt/pro/htx.py +5 -1
- ccxt/pro/independentreserve.py +6 -4
- ccxt/pro/kraken.py +79 -6
- ccxt/pro/okx.py +5 -5
- ccxt/pro/onetrading.py +3 -2
- ccxt/pro/oxfun.py +1 -1
- ccxt/pro/poloniexfutures.py +5 -2
- ccxt/pro/vertex.py +3 -2
- ccxt/pro/woo.py +2 -1
- ccxt/pro/woofipro.py +3 -2
- ccxt/test/tests_async.py +3 -3
- ccxt/test/tests_helpers.py +1 -1
- ccxt/test/tests_init.py +3 -3
- ccxt/test/tests_sync.py +3 -3
- ccxt/whitebit.py +1 -1
- ccxt/woo.py +321 -81
- ccxt/xt.py +3 -3
- ccxt/yobit.py +1 -1
- ccxt/zonda.py +1 -1
- {ccxt-4.3.62.dist-info → ccxt-4.3.64.dist-info}/METADATA +4 -4
- {ccxt-4.3.62.dist-info → ccxt-4.3.64.dist-info}/RECORD +74 -74
- {ccxt-4.3.62.dist-info → ccxt-4.3.64.dist-info}/LICENSE.txt +0 -0
- {ccxt-4.3.62.dist-info → ccxt-4.3.64.dist-info}/WHEEL +0 -0
- {ccxt-4.3.62.dist-info → ccxt-4.3.64.dist-info}/top_level.txt +0 -0
ccxt/async_support/bingx.py
CHANGED
@@ -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
|
-
|
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
|
-
#
|
1722
|
-
#
|
1723
|
-
#
|
1724
|
-
#
|
1725
|
-
#
|
1726
|
-
#
|
1727
|
-
#
|
1728
|
-
#
|
1729
|
-
#
|
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
|
-
#
|
1739
|
-
#
|
1740
|
-
#
|
1741
|
-
#
|
1742
|
-
#
|
1743
|
-
#
|
1744
|
-
#
|
1745
|
-
#
|
1746
|
-
#
|
1747
|
-
#
|
1748
|
-
#
|
1749
|
-
#
|
1750
|
-
#
|
1751
|
-
#
|
1752
|
-
#
|
1753
|
-
#
|
1754
|
-
#
|
1755
|
-
#
|
1756
|
-
#
|
1757
|
-
#
|
1758
|
-
#
|
1759
|
-
#
|
1760
|
-
#
|
1761
|
-
#
|
1762
|
-
#
|
1763
|
-
#
|
1764
|
-
#
|
1765
|
-
#
|
1766
|
-
#
|
1767
|
-
#
|
1768
|
-
#
|
1769
|
-
#
|
1770
|
-
#
|
1771
|
-
#
|
1772
|
-
#
|
1773
|
-
#
|
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
|
-
|
1788
|
-
|
1789
|
-
|
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.
|
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
|
-
|
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(
|
1802
|
-
account['used'] = self.safe_string(
|
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#
|
1810
|
-
:see: https://bingx-api.github.io/docs/#/standard/contract-interface.html#
|
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
|
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
|
-
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
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
|
-
#
|
1853
|
-
#
|
1854
|
-
#
|
1855
|
-
#
|
1856
|
-
#
|
1857
|
-
#
|
1858
|
-
#
|
1859
|
-
#
|
1860
|
-
#
|
1861
|
-
#
|
1862
|
-
#
|
1863
|
-
#
|
1864
|
-
#
|
1865
|
-
#
|
1866
|
-
#
|
1867
|
-
#
|
1868
|
-
#
|
1869
|
-
#
|
1870
|
-
#
|
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':
|
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':
|
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
|
-
|
4294
|
-
|
4295
|
-
|
4296
|
-
|
4297
|
-
|
4298
|
-
|
4299
|
-
|
4300
|
-
|
4301
|
-
|
4302
|
-
|
4303
|
-
|
4304
|
-
|
4305
|
-
|
4306
|
-
|
4307
|
-
|
4308
|
-
|
4309
|
-
|
4310
|
-
|
4311
|
-
|
4312
|
-
|
4313
|
-
|
4314
|
-
|
4315
|
-
|
4316
|
-
|
4317
|
-
|
4318
|
-
|
4319
|
-
|
4320
|
-
|
4321
|
-
|
4322
|
-
|
4323
|
-
|
4324
|
-
|
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]
|