ccxt 4.3.62 → 4.3.63
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.
- package/README.md +3 -3
- package/dist/ccxt.browser.min.js +3 -3
- package/dist/cjs/ccxt.js +2 -1
- package/dist/cjs/src/ace.js +34 -15
- package/dist/cjs/src/base/Exchange.js +8 -1
- package/dist/cjs/src/base/errors.js +8 -1
- package/dist/cjs/src/binance.js +6 -9
- package/dist/cjs/src/bingx.js +466 -151
- package/dist/cjs/src/cryptocom.js +18 -2
- package/dist/cjs/src/mercado.js +5 -1
- package/dist/cjs/src/pro/binance.js +58 -34
- package/dist/cjs/src/pro/bitfinex2.js +6 -3
- package/dist/cjs/src/pro/bitget.js +4 -1
- package/dist/cjs/src/pro/bitvavo.js +1 -1
- package/dist/cjs/src/pro/bybit.js +44 -18
- package/dist/cjs/src/pro/cryptocom.js +7 -1
- package/dist/cjs/src/pro/gate.js +6 -2
- package/dist/cjs/src/pro/htx.js +5 -1
- package/dist/cjs/src/pro/independentreserve.js +5 -3
- package/dist/cjs/src/pro/kraken.js +82 -4
- package/dist/cjs/src/pro/okx.js +3 -3
- package/dist/cjs/src/pro/poloniexfutures.js +5 -1
- package/dist/cjs/src/pro/woofipro.js +1 -1
- package/dist/cjs/src/woo.js +313 -81
- package/js/ccxt.d.ts +3 -3
- package/js/ccxt.js +3 -3
- package/js/src/abstract/cryptocom.d.ts +11 -0
- package/js/src/abstract/woo.d.ts +3 -0
- package/js/src/ace.js +34 -15
- package/js/src/base/Exchange.d.ts +1 -0
- package/js/src/base/Exchange.js +8 -1
- package/js/src/base/errorHierarchy.d.ts +3 -1
- package/js/src/base/errorHierarchy.js +3 -1
- package/js/src/base/errors.d.ts +5 -1
- package/js/src/base/errors.js +8 -2
- package/js/src/binance.js +6 -9
- package/js/src/bingx.d.ts +1 -0
- package/js/src/bingx.js +466 -151
- package/js/src/coinbaseinternational.d.ts +1 -1
- package/js/src/cryptocom.js +18 -2
- package/js/src/mercado.js +5 -1
- package/js/src/pro/binance.d.ts +1 -0
- package/js/src/pro/binance.js +59 -35
- package/js/src/pro/bitfinex2.js +7 -4
- package/js/src/pro/bitget.js +5 -2
- package/js/src/pro/bitvavo.js +1 -1
- package/js/src/pro/bybit.d.ts +1 -0
- package/js/src/pro/bybit.js +44 -18
- package/js/src/pro/cryptocom.js +8 -2
- package/js/src/pro/gate.js +7 -3
- package/js/src/pro/htx.js +6 -2
- package/js/src/pro/independentreserve.js +6 -4
- package/js/src/pro/kraken.d.ts +3 -1
- package/js/src/pro/kraken.js +83 -5
- package/js/src/pro/okx.js +4 -4
- package/js/src/pro/poloniexfutures.js +6 -2
- package/js/src/pro/woofipro.js +1 -1
- package/js/src/woo.d.ts +5 -1
- package/js/src/woo.js +313 -81
- package/js/src/xt.d.ts +3 -3
- package/package.json +1 -1
package/js/src/bingx.js
CHANGED
|
@@ -74,6 +74,7 @@ export default class bingx extends Exchange {
|
|
|
74
74
|
'fetchOrder': true,
|
|
75
75
|
'fetchOrderBook': true,
|
|
76
76
|
'fetchOrders': true,
|
|
77
|
+
'fetchPosition': true,
|
|
77
78
|
'fetchPositionHistory': false,
|
|
78
79
|
'fetchPositionMode': true,
|
|
79
80
|
'fetchPositions': true,
|
|
@@ -1779,6 +1780,7 @@ export default class bingx extends Exchange {
|
|
|
1779
1780
|
* @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Assets
|
|
1780
1781
|
* @see https://bingx-api.github.io/docs/#/swapV2/account-api.html#Get%20Perpetual%20Swap%20Account%20Asset%20Information
|
|
1781
1782
|
* @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Query%20standard%20contract%20balance
|
|
1783
|
+
* @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Account%20Assets
|
|
1782
1784
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1783
1785
|
* @param {boolean} [params.standard] whether to fetch standard contract balances
|
|
1784
1786
|
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
|
|
@@ -1787,104 +1789,216 @@ export default class bingx extends Exchange {
|
|
|
1787
1789
|
let response = undefined;
|
|
1788
1790
|
let standard = undefined;
|
|
1789
1791
|
[standard, params] = this.handleOptionAndParams(params, 'fetchBalance', 'standard', false);
|
|
1792
|
+
let subType = undefined;
|
|
1793
|
+
[subType, params] = this.handleSubTypeAndParams('fetchBalance', undefined, params);
|
|
1790
1794
|
const [marketType, marketTypeQuery] = this.handleMarketTypeAndParams('fetchBalance', undefined, params);
|
|
1791
1795
|
if (standard) {
|
|
1792
1796
|
response = await this.contractV1PrivateGetBalance(marketTypeQuery);
|
|
1797
|
+
//
|
|
1798
|
+
// {
|
|
1799
|
+
// "code": 0,
|
|
1800
|
+
// "timestamp": 1721192833454,
|
|
1801
|
+
// "data": [
|
|
1802
|
+
// {
|
|
1803
|
+
// "asset": "USDT",
|
|
1804
|
+
// "balance": "4.72644300000000000000",
|
|
1805
|
+
// "crossWalletBalance": "4.72644300000000000000",
|
|
1806
|
+
// "crossUnPnl": "0",
|
|
1807
|
+
// "availableBalance": "4.72644300000000000000",
|
|
1808
|
+
// "maxWithdrawAmount": "4.72644300000000000000",
|
|
1809
|
+
// "marginAvailable": false,
|
|
1810
|
+
// "updateTime": 1721192833443
|
|
1811
|
+
// },
|
|
1812
|
+
// ]
|
|
1813
|
+
// }
|
|
1814
|
+
//
|
|
1793
1815
|
}
|
|
1794
1816
|
else if (marketType === 'spot') {
|
|
1795
1817
|
response = await this.spotV1PrivateGetAccountBalance(marketTypeQuery);
|
|
1818
|
+
//
|
|
1819
|
+
// {
|
|
1820
|
+
// "code": 0,
|
|
1821
|
+
// "msg": "",
|
|
1822
|
+
// "debugMsg": "",
|
|
1823
|
+
// "data": {
|
|
1824
|
+
// "balances": [
|
|
1825
|
+
// {
|
|
1826
|
+
// "asset": "USDT",
|
|
1827
|
+
// "free": "45.733046995800514",
|
|
1828
|
+
// "locked": "0"
|
|
1829
|
+
// },
|
|
1830
|
+
// ]
|
|
1831
|
+
// }
|
|
1832
|
+
// }
|
|
1833
|
+
//
|
|
1796
1834
|
}
|
|
1797
1835
|
else {
|
|
1798
|
-
|
|
1836
|
+
if (subType === 'inverse') {
|
|
1837
|
+
response = await this.cswapV1PrivateGetUserBalance(marketTypeQuery);
|
|
1838
|
+
//
|
|
1839
|
+
// {
|
|
1840
|
+
// "code": 0,
|
|
1841
|
+
// "msg": "",
|
|
1842
|
+
// "timestamp": 1721191833813,
|
|
1843
|
+
// "data": [
|
|
1844
|
+
// {
|
|
1845
|
+
// "asset": "SOL",
|
|
1846
|
+
// "balance": "0.35707951",
|
|
1847
|
+
// "equity": "0.35791051",
|
|
1848
|
+
// "unrealizedProfit": "0.00083099",
|
|
1849
|
+
// "availableMargin": "0.35160653",
|
|
1850
|
+
// "usedMargin": "0.00630397",
|
|
1851
|
+
// "freezedMargin": "0",
|
|
1852
|
+
// "shortUid": "12851936"
|
|
1853
|
+
// }
|
|
1854
|
+
// ]
|
|
1855
|
+
// }
|
|
1856
|
+
//
|
|
1857
|
+
}
|
|
1858
|
+
else {
|
|
1859
|
+
response = await this.swapV2PrivateGetUserBalance(marketTypeQuery);
|
|
1860
|
+
//
|
|
1861
|
+
// {
|
|
1862
|
+
// "code": 0,
|
|
1863
|
+
// "msg": "",
|
|
1864
|
+
// "data": {
|
|
1865
|
+
// "balance": {
|
|
1866
|
+
// "userId": "1177064765068660742",
|
|
1867
|
+
// "asset": "USDT",
|
|
1868
|
+
// "balance": "51.5198",
|
|
1869
|
+
// "equity": "50.5349",
|
|
1870
|
+
// "unrealizedProfit": "-0.9849",
|
|
1871
|
+
// "realisedProfit": "-0.2134",
|
|
1872
|
+
// "availableMargin": "49.1428",
|
|
1873
|
+
// "usedMargin": "1.3922",
|
|
1874
|
+
// "freezedMargin": "0.0000",
|
|
1875
|
+
// "shortUid": "12851936"
|
|
1876
|
+
// }
|
|
1877
|
+
// }
|
|
1878
|
+
// }
|
|
1879
|
+
//
|
|
1880
|
+
}
|
|
1799
1881
|
}
|
|
1882
|
+
return this.parseBalance(response);
|
|
1883
|
+
}
|
|
1884
|
+
parseBalance(response) {
|
|
1885
|
+
//
|
|
1886
|
+
// standard
|
|
1887
|
+
//
|
|
1888
|
+
// {
|
|
1889
|
+
// "code": 0,
|
|
1890
|
+
// "timestamp": 1721192833454,
|
|
1891
|
+
// "data": [
|
|
1892
|
+
// {
|
|
1893
|
+
// "asset": "USDT",
|
|
1894
|
+
// "balance": "4.72644300000000000000",
|
|
1895
|
+
// "crossWalletBalance": "4.72644300000000000000",
|
|
1896
|
+
// "crossUnPnl": "0",
|
|
1897
|
+
// "availableBalance": "4.72644300000000000000",
|
|
1898
|
+
// "maxWithdrawAmount": "4.72644300000000000000",
|
|
1899
|
+
// "marginAvailable": false,
|
|
1900
|
+
// "updateTime": 1721192833443
|
|
1901
|
+
// },
|
|
1902
|
+
// ]
|
|
1903
|
+
// }
|
|
1800
1904
|
//
|
|
1801
1905
|
// spot
|
|
1802
1906
|
//
|
|
1803
|
-
//
|
|
1804
|
-
//
|
|
1805
|
-
//
|
|
1806
|
-
//
|
|
1807
|
-
//
|
|
1808
|
-
//
|
|
1809
|
-
//
|
|
1810
|
-
//
|
|
1811
|
-
//
|
|
1812
|
-
//
|
|
1813
|
-
//
|
|
1814
|
-
//
|
|
1815
|
-
//
|
|
1816
|
-
//
|
|
1907
|
+
// {
|
|
1908
|
+
// "code": 0,
|
|
1909
|
+
// "msg": "",
|
|
1910
|
+
// "debugMsg": "",
|
|
1911
|
+
// "data": {
|
|
1912
|
+
// "balances": [
|
|
1913
|
+
// {
|
|
1914
|
+
// "asset": "USDT",
|
|
1915
|
+
// "free": "45.733046995800514",
|
|
1916
|
+
// "locked": "0"
|
|
1917
|
+
// },
|
|
1918
|
+
// ]
|
|
1919
|
+
// }
|
|
1920
|
+
// }
|
|
1817
1921
|
//
|
|
1818
|
-
// swap
|
|
1922
|
+
// inverse swap
|
|
1819
1923
|
//
|
|
1820
|
-
//
|
|
1821
|
-
//
|
|
1822
|
-
//
|
|
1823
|
-
//
|
|
1824
|
-
//
|
|
1825
|
-
//
|
|
1826
|
-
//
|
|
1827
|
-
//
|
|
1828
|
-
//
|
|
1829
|
-
//
|
|
1830
|
-
//
|
|
1831
|
-
//
|
|
1832
|
-
//
|
|
1833
|
-
//
|
|
1834
|
-
//
|
|
1835
|
-
//
|
|
1836
|
-
//
|
|
1837
|
-
//
|
|
1838
|
-
//
|
|
1839
|
-
//
|
|
1840
|
-
//
|
|
1841
|
-
//
|
|
1842
|
-
//
|
|
1843
|
-
//
|
|
1844
|
-
//
|
|
1845
|
-
//
|
|
1846
|
-
//
|
|
1847
|
-
//
|
|
1848
|
-
//
|
|
1849
|
-
//
|
|
1850
|
-
//
|
|
1851
|
-
//
|
|
1852
|
-
//
|
|
1853
|
-
//
|
|
1854
|
-
//
|
|
1855
|
-
//
|
|
1856
|
-
//
|
|
1857
|
-
// "maxWithdrawAmount":"0",
|
|
1858
|
-
// "marginAvailable":false,
|
|
1859
|
-
// "updateTime":"1691148990902"
|
|
1860
|
-
// },
|
|
1861
|
-
// ]
|
|
1924
|
+
// {
|
|
1925
|
+
// "code": 0,
|
|
1926
|
+
// "msg": "",
|
|
1927
|
+
// "timestamp": 1721191833813,
|
|
1928
|
+
// "data": [
|
|
1929
|
+
// {
|
|
1930
|
+
// "asset": "SOL",
|
|
1931
|
+
// "balance": "0.35707951",
|
|
1932
|
+
// "equity": "0.35791051",
|
|
1933
|
+
// "unrealizedProfit": "0.00083099",
|
|
1934
|
+
// "availableMargin": "0.35160653",
|
|
1935
|
+
// "usedMargin": "0.00630397",
|
|
1936
|
+
// "freezedMargin": "0",
|
|
1937
|
+
// "shortUid": "12851936"
|
|
1938
|
+
// }
|
|
1939
|
+
// ]
|
|
1940
|
+
// }
|
|
1941
|
+
//
|
|
1942
|
+
// linear swap
|
|
1943
|
+
//
|
|
1944
|
+
// {
|
|
1945
|
+
// "code": 0,
|
|
1946
|
+
// "msg": "",
|
|
1947
|
+
// "data": {
|
|
1948
|
+
// "balance": {
|
|
1949
|
+
// "userId": "1177064765068660742",
|
|
1950
|
+
// "asset": "USDT",
|
|
1951
|
+
// "balance": "51.5198",
|
|
1952
|
+
// "equity": "50.5349",
|
|
1953
|
+
// "unrealizedProfit": "-0.9849",
|
|
1954
|
+
// "realisedProfit": "-0.2134",
|
|
1955
|
+
// "availableMargin": "49.1428",
|
|
1956
|
+
// "usedMargin": "1.3922",
|
|
1957
|
+
// "freezedMargin": "0.0000",
|
|
1958
|
+
// "shortUid": "12851936"
|
|
1959
|
+
// }
|
|
1960
|
+
// }
|
|
1862
1961
|
// }
|
|
1863
1962
|
//
|
|
1864
|
-
return this.parseBalance(response);
|
|
1865
|
-
}
|
|
1866
|
-
parseBalance(response) {
|
|
1867
|
-
const data = this.safeValue(response, 'data');
|
|
1868
|
-
const balances = this.safeValue2(data, 'balance', 'balances', data);
|
|
1869
1963
|
const result = { 'info': response };
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1964
|
+
const standardAndInverseBalances = this.safeList(response, 'data');
|
|
1965
|
+
const firstStandardOrInverse = this.safeDict(standardAndInverseBalances, 0);
|
|
1966
|
+
const isStandardOrInverse = firstStandardOrInverse !== undefined;
|
|
1967
|
+
const spotData = this.safeDict(response, 'data', {});
|
|
1968
|
+
const spotBalances = this.safeList(spotData, 'balances');
|
|
1969
|
+
const firstSpot = this.safeDict(spotBalances, 0);
|
|
1970
|
+
const isSpot = firstSpot !== undefined;
|
|
1971
|
+
if (isStandardOrInverse) {
|
|
1972
|
+
for (let i = 0; i < standardAndInverseBalances.length; i++) {
|
|
1973
|
+
const balance = standardAndInverseBalances[i];
|
|
1873
1974
|
const currencyId = this.safeString(balance, 'asset');
|
|
1874
1975
|
const code = this.safeCurrencyCode(currencyId);
|
|
1875
1976
|
const account = this.account();
|
|
1876
|
-
account['free'] = this.safeString2(balance, '
|
|
1977
|
+
account['free'] = this.safeString2(balance, 'availableMargin', 'availableBalance');
|
|
1978
|
+
account['used'] = this.safeString(balance, 'usedMargin');
|
|
1979
|
+
account['total'] = this.safeString(balance, 'maxWithdrawAmount');
|
|
1980
|
+
result[code] = account;
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
else if (isSpot) {
|
|
1984
|
+
for (let i = 0; i < spotBalances.length; i++) {
|
|
1985
|
+
const balance = spotBalances[i];
|
|
1986
|
+
const currencyId = this.safeString(balance, 'asset');
|
|
1987
|
+
const code = this.safeCurrencyCode(currencyId);
|
|
1988
|
+
const account = this.account();
|
|
1989
|
+
account['free'] = this.safeString(balance, 'free');
|
|
1877
1990
|
account['used'] = this.safeString(balance, 'locked');
|
|
1878
|
-
account['total'] = this.safeString(balance, 'balance');
|
|
1879
1991
|
result[code] = account;
|
|
1880
1992
|
}
|
|
1881
1993
|
}
|
|
1882
1994
|
else {
|
|
1883
|
-
const
|
|
1995
|
+
const linearSwapData = this.safeDict(response, 'data', {});
|
|
1996
|
+
const linearSwapBalance = this.safeDict(linearSwapData, 'balance');
|
|
1997
|
+
const currencyId = this.safeString(linearSwapBalance, 'asset');
|
|
1884
1998
|
const code = this.safeCurrencyCode(currencyId);
|
|
1885
1999
|
const account = this.account();
|
|
1886
|
-
account['free'] = this.safeString(
|
|
1887
|
-
account['used'] = this.safeString(
|
|
2000
|
+
account['free'] = this.safeString(linearSwapBalance, 'availableMargin');
|
|
2001
|
+
account['used'] = this.safeString(linearSwapBalance, 'usedMargin');
|
|
1888
2002
|
result[code] = account;
|
|
1889
2003
|
}
|
|
1890
2004
|
return this.safeBalance(result);
|
|
@@ -1894,12 +2008,13 @@ export default class bingx extends Exchange {
|
|
|
1894
2008
|
* @method
|
|
1895
2009
|
* @name bingx#fetchPositions
|
|
1896
2010
|
* @description fetch all open positions
|
|
1897
|
-
* @see https://bingx-api.github.io/docs/#/swapV2/account-api.html#
|
|
1898
|
-
* @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#
|
|
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/standard/contract-interface.html#position
|
|
2013
|
+
* @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20warehouse
|
|
1899
2014
|
* @param {string[]|undefined} symbols list of unified market symbols
|
|
1900
2015
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1901
2016
|
* @param {boolean} [params.standard] whether to fetch standard contract positions
|
|
1902
|
-
* @returns {object[]} a list of [position
|
|
2017
|
+
* @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
|
|
1903
2018
|
*/
|
|
1904
2019
|
await this.loadMarkets();
|
|
1905
2020
|
symbols = this.marketSymbols(symbols);
|
|
@@ -1910,55 +2025,217 @@ export default class bingx extends Exchange {
|
|
|
1910
2025
|
response = await this.contractV1PrivateGetAllPosition(params);
|
|
1911
2026
|
}
|
|
1912
2027
|
else {
|
|
1913
|
-
|
|
2028
|
+
let market = undefined;
|
|
2029
|
+
if (symbols !== undefined) {
|
|
2030
|
+
symbols = this.marketSymbols(symbols);
|
|
2031
|
+
const firstSymbol = this.safeString(symbols, 0);
|
|
2032
|
+
if (firstSymbol !== undefined) {
|
|
2033
|
+
market = this.market(firstSymbol);
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
let subType = undefined;
|
|
2037
|
+
[subType, params] = this.handleSubTypeAndParams('fetchPositions', market, params);
|
|
2038
|
+
if (subType === 'inverse') {
|
|
2039
|
+
response = await this.cswapV1PrivateGetUserPositions(params);
|
|
2040
|
+
//
|
|
2041
|
+
// {
|
|
2042
|
+
// "code": 0,
|
|
2043
|
+
// "msg": "",
|
|
2044
|
+
// "timestamp": 0,
|
|
2045
|
+
// "data": [
|
|
2046
|
+
// {
|
|
2047
|
+
// "symbol": "SOL-USD",
|
|
2048
|
+
// "positionId": "1813080351385337856",
|
|
2049
|
+
// "positionSide": "LONG",
|
|
2050
|
+
// "isolated": false,
|
|
2051
|
+
// "positionAmt": "1",
|
|
2052
|
+
// "availableAmt": "1",
|
|
2053
|
+
// "unrealizedProfit": "-0.00009074",
|
|
2054
|
+
// "initialMargin": "0.00630398",
|
|
2055
|
+
// "liquidationPrice": 23.968303426677032,
|
|
2056
|
+
// "avgPrice": "158.63",
|
|
2057
|
+
// "leverage": 10,
|
|
2058
|
+
// "markPrice": "158.402",
|
|
2059
|
+
// "riskRate": "0.00123783",
|
|
2060
|
+
// "maxMarginReduction": "0",
|
|
2061
|
+
// "updateTime": 1721107015848
|
|
2062
|
+
// }
|
|
2063
|
+
// ]
|
|
2064
|
+
// }
|
|
2065
|
+
//
|
|
2066
|
+
}
|
|
2067
|
+
else {
|
|
2068
|
+
response = await this.swapV2PrivateGetUserPositions(params);
|
|
2069
|
+
//
|
|
2070
|
+
// {
|
|
2071
|
+
// "code": 0,
|
|
2072
|
+
// "msg": "",
|
|
2073
|
+
// "data": [
|
|
2074
|
+
// {
|
|
2075
|
+
// "positionId": "1792480725958881280",
|
|
2076
|
+
// "symbol": "LTC-USDT",
|
|
2077
|
+
// "currency": "USDT",
|
|
2078
|
+
// "positionAmt": "0.1",
|
|
2079
|
+
// "availableAmt": "0.1",
|
|
2080
|
+
// "positionSide": "LONG",
|
|
2081
|
+
// "isolated": false,
|
|
2082
|
+
// "avgPrice": "83.53",
|
|
2083
|
+
// "initialMargin": "1.3922",
|
|
2084
|
+
// "margin": "0.3528",
|
|
2085
|
+
// "leverage": 6,
|
|
2086
|
+
// "unrealizedProfit": "-1.0393",
|
|
2087
|
+
// "realisedProfit": "-0.2119",
|
|
2088
|
+
// "liquidationPrice": 0,
|
|
2089
|
+
// "pnlRatio": "-0.7465",
|
|
2090
|
+
// "maxMarginReduction": "0.0000",
|
|
2091
|
+
// "riskRate": "0.0008",
|
|
2092
|
+
// "markPrice": "73.14",
|
|
2093
|
+
// "positionValue": "7.3136",
|
|
2094
|
+
// "onlyOnePosition": true,
|
|
2095
|
+
// "updateTime": 1721088016688
|
|
2096
|
+
// }
|
|
2097
|
+
// ]
|
|
2098
|
+
// }
|
|
2099
|
+
//
|
|
2100
|
+
}
|
|
1914
2101
|
}
|
|
1915
|
-
//
|
|
1916
|
-
// {
|
|
1917
|
-
// "code": 0,
|
|
1918
|
-
// "msg": "",
|
|
1919
|
-
// "data": [
|
|
1920
|
-
// {
|
|
1921
|
-
// "symbol": "BTC-USDT",
|
|
1922
|
-
// "positionId": "12345678",
|
|
1923
|
-
// "positionSide": "LONG",
|
|
1924
|
-
// "isolated": true,
|
|
1925
|
-
// "positionAmt": "123.33",
|
|
1926
|
-
// "availableAmt": "128.99",
|
|
1927
|
-
// "unrealizedProfit": "1.22",
|
|
1928
|
-
// "realisedProfit": "8.1",
|
|
1929
|
-
// "initialMargin": "123.33",
|
|
1930
|
-
// "avgPrice": "2.2",
|
|
1931
|
-
// "leverage": 10,
|
|
1932
|
-
// }
|
|
1933
|
-
// ]
|
|
1934
|
-
// }
|
|
1935
|
-
//
|
|
1936
2102
|
const positions = this.safeList(response, 'data', []);
|
|
1937
2103
|
return this.parsePositions(positions, symbols);
|
|
1938
2104
|
}
|
|
2105
|
+
async fetchPosition(symbol, params = {}) {
|
|
2106
|
+
/**
|
|
2107
|
+
* @method
|
|
2108
|
+
* @name bingx#fetchPosition
|
|
2109
|
+
* @description fetch data on a single open contract trade position
|
|
2110
|
+
* @see https://bingx-api.github.io/docs/#/en-us/swapV2/account-api.html#Query%20position%20data
|
|
2111
|
+
* @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20warehouse
|
|
2112
|
+
* @param {string} symbol unified market symbol of the market the position is held in
|
|
2113
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2114
|
+
* @returns {object} a [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
|
|
2115
|
+
*/
|
|
2116
|
+
await this.loadMarkets();
|
|
2117
|
+
const market = this.market(symbol);
|
|
2118
|
+
if (!market['swap']) {
|
|
2119
|
+
throw new BadRequest(this.id + ' fetchPosition() supports swap markets only');
|
|
2120
|
+
}
|
|
2121
|
+
const request = {
|
|
2122
|
+
'symbol': market['id'],
|
|
2123
|
+
};
|
|
2124
|
+
let response = undefined;
|
|
2125
|
+
if (market['inverse']) {
|
|
2126
|
+
response = await this.cswapV1PrivateGetUserPositions(this.extend(request, params));
|
|
2127
|
+
//
|
|
2128
|
+
// {
|
|
2129
|
+
// "code": 0,
|
|
2130
|
+
// "msg": "",
|
|
2131
|
+
// "timestamp": 0,
|
|
2132
|
+
// "data": [
|
|
2133
|
+
// {
|
|
2134
|
+
// "symbol": "SOL-USD",
|
|
2135
|
+
// "positionId": "1813080351385337856",
|
|
2136
|
+
// "positionSide": "LONG",
|
|
2137
|
+
// "isolated": false,
|
|
2138
|
+
// "positionAmt": "1",
|
|
2139
|
+
// "availableAmt": "1",
|
|
2140
|
+
// "unrealizedProfit": "-0.00009074",
|
|
2141
|
+
// "initialMargin": "0.00630398",
|
|
2142
|
+
// "liquidationPrice": 23.968303426677032,
|
|
2143
|
+
// "avgPrice": "158.63",
|
|
2144
|
+
// "leverage": 10,
|
|
2145
|
+
// "markPrice": "158.402",
|
|
2146
|
+
// "riskRate": "0.00123783",
|
|
2147
|
+
// "maxMarginReduction": "0",
|
|
2148
|
+
// "updateTime": 1721107015848
|
|
2149
|
+
// }
|
|
2150
|
+
// ]
|
|
2151
|
+
// }
|
|
2152
|
+
//
|
|
2153
|
+
}
|
|
2154
|
+
else {
|
|
2155
|
+
response = await this.swapV2PrivateGetUserPositions(this.extend(request, params));
|
|
2156
|
+
//
|
|
2157
|
+
// {
|
|
2158
|
+
// "code": 0,
|
|
2159
|
+
// "msg": "",
|
|
2160
|
+
// "data": [
|
|
2161
|
+
// {
|
|
2162
|
+
// "positionId": "1792480725958881280",
|
|
2163
|
+
// "symbol": "LTC-USDT",
|
|
2164
|
+
// "currency": "USDT",
|
|
2165
|
+
// "positionAmt": "0.1",
|
|
2166
|
+
// "availableAmt": "0.1",
|
|
2167
|
+
// "positionSide": "LONG",
|
|
2168
|
+
// "isolated": false,
|
|
2169
|
+
// "avgPrice": "83.53",
|
|
2170
|
+
// "initialMargin": "1.3922",
|
|
2171
|
+
// "margin": "0.3528",
|
|
2172
|
+
// "leverage": 6,
|
|
2173
|
+
// "unrealizedProfit": "-1.0393",
|
|
2174
|
+
// "realisedProfit": "-0.2119",
|
|
2175
|
+
// "liquidationPrice": 0,
|
|
2176
|
+
// "pnlRatio": "-0.7465",
|
|
2177
|
+
// "maxMarginReduction": "0.0000",
|
|
2178
|
+
// "riskRate": "0.0008",
|
|
2179
|
+
// "markPrice": "73.14",
|
|
2180
|
+
// "positionValue": "7.3136",
|
|
2181
|
+
// "onlyOnePosition": true,
|
|
2182
|
+
// "updateTime": 1721088016688
|
|
2183
|
+
// }
|
|
2184
|
+
// ]
|
|
2185
|
+
// }
|
|
2186
|
+
//
|
|
2187
|
+
}
|
|
2188
|
+
const data = this.safeList(response, 'data', []);
|
|
2189
|
+
const first = this.safeDict(data, 0, {});
|
|
2190
|
+
return this.parsePosition(first, market);
|
|
2191
|
+
}
|
|
1939
2192
|
parsePosition(position, market = undefined) {
|
|
1940
2193
|
//
|
|
1941
|
-
//
|
|
1942
|
-
//
|
|
1943
|
-
//
|
|
1944
|
-
//
|
|
1945
|
-
//
|
|
1946
|
-
//
|
|
1947
|
-
//
|
|
1948
|
-
//
|
|
1949
|
-
//
|
|
1950
|
-
//
|
|
1951
|
-
//
|
|
1952
|
-
//
|
|
1953
|
-
//
|
|
1954
|
-
//
|
|
1955
|
-
//
|
|
1956
|
-
//
|
|
1957
|
-
//
|
|
1958
|
-
//
|
|
1959
|
-
//
|
|
1960
|
-
//
|
|
1961
|
-
//
|
|
2194
|
+
// inverse swap
|
|
2195
|
+
//
|
|
2196
|
+
// {
|
|
2197
|
+
// "symbol": "SOL-USD",
|
|
2198
|
+
// "positionId": "1813080351385337856",
|
|
2199
|
+
// "positionSide": "LONG",
|
|
2200
|
+
// "isolated": false,
|
|
2201
|
+
// "positionAmt": "1",
|
|
2202
|
+
// "availableAmt": "1",
|
|
2203
|
+
// "unrealizedProfit": "-0.00009074",
|
|
2204
|
+
// "initialMargin": "0.00630398",
|
|
2205
|
+
// "liquidationPrice": 23.968303426677032,
|
|
2206
|
+
// "avgPrice": "158.63",
|
|
2207
|
+
// "leverage": 10,
|
|
2208
|
+
// "markPrice": "158.402",
|
|
2209
|
+
// "riskRate": "0.00123783",
|
|
2210
|
+
// "maxMarginReduction": "0",
|
|
2211
|
+
// "updateTime": 1721107015848
|
|
2212
|
+
// }
|
|
2213
|
+
//
|
|
2214
|
+
// linear swap
|
|
2215
|
+
//
|
|
2216
|
+
// {
|
|
2217
|
+
// "positionId": "1792480725958881280",
|
|
2218
|
+
// "symbol": "LTC-USDT",
|
|
2219
|
+
// "currency": "USDT",
|
|
2220
|
+
// "positionAmt": "0.1",
|
|
2221
|
+
// "availableAmt": "0.1",
|
|
2222
|
+
// "positionSide": "LONG",
|
|
2223
|
+
// "isolated": false,
|
|
2224
|
+
// "avgPrice": "83.53",
|
|
2225
|
+
// "initialMargin": "1.3922",
|
|
2226
|
+
// "margin": "0.3528",
|
|
2227
|
+
// "leverage": 6,
|
|
2228
|
+
// "unrealizedProfit": "-1.0393",
|
|
2229
|
+
// "realisedProfit": "-0.2119",
|
|
2230
|
+
// "liquidationPrice": 0,
|
|
2231
|
+
// "pnlRatio": "-0.7465",
|
|
2232
|
+
// "maxMarginReduction": "0.0000",
|
|
2233
|
+
// "riskRate": "0.0008",
|
|
2234
|
+
// "markPrice": "73.14",
|
|
2235
|
+
// "positionValue": "7.3136",
|
|
2236
|
+
// "onlyOnePosition": true,
|
|
2237
|
+
// "updateTime": 1721088016688
|
|
2238
|
+
// }
|
|
1962
2239
|
//
|
|
1963
2240
|
// standard position
|
|
1964
2241
|
//
|
|
@@ -1994,13 +2271,13 @@ export default class bingx extends Exchange {
|
|
|
1994
2271
|
'percentage': undefined,
|
|
1995
2272
|
'contracts': this.safeNumber(position, 'positionAmt'),
|
|
1996
2273
|
'contractSize': undefined,
|
|
1997
|
-
'markPrice':
|
|
2274
|
+
'markPrice': this.safeNumber(position, 'markPrice'),
|
|
1998
2275
|
'lastPrice': undefined,
|
|
1999
2276
|
'side': this.safeStringLower(position, 'positionSide'),
|
|
2000
2277
|
'hedged': undefined,
|
|
2001
2278
|
'timestamp': undefined,
|
|
2002
2279
|
'datetime': undefined,
|
|
2003
|
-
'lastUpdateTimestamp':
|
|
2280
|
+
'lastUpdateTimestamp': this.safeInteger(position, 'updateTime'),
|
|
2004
2281
|
'maintenanceMargin': undefined,
|
|
2005
2282
|
'maintenanceMarginPercentage': undefined,
|
|
2006
2283
|
'collateral': undefined,
|
|
@@ -4568,6 +4845,7 @@ export default class bingx extends Exchange {
|
|
|
4568
4845
|
* @name bingx#fetchMyLiquidations
|
|
4569
4846
|
* @description retrieves the users liquidated positions
|
|
4570
4847
|
* @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#User's%20Force%20Orders
|
|
4848
|
+
* @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20force%20orders
|
|
4571
4849
|
* @param {string} [symbol] unified CCXT market symbol
|
|
4572
4850
|
* @param {int} [since] the earliest time in ms to fetch liquidations for
|
|
4573
4851
|
* @param {int} [limit] the maximum number of liquidation structures to retrieve
|
|
@@ -4591,38 +4869,75 @@ export default class bingx extends Exchange {
|
|
|
4591
4869
|
if (limit !== undefined) {
|
|
4592
4870
|
request['limit'] = limit;
|
|
4593
4871
|
}
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4872
|
+
let subType = undefined;
|
|
4873
|
+
[subType, params] = this.handleSubTypeAndParams('fetchMyLiquidations', market, params);
|
|
4874
|
+
let response = undefined;
|
|
4875
|
+
let liquidations = undefined;
|
|
4876
|
+
if (subType === 'inverse') {
|
|
4877
|
+
response = await this.cswapV1PrivateGetTradeForceOrders(this.extend(request, params));
|
|
4878
|
+
//
|
|
4879
|
+
// {
|
|
4880
|
+
// "code": 0,
|
|
4881
|
+
// "msg": "",
|
|
4882
|
+
// "timestamp": 1721280071678,
|
|
4883
|
+
// "data": [
|
|
4884
|
+
// {
|
|
4885
|
+
// "orderId": "string",
|
|
4886
|
+
// "symbol": "string",
|
|
4887
|
+
// "type": "string",
|
|
4888
|
+
// "side": "string",
|
|
4889
|
+
// "positionSide": "string",
|
|
4890
|
+
// "price": "string",
|
|
4891
|
+
// "quantity": "float64",
|
|
4892
|
+
// "stopPrice": "string",
|
|
4893
|
+
// "workingType": "string",
|
|
4894
|
+
// "status": "string",
|
|
4895
|
+
// "time": "int64",
|
|
4896
|
+
// "avgPrice": "string",
|
|
4897
|
+
// "executedQty": "string",
|
|
4898
|
+
// "profit": "string",
|
|
4899
|
+
// "commission": "string",
|
|
4900
|
+
// "updateTime": "string"
|
|
4901
|
+
// }
|
|
4902
|
+
// ]
|
|
4903
|
+
// }
|
|
4904
|
+
//
|
|
4905
|
+
liquidations = this.safeList(response, 'data', []);
|
|
4906
|
+
}
|
|
4907
|
+
else {
|
|
4908
|
+
response = await this.swapV2PrivateGetTradeForceOrders(this.extend(request, params));
|
|
4909
|
+
//
|
|
4910
|
+
// {
|
|
4911
|
+
// "code": 0,
|
|
4912
|
+
// "msg": "",
|
|
4913
|
+
// "data": {
|
|
4914
|
+
// "orders": [
|
|
4915
|
+
// {
|
|
4916
|
+
// "time": "int64",
|
|
4917
|
+
// "symbol": "string",
|
|
4918
|
+
// "side": "string",
|
|
4919
|
+
// "type": "string",
|
|
4920
|
+
// "positionSide": "string",
|
|
4921
|
+
// "cumQuote": "string",
|
|
4922
|
+
// "status": "string",
|
|
4923
|
+
// "stopPrice": "string",
|
|
4924
|
+
// "price": "string",
|
|
4925
|
+
// "origQty": "string",
|
|
4926
|
+
// "avgPrice": "string",
|
|
4927
|
+
// "executedQty": "string",
|
|
4928
|
+
// "orderId": "int64",
|
|
4929
|
+
// "profit": "string",
|
|
4930
|
+
// "commission": "string",
|
|
4931
|
+
// "workingType": "string",
|
|
4932
|
+
// "updateTime": "int64"
|
|
4933
|
+
// },
|
|
4934
|
+
// ]
|
|
4935
|
+
// }
|
|
4936
|
+
// }
|
|
4937
|
+
//
|
|
4938
|
+
const data = this.safeDict(response, 'data', {});
|
|
4939
|
+
liquidations = this.safeList(data, 'orders', []);
|
|
4940
|
+
}
|
|
4626
4941
|
return this.parseLiquidations(liquidations, market, since, limit);
|
|
4627
4942
|
}
|
|
4628
4943
|
parseLiquidation(liquidation, market = undefined) {
|