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
@@ -57,8 +57,11 @@ class coinmate extends coinmate$1 {
57
57
  'fetchOrderBook': true,
58
58
  'fetchOrders': true,
59
59
  'fetchPosition': false,
60
+ 'fetchPositionHistory': false,
60
61
  'fetchPositionMode': false,
61
62
  'fetchPositions': false,
63
+ 'fetchPositionsForSymbol': false,
64
+ 'fetchPositionsHistory': false,
62
65
  'fetchPositionsRisk': false,
63
66
  'fetchPremiumIndexOHLCV': false,
64
67
  'fetchTicker': true,
@@ -65,8 +65,11 @@ class coinone extends coinone$1 {
65
65
  'fetchOrder': true,
66
66
  'fetchOrderBook': true,
67
67
  'fetchPosition': false,
68
+ 'fetchPositionHistory': false,
68
69
  'fetchPositionMode': false,
69
70
  'fetchPositions': false,
71
+ 'fetchPositionsForSymbol': false,
72
+ 'fetchPositionsHistory': false,
70
73
  'fetchPositionsRisk': false,
71
74
  'fetchPremiumIndexOHLCV': false,
72
75
  'fetchTicker': true,
@@ -89,7 +89,11 @@ class coinsph extends coinsph$1 {
89
89
  'fetchOrders': false,
90
90
  'fetchOrderTrades': true,
91
91
  'fetchPosition': false,
92
+ 'fetchPositionHistory': false,
93
+ 'fetchPositionMode': false,
92
94
  'fetchPositions': false,
95
+ 'fetchPositionsForSymbol': false,
96
+ 'fetchPositionsHistory': false,
93
97
  'fetchPositionsRisk': false,
94
98
  'fetchPremiumIndexOHLCV': false,
95
99
  'fetchStatus': true,
@@ -57,8 +57,11 @@ class coinspot extends coinspot$1 {
57
57
  'fetchOpenInterestHistory': false,
58
58
  'fetchOrderBook': true,
59
59
  'fetchPosition': false,
60
+ 'fetchPositionHistory': false,
60
61
  'fetchPositionMode': false,
61
62
  'fetchPositions': false,
63
+ 'fetchPositionsForSymbol': false,
64
+ 'fetchPositionsHistory': false,
62
65
  'fetchPositionsRisk': false,
63
66
  'fetchPremiumIndexOHLCV': false,
64
67
  'fetchTicker': true,
@@ -80,8 +80,10 @@ class cryptocom extends cryptocom$1 {
80
80
  'fetchOrderBook': true,
81
81
  'fetchOrders': true,
82
82
  'fetchPosition': true,
83
+ 'fetchPositionHistory': false,
83
84
  'fetchPositionMode': false,
84
85
  'fetchPositions': true,
86
+ 'fetchPositionsHistory': false,
85
87
  'fetchPremiumIndexOHLCV': false,
86
88
  'fetchSettlementHistory': true,
87
89
  'fetchStatus': false,
@@ -62,7 +62,12 @@ class exmo extends exmo$1 {
62
62
  'fetchOrderBook': true,
63
63
  'fetchOrderBooks': true,
64
64
  'fetchOrderTrades': true,
65
+ 'fetchPosition': false,
66
+ 'fetchPositionHistory': false,
65
67
  'fetchPositionMode': false,
68
+ 'fetchPositions': false,
69
+ 'fetchPositionsHistory': false,
70
+ 'fetchPositionsRisk': false,
66
71
  'fetchPremiumIndexOHLCV': false,
67
72
  'fetchTicker': true,
68
73
  'fetchTickers': true,
@@ -138,8 +138,10 @@ class gate extends gate$1 {
138
138
  'fetchOrder': true,
139
139
  'fetchOrderBook': true,
140
140
  'fetchPosition': true,
141
+ 'fetchPositionHistory': 'emulated',
141
142
  'fetchPositionMode': false,
142
143
  'fetchPositions': true,
144
+ 'fetchPositionsHistory': true,
143
145
  'fetchPremiumIndexOHLCV': false,
144
146
  'fetchSettlementHistory': true,
145
147
  'fetchTicker': true,
@@ -654,7 +656,6 @@ class gate extends gate$1 {
654
656
  'option': 'options',
655
657
  'options': 'options',
656
658
  },
657
- 'defaultType': 'spot',
658
659
  'swap': {
659
660
  'fetchMarkets': {
660
661
  'settlementCurrencies': ['usdt', 'btc'],
@@ -5320,41 +5321,69 @@ class gate extends gate$1 {
5320
5321
  // "pending_orders": 0
5321
5322
  // }
5322
5323
  //
5324
+ // fetchPositionsHistory (swap and future)
5325
+ //
5326
+ // {
5327
+ // "contract": "SLERF_USDT", // Futures contract
5328
+ // "text": "web", // Text of close order
5329
+ // "long_price": "0.766306", // When 'side' is 'long,' it indicates the opening average price; when 'side' is 'short,' it indicates the closing average price.
5330
+ // "pnl": "-23.41702352", // PNL
5331
+ // "pnl_pnl": "-22.7187", // Position P/L
5332
+ // "pnl_fee": "-0.06527125", // Transaction Fees
5333
+ // "pnl_fund": "-0.63305227", // Funding Fees
5334
+ // "accum_size": "100",
5335
+ // "time": 1711279263, // Position close time
5336
+ // "short_price": "0.539119", // When 'side' is 'long,' it indicates the opening average price; when 'side' is 'short,' it indicates the closing average price
5337
+ // "side": "long", // Position side, long or short
5338
+ // "max_size": "100", // Max Trade Size
5339
+ // "first_open_time": 1711037985 // First Open Time
5340
+ // }
5341
+ //
5323
5342
  const contract = this.safeString(position, 'contract');
5324
5343
  market = this.safeMarket(contract, market, '_', 'contract');
5325
- const size = this.safeString(position, 'size');
5326
- let side = undefined;
5327
- if (Precise["default"].stringGt(size, '0')) {
5328
- side = 'long';
5329
- }
5330
- else if (Precise["default"].stringLt(size, '0')) {
5331
- side = 'short';
5344
+ const size = this.safeString2(position, 'size', 'accum_size');
5345
+ let side = this.safeString(position, 'side');
5346
+ if (side === undefined) {
5347
+ if (Precise["default"].stringGt(size, '0')) {
5348
+ side = 'long';
5349
+ }
5350
+ else if (Precise["default"].stringLt(size, '0')) {
5351
+ side = 'short';
5352
+ }
5332
5353
  }
5333
5354
  const maintenanceRate = this.safeString(position, 'maintenance_rate');
5334
5355
  const notional = this.safeString(position, 'value');
5335
5356
  const leverage = this.safeString(position, 'leverage');
5336
5357
  let marginMode = undefined;
5337
- if (leverage === '0') {
5338
- marginMode = 'cross';
5339
- }
5340
- else {
5341
- marginMode = 'isolated';
5358
+ if (leverage !== undefined) {
5359
+ if (leverage === '0') {
5360
+ marginMode = 'cross';
5361
+ }
5362
+ else {
5363
+ marginMode = 'isolated';
5364
+ }
5342
5365
  }
5343
- const unrealisedPnl = this.safeString(position, 'unrealised_pnl');
5344
5366
  // Initial Position Margin = ( Position Value / Leverage ) + Close Position Fee
5345
5367
  // *The default leverage under the full position is the highest leverage in the market.
5346
5368
  // *Trading fee is charged as Taker Fee Rate (0.075%).
5347
- const takerFee = '0.00075';
5348
- const feePaid = Precise["default"].stringMul(takerFee, notional);
5349
- const initialMarginString = Precise["default"].stringAdd(Precise["default"].stringDiv(notional, leverage), feePaid);
5350
- const timestamp = this.safeTimestamp(position, 'open_time');
5369
+ let feePaid = this.safeString(position, 'pnl_fee');
5370
+ let initialMarginString = undefined;
5371
+ if (feePaid === undefined) {
5372
+ const takerFee = '0.00075';
5373
+ feePaid = Precise["default"].stringMul(takerFee, notional);
5374
+ initialMarginString = Precise["default"].stringAdd(Precise["default"].stringDiv(notional, leverage), feePaid);
5375
+ }
5376
+ let timestamp = this.safeTimestamp2(position, 'open_time', 'first_open_time');
5377
+ if (timestamp === 0) {
5378
+ timestamp = undefined;
5379
+ }
5351
5380
  return this.safePosition({
5352
5381
  'info': position,
5353
5382
  'id': undefined,
5354
5383
  'symbol': this.safeString(market, 'symbol'),
5355
5384
  'timestamp': timestamp,
5356
5385
  'datetime': this.iso8601(timestamp),
5357
- 'lastUpdateTimestamp': this.safeTimestamp(position, 'update_time'),
5386
+ 'lastUpdateTimestamp': this.safeTimestamp2(position, 'update_time', 'time'),
5358
5387
  'initialMargin': this.parseNumber(initialMarginString),
5359
5388
  'initialMarginPercentage': this.parseNumber(Precise["default"].stringDiv(initialMarginString, notional)),
5360
5389
  'maintenanceMargin': this.parseNumber(Precise["default"].stringMul(maintenanceRate, notional)),
@@ -5362,11 +5391,10 @@ class gate extends gate$1 {
5362
5391
  'entryPrice': this.safeNumber(position, 'entry_price'),
5363
5392
  'notional': this.parseNumber(notional),
5364
5393
  'leverage': this.safeNumber(position, 'leverage'),
5365
- 'unrealizedPnl': this.parseNumber(unrealisedPnl),
5366
- 'realizedPnl': this.safeNumber(position, 'realised_pnl'),
5394
+ 'unrealizedPnl': this.safeNumber(position, 'unrealised_pnl'),
5395
+ 'realizedPnl': this.safeNumber2(position, 'realised_pnl', 'pnl'),
5367
5396
  'contracts': this.parseNumber(Precise["default"].stringAbs(size)),
5368
5397
  'contractSize': this.safeNumber(market, 'contractSize'),
5369
- // 'realisedPnl': position['realised_pnl'],
5370
5398
  'marginRatio': undefined,
5371
5399
  'liquidationPrice': this.safeNumber(position, 'liq_price'),
5372
5400
  'markPrice': this.safeNumber(position, 'mark_price'),
@@ -7387,6 +7415,80 @@ class gate extends gate$1 {
7387
7415
  'quoteVolume': undefined,
7388
7416
  };
7389
7417
  }
7418
+ async fetchPositionsHistory(symbols = undefined, since = undefined, limit = undefined, params = {}) {
7419
+ /**
7420
+ * @method
7421
+ * @name gate#fetchPositionsHistory
7422
+ * @description fetches historical positions
7423
+ * @see https://www.gate.io/docs/developers/apiv4/#list-position-close-history
7424
+ * @see https://www.gate.io/docs/developers/apiv4/#list-position-close-history-2
7425
+ * @param {string[]} symbols unified conract symbols, must all have the same settle currency and the same market type
7426
+ * @param {int} [since] the earliest time in ms to fetch positions for
7427
+ * @param {int} [limit] the maximum amount of records to fetch, default=1000
7428
+ * @param {object} params extra parameters specific to the exchange api endpoint
7429
+ * @param {int} [params.until] the latest time in ms to fetch positions for
7430
+ *
7431
+ * EXCHANGE SPECIFIC PARAMETERS
7432
+ * @param {int} offset list offset, starting from 0
7433
+ * @param {string} side long or short
7434
+ * @param {string} pnl query profit or loss
7435
+ * @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
7436
+ */
7437
+ await this.loadMarkets();
7438
+ let market = undefined;
7439
+ if (symbols !== undefined) {
7440
+ const symbolsLength = symbols.length;
7441
+ if (symbolsLength === 1) {
7442
+ market = this.market(symbols[0]);
7443
+ }
7444
+ }
7445
+ let marketType = undefined;
7446
+ [marketType, params] = this.handleMarketTypeAndParams('fetchPositionsHistory', market, params, 'swap');
7447
+ const until = this.safeInteger(params, 'until');
7448
+ params = this.omit(params, 'until');
7449
+ let request = {};
7450
+ [request, params] = this.prepareRequest(market, marketType, params);
7451
+ if (limit !== undefined) {
7452
+ request['limit'] = limit;
7453
+ }
7454
+ if (since !== undefined) {
7455
+ request['from'] = this.parseToInt(since / 1000);
7456
+ }
7457
+ if (until !== undefined) {
7458
+ request['to'] = this.parseToInt(until / 1000);
7459
+ }
7460
+ let response = undefined;
7461
+ if (marketType === 'swap') {
7462
+ response = await this.privateFuturesGetSettlePositionClose(this.extend(request, params));
7463
+ }
7464
+ else if (marketType === 'future') {
7465
+ response = await this.privateDeliveryGetSettlePositionClose(this.extend(request, params));
7466
+ }
7467
+ else {
7468
+ throw new errors.NotSupported(this.id + ' fetchPositionsHistory() does not support markets of type ' + marketType);
7469
+ }
7470
+ //
7471
+ // [
7472
+ // {
7473
+ // "contract": "SLERF_USDT",
7474
+ // "text": "web",
7475
+ // "long_price": "0.766306",
7476
+ // "pnl": "-23.41702352",
7477
+ // "pnl_pnl": "-22.7187",
7478
+ // "pnl_fee": "-0.06527125",
7479
+ // "pnl_fund": "-0.63305227",
7480
+ // "accum_size": "100",
7481
+ // "time": 1711279263,
7482
+ // "short_price": "0.539119",
7483
+ // "side": "long",
7484
+ // "max_size": "100",
7485
+ // "first_open_time": 1711037985
7486
+ // },
7487
+ // ...
7488
+ // ]
7489
+ //
7490
+ return this.parsePositions(response, symbols, params);
7491
+ }
7390
7492
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
7391
7493
  if (response === undefined) {
7392
7494
  return undefined;
@@ -3241,8 +3241,9 @@ class hitbtc extends hitbtc$1 {
3241
3241
  throw new errors.ArgumentsRequired(this.id + ' modifyMarginHelper() requires a leverage parameter for swap markets');
3242
3242
  }
3243
3243
  }
3244
- if (amount !== 0) {
3245
- amount = this.amountToPrecision(symbol, amount);
3244
+ const stringAmount = this.numberToString(amount);
3245
+ if (stringAmount !== '0') {
3246
+ amount = this.amountToPrecision(symbol, stringAmount);
3246
3247
  }
3247
3248
  else {
3248
3249
  amount = '0';
@@ -3344,7 +3345,7 @@ class hitbtc extends hitbtc$1 {
3344
3345
  * @param {bool} [params.margin] true for reducing spot-margin
3345
3346
  * @returns {object} a [margin structure]{@link https://docs.ccxt.com/#/?id=reduce-margin-structure}
3346
3347
  */
3347
- if (amount !== 0) {
3348
+ if (this.numberToString(amount) !== '0') {
3348
3349
  throw new errors.BadRequest(this.id + ' reduceMargin() on hitbtc requires the amount to be 0 and that will remove the entire margin amount');
3349
3350
  }
3350
3351
  return await this.modifyMarginHelper(symbol, amount, 'reduce', params);
@@ -102,7 +102,9 @@ class htx extends htx$1 {
102
102
  'fetchOrders': true,
103
103
  'fetchOrderTrades': true,
104
104
  'fetchPosition': true,
105
+ 'fetchPositionHistory': 'emulated',
105
106
  'fetchPositions': true,
107
+ 'fetchPositionsHistory': false,
106
108
  'fetchPositionsRisk': false,
107
109
  'fetchPremiumIndexOHLCV': true,
108
110
  'fetchSettlementHistory': true,
@@ -77,8 +77,11 @@ class idex extends idex$1 {
77
77
  'fetchOrderBook': true,
78
78
  'fetchOrders': false,
79
79
  'fetchPosition': false,
80
+ 'fetchPositionHistory': false,
80
81
  'fetchPositionMode': false,
81
82
  'fetchPositions': false,
83
+ 'fetchPositionsForSymbol': false,
84
+ 'fetchPositionsHistory': false,
82
85
  'fetchPositionsRisk': false,
83
86
  'fetchPremiumIndexOHLCV': false,
84
87
  'fetchStatus': true,
@@ -62,8 +62,11 @@ class independentreserve extends independentreserve$1 {
62
62
  'fetchOrder': true,
63
63
  'fetchOrderBook': true,
64
64
  'fetchPosition': false,
65
+ 'fetchPositionHistory': false,
65
66
  'fetchPositionMode': false,
66
67
  'fetchPositions': false,
68
+ 'fetchPositionsForSymbol': false,
69
+ 'fetchPositionsHistory': false,
67
70
  'fetchPositionsRisk': false,
68
71
  'fetchPremiumIndexOHLCV': false,
69
72
  'fetchTicker': true,
@@ -69,8 +69,11 @@ class indodax extends indodax$1 {
69
69
  'fetchOrderBook': true,
70
70
  'fetchOrders': false,
71
71
  'fetchPosition': false,
72
+ 'fetchPositionHistory': false,
72
73
  'fetchPositionMode': false,
73
74
  'fetchPositions': false,
75
+ 'fetchPositionsForSymbol': false,
76
+ 'fetchPositionsHistory': false,
74
77
  'fetchPositionsRisk': false,
75
78
  'fetchPremiumIndexOHLCV': false,
76
79
  'fetchTicker': true,
@@ -88,7 +88,9 @@ class kucoin extends kucoin$1 {
88
88
  'fetchOrderBooks': false,
89
89
  'fetchOrdersByStatus': true,
90
90
  'fetchOrderTrades': true,
91
+ 'fetchPositionHistory': false,
91
92
  'fetchPositionMode': false,
93
+ 'fetchPositionsHistory': false,
92
94
  'fetchPremiumIndexOHLCV': false,
93
95
  'fetchStatus': true,
94
96
  'fetchTicker': true,
@@ -78,8 +78,10 @@ class kucoinfutures extends kucoinfutures$1 {
78
78
  'fetchOrder': true,
79
79
  'fetchOrderBook': true,
80
80
  'fetchPosition': true,
81
+ 'fetchPositionHistory': false,
81
82
  'fetchPositionMode': false,
82
83
  'fetchPositions': true,
84
+ 'fetchPositionsHistory': false,
83
85
  'fetchPremiumIndexOHLCV': false,
84
86
  'fetchStatus': true,
85
87
  'fetchTicker': true,
@@ -55,7 +55,13 @@ class latoken extends latoken$1 {
55
55
  'fetchOrder': true,
56
56
  'fetchOrderBook': true,
57
57
  'fetchOrders': true,
58
+ 'fetchPosition': false,
59
+ 'fetchPositionHistory': false,
58
60
  'fetchPositionMode': false,
61
+ 'fetchPositions': false,
62
+ 'fetchPositionsForSymbol': false,
63
+ 'fetchPositionsHistory': false,
64
+ 'fetchPositionsRisk': false,
59
65
  'fetchTicker': true,
60
66
  'fetchTickers': true,
61
67
  'fetchTime': true,
@@ -61,8 +61,11 @@ class luno extends luno$1 {
61
61
  'fetchOrderBook': true,
62
62
  'fetchOrders': true,
63
63
  'fetchPosition': false,
64
+ 'fetchPositionHistory': false,
64
65
  'fetchPositionMode': false,
65
66
  'fetchPositions': false,
67
+ 'fetchPositionsForSymbol': false,
68
+ 'fetchPositionsHistory': false,
66
69
  'fetchPositionsRisk': false,
67
70
  'fetchPremiumIndexOHLCV': false,
68
71
  'fetchTicker': true,
@@ -63,8 +63,13 @@ class lykke extends lykke$1 {
63
63
  'fetchOrderBook': true,
64
64
  'fetchOrders': false,
65
65
  'fetchOrderTrades': false,
66
+ 'fetchPosition': false,
67
+ 'fetchPositionHistory': false,
66
68
  'fetchPositionMode': false,
67
69
  'fetchPositions': false,
70
+ 'fetchPositionsForSymbol': false,
71
+ 'fetchPositionsHistory': false,
72
+ 'fetchPositionsRisk': false,
68
73
  'fetchPremiumIndexOHLCV': false,
69
74
  'fetchTicker': true,
70
75
  'fetchTickers': true,
@@ -63,8 +63,11 @@ class mercado extends mercado$1 {
63
63
  'fetchOrderBook': true,
64
64
  'fetchOrders': true,
65
65
  'fetchPosition': false,
66
+ 'fetchPositionHistory': false,
66
67
  'fetchPositionMode': false,
67
68
  'fetchPositions': false,
69
+ 'fetchPositionsForSymbol': false,
70
+ 'fetchPositionsHistory': false,
68
71
  'fetchPositionsRisk': false,
69
72
  'fetchPremiumIndexOHLCV': false,
70
73
  'fetchTicker': true,
@@ -90,8 +90,10 @@ class mexc extends mexc$1 {
90
90
  'fetchOrders': true,
91
91
  'fetchOrderTrades': true,
92
92
  'fetchPosition': true,
93
+ 'fetchPositionHistory': 'emulated',
93
94
  'fetchPositionMode': true,
94
95
  'fetchPositions': true,
96
+ 'fetchPositionsHistory': true,
95
97
  'fetchPositionsRisk': undefined,
96
98
  'fetchPremiumIndexOHLCV': false,
97
99
  'fetchStatus': true,
@@ -4863,6 +4865,8 @@ class mexc extends mexc$1 {
4863
4865
  return this.parsePositions(data, symbols);
4864
4866
  }
4865
4867
  parsePosition(position, market = undefined) {
4868
+ //
4869
+ // fetchPositions
4866
4870
  //
4867
4871
  // {
4868
4872
  // "positionId": 1394650,
@@ -4887,6 +4891,40 @@ class mexc extends mexc$1 {
4887
4891
  // "autoAddIm": false
4888
4892
  // }
4889
4893
  //
4894
+ // fetchPositionsHistory
4895
+ //
4896
+ // {
4897
+ // positionId: '390281084',
4898
+ // symbol: 'RVN_USDT',
4899
+ // positionType: '1',
4900
+ // openType: '2',
4901
+ // state: '3',
4902
+ // holdVol: '0',
4903
+ // frozenVol: '0',
4904
+ // closeVol: '1141',
4905
+ // holdAvgPrice: '0.03491',
4906
+ // holdAvgPriceFullyScale: '0.03491',
4907
+ // openAvgPrice: '0.03491',
4908
+ // openAvgPriceFullyScale: '0.03491',
4909
+ // closeAvgPrice: '0.03494',
4910
+ // liquidatePrice: '0.03433',
4911
+ // oim: '0',
4912
+ // im: '0',
4913
+ // holdFee: '0',
4914
+ // realised: '0.1829',
4915
+ // leverage: '50',
4916
+ // createTime: '1711512408000',
4917
+ // updateTime: '1711512553000',
4918
+ // autoAddIm: false,
4919
+ // version: '4',
4920
+ // profitRatio: '0.0227',
4921
+ // newOpenAvgPrice: '0.03491',
4922
+ // newCloseAvgPrice: '0.03494',
4923
+ // closeProfitLoss: '0.3423',
4924
+ // fee: '0.1593977',
4925
+ // positionShowStatus: 'CLOSED'
4926
+ // }
4927
+ //
4890
4928
  market = this.safeMarket(this.safeString(position, 'symbol'), market);
4891
4929
  const symbol = market['symbol'];
4892
4930
  const contracts = this.safeString(position, 'holdVol');
@@ -5524,6 +5562,79 @@ class mexc extends mexc$1 {
5524
5562
  }
5525
5563
  return [marginMode, params];
5526
5564
  }
5565
+ async fetchPositionsHistory(symbols = undefined, since = undefined, limit = undefined, params = {}) {
5566
+ /**
5567
+ * @method
5568
+ * @name mexc#fetchPositionsHistory
5569
+ * @description fetches historical positions
5570
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-user-s-history-position-information
5571
+ * @param {string[]} [symbols] unified contract symbols
5572
+ * @param {int} [since] not used by mexc fetchPositionsHistory
5573
+ * @param {int} [limit] the maximum amount of candles to fetch, default=1000
5574
+ * @param {object} params extra parameters specific to the exchange api endpoint
5575
+ *
5576
+ * EXCHANGE SPECIFIC PARAMETERS
5577
+ * @param {int} type position type,1: long, 2: short
5578
+ * @param {int} page_num current page number, default is 1
5579
+ * @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
5580
+ */
5581
+ await this.loadMarkets();
5582
+ const request = {};
5583
+ if (symbols !== undefined) {
5584
+ const symbolsLength = symbols.length;
5585
+ if (symbolsLength === 1) {
5586
+ const market = this.market(symbols[0]);
5587
+ request['symbol'] = market['id'];
5588
+ }
5589
+ }
5590
+ if (limit !== undefined) {
5591
+ request['page_size'] = limit;
5592
+ }
5593
+ const response = await this.contractPrivateGetPositionListHistoryPositions(this.extend(request, params));
5594
+ //
5595
+ // {
5596
+ // success: true,
5597
+ // code: '0',
5598
+ // data: [
5599
+ // {
5600
+ // positionId: '390281084',
5601
+ // symbol: 'RVN_USDT',
5602
+ // positionType: '1',
5603
+ // openType: '2',
5604
+ // state: '3',
5605
+ // holdVol: '0',
5606
+ // frozenVol: '0',
5607
+ // closeVol: '1141',
5608
+ // holdAvgPrice: '0.03491',
5609
+ // holdAvgPriceFullyScale: '0.03491',
5610
+ // openAvgPrice: '0.03491',
5611
+ // openAvgPriceFullyScale: '0.03491',
5612
+ // closeAvgPrice: '0.03494',
5613
+ // liquidatePrice: '0.03433',
5614
+ // oim: '0',
5615
+ // im: '0',
5616
+ // holdFee: '0',
5617
+ // realised: '0.1829',
5618
+ // leverage: '50',
5619
+ // createTime: '1711512408000',
5620
+ // updateTime: '1711512553000',
5621
+ // autoAddIm: false,
5622
+ // version: '4',
5623
+ // profitRatio: '0.0227',
5624
+ // newOpenAvgPrice: '0.03491',
5625
+ // newCloseAvgPrice: '0.03494',
5626
+ // closeProfitLoss: '0.3423',
5627
+ // fee: '0.1593977',
5628
+ // positionShowStatus: 'CLOSED'
5629
+ // },
5630
+ // ...
5631
+ // ]
5632
+ // }
5633
+ //
5634
+ const data = this.safeList(response, 'data');
5635
+ const positions = this.parsePositions(data, symbols, params);
5636
+ return this.filterBySinceLimit(positions, since, limit);
5637
+ }
5527
5638
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
5528
5639
  const section = this.safeString(api, 0);
5529
5640
  const access = this.safeString(api, 1);
@@ -70,7 +70,11 @@ class ndax extends ndax$1 {
70
70
  'fetchOrders': true,
71
71
  'fetchOrderTrades': true,
72
72
  'fetchPosition': false,
73
+ 'fetchPositionHistory': false,
74
+ 'fetchPositionMode': false,
73
75
  'fetchPositions': false,
76
+ 'fetchPositionsForSymbol': false,
77
+ 'fetchPositionsHistory': false,
74
78
  'fetchPositionsRisk': false,
75
79
  'fetchPremiumIndexOHLCV': false,
76
80
  'fetchTicker': true,
@@ -75,7 +75,11 @@ class novadax extends novadax$1 {
75
75
  'fetchOrders': true,
76
76
  'fetchOrderTrades': true,
77
77
  'fetchPosition': false,
78
+ 'fetchPositionHistory': false,
79
+ 'fetchPositionMode': false,
78
80
  'fetchPositions': false,
81
+ 'fetchPositionsForSymbol': false,
82
+ 'fetchPositionsHistory': false,
79
83
  'fetchPositionsRisk': false,
80
84
  'fetchPremiumIndexOHLCV': false,
81
85
  'fetchTicker': true,