ccxt 4.3.62 → 4.3.64

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 (86) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +2 -1
  4. package/dist/cjs/src/ace.js +34 -15
  5. package/dist/cjs/src/alpaca.js +1 -0
  6. package/dist/cjs/src/base/Exchange.js +11 -4
  7. package/dist/cjs/src/base/errors.js +8 -1
  8. package/dist/cjs/src/binance.js +6 -9
  9. package/dist/cjs/src/bingx.js +554 -151
  10. package/dist/cjs/src/bitfinex.js +1 -1
  11. package/dist/cjs/src/bitfinex2.js +1 -1
  12. package/dist/cjs/src/cryptocom.js +18 -2
  13. package/dist/cjs/src/independentreserve.js +107 -0
  14. package/dist/cjs/src/kucoin.js +2 -0
  15. package/dist/cjs/src/mercado.js +5 -1
  16. package/dist/cjs/src/pro/binance.js +58 -34
  17. package/dist/cjs/src/pro/bitfinex2.js +6 -3
  18. package/dist/cjs/src/pro/bitget.js +4 -1
  19. package/dist/cjs/src/pro/bitmart.js +3 -3
  20. package/dist/cjs/src/pro/bitvavo.js +1 -1
  21. package/dist/cjs/src/pro/bybit.js +44 -18
  22. package/dist/cjs/src/pro/cryptocom.js +7 -1
  23. package/dist/cjs/src/pro/gate.js +7 -3
  24. package/dist/cjs/src/pro/gemini.js +4 -2
  25. package/dist/cjs/src/pro/htx.js +5 -1
  26. package/dist/cjs/src/pro/independentreserve.js +5 -3
  27. package/dist/cjs/src/pro/kraken.js +82 -4
  28. package/dist/cjs/src/pro/okx.js +3 -3
  29. package/dist/cjs/src/pro/onetrading.js +3 -2
  30. package/dist/cjs/src/pro/poloniexfutures.js +5 -1
  31. package/dist/cjs/src/pro/vertex.js +3 -2
  32. package/dist/cjs/src/pro/woo.js +2 -1
  33. package/dist/cjs/src/pro/woofipro.js +3 -2
  34. package/dist/cjs/src/woo.js +344 -81
  35. package/js/ccxt.d.ts +3 -3
  36. package/js/ccxt.js +3 -3
  37. package/js/src/abstract/cryptocom.d.ts +11 -0
  38. package/js/src/abstract/kucoin.d.ts +1 -0
  39. package/js/src/abstract/kucoinfutures.d.ts +1 -0
  40. package/js/src/abstract/woo.d.ts +3 -0
  41. package/js/src/ace.js +34 -15
  42. package/js/src/alpaca.js +1 -0
  43. package/js/src/base/Exchange.d.ts +1 -0
  44. package/js/src/base/Exchange.js +11 -4
  45. package/js/src/base/errorHierarchy.d.ts +3 -1
  46. package/js/src/base/errorHierarchy.js +3 -1
  47. package/js/src/base/errors.d.ts +5 -1
  48. package/js/src/base/errors.js +8 -2
  49. package/js/src/binance.js +6 -9
  50. package/js/src/bingx.d.ts +4 -1
  51. package/js/src/bingx.js +554 -151
  52. package/js/src/bitfinex.js +1 -1
  53. package/js/src/bitfinex2.js +1 -1
  54. package/js/src/coinbaseinternational.d.ts +1 -1
  55. package/js/src/cryptocom.js +18 -2
  56. package/js/src/independentreserve.d.ts +3 -1
  57. package/js/src/independentreserve.js +106 -0
  58. package/js/src/kucoin.js +2 -0
  59. package/js/src/mercado.js +5 -1
  60. package/js/src/pro/binance.d.ts +1 -0
  61. package/js/src/pro/binance.js +59 -35
  62. package/js/src/pro/bitfinex2.js +7 -4
  63. package/js/src/pro/bitget.js +5 -2
  64. package/js/src/pro/bitmart.js +3 -3
  65. package/js/src/pro/bitvavo.js +1 -1
  66. package/js/src/pro/bybit.d.ts +1 -0
  67. package/js/src/pro/bybit.js +44 -18
  68. package/js/src/pro/cryptocom.js +8 -2
  69. package/js/src/pro/gate.js +8 -4
  70. package/js/src/pro/gemini.js +4 -2
  71. package/js/src/pro/htx.js +6 -2
  72. package/js/src/pro/independentreserve.js +6 -4
  73. package/js/src/pro/kraken.d.ts +3 -1
  74. package/js/src/pro/kraken.js +83 -5
  75. package/js/src/pro/okx.js +4 -4
  76. package/js/src/pro/onetrading.js +3 -2
  77. package/js/src/pro/poloniexfutures.js +6 -2
  78. package/js/src/pro/vertex.js +3 -2
  79. package/js/src/pro/woo.js +2 -1
  80. package/js/src/pro/woofipro.js +3 -2
  81. package/js/src/whitebit.d.ts +1 -1
  82. package/js/src/woo.d.ts +6 -2
  83. package/js/src/woo.js +344 -81
  84. package/js/src/xt.d.ts +3 -3
  85. package/js/src/zonda.d.ts +1 -1
  86. 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,
