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
package/js/src/coinex.js CHANGED
@@ -93,7 +93,9 @@ export default class coinex extends Exchange {
93
93
  'fetchOrder': true,
94
94
  'fetchOrderBook': true,
95
95
  'fetchPosition': true,
96
+ 'fetchPositionHistory': true,
96
97
  'fetchPositions': true,
98
+ 'fetchPositionsHistory': false,
97
99
  'fetchPositionsRisk': false,
98
100
  'fetchPremiumIndexOHLCV': false,
99
101
  'fetchTicker': true,
@@ -1455,24 +1457,24 @@ export default class coinex extends Exchange {
1455
1457
  }
1456
1458
  parseOHLCV(ohlcv, market = undefined) {
1457
1459
  //
1458
- // [
1459
- // 1591484400,
1460
- // "0.02505349",
1461
- // "0.02506988",
1462
- // "0.02507000",
1463
- // "0.02505304",
1464
- // "343.19716223",
1465
- // "8.6021323866383196",
1466
- // "ETHBTC"
1467
- // ]
1460
+ // {
1461
+ // "close": "66999.95",
1462
+ // "created_at": 1713934620000,
1463
+ // "high": "66999.95",
1464
+ // "low": "66988.53",
1465
+ // "market": "BTCUSDT",
1466
+ // "open": "66988.53",
1467
+ // "value": "0.1572393", // base volume
1468
+ // "volume": "10533.2501364336" // quote volume
1469
+ // }
1468
1470
  //
1469
1471
  return [
1470
- this.safeTimestamp(ohlcv, 0),
1471
- this.safeNumber(ohlcv, 1),
1472
- this.safeNumber(ohlcv, 3),
1473
- this.safeNumber(ohlcv, 4),
1474
- this.safeNumber(ohlcv, 2),
1475
- this.safeNumber(ohlcv, 5),
1472
+ this.safeInteger(ohlcv, 'created_at'),
1473
+ this.safeNumber(ohlcv, 'open'),
1474
+ this.safeNumber(ohlcv, 'high'),
1475
+ this.safeNumber(ohlcv, 'low'),
1476
+ this.safeNumber(ohlcv, 'close'),
1477
+ this.safeNumber(ohlcv, 'value'),
1476
1478
  ];
1477
1479
  }
1478
1480
  async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
@@ -1480,8 +1482,8 @@ export default class coinex extends Exchange {
1480
1482
  * @method
1481
1483
  * @name coinex#fetchOHLCV
1482
1484
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1483
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot001_market006_market_kline
1484
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http012_market_kline
1485
+ * @see https://docs.coinex.com/api/v2/spot/market/http/list-market-kline
1486
+ * @see https://docs.coinex.com/api/v2/futures/market/http/list-market-kline
1485
1487
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1486
1488
  * @param {string} timeframe the length of time each candle represents
1487
1489
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -1493,39 +1495,34 @@ export default class coinex extends Exchange {
1493
1495
  const market = this.market(symbol);
1494
1496
  const request = {
1495
1497
  'market': market['id'],
1496
- 'type': this.safeString(this.timeframes, timeframe, timeframe),
1498
+ 'period': this.safeString(this.timeframes, timeframe, timeframe),
1497
1499
  };
1498
1500
  if (limit !== undefined) {
1499
1501
  request['limit'] = limit;
1500
1502
  }
1501
1503
  let response = undefined;
1502
1504
  if (market['swap']) {
1503
- response = await this.v1PerpetualPublicGetMarketKline(this.extend(request, params));
1505
+ response = await this.v2PublicGetFuturesKline(this.extend(request, params));
1504
1506
  }
1505
1507
  else {
1506
- response = await this.v1PublicGetMarketKline(this.extend(request, params));
1508
+ response = await this.v2PublicGetSpotKline(this.extend(request, params));
1507
1509
  }
1508
1510
  //
1509
- // Spot
1510
- //
1511
- // {
1512
- // "code": 0,
1513
- // "data": [
1514
- // [1591484400, "0.02505349", "0.02506988", "0.02507000", "0.02505304", "343.19716223", "8.6021323866383196", "ETHBTC"],
1515
- // [1591484700, "0.02506990", "0.02508109", "0.02508109", "0.02506979", "91.59841581", "2.2972047780447000", "ETHBTC"],
1516
- // [1591485000, "0.02508106", "0.02507996", "0.02508106", "0.02507500", "65.15307697", "1.6340597822306000", "ETHBTC"],
1517
- // ],
1518
- // "message": "OK"
1519
- // }
1520
- //
1521
- // Swap
1511
+ // Spot and Swap
1522
1512
  //
1523
1513
  // {
1524
1514
  // "code": 0,
1525
1515
  // "data": [
1526
- // [1650569400, "41524.64", "41489.31", "41564.61", "41480.58", "29.7060", "1233907.099562"],
1527
- // [1650569700, "41489.31", "41438.29", "41489.31", "41391.87", "42.4115", "1756154.189061"],
1528
- // [1650570000, "41438.29", "41482.21", "41485.05", "41427.31", "22.2892", "924000.317861"]
1516
+ // {
1517
+ // "close": "66999.95",
1518
+ // "created_at": 1713934620000,
1519
+ // "high": "66999.95",
1520
+ // "low": "66988.53",
1521
+ // "market": "BTCUSDT",
1522
+ // "open": "66988.53",
1523
+ // "value": "0.1572393",
1524
+ // "volume": "10533.2501364336"
1525
+ // },
1529
1526
  // ],
1530
1527
  // "message": "OK"
1531
1528
  // }
@@ -1535,190 +1532,144 @@ export default class coinex extends Exchange {
1535
1532
  }
1536
1533
  async fetchMarginBalance(params = {}) {
1537
1534
  await this.loadMarkets();
1538
- const symbol = this.safeString(params, 'symbol');
1539
- let marketId = this.safeString(params, 'market');
1540
- let market = undefined;
1541
- if (symbol !== undefined) {
1542
- market = this.market(symbol);
1543
- marketId = market['id'];
1544
- }
1545
- else if (marketId === undefined) {
1546
- throw new ArgumentsRequired(this.id + ' fetchMarginBalance() fetching a margin account requires a market parameter or a symbol parameter');
1547
- }
1548
- params = this.omit(params, ['symbol', 'market']);
1549
- const request = {
1550
- 'market': marketId,
1551
- };
1552
- const response = await this.v1PrivateGetMarginAccount(this.extend(request, params));
1535
+ const response = await this.v2PrivateGetAssetsMarginBalance(params);
1553
1536
  //
1554
- // {
1555
- // "code": 0,
1556
- // "data": {
1557
- // "account_id": 126,
1558
- // "leverage": 3,
1559
- // "market_type": "AAVEUSDT",
1560
- // "sell_asset_type": "AAVE",
1561
- // "buy_asset_type": "USDT",
1562
- // "balance": {
1563
- // "sell_type": "0.3", // borrowed
1564
- // "buy_type": "30"
1565
- // },
1566
- // "frozen": {
1567
- // "sell_type": "0",
1568
- // "buy_type": "0"
1569
- // },
1570
- // "loan": {
1571
- // "sell_type": "0.3", // loan
1572
- // "buy_type": "0"
1573
- // },
1574
- // "interest": {
1575
- // "sell_type": "0.0000125",
1576
- // "buy_type": "0"
1577
- // },
1578
- // "can_transfer": {
1579
- // "sell_type": "0.02500646",
1580
- // "buy_type": "4.28635738"
1581
- // },
1582
- // "warn_rate": "",
1583
- // "liquidation_price": ""
1584
- // },
1585
- // "message": "Success"
1586
- // }
1537
+ // {
1538
+ // "data": [
1539
+ // {
1540
+ // "margin_account": "BTCUSDT",
1541
+ // "base_ccy": "BTC",
1542
+ // "quote_ccy": "USDT",
1543
+ // "available": {
1544
+ // "base_ccy": "0.00000026",
1545
+ // "quote_ccy": "0"
1546
+ // },
1547
+ // "frozen": {
1548
+ // "base_ccy": "0",
1549
+ // "quote_ccy": "0"
1550
+ // },
1551
+ // "repaid": {
1552
+ // "base_ccy": "0",
1553
+ // "quote_ccy": "0"
1554
+ // },
1555
+ // "interest": {
1556
+ // "base_ccy": "0",
1557
+ // "quote_ccy": "0"
1558
+ // },
1559
+ // "rik_rate": "",
1560
+ // "liq_price": ""
1561
+ // },
1562
+ // ],
1563
+ // "code": 0,
1564
+ // "message": "OK"
1565
+ // }
1587
1566
  //
1588
1567
  const result = { 'info': response };
1589
- const data = this.safeValue(response, 'data', {});
1590
- const free = this.safeValue(data, 'can_transfer', {});
1591
- const total = this.safeValue(data, 'balance', {});
1592
- const loan = this.safeValue(data, 'loan', {});
1593
- const interest = this.safeValue(data, 'interest', {});
1594
- //
1595
- const sellAccount = this.account();
1596
- const sellCurrencyId = this.safeString(data, 'sell_asset_type');
1597
- const sellCurrencyCode = this.safeCurrencyCode(sellCurrencyId);
1598
- sellAccount['free'] = this.safeString(free, 'sell_type');
1599
- sellAccount['total'] = this.safeString(total, 'sell_type');
1600
- const sellDebt = this.safeString(loan, 'sell_type');
1601
- const sellInterest = this.safeString(interest, 'sell_type');
1602
- sellAccount['debt'] = Precise.stringAdd(sellDebt, sellInterest);
1603
- result[sellCurrencyCode] = sellAccount;
1604
- //
1605
- const buyAccount = this.account();
1606
- const buyCurrencyId = this.safeString(data, 'buy_asset_type');
1607
- const buyCurrencyCode = this.safeCurrencyCode(buyCurrencyId);
1608
- buyAccount['free'] = this.safeString(free, 'buy_type');
1609
- buyAccount['total'] = this.safeString(total, 'buy_type');
1610
- const buyDebt = this.safeString(loan, 'buy_type');
1611
- const buyInterest = this.safeString(interest, 'buy_type');
1612
- buyAccount['debt'] = Precise.stringAdd(buyDebt, buyInterest);
1613
- result[buyCurrencyCode] = buyAccount;
1614
- //
1568
+ const balances = this.safeList(response, 'data', []);
1569
+ for (let i = 0; i < balances.length; i++) {
1570
+ const entry = balances[i];
1571
+ const free = this.safeDict(entry, 'available', {});
1572
+ const used = this.safeDict(entry, 'frozen', {});
1573
+ const loan = this.safeDict(entry, 'repaid', {});
1574
+ const interest = this.safeDict(entry, 'interest', {});
1575
+ const baseAccount = this.account();
1576
+ const baseCurrencyId = this.safeString(entry, 'base_ccy');
1577
+ const baseCurrencyCode = this.safeCurrencyCode(baseCurrencyId);
1578
+ baseAccount['free'] = this.safeString(free, 'base_ccy');
1579
+ baseAccount['used'] = this.safeString(used, 'base_ccy');
1580
+ const baseDebt = this.safeString(loan, 'base_ccy');
1581
+ const baseInterest = this.safeString(interest, 'base_ccy');
1582
+ baseAccount['debt'] = Precise.stringAdd(baseDebt, baseInterest);
1583
+ result[baseCurrencyCode] = baseAccount;
1584
+ }
1615
1585
  return this.safeBalance(result);
1616
1586
  }
1617
1587
  async fetchSpotBalance(params = {}) {
1618
1588
  await this.loadMarkets();
1619
- const response = await this.v1PrivateGetBalanceInfo(params);
1589
+ const response = await this.v2PrivateGetAssetsSpotBalance(params);
1620
1590
  //
1621
1591
  // {
1622
- // "code": 0,
1623
- // "data": {
1624
- // "BCH": { # BCH account
1625
- // "available": "13.60109", # Available BCH
1626
- // "frozen": "0.00000" # Frozen BCH
1627
- // },
1628
- // "BTC": { # BTC account
1629
- // "available": "32590.16", # Available BTC
1630
- // "frozen": "7000.00" # Frozen BTC
1631
- // },
1632
- // "ETH": { # ETH account
1633
- // "available": "5.06000", # Available ETH
1634
- // "frozen": "0.00000" # Frozen ETH
1635
- // }
1636
- // },
1637
- // "message": "Ok"
1592
+ // "code": 0,
1593
+ // "data": [
1594
+ // {
1595
+ // "available": "0.00000046",
1596
+ // "ccy": "USDT",
1597
+ // "frozen": "0"
1598
+ // }
1599
+ // ],
1600
+ // "message": "OK"
1638
1601
  // }
1639
1602
  //
1640
1603
  const result = { 'info': response };
1641
- const balances = this.safeValue(response, 'data', {});
1642
- const currencyIds = Object.keys(balances);
1643
- for (let i = 0; i < currencyIds.length; i++) {
1644
- const currencyId = currencyIds[i];
1604
+ const balances = this.safeList(response, 'data', []);
1605
+ for (let i = 0; i < balances.length; i++) {
1606
+ const entry = balances[i];
1607
+ const currencyId = this.safeString(entry, 'ccy');
1645
1608
  const code = this.safeCurrencyCode(currencyId);
1646
- const balance = this.safeValue(balances, currencyId, {});
1647
1609
  const account = this.account();
1648
- account['free'] = this.safeString(balance, 'available');
1649
- account['used'] = this.safeString(balance, 'frozen');
1610
+ account['free'] = this.safeString(entry, 'available');
1611
+ account['used'] = this.safeString(entry, 'frozen');
1650
1612
  result[code] = account;
1651
1613
  }
1652
1614
  return this.safeBalance(result);
1653
1615
  }
1654
1616
  async fetchSwapBalance(params = {}) {
1655
1617
  await this.loadMarkets();
1656
- const response = await this.v1PerpetualPrivateGetAssetQuery(params);
1618
+ const response = await this.v2PrivateGetAssetsFuturesBalance(params);
1657
1619
  //
1658
1620
  // {
1659
1621
  // "code": 0,
1660
- // "data": {
1661
- // "USDT": {
1662
- // "available": "37.24817690383456000000",
1663
- // "balance_total": "37.24817690383456000000",
1664
- // "frozen": "0.00000000000000000000",
1665
- // "margin": "0.00000000000000000000",
1666
- // "profit_unreal": "0.00000000000000000000",
1667
- // "transfer": "37.24817690383456000000"
1622
+ // "data": [
1623
+ // {
1624
+ // "available": "0.00000046",
1625
+ // "ccy": "USDT",
1626
+ // "frozen": "0",
1627
+ // "margin": "0",
1628
+ // "transferrable": "0.00000046",
1629
+ // "unrealized_pnl": "0"
1668
1630
  // }
1669
- // },
1631
+ // ],
1670
1632
  // "message": "OK"
1671
1633
  // }
1672
1634
  //
1673
1635
  const result = { 'info': response };
1674
- const balances = this.safeValue(response, 'data', {});
1675
- const currencyIds = Object.keys(balances);
1676
- for (let i = 0; i < currencyIds.length; i++) {
1677
- const currencyId = currencyIds[i];
1636
+ const balances = this.safeList(response, 'data', []);
1637
+ for (let i = 0; i < balances.length; i++) {
1638
+ const entry = balances[i];
1639
+ const currencyId = this.safeString(entry, 'ccy');
1678
1640
  const code = this.safeCurrencyCode(currencyId);
1679
- const balance = this.safeValue(balances, currencyId, {});
1680
1641
  const account = this.account();
1681
- account['free'] = this.safeString(balance, 'available');
1682
- account['used'] = this.safeString(balance, 'frozen');
1683
- account['total'] = this.safeString(balance, 'balance_total');
1642
+ account['free'] = this.safeString(entry, 'available');
1643
+ account['used'] = this.safeString(entry, 'frozen');
1684
1644
  result[code] = account;
1685
1645
  }
1686
1646
  return this.safeBalance(result);
1687
1647
  }
1688
1648
  async fetchFinancialBalance(params = {}) {
1689
1649
  await this.loadMarkets();
1690
- const response = await this.v1PrivateGetAccountInvestmentBalance(params);
1650
+ const response = await this.v2PrivateGetAssetsFinancialBalance(params);
1691
1651
  //
1692
1652
  // {
1693
- // "code": 0,
1694
- // "data": [
1695
- // {
1696
- // "asset": "CET",
1697
- // "available": "0",
1698
- // "frozen": "0",
1699
- // "lock": "0",
1700
- // },
1701
- // {
1702
- // "asset": "USDT",
1703
- // "available": "999900",
1704
- // "frozen": "0",
1705
- // "lock": "0"
1706
- // }
1707
- // ],
1708
- // "message": "Success"
1709
- // }
1653
+ // "code": 0,
1654
+ // "data": [
1655
+ // {
1656
+ // "available": "0.00000046",
1657
+ // "ccy": "USDT",
1658
+ // "frozen": "0"
1659
+ // }
1660
+ // ],
1661
+ // "message": "OK"
1662
+ // }
1710
1663
  //
1711
1664
  const result = { 'info': response };
1712
- const balances = this.safeValue(response, 'data', {});
1665
+ const balances = this.safeList(response, 'data', []);
1713
1666
  for (let i = 0; i < balances.length; i++) {
1714
- const balance = balances[i];
1715
- const currencyId = this.safeString(balance, 'asset');
1667
+ const entry = balances[i];
1668
+ const currencyId = this.safeString(entry, 'ccy');
1716
1669
  const code = this.safeCurrencyCode(currencyId);
1717
1670
  const account = this.account();
1718
- account['free'] = this.safeString(balance, 'available');
1719
- const frozen = this.safeString(balance, 'frozen');
1720
- const locked = this.safeString(balance, 'lock');
1721
- account['used'] = Precise.stringAdd(frozen, locked);
1671
+ account['free'] = this.safeString(entry, 'available');
1672
+ account['used'] = this.safeString(entry, 'frozen');
1722
1673
  result[code] = account;
1723
1674
  }
1724
1675
  return this.safeBalance(result);
@@ -1728,10 +1679,10 @@ export default class coinex extends Exchange {
1728
1679
  * @method
1729
1680
  * @name coinex#fetchBalance
1730
1681
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
1731
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account001_account_info // spot
1732
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account004_investment_balance // financial
1733
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account006_margin_account // margin
1734
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http016_asset_query // swap
1682
+ * @see https://docs.coinex.com/api/v2/assets/balance/http/get-spot-balance // spot
1683
+ * @see https://docs.coinex.com/api/v2/assets/balance/http/get-futures-balance // swap
1684
+ * @see https://docs.coinex.com/api/v2/assets/balance/http/get-marigin-balance // margin
1685
+ * @see https://docs.coinex.com/api/v2/assets/balance/http/get-financial-balance // financial
1735
1686
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1736
1687
  * @param {string} [params.type] 'margin', 'swap', 'financial', or 'spot'
1737
1688
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
@@ -3766,7 +3717,7 @@ export default class coinex extends Exchange {
3766
3717
  // "side": 2,
3767
3718
  // "stop_loss_price": "0.00000000000000000000",
3768
3719
  // "stop_loss_type": 0,
3769
- // "sys": 0,
3720
+ // "sy s": 0,
3770
3721
  // "take_profit_price": "0.00000000000000000000",
3771
3722
  // "take_profit_type": 0,
3772
3723
  // "taker_fee": "0.00000000000000000000",
@@ -3848,7 +3799,7 @@ export default class coinex extends Exchange {
3848
3799
  // "side": 2,
3849
3800
  // "stop_loss_price": "0.00000000000000000000",
3850
3801
  // "stop_loss_type": 0,
3851
- // "sys": 0,
3802
+ // "s ys": 0,
3852
3803
  // "take_profit_price": "0.00000000000000000000",
3853
3804
  // "take_profit_type": 0,
3854
3805
  // "taker_fee": "0.00000000000000000000",
@@ -3865,6 +3816,8 @@ export default class coinex extends Exchange {
3865
3816
  return this.parsePosition(data[0], market);
3866
3817
  }
3867
3818
  parsePosition(position, market = undefined) {
3819
+ //
3820
+ // fetchPosition
3868
3821
  //
3869
3822
  // {
3870
3823
  // "adl_sort": 3396,
@@ -3908,7 +3861,7 @@ export default class coinex extends Exchange {
3908
3861
  // "side": 2,
3909
3862
  // "stop_loss_price": "0.00000000000000000000",
3910
3863
  // "stop_loss_type": 0,
3911
- // "sys": 0,
3864
+ // "s ys": 0,
3912
3865
  // "take_profit_price": "0.00000000000000000000",
3913
3866
  // "take_profit_type": 0,
3914
3867
  // "taker_fee": "0.00000000000000000000",
@@ -3918,6 +3871,40 @@ export default class coinex extends Exchange {
3918
3871
  // "user_id": 3620173
3919
3872
  // }
3920
3873
  //
3874
+ //
3875
+ // fetchPositionHistory
3876
+ //
3877
+ // {
3878
+ // amount_max: '10',
3879
+ // amount_max_margin: '2.03466666666666666666',
3880
+ // bkr_price: '0',
3881
+ // create_time: '1711150526.2581',
3882
+ // deal_all: '12.591',
3883
+ // deal_asset_fee: '0',
3884
+ // fee_asset: '',
3885
+ // finish_type: '5',
3886
+ // first_price: '0.6104',
3887
+ // latest_price: '0.6487',
3888
+ // leverage: '3',
3889
+ // liq_amount: '0',
3890
+ // liq_price: '0',
3891
+ // liq_profit: '0',
3892
+ // mainten_margin: '0.01',
3893
+ // market: 'XRPUSDT',
3894
+ // market_type: '1',
3895
+ // open_price: '0.6104',
3896
+ // open_val_max: '6.104',
3897
+ // position_id: '297371462',
3898
+ // profit_real: '0.35702107169',
3899
+ // settle_price: '0.6104',
3900
+ // settle_val: '0',
3901
+ // side: '2',
3902
+ // s ys: "0",
3903
+ // type: '2',
3904
+ // update_time: '1711391446.133233',
3905
+ // user_id: '3685860'
3906
+ // }
3907
+ //
3921
3908
  const marketId = this.safeString(position, 'market');
3922
3909
  market = this.safeMarket(marketId, market, undefined, 'swap');
3923
3910
  const symbol = market['symbol'];
@@ -3933,7 +3920,7 @@ export default class coinex extends Exchange {
3933
3920
  const timestamp = this.safeTimestamp(position, 'update_time');
3934
3921
  const maintenanceMargin = this.safeString(position, 'mainten_margin_amount');
3935
3922
  const maintenanceMarginPercentage = this.safeString(position, 'mainten_margin');
3936
- const collateral = this.safeString(position, 'margin_amount');
3923
+ const collateral = this.safeString2(position, 'margin_amount', 'amount_max_margin');
3937
3924
  const leverage = this.safeString(position, 'leverage');
3938
3925
  const notional = this.safeString(position, 'open_val');
3939
3926
  const initialMargin = Precise.stringDiv(notional, leverage);
@@ -4163,7 +4150,7 @@ export default class coinex extends Exchange {
4163
4150
  // "side": 2,
4164
4151
  // "stop_loss_price": "0.00000000000000000000",
4165
4152
  // "stop_loss_type": 0,
4166
- // "sys": 0,
4153
+ // "s ys": 0,
4167
4154
  // "take_profit_price": "0.00000000000000000000",
4168
4155
  // "take_profit_type": 0,
4169
4156
  // "taker_fee": "0.00000000000000000000",
@@ -4228,7 +4215,7 @@ export default class coinex extends Exchange {
4228
4215
  // "side": 2,
4229
4216
  // "stop_loss_price": "0.00000000000000000000",
4230
4217
  // "stop_loss_type": 0,
4231
- // "sys": 0,
4218
+ // "sy s": 0,
4232
4219
  // "take_profit_price": "0.00000000000000000000",
4233
4220
  // "take_profit_type": 0,
4234
4221
  // "taker_fee": "0.00000000000000000000",
@@ -5611,6 +5598,80 @@ export default class coinex extends Exchange {
5611
5598
  'shortLeverage': leverageValue,
5612
5599
  };
5613
5600
  }
5601
+ async fetchPositionHistory(symbol, since = undefined, limit = undefined, params = {}) {
5602
+ /**
5603
+ * @method
5604
+ * @name coinex#fetchPositionHistory
5605
+ * @description fetches historical positions
5606
+ * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033-0_finished_position
5607
+ * @param {string} symbol unified contract symbol
5608
+ * @param {int} [since] not used by coinex fetchPositionHistory
5609
+ * @param {int} [limit] the maximum amount of records to fetch, default=1000
5610
+ * @param {object} params extra parameters specific to the exchange api endpoint
5611
+ *
5612
+ * EXCHANGE SPECIFIC PARAMETERS
5613
+ * @param {int} [params.side] 0: all 1: sell, 2: buy
5614
+ * @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
5615
+ */
5616
+ await this.loadMarkets();
5617
+ const market = this.market(symbol);
5618
+ if (limit === undefined) {
5619
+ limit = 1000;
5620
+ }
5621
+ const request = {
5622
+ 'market': market['id'],
5623
+ 'side': 0,
5624
+ 'limit': limit,
5625
+ };
5626
+ const response = await this.v1PerpetualPrivateGetPositionFinished(this.extend(request, params));
5627
+ //
5628
+ // {
5629
+ // code: '0',
5630
+ // data: {
5631
+ // limit: '1000',
5632
+ // offset: '0',
5633
+ // records: [
5634
+ // {
5635
+ // amount_max: '10',
5636
+ // amount_max_margin: '2.03466666666666666666',
5637
+ // bkr_price: '0',
5638
+ // create_time: '1711150526.2581',
5639
+ // deal_all: '12.591',
5640
+ // deal_asset_fee: '0',
5641
+ // fee_asset: '',
5642
+ // finish_type: '5',
5643
+ // first_price: '0.6104',
5644
+ // latest_price: '0.6487',
5645
+ // leverage: '3',
5646
+ // liq_amount: '0',
5647
+ // liq_price: '0',
5648
+ // liq_profit: '0',
5649
+ // mainten_margin: '0.01',
5650
+ // market: 'XRPUSDT',
5651
+ // market_type: '1',
5652
+ // open_price: '0.6104',
5653
+ // open_val_max: '6.104',
5654
+ // position_id: '297371462',
5655
+ // profit_real: '0.35702107169',
5656
+ // settle_price: '0.6104',
5657
+ // settle_val: '0',
5658
+ // side: '2',
5659
+ // sy s: '0',
5660
+ // type: '2',
5661
+ // update_time: '1711391446.133233',
5662
+ // user_id: '3685860'
5663
+ // },
5664
+ // ...
5665
+ // ]
5666
+ // },
5667
+ // message: 'OK'
5668
+ // }
5669
+ //
5670
+ const data = this.safeDict(response, 'data');
5671
+ const records = this.safeList(data, 'records');
5672
+ const positions = this.parsePositions(records);
5673
+ return this.filterBySymbolSinceLimit(positions, symbol, since, limit);
5674
+ }
5614
5675
  handleMarginModeAndParams(methodName, params = {}, defaultValue = undefined) {
5615
5676
  /**
5616
5677
  * @ignore
@@ -5717,7 +5778,11 @@ export default class coinex extends Exchange {
5717
5778
  this.checkRequiredCredentials();
5718
5779
  query = this.keysort(query);
5719
5780
  const urlencoded = this.rawencode(query);
5720
- const preparedString = method + '/' + version + '/' + path + '?' + urlencoded + nonce + this.secret;
5781
+ let preparedString = method + '/' + version + '/' + path;
5782
+ if (urlencoded) {
5783
+ preparedString += '?' + urlencoded;
5784
+ }
5785
+ preparedString += nonce + this.secret;
5721
5786
  const signature = this.hash(this.encode(preparedString), sha256);
5722
5787
  headers = {
5723
5788
  'X-COINEX-KEY': this.apiKey,
@@ -5725,7 +5790,9 @@ export default class coinex extends Exchange {
5725
5790
  'X-COINEX-TIMESTAMP': nonce,
5726
5791
  };
5727
5792
  if ((method === 'GET') || (method === 'DELETE') || (method === 'PUT')) {
5728
- url += '?' + urlencoded;
5793
+ if (urlencoded) {
5794
+ url += '?' + urlencoded;
5795
+ }
5729
5796
  }
5730
5797
  else {
5731
5798
  body = this.json(query);
@@ -63,7 +63,7 @@ export default class coinlist extends Exchange {
63
63
  };
64
64
  parseTransferStatus(status: any): string;
65
65
  fetchDepositsWithdrawals(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<Transaction[]>;
66
- withdraw(code: string, amount: number, address: any, tag?: any, params?: {}): Promise<Transaction>;
66
+ withdraw(code: string, amount: number, address: string, tag?: any, params?: {}): Promise<Transaction>;
67
67
  parseTransaction(transaction: any, currency?: Currency): Transaction;
68
68
  parseTransactionType(type: any): string;
69
69
  fetchLedger(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<any>;