ccxt 4.3.6 → 4.3.8

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 (196) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/ccxt.js +1 -1
  3. package/dist/cjs/src/ace.js +5 -0
  4. package/dist/cjs/src/alpaca.js +6 -0
  5. package/dist/cjs/src/base/Exchange.js +47 -3
  6. package/dist/cjs/src/binance.js +3 -1
  7. package/dist/cjs/src/bingx.js +3 -1
  8. package/dist/cjs/src/bitbank.js +3 -0
  9. package/dist/cjs/src/bitget.js +75 -2
  10. package/dist/cjs/src/bithumb.js +4 -0
  11. package/dist/cjs/src/bitmex.js +2 -0
  12. package/dist/cjs/src/bitopro.js +5 -0
  13. package/dist/cjs/src/bitso.js +3 -0
  14. package/dist/cjs/src/bitstamp.js +3 -0
  15. package/dist/cjs/src/bitteam.js +4 -0
  16. package/dist/cjs/src/bitvavo.js +3 -0
  17. package/dist/cjs/src/bl3p.js +3 -0
  18. package/dist/cjs/src/btcalpha.js +3 -0
  19. package/dist/cjs/src/btcbox.js +3 -0
  20. package/dist/cjs/src/btcmarkets.js +3 -0
  21. package/dist/cjs/src/btcturk.js +3 -0
  22. package/dist/cjs/src/bybit.js +123 -12
  23. package/dist/cjs/src/cex.js +6 -0
  24. package/dist/cjs/src/coinbase.js +95 -17
  25. package/dist/cjs/src/coinbaseinternational.js +2 -0
  26. package/dist/cjs/src/coinbasepro.js +6 -0
  27. package/dist/cjs/src/coincheck.js +3 -0
  28. package/dist/cjs/src/coinex.js +257 -190
  29. package/dist/cjs/src/coinlist.js +4 -0
  30. package/dist/cjs/src/coinmate.js +3 -0
  31. package/dist/cjs/src/coinone.js +3 -0
  32. package/dist/cjs/src/coinsph.js +4 -0
  33. package/dist/cjs/src/coinspot.js +3 -0
  34. package/dist/cjs/src/cryptocom.js +2 -0
  35. package/dist/cjs/src/exmo.js +5 -0
  36. package/dist/cjs/src/gate.js +124 -22
  37. package/dist/cjs/src/hitbtc.js +4 -3
  38. package/dist/cjs/src/htx.js +2 -0
  39. package/dist/cjs/src/idex.js +3 -0
  40. package/dist/cjs/src/independentreserve.js +3 -0
  41. package/dist/cjs/src/indodax.js +3 -0
  42. package/dist/cjs/src/kucoin.js +2 -0
  43. package/dist/cjs/src/kucoinfutures.js +2 -0
  44. package/dist/cjs/src/latoken.js +6 -0
  45. package/dist/cjs/src/luno.js +3 -0
  46. package/dist/cjs/src/lykke.js +5 -0
  47. package/dist/cjs/src/mercado.js +3 -0
  48. package/dist/cjs/src/mexc.js +111 -0
  49. package/dist/cjs/src/ndax.js +4 -0
  50. package/dist/cjs/src/novadax.js +4 -0
  51. package/dist/cjs/src/okx.js +84 -1
  52. package/dist/cjs/src/onetrading.js +3 -0
  53. package/dist/cjs/src/p2b.js +3 -0
  54. package/dist/cjs/src/pro/bybit.js +1 -1
  55. package/dist/cjs/src/pro/coinbase.js +30 -29
  56. package/dist/cjs/src/probit.js +3 -0
  57. package/dist/cjs/src/timex.js +3 -0
  58. package/dist/cjs/src/tradeogre.js +3 -0
  59. package/dist/cjs/src/wavesexchange.js +3 -0
  60. package/dist/cjs/src/wazirx.js +3 -0
  61. package/dist/cjs/src/woo.js +3 -1
  62. package/dist/cjs/src/yobit.js +3 -0
  63. package/js/ccxt.d.ts +1 -1
  64. package/js/ccxt.js +1 -1
  65. package/js/src/abstract/coinbase.d.ts +5 -0
  66. package/js/src/ace.js +5 -0
  67. package/js/src/alpaca.js +6 -0
  68. package/js/src/ascendex.d.ts +2 -2
  69. package/js/src/base/Exchange.d.ts +23 -19
  70. package/js/src/base/Exchange.js +47 -3
  71. package/js/src/base/functions/generic.d.ts +20 -19
  72. package/js/src/bigone.d.ts +1 -1
  73. package/js/src/binance.d.ts +3 -3
  74. package/js/src/binance.js +3 -1
  75. package/js/src/bingx.d.ts +3 -3
  76. package/js/src/bingx.js +3 -1
  77. package/js/src/bitbank.d.ts +1 -1
  78. package/js/src/bitbank.js +3 -0
  79. package/js/src/bitfinex.d.ts +1 -1
  80. package/js/src/bitfinex2.d.ts +1 -1
  81. package/js/src/bitflyer.d.ts +1 -1
  82. package/js/src/bitget.d.ts +4 -3
  83. package/js/src/bitget.js +75 -2
  84. package/js/src/bithumb.d.ts +1 -1
  85. package/js/src/bithumb.js +4 -0
  86. package/js/src/bitmart.d.ts +1 -1
  87. package/js/src/bitmex.d.ts +1 -1
  88. package/js/src/bitmex.js +2 -0
  89. package/js/src/bitopro.d.ts +1 -1
  90. package/js/src/bitopro.js +5 -0
  91. package/js/src/bitrue.d.ts +1 -1
  92. package/js/src/bitso.d.ts +1 -1
  93. package/js/src/bitso.js +3 -0
  94. package/js/src/bitstamp.d.ts +1 -1
  95. package/js/src/bitstamp.js +3 -0
  96. package/js/src/bitteam.js +4 -0
  97. package/js/src/bitvavo.d.ts +1 -1
  98. package/js/src/bitvavo.js +3 -0
  99. package/js/src/bl3p.js +3 -0
  100. package/js/src/blockchaincom.d.ts +1 -1
  101. package/js/src/btcalpha.js +3 -0
  102. package/js/src/btcbox.js +3 -0
  103. package/js/src/btcmarkets.d.ts +1 -1
  104. package/js/src/btcmarkets.js +3 -0
  105. package/js/src/btcturk.js +3 -0
  106. package/js/src/bybit.d.ts +8 -7
  107. package/js/src/bybit.js +123 -12
  108. package/js/src/cex.js +6 -0
  109. package/js/src/coinbase.d.ts +2 -2
  110. package/js/src/coinbase.js +95 -17
  111. package/js/src/coinbaseinternational.d.ts +2 -2
  112. package/js/src/coinbaseinternational.js +2 -0
  113. package/js/src/coinbasepro.d.ts +1 -1
  114. package/js/src/coinbasepro.js +6 -0
  115. package/js/src/coincheck.js +3 -0
  116. package/js/src/coinex.d.ts +8 -7
  117. package/js/src/coinex.js +257 -190
  118. package/js/src/coinlist.d.ts +1 -1
  119. package/js/src/coinlist.js +4 -0
  120. package/js/src/coinmate.d.ts +1 -1
  121. package/js/src/coinmate.js +3 -0
  122. package/js/src/coinone.js +3 -0
  123. package/js/src/coinsph.d.ts +1 -1
  124. package/js/src/coinsph.js +4 -0
  125. package/js/src/coinspot.js +3 -0
  126. package/js/src/cryptocom.d.ts +1 -1
  127. package/js/src/cryptocom.js +2 -0
  128. package/js/src/delta.d.ts +2 -2
  129. package/js/src/deribit.d.ts +1 -1
  130. package/js/src/digifinex.d.ts +3 -3
  131. package/js/src/exmo.d.ts +3 -3
  132. package/js/src/exmo.js +5 -0
  133. package/js/src/gate.d.ts +8 -7
  134. package/js/src/gate.js +124 -22
  135. package/js/src/gemini.d.ts +2 -2
  136. package/js/src/hitbtc.d.ts +3 -3
  137. package/js/src/hitbtc.js +4 -3
  138. package/js/src/hollaex.d.ts +2 -2
  139. package/js/src/htx.d.ts +3 -3
  140. package/js/src/htx.js +2 -0
  141. package/js/src/huobijp.d.ts +1 -1
  142. package/js/src/hyperliquid.d.ts +2 -2
  143. package/js/src/idex.d.ts +2 -2
  144. package/js/src/idex.js +3 -0
  145. package/js/src/independentreserve.js +3 -0
  146. package/js/src/indodax.d.ts +1 -1
  147. package/js/src/indodax.js +3 -0
  148. package/js/src/kraken.d.ts +1 -1
  149. package/js/src/kucoin.d.ts +2 -2
  150. package/js/src/kucoin.js +2 -0
  151. package/js/src/kucoinfutures.d.ts +1 -1
  152. package/js/src/kucoinfutures.js +2 -0
  153. package/js/src/kuna.d.ts +1 -1
  154. package/js/src/latoken.js +6 -0
  155. package/js/src/lbank.d.ts +1 -1
  156. package/js/src/luno.js +3 -0
  157. package/js/src/lykke.d.ts +1 -1
  158. package/js/src/lykke.js +5 -0
  159. package/js/src/mercado.d.ts +1 -1
  160. package/js/src/mercado.js +3 -0
  161. package/js/src/mexc.d.ts +5 -4
  162. package/js/src/mexc.js +111 -0
  163. package/js/src/ndax.d.ts +1 -1
  164. package/js/src/ndax.js +4 -0
  165. package/js/src/novadax.d.ts +1 -1
  166. package/js/src/novadax.js +4 -0
  167. package/js/src/okcoin.d.ts +2 -2
  168. package/js/src/okx.d.ts +10 -9
  169. package/js/src/okx.js +84 -1
  170. package/js/src/onetrading.d.ts +1 -1
  171. package/js/src/onetrading.js +3 -0
  172. package/js/src/p2b.js +3 -0
  173. package/js/src/paymium.d.ts +1 -1
  174. package/js/src/phemex.d.ts +1 -1
  175. package/js/src/poloniex.d.ts +1 -1
  176. package/js/src/pro/bybit.js +1 -1
  177. package/js/src/pro/coinbase.d.ts +2 -2
  178. package/js/src/pro/coinbase.js +30 -29
  179. package/js/src/pro/luno.d.ts +2 -2
  180. package/js/src/probit.d.ts +2 -2
  181. package/js/src/probit.js +3 -0
  182. package/js/src/timex.js +3 -0
  183. package/js/src/tokocrypto.d.ts +1 -1
  184. package/js/src/tradeogre.js +3 -0
  185. package/js/src/upbit.d.ts +2 -2
  186. package/js/src/wavesexchange.d.ts +1 -1
  187. package/js/src/wavesexchange.js +3 -0
  188. package/js/src/wazirx.js +3 -0
  189. package/js/src/whitebit.d.ts +2 -2
  190. package/js/src/woo.d.ts +1 -1
  191. package/js/src/woo.js +3 -1
  192. package/js/src/yobit.d.ts +1 -1
  193. package/js/src/yobit.js +3 -0
  194. package/js/src/zaif.d.ts +1 -1
  195. package/js/src/zonda.d.ts +2 -2
  196. package/package.json +1 -1
