ccxt 4.3.61 → 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.
Files changed (104) 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/base/Exchange.js +8 -1
  6. package/dist/cjs/src/base/errors.js +8 -1
  7. package/dist/cjs/src/binance.js +50 -43
  8. package/dist/cjs/src/bingx.js +507 -184
  9. package/dist/cjs/src/bybit.js +1 -1
  10. package/dist/cjs/src/cryptocom.js +18 -2
  11. package/dist/cjs/src/mercado.js +5 -1
  12. package/dist/cjs/src/pro/alpaca.js +3 -3
  13. package/dist/cjs/src/pro/binance.js +60 -38
  14. package/dist/cjs/src/pro/bingx.js +2 -2
  15. package/dist/cjs/src/pro/bitfinex2.js +8 -5
  16. package/dist/cjs/src/pro/bitget.js +5 -2
  17. package/dist/cjs/src/pro/bitmex.js +1 -1
  18. package/dist/cjs/src/pro/bitopro.js +1 -1
  19. package/dist/cjs/src/pro/bitvavo.js +1 -1
  20. package/dist/cjs/src/pro/bybit.js +49 -23
  21. package/dist/cjs/src/pro/coinbaseexchange.js +2 -2
  22. package/dist/cjs/src/pro/coincheck.js +1 -1
  23. package/dist/cjs/src/pro/coinone.js +1 -1
  24. package/dist/cjs/src/pro/cryptocom.js +8 -2
  25. package/dist/cjs/src/pro/deribit.js +1 -1
  26. package/dist/cjs/src/pro/gate.js +8 -4
  27. package/dist/cjs/src/pro/hollaex.js +1 -1
  28. package/dist/cjs/src/pro/htx.js +6 -2
  29. package/dist/cjs/src/pro/hyperliquid.js +3 -3
  30. package/dist/cjs/src/pro/independentreserve.js +5 -3
  31. package/dist/cjs/src/pro/kraken.js +83 -5
  32. package/dist/cjs/src/pro/kucoin.js +1 -1
  33. package/dist/cjs/src/pro/mexc.js +1 -1
  34. package/dist/cjs/src/pro/okx.js +4 -4
  35. package/dist/cjs/src/pro/oxfun.js +1 -1
  36. package/dist/cjs/src/pro/phemex.js +1 -1
  37. package/dist/cjs/src/pro/poloniexfutures.js +5 -1
  38. package/dist/cjs/src/pro/upbit.js +1 -1
  39. package/dist/cjs/src/pro/vertex.js +2 -2
  40. package/dist/cjs/src/pro/whitebit.js +1 -1
  41. package/dist/cjs/src/pro/woo.js +1 -1
  42. package/dist/cjs/src/pro/woofipro.js +1 -1
  43. package/dist/cjs/src/tradeogre.js +1 -1
  44. package/dist/cjs/src/woo.js +313 -81
  45. package/dist/cjs/src/xt.js +1 -1
  46. package/js/ccxt.d.ts +3 -3
  47. package/js/ccxt.js +3 -3
  48. package/js/src/abstract/cryptocom.d.ts +11 -0
  49. package/js/src/abstract/woo.d.ts +3 -0
  50. package/js/src/ace.js +34 -15
  51. package/js/src/base/Exchange.d.ts +1 -0
  52. package/js/src/base/Exchange.js +8 -1
  53. package/js/src/base/errorHierarchy.d.ts +3 -1
  54. package/js/src/base/errorHierarchy.js +3 -1
  55. package/js/src/base/errors.d.ts +5 -1
  56. package/js/src/base/errors.js +8 -2
  57. package/js/src/base/ws/Client.d.ts +1 -1
  58. package/js/src/binance.js +50 -43
  59. package/js/src/bingx.d.ts +1 -0
  60. package/js/src/bingx.js +507 -184
  61. package/js/src/bybit.js +1 -1
  62. package/js/src/coinbaseinternational.d.ts +1 -1
  63. package/js/src/cryptocom.js +18 -2
  64. package/js/src/mercado.js +5 -1
  65. package/js/src/pro/alpaca.js +3 -3
  66. package/js/src/pro/binance.d.ts +1 -0
  67. package/js/src/pro/binance.js +61 -39
  68. package/js/src/pro/bingx.js +2 -2
  69. package/js/src/pro/bitfinex2.js +9 -6
  70. package/js/src/pro/bitget.js +6 -3
  71. package/js/src/pro/bitmex.js +1 -1
  72. package/js/src/pro/bitopro.js +1 -1
  73. package/js/src/pro/bitvavo.js +1 -1
  74. package/js/src/pro/bybit.d.ts +1 -0
  75. package/js/src/pro/bybit.js +49 -23
  76. package/js/src/pro/coinbaseexchange.js +2 -2
  77. package/js/src/pro/coincheck.js +1 -1
  78. package/js/src/pro/coinone.js +1 -1
  79. package/js/src/pro/cryptocom.js +9 -3
  80. package/js/src/pro/deribit.js +1 -1
  81. package/js/src/pro/gate.js +9 -5
  82. package/js/src/pro/hollaex.js +1 -1
  83. package/js/src/pro/htx.js +7 -3
  84. package/js/src/pro/hyperliquid.js +3 -3
  85. package/js/src/pro/independentreserve.js +6 -4
  86. package/js/src/pro/kraken.d.ts +3 -1
  87. package/js/src/pro/kraken.js +84 -6
  88. package/js/src/pro/kucoin.js +1 -1
  89. package/js/src/pro/mexc.js +1 -1
  90. package/js/src/pro/okx.js +5 -5
  91. package/js/src/pro/oxfun.js +1 -1
  92. package/js/src/pro/phemex.js +1 -1
  93. package/js/src/pro/poloniexfutures.js +6 -2
  94. package/js/src/pro/upbit.js +1 -1
  95. package/js/src/pro/vertex.js +2 -2
  96. package/js/src/pro/whitebit.js +1 -1
  97. package/js/src/pro/woo.js +1 -1
  98. package/js/src/pro/woofipro.js +1 -1
  99. package/js/src/tradeogre.js +1 -1
  100. package/js/src/woo.d.ts +5 -1
  101. package/js/src/woo.js +313 -81
  102. package/js/src/xt.d.ts +3 -3
  103. package/js/src/xt.js +1 -1
  104. 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,