@@ -82,6 +83,7 @@ export default class bingx extends Exchange {
82
83
  'fetchTickers': true,
83
84
  'fetchTime': true,
84
85
  'fetchTrades': true,
86
+ 'fetchTradingFee': true,
85
87
  'fetchTransfers': true,
86
88
  'fetchWithdrawals': true,
87
89
  'reduceMargin': true,
@@ -1779,6 +1781,7 @@ export default class bingx extends Exchange {
1779
1781
  * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Assets
1780
1782
  * @see https://bingx-api.github.io/docs/#/swapV2/account-api.html#Get%20Perpetual%20Swap%20Account%20Asset%20Information
1781
1783
  * @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Query%20standard%20contract%20balance
1784
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Account%20Assets
1782
1785
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1783
1786
  * @param {boolean} [params.standard] whether to fetch standard contract balances
1784
1787
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
@@ -1787,104 +1790,216 @@ export default class bingx extends Exchange {
1787
1790
  let response = undefined;
1788
1791
  let standard = undefined;
1789
1792
  [standard, params] = this.handleOptionAndParams(params, 'fetchBalance', 'standard', false);
1793
+ let subType = undefined;
1794
+ [subType, params] = this.handleSubTypeAndParams('fetchBalance', undefined, params);
1790
1795
  const [marketType, marketTypeQuery] = this.handleMarketTypeAndParams('fetchBalance', undefined, params);
1791
1796
  if (standard) {
1792
1797
  response = await this.contractV1PrivateGetBalance(marketTypeQuery);
1798
+ //
1799
+ // {
1800
+ // "code": 0,
1801
+ // "timestamp": 1721192833454,
1802
+ // "data": [
1803
+ // {
1804
+ // "asset": "USDT",
1805
+ // "balance": "4.72644300000000000000",
1806
+ // "crossWalletBalance": "4.72644300000000000000",
1807
+ // "crossUnPnl": "0",
1808
+ // "availableBalance": "4.72644300000000000000",
1809
+ // "maxWithdrawAmount": "4.72644300000000000000",
1810
+ // "marginAvailable": false,
1811
+ // "updateTime": 1721192833443
1812
+ // },
1813
+ // ]
1814
+ // }
1815
+ //
1793
1816
  }
1794
1817
  else if (marketType === 'spot') {
1795
1818
  response = await this.spotV1PrivateGetAccountBalance(marketTypeQuery);
1819
+ //
1820
+ // {
1821
+ // "code": 0,
1822
+ // "msg": "",
1823
+ // "debugMsg": "",
1824
+ // "data": {
1825
+ // "balances": [
1826
+ // {
1827
+ // "asset": "USDT",
1828
+ // "free": "45.733046995800514",
1829
+ // "locked": "0"
1830
+ // },
1831
+ // ]
1832
+ // }
1833
+ // }
1834
+ //
1796
1835
  }
1797
1836
  else {
1798
- response = await this.swapV2PrivateGetUserBalance(marketTypeQuery);
1837
+ if (subType === 'inverse') {
1838
+ response = await this.cswapV1PrivateGetUserBalance(marketTypeQuery);
1839
+ //
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
+ }
1859
+ else {
1860
+ response = await this.swapV2PrivateGetUserBalance(marketTypeQuery);
1861
+ //
1862
+ // {
1863
+ // "code": 0,
1864
+ // "msg": "",
1865
+ // "data": {
1866
+ // "balance": {
1867
+ // "userId": "1177064765068660742",
1868
+ // "asset": "USDT",
1869
+ // "balance": "51.5198",
1870
+ // "equity": "50.5349",
1871
+ // "unrealizedProfit": "-0.9849",
1872
+ // "realisedProfit": "-0.2134",
1873
+ // "availableMargin": "49.1428",
1874
+ // "usedMargin": "1.3922",
1875
+ // "freezedMargin": "0.0000",
1876
+ // "shortUid": "12851936"
1877
+ // }
1878
+ // }
1879
+ // }
1880
+ //
1881
+ }
1799
1882
  }
1883
+ return this.parseBalance(response);
1884
+ }
1885
+ parseBalance(response) {
1886
+ //
1887
+ // standard
1888
+ //
1889
+ // {
1890
+ // "code": 0,
1891
+ // "timestamp": 1721192833454,
1892
+ // "data": [
1893
+ // {
1894
+ // "asset": "USDT",
1895
+ // "balance": "4.72644300000000000000",
1896
+ // "crossWalletBalance": "4.72644300000000000000",
1897
+ // "crossUnPnl": "0",
1898
+ // "availableBalance": "4.72644300000000000000",
1899
+ // "maxWithdrawAmount": "4.72644300000000000000",
1900
+ // "marginAvailable": false,
1901
+ // "updateTime": 1721192833443
1902
+ // },
1903
+ // ]
1904
+ // }
1800
1905
  //
1801
1906
  // spot
1802
1907
  //
1803
- // {
1804
- // "code": 0,
1805
- // "msg": "",
1806
- // "ttl": 1,
1807
- // "data": {
1808
- // "balances": [
1809
- // {
1810
- // "asset": "USDT",
1811
- // "free": "16.73971130673954",
1812
- // "locked": "0"
1813
- // }
1814
- // ]
1815
- // }
1816
- // }
1908
+ // {
1909
+ // "code": 0,
1910
+ // "msg": "",
1911
+ // "debugMsg": "",
1912
+ // "data": {
1913
+ // "balances": [
1914
+ // {
1915
+ // "asset": "USDT",
1916
+ // "free": "45.733046995800514",
1917
+ // "locked": "0"
1918
+ // },
1919
+ // ]
1920
+ // }
1921
+ // }
1817
1922
  //
1818
- // swap
1923
+ // inverse swap
1819
1924
  //
1820
- // {
1821
- // "code": 0,
1822
- // "msg": "",
1823
- // "data": {
1824
- // "balance": {
1825
- // "asset": "USDT",
1826
- // "balance": "15.6128",
1827
- // "equity": "15.6128",
1828
- // "unrealizedProfit": "0.0000",
1829
- // "realisedProfit": "0.0000",
1830
- // "availableMargin": "15.6128",
1831
- // "usedMargin": "0.0000",
1832
- // "freezedMargin": "0.0000"
1833
- // }
1834
- // }
1835
- // }
1836
- // standard futures
1837
- // {
1838
- // "code":"0",
1839
- // "timestamp":"1691148990942",
1840
- // "data":[
1841
- // {
1842
- // "asset":"VST",
1843
- // "balance":"100000.00000000000000000000",
1844
- // "crossWalletBalance":"100000.00000000000000000000",
1845
- // "crossUnPnl":"0",
1846
- // "availableBalance":"100000.00000000000000000000",
1847
- // "maxWithdrawAmount":"100000.00000000000000000000",
1848
- // "marginAvailable":false,
1849
- // "updateTime":"1691148990902"
1850
- // },
1851
- // {
1852
- // "asset":"USDT",
1853
- // "balance":"0",
1854
- // "crossWalletBalance":"0",
1855
- // "crossUnPnl":"0",
1856
- // "availableBalance":"0",
1857
- // "maxWithdrawAmount":"0",
1858
- // "marginAvailable":false,
1859
- // "updateTime":"1691148990902"
1860
- // },
1861
- // ]
1925
+ // {
1926
+ // "code": 0,
1927
+ // "msg": "",
1928
+ // "timestamp": 1721191833813,
1929
+ // "data": [
1930
+ // {
1931
+ // "asset": "SOL",
1932
+ // "balance": "0.35707951",
1933
+ // "equity": "0.35791051",
1934
+ // "unrealizedProfit": "0.00083099",
1935
+ // "availableMargin": "0.35160653",
1936
+ // "usedMargin": "0.00630397",
1937
+ // "freezedMargin": "0",
1938
+ // "shortUid": "12851936"
1939
+ // }
1940
+ // ]
1941
+ // }
1942
+ //
1943
+ // linear swap
1944
+ //
1945
+ // {
1946
+ // "code": 0,
1947
+ // "msg": "",
1948
+ // "data": {
1949
+ // "balance": {
1950
+ // "userId": "1177064765068660742",
1951
+ // "asset": "USDT",
1952
+ // "balance": "51.5198",
1953
+ // "equity": "50.5349",
1954
+ // "unrealizedProfit": "-0.9849",
1955
+ // "realisedProfit": "-0.2134",
1956
+ // "availableMargin": "49.1428",
1957
+ // "usedMargin": "1.3922",
1958
+ // "freezedMargin": "0.0000",
1959
+ // "shortUid": "12851936"
1960
+ // }
1961
+ // }
1862
1962
  // }
1863
1963
  //
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
1964
  const result = { 'info': response };
1870
- if (Array.isArray(balances)) {
1871
- for (let i = 0; i < balances.length; i++) {
1872
- const balance = balances[i];
1965
+ const standardAndInverseBalances = this.safeList(response, 'data');
1966
+ const firstStandardOrInverse = this.safeDict(standardAndInverseBalances, 0);
1967
+ const isStandardOrInverse = firstStandardOrInverse !== undefined;
1968
+ const spotData = this.safeDict(response, 'data', {});
1969
+ const spotBalances = this.safeList(spotData, 'balances');
1970
+ const firstSpot = this.safeDict(spotBalances, 0);
1971
+ const isSpot = firstSpot !== undefined;
1972
+ if (isStandardOrInverse) {
1973
+ for (let i = 0; i < standardAndInverseBalances.length; i++) {
1974
+ const balance = standardAndInverseBalances[i];
1975
+ const currencyId = this.safeString(balance, 'asset');
1976
+ const code = this.safeCurrencyCode(currencyId);
1977
+ const account = this.account();
1978
+ account['free'] = this.safeString2(balance, 'availableMargin', 'availableBalance');
1979
+ account['used'] = this.safeString(balance, 'usedMargin');
1980
+ account['total'] = this.safeString(balance, 'maxWithdrawAmount');
1981
+ result[code] = account;
1982
+ }
1983
+ }
1984
+ else if (isSpot) {
1985
+ for (let i = 0; i < spotBalances.length; i++) {
1986
+ const balance = spotBalances[i];
1873
1987
  const currencyId = this.safeString(balance, 'asset');
1874
1988
  const code = this.safeCurrencyCode(currencyId);
1875
1989
  const account = this.account();
1876
- account['free'] = this.safeString2(balance, 'free', 'availableBalance');
1990
+ account['free'] = this.safeString(balance, 'free');
1877
1991
  account['used'] = this.safeString(balance, 'locked');
1878
- account['total'] = this.safeString(balance, 'balance');
1879
1992
  result[code] = account;
1880
1993
  }
1881
1994
  }
1882
1995
  else {
1883
- const currencyId = this.safeString(balances, 'asset');
1996
+ const linearSwapData = this.safeDict(response, 'data', {});
1997
+ const linearSwapBalance = this.safeDict(linearSwapData, 'balance');
1998
+ const currencyId = this.safeString(linearSwapBalance, 'asset');
1884
1999
  const code = this.safeCurrencyCode(currencyId);
1885
2000
  const account = this.account();
1886
- account['free'] = this.safeString(balances, 'availableMargin');
1887
- account['used'] = this.safeString(balances, 'usedMargin');
2001
+ account['free'] = this.safeString(linearSwapBalance, 'availableMargin');
2002
+ account['used'] = this.safeString(linearSwapBalance, 'usedMargin');
1888
2003
  result[code] = account;
1889
2004
  }
1890
2005
  return this.safeBalance(result);
@@ -1894,12 +2009,13 @@ export default class bingx extends Exchange {
1894
2009
  * @method
1895
2010
  * @name bingx#fetchPositions
1896
2011
  * @description fetch all open positions
1897
- * @see https://bingx-api.github.io/docs/#/swapV2/account-api.html#Perpetual%20Swap%20Positions
1898
- * @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Query%20standard%20contract%20balance
2012
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/account-api.html#Query%20position%20data
2013
+ * @see https://bingx-api.github.io/docs/#/en-us/standard/contract-interface.html#position
2014
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20warehouse
1899
2015
  * @param {string[]|undefined} symbols list of unified market symbols
1900
2016
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1901
2017
  * @param {boolean} [params.standard] whether to fetch standard contract positions
1902
- * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
2018
+ * @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
1903
2019
  */
1904
2020
  await this.loadMarkets();
1905
2021
  symbols = this.marketSymbols(symbols);
@@ -1910,55 +2026,217 @@ export default class bingx extends Exchange {
1910
2026
  response = await this.contractV1PrivateGetAllPosition(params);
1911
2027
  }
1912
2028
  else {
1913
- response = await this.swapV2PrivateGetUserPositions(params);
2029
+ let market = undefined;
2030
+ if (symbols !== undefined) {
2031
+ symbols = this.marketSymbols(symbols);
2032
+ const firstSymbol = this.safeString(symbols, 0);
2033
+ if (firstSymbol !== undefined) {
2034
+ market = this.market(firstSymbol);
2035
+ }
2036
+ }
2037
+ let subType = undefined;
2038
+ [subType, params] = this.handleSubTypeAndParams('fetchPositions', market, params);
2039
+ if (subType === 'inverse') {
2040
+ response = await this.cswapV1PrivateGetUserPositions(params);
2041
+ //
2042
+ // {
2043
+ // "code": 0,
2044
+ // "msg": "",
2045
+ // "timestamp": 0,
2046
+ // "data": [
2047
+ // {
2048
+ // "symbol": "SOL-USD",
2049
+ // "positionId": "1813080351385337856",
2050
+ // "positionSide": "LONG",
2051
+ // "isolated": false,
2052
+ // "positionAmt": "1",
2053
+ // "availableAmt": "1",
2054
+ // "unrealizedProfit": "-0.00009074",
2055
+ // "initialMargin": "0.00630398",
2056
+ // "liquidationPrice": 23.968303426677032,
2057
+ // "avgPrice": "158.63",
2058
+ // "leverage": 10,
2059
+ // "markPrice": "158.402",
2060
+ // "riskRate": "0.00123783",
2061
+ // "maxMarginReduction": "0",
2062
+ // "updateTime": 1721107015848
2063
+ // }
2064
+ // ]
2065
+ // }
2066
+ //
2067
+ }
2068
+ else {
2069
+ response = await this.swapV2PrivateGetUserPositions(params);
2070
+ //
2071
+ // {
2072
+ // "code": 0,
2073
+ // "msg": "",
2074
+ // "data": [
2075
+ // {
2076
+ // "positionId": "1792480725958881280",
2077
+ // "symbol": "LTC-USDT",
2078
+ // "currency": "USDT",
2079
+ // "positionAmt": "0.1",
2080
+ // "availableAmt": "0.1",
2081
+ // "positionSide": "LONG",
2082
+ // "isolated": false,
2083
+ // "avgPrice": "83.53",
2084
+ // "initialMargin": "1.3922",
2085
+ // "margin": "0.3528",
2086
+ // "leverage": 6,
2087
+ // "unrealizedProfit": "-1.0393",
2088
+ // "realisedProfit": "-0.2119",
2089
+ // "liquidationPrice": 0,
2090
+ // "pnlRatio": "-0.7465",
2091
+ // "maxMarginReduction": "0.0000",
2092
+ // "riskRate": "0.0008",
2093
+ // "markPrice": "73.14",
2094
+ // "positionValue": "7.3136",
2095
+ // "onlyOnePosition": true,
2096
+ // "updateTime": 1721088016688
2097
+ // }
2098
+ // ]
2099
+ // }
2100
+ //
2101
+ }
1914
2102
  }
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
2103
  const positions = this.safeList(response, 'data', []);
1937
2104
  return this.parsePositions(positions, symbols);
1938
2105
  }
2106
+ async fetchPosition(symbol, params = {}) {
2107
+ /**
2108
+ * @method
2109
+ * @name bingx#fetchPosition
2110
+ * @description fetch data on a single open contract trade position
2111
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/account-api.html#Query%20position%20data
2112
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20warehouse
2113
+ * @param {string} symbol unified market symbol of the market the position is held in
2114
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2115
+ * @returns {object} a [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
2116
+ */
2117
+ await this.loadMarkets();
2118
+ const market = this.market(symbol);
2119
+ if (!market['swap']) {
2120
+ throw new BadRequest(this.id + ' fetchPosition() supports swap markets only');
2121
+ }
2122
+ const request = {
2123
+ 'symbol': market['id'],
2124
+ };
2125
+ let response = undefined;
2126
+ if (market['inverse']) {
2127
+ response = await this.cswapV1PrivateGetUserPositions(this.extend(request, params));
2128
+ //
2129
+ // {
2130
+ // "code": 0,
2131
+ // "msg": "",
2132
+ // "timestamp": 0,
2133
+ // "data": [
2134
+ // {
2135
+ // "symbol": "SOL-USD",
2136
+ // "positionId": "1813080351385337856",
2137
+ // "positionSide": "LONG",
2138
+ // "isolated": false,
2139
+ // "positionAmt": "1",
2140
+ // "availableAmt": "1",
2141
+ // "unrealizedProfit": "-0.00009074",
2142
+ // "initialMargin": "0.00630398",
2143
+ // "liquidationPrice": 23.968303426677032,
2144
+ // "avgPrice": "158.63",
2145
+ // "leverage": 10,
2146
+ // "markPrice": "158.402",
2147
+ // "riskRate": "0.00123783",
2148
+ // "maxMarginReduction": "0",
2149
+ // "updateTime": 1721107015848
2150
+ // }
2151
+ // ]
2152
+ // }
2153
+ //
2154
+ }
2155
+ else {
2156
+ response = await this.swapV2PrivateGetUserPositions(this.extend(request, params));
2157
+ //
2158
+ // {
2159
+ // "code": 0,
2160
+ // "msg": "",
2161
+ // "data": [
2162
+ // {
2163
+ // "positionId": "1792480725958881280",
2164
+ // "symbol": "LTC-USDT",
2165
+ // "currency": "USDT",
2166
+ // "positionAmt": "0.1",
2167
+ // "availableAmt": "0.1",
2168
+ // "positionSide": "LONG",
2169
+ // "isolated": false,
2170
+ // "avgPrice": "83.53",
2171
+ // "initialMargin": "1.3922",
2172
+ // "margin": "0.3528",
2173
+ // "leverage": 6,
2174
+ // "unrealizedProfit": "-1.0393",
2175
+ // "realisedProfit": "-0.2119",
2176
+ // "liquidationPrice": 0,
2177
+ // "pnlRatio": "-0.7465",
2178
+ // "maxMarginReduction": "0.0000",
2179
+ // "riskRate": "0.0008",
2180
+ // "markPrice": "73.14",
2181
+ // "positionValue": "7.3136",
2182
+ // "onlyOnePosition": true,
2183
+ // "updateTime": 1721088016688
2184
+ // }
2185
+ // ]
2186
+ // }
2187
+ //
2188
+ }
2189
+ const data = this.safeList(response, 'data', []);
2190
+ const first = this.safeDict(data, 0, {});
2191
+ return this.parsePosition(first, market);
2192
+ }
1939
2193
  parsePosition(position, market = undefined) {
1940
2194
  //
1941
- // {
1942
- // "positionId":"1773122376147623936",
1943
- // "symbol":"XRP-USDT",
1944
- // "currency":"USDT",
1945
- // "positionAmt":"3",
1946
- // "availableAmt":"3",
1947
- // "positionSide":"LONG",
1948
- // "isolated":false,
1949
- // "avgPrice":"0.6139",
1950
- // "initialMargin":"0.0897",
1951
- // "leverage":20,
1952
- // "unrealizedProfit":"-0.0023",
1953
- // "realisedProfit":"-0.0009",
1954
- // "liquidationPrice":0,
1955
- // "pnlRatio":"-0.0260",
1956
- // "maxMarginReduction":"",
1957
- // "riskRate":"",
1958
- // "markPrice":"",
1959
- // "positionValue":"",
1960
- // "onlyOnePosition":false
1961
- // }
2195
+ // inverse swap
2196
+ //
2197
+ // {
2198
+ // "symbol": "SOL-USD",
2199
+ // "positionId": "1813080351385337856",
2200
+ // "positionSide": "LONG",
2201
+ // "isolated": false,
2202
+ // "positionAmt": "1",
2203
+ // "availableAmt": "1",
2204
+ // "unrealizedProfit": "-0.00009074",
2205
+ // "initialMargin": "0.00630398",
2206
+ // "liquidationPrice": 23.968303426677032,
2207
+ // "avgPrice": "158.63",
2208
+ // "leverage": 10,
2209
+ // "markPrice": "158.402",
2210
+ // "riskRate": "0.00123783",
2211
+ // "maxMarginReduction": "0",
2212
+ // "updateTime": 1721107015848
2213
+ // }
2214
+ //
2215
+ // linear swap
2216
+ //
2217
+ // {
2218
+ // "positionId": "1792480725958881280",
2219
+ // "symbol": "LTC-USDT",
2220
+ // "currency": "USDT",
2221
+ // "positionAmt": "0.1",
2222
+ // "availableAmt": "0.1",
2223
+ // "positionSide": "LONG",
2224
+ // "isolated": false,
2225
+ // "avgPrice": "83.53",
2226
+ // "initialMargin": "1.3922",
2227
+ // "margin": "0.3528",
2228
+ // "leverage": 6,
2229
+ // "unrealizedProfit": "-1.0393",
2230
+ // "realisedProfit": "-0.2119",
2231
+ // "liquidationPrice": 0,
2232
+ // "pnlRatio": "-0.7465",
2233
+ // "maxMarginReduction": "0.0000",
2234
+ // "riskRate": "0.0008",
2235
+ // "markPrice": "73.14",
2236
+ // "positionValue": "7.3136",
2237
+ // "onlyOnePosition": true,
2238
+ // "updateTime": 1721088016688
2239
+ // }
1962
2240
  //
1963
2241
  // standard position
1964
2242
  //
@@ -1994,13 +2272,13 @@ export default class bingx extends Exchange {
1994
2272
  'percentage': undefined,
1995
2273
  'contracts': this.safeNumber(position, 'positionAmt'),
1996
2274
  'contractSize': undefined,
1997
- 'markPrice': undefined,
2275
+ 'markPrice': this.safeNumber(position, 'markPrice'),
1998
2276
  'lastPrice': undefined,
1999
2277
  'side': this.safeStringLower(position, 'positionSide'),
2000
2278
  'hedged': undefined,
2001
2279
  'timestamp': undefined,
2002
2280
  'datetime': undefined,
2003
- 'lastUpdateTimestamp': undefined,
2281
+ 'lastUpdateTimestamp': this.safeInteger(position, 'updateTime'),
2004
2282
  'maintenanceMargin': undefined,
2005
2283
  'maintenanceMarginPercentage': undefined,
2006
2284
  'collateral': undefined,
@@ -4568,6 +4846,7 @@ export default class bingx extends Exchange {
4568
4846
  * @name bingx#fetchMyLiquidations
4569
4847
  * @description retrieves the users liquidated positions
4570
4848
  * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#User's%20Force%20Orders
4849
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20force%20orders
4571
4850
  * @param {string} [symbol] unified CCXT market symbol
4572
4851
  * @param {int} [since] the earliest time in ms to fetch liquidations for
4573
4852
  * @param {int} [limit] the maximum number of liquidation structures to retrieve
@@ -4591,38 +4870,75 @@ export default class bingx extends Exchange {
4591
4870
  if (limit !== undefined) {
4592
4871
  request['limit'] = limit;
4593
4872
  }
4594
- const response = await this.swapV2PrivateGetTradeForceOrders(this.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
- const data = this.safeDict(response, 'data', {});
4625
- const liquidations = this.safeList(data, 'orders', []);
4873
+ let subType = undefined;
4874
+ [subType, params] = this.handleSubTypeAndParams('fetchMyLiquidations', market, params);
4875
+ let response = undefined;
4876
+ let liquidations = undefined;
4877
+ if (subType === 'inverse') {
4878
+ response = await this.cswapV1PrivateGetTradeForceOrders(this.extend(request, params));
4879
+ //
4880
+ // {
4881
+ // "code": 0,
4882
+ // "msg": "",
4883
+ // "timestamp": 1721280071678,
4884
+ // "data": [
4885
+ // {
4886
+ // "orderId": "string",
4887
+ // "symbol": "string",
4888
+ // "type": "string",
4889
+ // "side": "string",
4890
+ // "positionSide": "string",
4891
+ // "price": "string",
4892
+ // "quantity": "float64",
4893
+ // "stopPrice": "string",
4894
+ // "workingType": "string",
4895
+ // "status": "string",
4896
+ // "time": "int64",
4897
+ // "avgPrice": "string",
4898
+ // "executedQty": "string",
4899
+ // "profit": "string",
4900
+ // "commission": "string",
4901
+ // "updateTime": "string"
4902
+ // }
4903
+ // ]
4904
+ // }
4905
+ //
4906
+ liquidations = this.safeList(response, 'data', []);
4907
+ }
4908
+ else {
4909
+ response = await this.swapV2PrivateGetTradeForceOrders(this.extend(request, params));
4910
+ //
4911
+ // {
4912
+ // "code": 0,
4913
+ // "msg": "",
4914
+ // "data": {
4915
+ // "orders": [
4916
+ // {
4917
+ // "time": "int64",
4918
+ // "symbol": "string",
4919
+ // "side": "string",
4920
+ // "type": "string",
4921
+ // "positionSide": "string",
4922
+ // "cumQuote": "string",
4923
+ // "status": "string",
4924
+ // "stopPrice": "string",
4925
+ // "price": "string",
4926
+ // "origQty": "string",
4927
+ // "avgPrice": "string",
4928
+ // "executedQty": "string",
4929
+ // "orderId": "int64",
4930
+ // "profit": "string",
4931
+ // "commission": "string",
4932
+ // "workingType": "string",
4933
+ // "updateTime": "int64"
4934
+ // },
4935
+ // ]
4936
+ // }
4937
+ // }
4938
+ //
4939
+ const data = this.safeDict(response, 'data', {});
4940
+ liquidations = this.safeList(data, 'orders', []);
4941
+ }
4626
4942
  return this.parseLiquidations(liquidations, market, since, limit);
4627
4943
  }
4628
4944
  parseLiquidation(liquidation, market = undefined) {
@@ -5036,6 +5352,93 @@ export default class bingx extends Exchange {
5036
5352
  'marginMode': marginType,
5037
5353
  };
5038
5354
  }
5355
+ async fetchTradingFee(symbol, params = {}) {
5356
+ /**
5357
+ * @method
5358
+ * @name bingx#fetchTradingFee
5359
+ * @description fetch the trading fees for a market
5360
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Trading%20Commission%20Rate
5361
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/account-api.html#Query%20Trading%20Commission%20Rate
5362
+ * @see https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Trade%20Commission%20Rate
5363
+ * @param {string} symbol unified market symbol
5364
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5365
+ * @returns {object} a [fee structure]{@link https://docs.ccxt.com/#/?id=fee-structure}
5366
+ */
5367
+ await this.loadMarkets();
5368
+ const market = this.market(symbol);
5369
+ const request = {
5370
+ 'symbol': market['id'],
5371
+ };
5372
+ let response = undefined;
5373
+ let commission = {};
5374
+ const data = this.safeDict(response, 'data', {});
5375
+ if (market['spot']) {
5376
+ response = await this.spotV1PrivateGetUserCommissionRate(this.extend(request, params));
5377
+ //
5378
+ // {
5379
+ // "code": 0,
5380
+ // "msg": "",
5381
+ // "debugMsg": "",
5382
+ // "data": {
5383
+ // "takerCommissionRate": 0.001,
5384
+ // "makerCommissionRate": 0.001
5385
+ // }
5386
+ // }
5387
+ //
5388
+ commission = data;
5389
+ }
5390
+ else {
5391
+ if (market['inverse']) {
5392
+ response = await this.cswapV1PrivateGetUserCommissionRate(params);
5393
+ //
5394
+ // {
5395
+ // "code": 0,
5396
+ // "msg": "",
5397
+ // "timestamp": 1721365261438,
5398
+ // "data": {
5399
+ // "takerCommissionRate": "0.0005",
5400
+ // "makerCommissionRate": "0.0002"
5401
+ // }
5402
+ // }
5403
+ //
5404
+ commission = data;
5405
+ }
5406
+ else {
5407
+ response = await this.swapV2PrivateGetUserCommissionRate(params);
5408
+ //
5409
+ // {
5410
+ // "code": 0,
5411
+ // "msg": "",
5412
+ // "data": {
5413
+ // "commission": {
5414
+ // "takerCommissionRate": 0.0005,
5415
+ // "makerCommissionRate": 0.0002
5416
+ // }
5417
+ // }
5418
+ // }
5419
+ //
5420
+ commission = this.safeDict(data, 'commission', {});
5421
+ }
5422
+ }
5423
+ return this.parseTradingFee(commission, market);
5424
+ }
5425
+ parseTradingFee(fee, market = undefined) {
5426
+ //
5427
+ // {
5428
+ // "takerCommissionRate": 0.001,
5429
+ // "makerCommissionRate": 0.001
5430
+ // }
5431
+ //
5432
+ const symbol = (market !== undefined) ? market['symbol'] : undefined;
5433
+ return {
5434
+ 'info': fee,
5435
+ 'symbol': symbol,
5436
+ 'maker': this.safeNumber(fee, 'makerCommissionRate'),
5437
+ 'taker': this.safeNumber(fee, 'takerCommissionRate'),
5438
+ 'percentage': false,
5439
+ 'tierBased': false,
5440
+ };
5441
+ }
5039
5442
  sign(path, section = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
5040
5443
  const type = section[0];
5041
5444
  const version = section[1];