@@ -90,7 +90,9 @@ class coinex extends coinex$1 {
90
90
  'fetchOrder': true,
91
91
  'fetchOrderBook': true,
92
92
  'fetchPosition': true,
93
+ 'fetchPositionHistory': true,
93
94
  'fetchPositions': true,
95
+ 'fetchPositionsHistory': false,
94
96
  'fetchPositionsRisk': false,
95
97
  'fetchPremiumIndexOHLCV': false,
96
98
  'fetchTicker': true,
@@ -1452,24 +1454,24 @@ class coinex extends coinex$1 {
1452
1454
  }
1453
1455
  parseOHLCV(ohlcv, market = undefined) {
1454
1456
  //
1455
- // [
1456
- // 1591484400,
1457
- // "0.02505349",
1458
- // "0.02506988",
1459
- // "0.02507000",
1460
- // "0.02505304",
1461
- // "343.19716223",
1462
- // "8.6021323866383196",
1463
- // "ETHBTC"
1464
- // ]
1457
+ // {
1458
+ // "close": "66999.95",
1459
+ // "created_at": 1713934620000,
1460
+ // "high": "66999.95",
1461
+ // "low": "66988.53",
1462
+ // "market": "BTCUSDT",
1463
+ // "open": "66988.53",
1464
+ // "value": "0.1572393", // base volume
1465
+ // "volume": "10533.2501364336" // quote volume
1466
+ // }
1465
1467
  //
1466
1468
  return [
1467
- this.safeTimestamp(ohlcv, 0),
1468
- this.safeNumber(ohlcv, 1),
1469
- this.safeNumber(ohlcv, 3),
1470
- this.safeNumber(ohlcv, 4),
1471
- this.safeNumber(ohlcv, 2),
1472
- this.safeNumber(ohlcv, 5),
1469
+ this.safeInteger(ohlcv, 'created_at'),
1470
+ this.safeNumber(ohlcv, 'open'),
1471
+ this.safeNumber(ohlcv, 'high'),
1472
+ this.safeNumber(ohlcv, 'low'),
1473
+ this.safeNumber(ohlcv, 'close'),
1474
+ this.safeNumber(ohlcv, 'value'),
1473
1475
  ];
1474
1476
  }
1475
1477
  async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
@@ -1477,8 +1479,8 @@ class coinex extends coinex$1 {
1477
1479
  * @method
1478
1480
  * @name coinex#fetchOHLCV
1479
1481
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1480
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot001_market006_market_kline
1481
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http012_market_kline
1482
+ * @see https://docs.coinex.com/api/v2/spot/market/http/list-market-kline
1483
+ * @see https://docs.coinex.com/api/v2/futures/market/http/list-market-kline
1482
1484
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1483
1485
  * @param {string} timeframe the length of time each candle represents
1484
1486
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -1490,39 +1492,34 @@ class coinex extends coinex$1 {
1490
1492
  const market = this.market(symbol);
1491
1493
  const request = {
1492
1494
  'market': market['id'],
1493
- 'type': this.safeString(this.timeframes, timeframe, timeframe),
1495
+ 'period': this.safeString(this.timeframes, timeframe, timeframe),
1494
1496
  };
1495
1497
  if (limit !== undefined) {
1496
1498
  request['limit'] = limit;
1497
1499
  }
1498
1500
  let response = undefined;
1499
1501
  if (market['swap']) {
1500
- response = await this.v1PerpetualPublicGetMarketKline(this.extend(request, params));
1502
+ response = await this.v2PublicGetFuturesKline(this.extend(request, params));
1501
1503
  }
1502
1504
  else {
1503
- response = await this.v1PublicGetMarketKline(this.extend(request, params));
1505
+ response = await this.v2PublicGetSpotKline(this.extend(request, params));
1504
1506
  }
1505
1507
  //
1506
- // Spot
1507
- //
1508
- // {
1509
- // "code": 0,
1510
- // "data": [
1511
- // [1591484400, "0.02505349", "0.02506988", "0.02507000", "0.02505304", "343.19716223", "8.6021323866383196", "ETHBTC"],
1512
- // [1591484700, "0.02506990", "0.02508109", "0.02508109", "0.02506979", "91.59841581", "2.2972047780447000", "ETHBTC"],
1513
- // [1591485000, "0.02508106", "0.02507996", "0.02508106", "0.02507500", "65.15307697", "1.6340597822306000", "ETHBTC"],
1514
- // ],
1515
- // "message": "OK"
1516
- // }
1517
- //
1518
- // Swap
1508
+ // Spot and Swap
1519
1509
  //
1520
1510
  // {
1521
1511
  // "code": 0,
1522
1512
  // "data": [
1523
- // [1650569400, "41524.64", "41489.31", "41564.61", "41480.58", "29.7060", "1233907.099562"],
1524
- // [1650569700, "41489.31", "41438.29", "41489.31", "41391.87", "42.4115", "1756154.189061"],
1525
- // [1650570000, "41438.29", "41482.21", "41485.05", "41427.31", "22.2892", "924000.317861"]
1513
+ // {
1514
+ // "close": "66999.95",
1515
+ // "created_at": 1713934620000,
1516
+ // "high": "66999.95",
1517
+ // "low": "66988.53",
1518
+ // "market": "BTCUSDT",
1519
+ // "open": "66988.53",
1520
+ // "value": "0.1572393",
1521
+ // "volume": "10533.2501364336"
1522
+ // },
1526
1523
  // ],
1527
1524
  // "message": "OK"
1528
1525
  // }
@@ -1532,190 +1529,144 @@ class coinex extends coinex$1 {
1532
1529
  }
1533
1530
  async fetchMarginBalance(params = {}) {
1534
1531
  await this.loadMarkets();
1535
- const symbol = this.safeString(params, 'symbol');
1536
- let marketId = this.safeString(params, 'market');
1537
- let market = undefined;
1538
- if (symbol !== undefined) {
1539
- market = this.market(symbol);
1540
- marketId = market['id'];
1541
- }
1542
- else if (marketId === undefined) {
1543
- throw new errors.ArgumentsRequired(this.id + ' fetchMarginBalance() fetching a margin account requires a market parameter or a symbol parameter');
1544
- }
1545
- params = this.omit(params, ['symbol', 'market']);
1546
- const request = {
1547
- 'market': marketId,
1548
- };
1549
- const response = await this.v1PrivateGetMarginAccount(this.extend(request, params));
1532
+ const response = await this.v2PrivateGetAssetsMarginBalance(params);
1550
1533
  //
1551
- // {
1552
- // "code": 0,
1553
- // "data": {
1554
- // "account_id": 126,
1555
- // "leverage": 3,
1556
- // "market_type": "AAVEUSDT",
1557
- // "sell_asset_type": "AAVE",
1558
- // "buy_asset_type": "USDT",
1559
- // "balance": {
1560
- // "sell_type": "0.3", // borrowed
1561
- // "buy_type": "30"
1562
- // },
1563
- // "frozen": {
1564
- // "sell_type": "0",
1565
- // "buy_type": "0"
1566
- // },
1567
- // "loan": {
1568
- // "sell_type": "0.3", // loan
1569
- // "buy_type": "0"
1570
- // },
1571
- // "interest": {
1572
- // "sell_type": "0.0000125",
1573
- // "buy_type": "0"
1574
- // },
1575
- // "can_transfer": {
1576
- // "sell_type": "0.02500646",
1577
- // "buy_type": "4.28635738"
1578
- // },
1579
- // "warn_rate": "",
1580
- // "liquidation_price": ""
1581
- // },
1582
- // "message": "Success"
1583
- // }
1534
+ // {
1535
+ // "data": [
1536
+ // {
1537
+ // "margin_account": "BTCUSDT",
1538
+ // "base_ccy": "BTC",
1539
+ // "quote_ccy": "USDT",
1540
+ // "available": {
1541
+ // "base_ccy": "0.00000026",
1542
+ // "quote_ccy": "0"
1543
+ // },
1544
+ // "frozen": {
1545
+ // "base_ccy": "0",
1546
+ // "quote_ccy": "0"
1547
+ // },
1548
+ // "repaid": {
1549
+ // "base_ccy": "0",
1550
+ // "quote_ccy": "0"
1551
+ // },
1552
+ // "interest": {
1553
+ // "base_ccy": "0",
1554
+ // "quote_ccy": "0"
1555
+ // },
1556
+ // "rik_rate": "",
1557
+ // "liq_price": ""
1558
+ // },
1559
+ // ],
1560
+ // "code": 0,
1561
+ // "message": "OK"
1562
+ // }
1584
1563
  //
1585
1564
  const result = { 'info': response };
1586
- const data = this.safeValue(response, 'data', {});
1587
- const free = this.safeValue(data, 'can_transfer', {});
1588
- const total = this.safeValue(data, 'balance', {});
1589
- const loan = this.safeValue(data, 'loan', {});
1590
- const interest = this.safeValue(data, 'interest', {});
1591
- //
1592
- const sellAccount = this.account();
1593
- const sellCurrencyId = this.safeString(data, 'sell_asset_type');
1594
- const sellCurrencyCode = this.safeCurrencyCode(sellCurrencyId);
1595
- sellAccount['free'] = this.safeString(free, 'sell_type');
1596
- sellAccount['total'] = this.safeString(total, 'sell_type');
1597
- const sellDebt = this.safeString(loan, 'sell_type');
1598
- const sellInterest = this.safeString(interest, 'sell_type');
1599
- sellAccount['debt'] = Precise["default"].stringAdd(sellDebt, sellInterest);
1600
- result[sellCurrencyCode] = sellAccount;
1601
- //
1602
- const buyAccount = this.account();
1603
- const buyCurrencyId = this.safeString(data, 'buy_asset_type');
1604
- const buyCurrencyCode = this.safeCurrencyCode(buyCurrencyId);
1605
- buyAccount['free'] = this.safeString(free, 'buy_type');
1606
- buyAccount['total'] = this.safeString(total, 'buy_type');
1607
- const buyDebt = this.safeString(loan, 'buy_type');
1608
- const buyInterest = this.safeString(interest, 'buy_type');
1609
- buyAccount['debt'] = Precise["default"].stringAdd(buyDebt, buyInterest);
1610
- result[buyCurrencyCode] = buyAccount;
1611
- //
1565
+ const balances = this.safeList(response, 'data', []);
1566
+ for (let i = 0; i < balances.length; i++) {
1567
+ const entry = balances[i];
1568
+ const free = this.safeDict(entry, 'available', {});
1569
+ const used = this.safeDict(entry, 'frozen', {});
1570
+ const loan = this.safeDict(entry, 'repaid', {});
1571
+ const interest = this.safeDict(entry, 'interest', {});
1572
+ const baseAccount = this.account();
1573
+ const baseCurrencyId = this.safeString(entry, 'base_ccy');
1574
+ const baseCurrencyCode = this.safeCurrencyCode(baseCurrencyId);
1575
+ baseAccount['free'] = this.safeString(free, 'base_ccy');
1576
+ baseAccount['used'] = this.safeString(used, 'base_ccy');
1577
+ const baseDebt = this.safeString(loan, 'base_ccy');
1578
+ const baseInterest = this.safeString(interest, 'base_ccy');
1579
+ baseAccount['debt'] = Precise["default"].stringAdd(baseDebt, baseInterest);
1580
+ result[baseCurrencyCode] = baseAccount;
1581
+ }
1612
1582
  return this.safeBalance(result);
1613
1583
  }
1614
1584
  async fetchSpotBalance(params = {}) {
1615
1585
  await this.loadMarkets();
1616
- const response = await this.v1PrivateGetBalanceInfo(params);
1586
+ const response = await this.v2PrivateGetAssetsSpotBalance(params);
1617
1587
  //
1618
1588
  // {
1619
- // "code": 0,
1620
- // "data": {
1621
- // "BCH": { # BCH account
1622
- // "available": "13.60109", # Available BCH
1623
- // "frozen": "0.00000" # Frozen BCH
1624
- // },
1625
- // "BTC": { # BTC account
1626
- // "available": "32590.16", # Available BTC
1627
- // "frozen": "7000.00" # Frozen BTC
1628
- // },
1629
- // "ETH": { # ETH account
1630
- // "available": "5.06000", # Available ETH
1631
- // "frozen": "0.00000" # Frozen ETH
1632
- // }
1633
- // },
1634
- // "message": "Ok"
1589
+ // "code": 0,
1590
+ // "data": [
1591
+ // {
1592
+ // "available": "0.00000046",
1593
+ // "ccy": "USDT",
1594
+ // "frozen": "0"
1595
+ // }
1596
+ // ],
1597
+ // "message": "OK"
1635
1598
  // }
1636
1599
  //
1637
1600
  const result = { 'info': response };
1638
- const balances = this.safeValue(response, 'data', {});
1639
- const currencyIds = Object.keys(balances);
1640
- for (let i = 0; i < currencyIds.length; i++) {
1641
- const currencyId = currencyIds[i];
1601
+ const balances = this.safeList(response, 'data', []);
1602
+ for (let i = 0; i < balances.length; i++) {
1603
+ const entry = balances[i];
1604
+ const currencyId = this.safeString(entry, 'ccy');
1642
1605
  const code = this.safeCurrencyCode(currencyId);
1643
- const balance = this.safeValue(balances, currencyId, {});
1644
1606
  const account = this.account();
1645
- account['free'] = this.safeString(balance, 'available');
1646
- account['used'] = this.safeString(balance, 'frozen');
1607
+ account['free'] = this.safeString(entry, 'available');
1608
+ account['used'] = this.safeString(entry, 'frozen');
1647
1609
  result[code] = account;
1648
1610
  }
1649
1611
  return this.safeBalance(result);
1650
1612
  }
1651
1613
  async fetchSwapBalance(params = {}) {
1652
1614
  await this.loadMarkets();
1653
- const response = await this.v1PerpetualPrivateGetAssetQuery(params);
1615
+ const response = await this.v2PrivateGetAssetsFuturesBalance(params);
1654
1616
  //
1655
1617
  // {
1656
1618
  // "code": 0,
1657
- // "data": {
1658
- // "USDT": {
1659
- // "available": "37.24817690383456000000",
1660
- // "balance_total": "37.24817690383456000000",
1661
- // "frozen": "0.00000000000000000000",
1662
- // "margin": "0.00000000000000000000",
1663
- // "profit_unreal": "0.00000000000000000000",
1664
- // "transfer": "37.24817690383456000000"
1619
+ // "data": [
1620
+ // {
1621
+ // "available": "0.00000046",
1622
+ // "ccy": "USDT",
1623
+ // "frozen": "0",
1624
+ // "margin": "0",
1625
+ // "transferrable": "0.00000046",
1626
+ // "unrealized_pnl": "0"
1665
1627
  // }
1666
- // },
1628
+ // ],
1667
1629
  // "message": "OK"
1668
1630
  // }
1669
1631
  //
1670
1632
  const result = { 'info': response };
1671
- const balances = this.safeValue(response, 'data', {});
1672
- const currencyIds = Object.keys(balances);
1673
- for (let i = 0; i < currencyIds.length; i++) {
1674
- const currencyId = currencyIds[i];
1633
+ const balances = this.safeList(response, 'data', []);
1634
+ for (let i = 0; i < balances.length; i++) {
1635
+ const entry = balances[i];
1636
+ const currencyId = this.safeString(entry, 'ccy');
1675
1637
  const code = this.safeCurrencyCode(currencyId);
1676
- const balance = this.safeValue(balances, currencyId, {});
1677
1638
  const account = this.account();
1678
- account['free'] = this.safeString(balance, 'available');
1679
- account['used'] = this.safeString(balance, 'frozen');
1680
- account['total'] = this.safeString(balance, 'balance_total');
1639
+ account['free'] = this.safeString(entry, 'available');
1640
+ account['used'] = this.safeString(entry, 'frozen');
1681
1641
  result[code] = account;
1682
1642
  }
1683
1643
  return this.safeBalance(result);
1684
1644
  }
1685
1645
  async fetchFinancialBalance(params = {}) {
1686
1646
  await this.loadMarkets();
1687
- const response = await this.v1PrivateGetAccountInvestmentBalance(params);
1647
+ const response = await this.v2PrivateGetAssetsFinancialBalance(params);
1688
1648
  //
1689
1649
  // {
1690
- // "code": 0,
1691
- // "data": [
1692
- // {
1693
- // "asset": "CET",
1694
- // "available": "0",
1695
- // "frozen": "0",
1696
- // "lock": "0",
1697
- // },
1698
- // {
1699
- // "asset": "USDT",
1700
- // "available": "999900",
1701
- // "frozen": "0",
1702
- // "lock": "0"
1703
- // }
1704
- // ],
1705
- // "message": "Success"
1706
- // }
1650
+ // "code": 0,
1651
+ // "data": [
1652
+ // {
1653
+ // "available": "0.00000046",
1654
+ // "ccy": "USDT",
1655
+ // "frozen": "0"
1656
+ // }
1657
+ // ],
1658
+ // "message": "OK"
1659
+ // }
1707
1660
  //
1708
1661
  const result = { 'info': response };
1709
- const balances = this.safeValue(response, 'data', {});
1662
+ const balances = this.safeList(response, 'data', []);
1710
1663
  for (let i = 0; i < balances.length; i++) {
1711
- const balance = balances[i];
1712
- const currencyId = this.safeString(balance, 'asset');
1664
+ const entry = balances[i];
1665
+ const currencyId = this.safeString(entry, 'ccy');
1713
1666
  const code = this.safeCurrencyCode(currencyId);
1714
1667
  const account = this.account();
1715
- account['free'] = this.safeString(balance, 'available');
1716
- const frozen = this.safeString(balance, 'frozen');
1717
- const locked = this.safeString(balance, 'lock');
1718
- account['used'] = Precise["default"].stringAdd(frozen, locked);
1668
+ account['free'] = this.safeString(entry, 'available');
1669
+ account['used'] = this.safeString(entry, 'frozen');
1719
1670
  result[code] = account;
1720
1671
  }
1721
1672
  return this.safeBalance(result);
@@ -1725,10 +1676,10 @@ class coinex extends coinex$1 {
1725
1676
  * @method
1726
1677
  * @name coinex#fetchBalance
1727
1678
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
1728
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account001_account_info // spot
1729
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account004_investment_balance // financial
1730
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account006_margin_account // margin
1731
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http016_asset_query // swap
1679
+ * @see https://docs.coinex.com/api/v2/assets/balance/http/get-spot-balance // spot
1680
+ * @see https://docs.coinex.com/api/v2/assets/balance/http/get-futures-balance // swap
1681
+ * @see https://docs.coinex.com/api/v2/assets/balance/http/get-marigin-balance // margin
1682
+ * @see https://docs.coinex.com/api/v2/assets/balance/http/get-financial-balance // financial
1732
1683
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1733
1684
  * @param {string} [params.type] 'margin', 'swap', 'financial', or 'spot'
1734
1685
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
@@ -3763,7 +3714,7 @@ class coinex extends coinex$1 {
3763
3714
  // "side": 2,
3764
3715
  // "stop_loss_price": "0.00000000000000000000",
3765
3716
  // "stop_loss_type": 0,
3766
- // "sys": 0,
3717
+ // "sy s": 0,
3767
3718
  // "take_profit_price": "0.00000000000000000000",
3768
3719
  // "take_profit_type": 0,
3769
3720
  // "taker_fee": "0.00000000000000000000",
@@ -3845,7 +3796,7 @@ class coinex extends coinex$1 {
3845
3796
  // "side": 2,
3846
3797
  // "stop_loss_price": "0.00000000000000000000",
3847
3798
  // "stop_loss_type": 0,
3848
- // "sys": 0,
3799
+ // "s ys": 0,
3849
3800
  // "take_profit_price": "0.00000000000000000000",
3850
3801
  // "take_profit_type": 0,
3851
3802
  // "taker_fee": "0.00000000000000000000",
@@ -3862,6 +3813,8 @@ class coinex extends coinex$1 {
3862
3813
  return this.parsePosition(data[0], market);
3863
3814
  }
3864
3815
  parsePosition(position, market = undefined) {
3816
+ //
3817
+ // fetchPosition
3865
3818
  //
3866
3819
  // {
3867
3820
  // "adl_sort": 3396,
@@ -3905,7 +3858,7 @@ class coinex extends coinex$1 {
3905
3858
  // "side": 2,
3906
3859
  // "stop_loss_price": "0.00000000000000000000",
3907
3860
  // "stop_loss_type": 0,
3908
- // "sys": 0,
3861
+ // "s ys": 0,
3909
3862
  // "take_profit_price": "0.00000000000000000000",
3910
3863
  // "take_profit_type": 0,
3911
3864
  // "taker_fee": "0.00000000000000000000",
@@ -3915,6 +3868,40 @@ class coinex extends coinex$1 {
3915
3868
  // "user_id": 3620173
3916
3869
  // }
3917
3870
  //
3871
+ //
3872
+ // fetchPositionHistory
3873
+ //
3874
+ // {
3875
+ // amount_max: '10',
3876
+ // amount_max_margin: '2.03466666666666666666',
3877
+ // bkr_price: '0',
3878
+ // create_time: '1711150526.2581',
3879
+ // deal_all: '12.591',
3880
+ // deal_asset_fee: '0',
3881
+ // fee_asset: '',
3882
+ // finish_type: '5',
3883
+ // first_price: '0.6104',
3884
+ // latest_price: '0.6487',
3885
+ // leverage: '3',
3886
+ // liq_amount: '0',
3887
+ // liq_price: '0',
3888
+ // liq_profit: '0',
3889
+ // mainten_margin: '0.01',
3890
+ // market: 'XRPUSDT',
3891
+ // market_type: '1',
3892
+ // open_price: '0.6104',
3893
+ // open_val_max: '6.104',
3894
+ // position_id: '297371462',
3895
+ // profit_real: '0.35702107169',
3896
+ // settle_price: '0.6104',
3897
+ // settle_val: '0',
3898
+ // side: '2',
3899
+ // s ys: "0",
3900
+ // type: '2',
3901
+ // update_time: '1711391446.133233',
3902
+ // user_id: '3685860'
3903
+ // }
3904
+ //
3918
3905
  const marketId = this.safeString(position, 'market');
3919
3906
  market = this.safeMarket(marketId, market, undefined, 'swap');
3920
3907
  const symbol = market['symbol'];
@@ -3930,7 +3917,7 @@ class coinex extends coinex$1 {
3930
3917
  const timestamp = this.safeTimestamp(position, 'update_time');
3931
3918
  const maintenanceMargin = this.safeString(position, 'mainten_margin_amount');
3932
3919
  const maintenanceMarginPercentage = this.safeString(position, 'mainten_margin');
3933
- const collateral = this.safeString(position, 'margin_amount');
3920
+ const collateral = this.safeString2(position, 'margin_amount', 'amount_max_margin');
3934
3921
  const leverage = this.safeString(position, 'leverage');
3935
3922
  const notional = this.safeString(position, 'open_val');
3936
3923
  const initialMargin = Precise["default"].stringDiv(notional, leverage);
@@ -4160,7 +4147,7 @@ class coinex extends coinex$1 {
4160
4147
  // "side": 2,
4161
4148
  // "stop_loss_price": "0.00000000000000000000",
4162
4149
  // "stop_loss_type": 0,
4163
- // "sys": 0,
4150
+ // "s ys": 0,
4164
4151
  // "take_profit_price": "0.00000000000000000000",
4165
4152
  // "take_profit_type": 0,
4166
4153
  // "taker_fee": "0.00000000000000000000",
@@ -4225,7 +4212,7 @@ class coinex extends coinex$1 {
4225
4212
  // "side": 2,
4226
4213
  // "stop_loss_price": "0.00000000000000000000",
4227
4214
  // "stop_loss_type": 0,
4228
- // "sys": 0,
4215
+ // "sy s": 0,
4229
4216
  // "take_profit_price": "0.00000000000000000000",
4230
4217
  // "take_profit_type": 0,
4231
4218
  // "taker_fee": "0.00000000000000000000",
@@ -5608,6 +5595,80 @@ class coinex extends coinex$1 {
5608
5595
  'shortLeverage': leverageValue,
5609
5596
  };
5610
5597
  }
5598
+ async fetchPositionHistory(symbol, since = undefined, limit = undefined, params = {}) {
5599
+ /**
5600
+ * @method
5601
+ * @name coinex#fetchPositionHistory
5602
+ * @description fetches historical positions
5603
+ * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033-0_finished_position
5604
+ * @param {string} symbol unified contract symbol
5605
+ * @param {int} [since] not used by coinex fetchPositionHistory
5606
+ * @param {int} [limit] the maximum amount of records to fetch, default=1000
5607
+ * @param {object} params extra parameters specific to the exchange api endpoint
5608
+ *
5609
+ * EXCHANGE SPECIFIC PARAMETERS
5610
+ * @param {int} [params.side] 0: all 1: sell, 2: buy
5611
+ * @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
5612
+ */
5613
+ await this.loadMarkets();
5614
+ const market = this.market(symbol);
5615
+ if (limit === undefined) {
5616
+ limit = 1000;
5617
+ }
5618
+ const request = {
5619
+ 'market': market['id'],
5620
+ 'side': 0,
5621
+ 'limit': limit,
5622
+ };
5623
+ const response = await this.v1PerpetualPrivateGetPositionFinished(this.extend(request, params));
5624
+ //
5625
+ // {
5626
+ // code: '0',
5627
+ // data: {
5628
+ // limit: '1000',
5629
+ // offset: '0',
5630
+ // records: [
5631
+ // {
5632
+ // amount_max: '10',
5633
+ // amount_max_margin: '2.03466666666666666666',
5634
+ // bkr_price: '0',
5635
+ // create_time: '1711150526.2581',
5636
+ // deal_all: '12.591',
5637
+ // deal_asset_fee: '0',
5638
+ // fee_asset: '',
5639
+ // finish_type: '5',
5640
+ // first_price: '0.6104',
5641
+ // latest_price: '0.6487',
5642
+ // leverage: '3',
5643
+ // liq_amount: '0',
5644
+ // liq_price: '0',
5645
+ // liq_profit: '0',
5646
+ // mainten_margin: '0.01',
5647
+ // market: 'XRPUSDT',
5648
+ // market_type: '1',
5649
+ // open_price: '0.6104',
5650
+ // open_val_max: '6.104',
5651
+ // position_id: '297371462',
5652
+ // profit_real: '0.35702107169',
5653
+ // settle_price: '0.6104',
5654
+ // settle_val: '0',
5655
+ // side: '2',
5656
+ // sy s: '0',
5657
+ // type: '2',
5658
+ // update_time: '1711391446.133233',
5659
+ // user_id: '3685860'
5660
+ // },
5661
+ // ...
5662
+ // ]
5663
+ // },
5664
+ // message: 'OK'
5665
+ // }
5666
+ //
5667
+ const data = this.safeDict(response, 'data');
5668
+ const records = this.safeList(data, 'records');
5669
+ const positions = this.parsePositions(records);
5670
+ return this.filterBySymbolSinceLimit(positions, symbol, since, limit);
5671
+ }
5611
5672
  handleMarginModeAndParams(methodName, params = {}, defaultValue = undefined) {
5612
5673
  /**
5613
5674
  * @ignore
@@ -5714,7 +5775,11 @@ class coinex extends coinex$1 {
5714
5775
  this.checkRequiredCredentials();
5715
5776
  query = this.keysort(query);
5716
5777
  const urlencoded = this.rawencode(query);
5717
- const preparedString = method + '/' + version + '/' + path + '?' + urlencoded + nonce + this.secret;
5778
+ let preparedString = method + '/' + version + '/' + path;
5779
+ if (urlencoded) {
5780
+ preparedString += '?' + urlencoded;
5781
+ }
5782
+ preparedString += nonce + this.secret;
5718
5783
  const signature = this.hash(this.encode(preparedString), sha256.sha256);
5719
5784
  headers = {
5720
5785
  'X-COINEX-KEY': this.apiKey,
@@ -5722,7 +5787,9 @@ class coinex extends coinex$1 {
5722
5787
  'X-COINEX-TIMESTAMP': nonce,
5723
5788
  };
5724
5789
  if ((method === 'GET') || (method === 'DELETE') || (method === 'PUT')) {
5725
- url += '?' + urlencoded;
5790
+ if (urlencoded) {
5791
+ url += '?' + urlencoded;
5792
+ }
5726
5793
  }
5727
5794
  else {
5728
5795
  body = this.json(query);
@@ -87,7 +87,11 @@ class coinlist extends coinlist$1 {
87
87
  'fetchOrders': true,
88
88
  'fetchOrderTrades': true,
89
89
  'fetchPosition': false,
90
+ 'fetchPositionHistory': false,
91
+ 'fetchPositionMode': false,
90
92
  'fetchPositions': false,
93
+ 'fetchPositionsForSymbol': false,
94
+ 'fetchPositionsHistory': false,
91
95
  'fetchPositionsRisk': false,
92
96
  'fetchPremiumIndexOHLCV': false,
93
97
  'fetchStatus': false,