@@ -522,37 +523,40 @@ export default class bingx extends Exchange {
522
523
  const response = await this.walletsV1PrivateGetCapitalConfigGetall(params);
523
524
  //
524
525
  // {
525
- // "code": 0,
526
- // "timestamp": 1688045966616,
527
- // "data": [
526
+ // "code": 0,
527
+ // "timestamp": 1702623271477,
528
+ // "data": [
529
+ // {
530
+ // "coin": "BTC",
531
+ // "name": "BTC",
532
+ // "networkList": [
528
533
  // {
529
- // "coin": "BTC",
530
534
  // "name": "BTC",
531
- // "networkList": [
532
- // {
533
- // "name": "BTC",
534
- // "network": "BTC",
535
- // "isDefault": true,
536
- // "minConfirm": "2",
537
- // "withdrawEnable": true,
538
- // "withdrawFee": "0.00035",
539
- // "withdrawMax": "1.62842",
540
- // "withdrawMin": "0.0005"
541
- // },
542
- // {
543
- // "name": "BTC",
544
- // "network": "BEP20",
545
- // "isDefault": false,
546
- // "minConfirm": "15",
547
- // "withdrawEnable": true,
548
- // "withdrawFee": "0.00001",
549
- // "withdrawMax": "1.62734",
550
- // "withdrawMin": "0.0001"
551
- // }
552
- // ]
553
- // },
554
- // ...
555
- // ],
535
+ // "network": "BTC",
536
+ // "isDefault": true,
537
+ // "minConfirm": 2,
538
+ // "withdrawEnable": true,
539
+ // "depositEnable": true,
540
+ // "withdrawFee": "0.0006",
541
+ // "withdrawMax": "1.17522",
542
+ // "withdrawMin": "0.0005",
543
+ // "depositMin": "0.0002"
544
+ // },
545
+ // {
546
+ // "name": "BTC",
547
+ // "network": "BEP20",
548
+ // "isDefault": false,
549
+ // "minConfirm": 15,
550
+ // "withdrawEnable": true,
551
+ // "depositEnable": true,
552
+ // "withdrawFee": "0.0000066",
553
+ // "withdrawMax": "1.17522",
554
+ // "withdrawMin": "0.0000066",
555
+ // "depositMin": "0.0002"
556
+ // }
557
+ // ]
558
+ // }
559
+ // ]
556
560
  // }
557
561
  //
558
562
  const data = this.safeList(response, 'data', []);
@@ -566,6 +570,7 @@ export default class bingx extends Exchange {
566
570
  const networks = {};
567
571
  let fee = undefined;
568
572
  let active = undefined;
573
+ let depositEnabled = undefined;
569
574
  let withdrawEnabled = undefined;
570
575
  let defaultLimits = {};
571
576
  for (let j = 0; j < networkList.length; j++) {
@@ -573,13 +578,17 @@ export default class bingx extends Exchange {
573
578
  const network = this.safeString(rawNetwork, 'network');
574
579
  const networkCode = this.networkIdToCode(network);
575
580
  const isDefault = this.safeBool(rawNetwork, 'isDefault');
581
+ depositEnabled = this.safeBool(rawNetwork, 'depositEnable');
576
582
  withdrawEnabled = this.safeBool(rawNetwork, 'withdrawEnable');
577
583
  const limits = {
578
- 'amounts': { 'min': this.safeNumber(rawNetwork, 'withdrawMin'), 'max': this.safeNumber(rawNetwork, 'withdrawMax') },
584
+ 'withdraw': {
585
+ 'min': this.safeNumber(rawNetwork, 'withdrawMin'),
586
+ 'max': this.safeNumber(rawNetwork, 'withdrawMax'),
587
+ },
579
588
  };
580
589
  if (isDefault) {
581
590
  fee = this.safeNumber(rawNetwork, 'withdrawFee');
582
- active = withdrawEnabled;
591
+ active = depositEnabled || withdrawEnabled;
583
592
  defaultLimits = limits;
584
593
  }
585
594
  networks[networkCode] = {
@@ -588,7 +597,7 @@ export default class bingx extends Exchange {
588
597
  'network': networkCode,
589
598
  'fee': fee,
590
599
  'active': active,
591
- 'deposit': undefined,
600
+ 'deposit': depositEnabled,
592
601
  'withdraw': withdrawEnabled,
593
602
  'precision': undefined,
594
603
  'limits': limits,
@@ -601,7 +610,7 @@ export default class bingx extends Exchange {
601
610
  'precision': undefined,
602
611
  'name': name,
603
612
  'active': active,
604
- 'deposit': undefined,
613
+ 'deposit': depositEnabled,
605
614
  'withdraw': withdrawEnabled,
606
615
  'networks': networks,
607
616
  'fee': fee,
@@ -1771,6 +1780,7 @@ export default class bingx extends Exchange {
1771
1780
  * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Assets
1772
1781
  * @see https://bingx-api.github.io/docs/#/swapV2/account-api.html#Get%20Perpetual%20Swap%20Account%20Asset%20Information
1773
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
1774
1784
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1775
1785
  * @param {boolean} [params.standard] whether to fetch standard contract balances
1776
1786
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
@@ -1779,104 +1789,216 @@ export default class bingx extends Exchange {
1779
1789
  let response = undefined;
1780
1790
  let standard = undefined;
1781
1791
  [standard, params] = this.handleOptionAndParams(params, 'fetchBalance', 'standard', false);
1792
+ let subType = undefined;
1793
+ [subType, params] = this.handleSubTypeAndParams('fetchBalance', undefined, params);
1782
1794
  const [marketType, marketTypeQuery] = this.handleMarketTypeAndParams('fetchBalance', undefined, params);
1783
1795
  if (standard) {
1784
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
+ //
1785
1815
  }
1786
1816
  else if (marketType === 'spot') {
1787
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
+ //
1788
1834
  }
1789
1835
  else {
1790
- response = await this.swapV2PrivateGetUserBalance(marketTypeQuery);
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
+ }
1791
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
+ // }
1792
1904
  //
1793
1905
  // spot
1794
1906
  //
1795
- // {
1796
- // "code": 0,
1797
- // "msg": "",
1798
- // "ttl": 1,
1799
- // "data": {
1800
- // "balances": [
1801
- // {
1802
- // "asset": "USDT",
1803
- // "free": "16.73971130673954",
1804
- // "locked": "0"
1805
- // }
1806
- // ]
1807
- // }
1808
- // }
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
+ // }
1809
1921
  //
1810
- // swap
1922
+ // inverse swap
1811
1923
  //
1812
- // {
1813
- // "code": 0,
1814
- // "msg": "",
1815
- // "data": {
1816
- // "balance": {
1817
- // "asset": "USDT",
1818
- // "balance": "15.6128",
1819
- // "equity": "15.6128",
1820
- // "unrealizedProfit": "0.0000",
1821
- // "realisedProfit": "0.0000",
1822
- // "availableMargin": "15.6128",
1823
- // "usedMargin": "0.0000",
1824
- // "freezedMargin": "0.0000"
1825
- // }
1826
- // }
1827
- // }
1828
- // standard futures
1829
- // {
1830
- // "code":"0",
1831
- // "timestamp":"1691148990942",
1832
- // "data":[
1833
- // {
1834
- // "asset":"VST",
1835
- // "balance":"100000.00000000000000000000",
1836
- // "crossWalletBalance":"100000.00000000000000000000",
1837
- // "crossUnPnl":"0",
1838
- // "availableBalance":"100000.00000000000000000000",
1839
- // "maxWithdrawAmount":"100000.00000000000000000000",
1840
- // "marginAvailable":false,
1841
- // "updateTime":"1691148990902"
1842
- // },
1843
- // {
1844
- // "asset":"USDT",
1845
- // "balance":"0",
1846
- // "crossWalletBalance":"0",
1847
- // "crossUnPnl":"0",
1848
- // "availableBalance":"0",
1849
- // "maxWithdrawAmount":"0",
1850
- // "marginAvailable":false,
1851
- // "updateTime":"1691148990902"
1852
- // },
1853
- // ]
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
+ // }
1854
1961
  // }
1855
1962
  //
1856
- return this.parseBalance(response);
1857
- }
1858
- parseBalance(response) {
1859
- const data = this.safeValue(response, 'data');
1860
- const balances = this.safeValue2(data, 'balance', 'balances', data);
1861
1963
  const result = { 'info': response };
1862
- if (Array.isArray(balances)) {
1863
- for (let i = 0; i < balances.length; i++) {
1864
- const balance = balances[i];
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];
1974
+ const currencyId = this.safeString(balance, 'asset');
1975
+ const code = this.safeCurrencyCode(currencyId);
1976
+ const account = this.account();
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];
1865
1986
  const currencyId = this.safeString(balance, 'asset');
1866
1987
  const code = this.safeCurrencyCode(currencyId);
1867
1988
  const account = this.account();
1868
- account['free'] = this.safeString2(balance, 'free', 'availableBalance');
1989
+ account['free'] = this.safeString(balance, 'free');
1869
1990
  account['used'] = this.safeString(balance, 'locked');
1870
- account['total'] = this.safeString(balance, 'balance');
1871
1991
  result[code] = account;
1872
1992
  }
1873
1993
  }
1874
1994
  else {
1875
- const currencyId = this.safeString(balances, 'asset');
1995
+ const linearSwapData = this.safeDict(response, 'data', {});
1996
+ const linearSwapBalance = this.safeDict(linearSwapData, 'balance');
1997
+ const currencyId = this.safeString(linearSwapBalance, 'asset');
1876
1998
  const code = this.safeCurrencyCode(currencyId);
1877
1999
  const account = this.account();
1878
- account['free'] = this.safeString(balances, 'availableMargin');
1879
- account['used'] = this.safeString(balances, 'usedMargin');
2000
+ account['free'] = this.safeString(linearSwapBalance, 'availableMargin');
2001
+ account['used'] = this.safeString(linearSwapBalance, 'usedMargin');
1880
2002
  result[code] = account;
1881
2003
  }
1882
2004
  return this.safeBalance(result);
@@ -1886,12 +2008,13 @@ export default class bingx extends Exchange {
1886
2008
  * @method
1887
2009
  * @name bingx#fetchPositions
1888
2010
  * @description fetch all open positions
1889
- * @see https://bingx-api.github.io/docs/#/swapV2/account-api.html#Perpetual%20Swap%20Positions
1890
- * @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Query%20standard%20contract%20balance
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
1891
2014
  * @param {string[]|undefined} symbols list of unified market symbols
1892
2015
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1893
2016
  * @param {boolean} [params.standard] whether to fetch standard contract positions
1894
- * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
2017
+ * @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
1895
2018
  */
1896
2019
  await this.loadMarkets();
1897
2020
  symbols = this.marketSymbols(symbols);
@@ -1902,55 +2025,217 @@ export default class bingx extends Exchange {
1902
2025
  response = await this.contractV1PrivateGetAllPosition(params);
1903
2026
  }
1904
2027
  else {
1905
- response = await this.swapV2PrivateGetUserPositions(params);
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
+ }
1906
2101
  }
1907
- //
1908
- // {
1909
- // "code": 0,
1910
- // "msg": "",
1911
- // "data": [
1912
- // {
1913
- // "symbol": "BTC-USDT",
1914
- // "positionId": "12345678",
1915
- // "positionSide": "LONG",
1916
- // "isolated": true,
1917
- // "positionAmt": "123.33",
1918
- // "availableAmt": "128.99",
1919
- // "unrealizedProfit": "1.22",
1920
- // "realisedProfit": "8.1",
1921
- // "initialMargin": "123.33",
1922
- // "avgPrice": "2.2",
1923
- // "leverage": 10,
1924
- // }
1925
- // ]
1926
- // }
1927
- //
1928
2102
  const positions = this.safeList(response, 'data', []);
1929
2103
  return this.parsePositions(positions, symbols);
1930
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
+ }
1931
2192
  parsePosition(position, market = undefined) {
1932
2193
  //
1933
- // {
1934
- // "positionId":"1773122376147623936",
1935
- // "symbol":"XRP-USDT",
1936
- // "currency":"USDT",
1937
- // "positionAmt":"3",
1938
- // "availableAmt":"3",
1939
- // "positionSide":"LONG",
1940
- // "isolated":false,
1941
- // "avgPrice":"0.6139",
1942
- // "initialMargin":"0.0897",
1943
- // "leverage":20,
1944
- // "unrealizedProfit":"-0.0023",
1945
- // "realisedProfit":"-0.0009",
1946
- // "liquidationPrice":0,
1947
- // "pnlRatio":"-0.0260",
1948
- // "maxMarginReduction":"",
1949
- // "riskRate":"",
1950
- // "markPrice":"",
1951
- // "positionValue":"",
1952
- // "onlyOnePosition":false
1953
- // }
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
+ // }
1954
2239
  //
1955
2240
  // standard position
1956
2241
  //
@@ -1986,13 +2271,13 @@ export default class bingx extends Exchange {
1986
2271
  'percentage': undefined,
1987
2272
  'contracts': this.safeNumber(position, 'positionAmt'),
1988
2273
  'contractSize': undefined,
1989
- 'markPrice': undefined,
2274
+ 'markPrice': this.safeNumber(position, 'markPrice'),
1990
2275
  'lastPrice': undefined,
1991
2276
  'side': this.safeStringLower(position, 'positionSide'),
1992
2277
  'hedged': undefined,
1993
2278
  'timestamp': undefined,
1994
2279
  'datetime': undefined,
1995
- 'lastUpdateTimestamp': undefined,
2280
+ 'lastUpdateTimestamp': this.safeInteger(position, 'updateTime'),
1996
2281
  'maintenanceMargin': undefined,
1997
2282
  'maintenanceMarginPercentage': undefined,
1998
2283
  'collateral': undefined,
@@ -4560,6 +4845,7 @@ export default class bingx extends Exchange {
4560
4845
  * @name bingx#fetchMyLiquidations
4561
4846
  * @description retrieves the users liquidated positions
4562
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
4563
4849
  * @param {string} [symbol] unified CCXT market symbol
4564
4850
  * @param {int} [since] the earliest time in ms to fetch liquidations for
4565
4851
  * @param {int} [limit] the maximum number of liquidation structures to retrieve
@@ -4583,38 +4869,75 @@ export default class bingx extends Exchange {
4583
4869
  if (limit !== undefined) {
4584
4870
  request['limit'] = limit;
4585
4871
  }
4586
- const response = await this.swapV2PrivateGetTradeForceOrders(this.extend(request, params));
4587
- //
4588
- // {
4589
- // "code": 0,
4590
- // "msg": "",
4591
- // "data": {
4592
- // "orders": [
4593
- // {
4594
- // "time": "int64",
4595
- // "symbol": "string",
4596
- // "side": "string",
4597
- // "type": "string",
4598
- // "positionSide": "string",
4599
- // "cumQuote": "string",
4600
- // "status": "string",
4601
- // "stopPrice": "string",
4602
- // "price": "string",
4603
- // "origQty": "string",
4604
- // "avgPrice": "string",
4605
- // "executedQty": "string",
4606
- // "orderId": "int64",
4607
- // "profit": "string",
4608
- // "commission": "string",
4609
- // "workingType": "string",
4610
- // "updateTime": "int64"
4611
- // },
4612
- // ]
4613
- // }
4614
- // }
4615
- //
4616
- const data = this.safeDict(response, 'data', {});
4617
- const liquidations = this.safeList(data, 'orders', []);
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
+ }
4618
4941
  return this.parseLiquidations(liquidations, market, since, limit);
4619
4942
  }
4620
4943
  parseLiquidation(liquidation, market = undefined) {