ccxt 4.3.18 → 4.3.20

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 (173) hide show
  1. package/README.md +7 -5
  2. package/dist/cjs/ccxt.js +6 -1
  3. package/dist/cjs/src/abstract/woofipro.js +9 -0
  4. package/dist/cjs/src/ascendex.js +3 -4
  5. package/dist/cjs/src/base/Exchange.js +45 -2
  6. package/dist/cjs/src/base/functions/crypto.js +10 -3
  7. package/dist/cjs/src/base/functions/encode.js +6 -3
  8. package/dist/cjs/src/base/functions/number.js +8 -5
  9. package/dist/cjs/src/base/functions/rsa.js +5 -5
  10. package/dist/cjs/src/bigone.js +1 -1
  11. package/dist/cjs/src/bitfinex.js +25 -1
  12. package/dist/cjs/src/bitfinex2.js +59 -51
  13. package/dist/cjs/src/bitget.js +4 -5
  14. package/dist/cjs/src/bitmart.js +3 -3
  15. package/dist/cjs/src/bitstamp.js +1 -3
  16. package/dist/cjs/src/bybit.js +39 -9
  17. package/dist/cjs/src/coinex.js +360 -560
  18. package/dist/cjs/src/coinlist.js +1 -2
  19. package/dist/cjs/src/deribit.js +1 -1
  20. package/dist/cjs/src/hollaex.js +3 -3
  21. package/dist/cjs/src/indodax.js +1 -1
  22. package/dist/cjs/src/latoken.js +1 -1
  23. package/dist/cjs/src/mexc.js +1 -1
  24. package/dist/cjs/src/novadax.js +0 -1
  25. package/dist/cjs/src/okx.js +17 -0
  26. package/dist/cjs/src/phemex.js +17 -6
  27. package/dist/cjs/src/poloniex.js +1 -2
  28. package/dist/cjs/src/pro/bitget.js +136 -192
  29. package/dist/cjs/src/pro/coinbaseinternational.js +9 -1
  30. package/dist/cjs/src/pro/htx.js +12 -7
  31. package/dist/cjs/src/pro/okx.js +85 -0
  32. package/dist/cjs/src/pro/woofipro.js +1263 -0
  33. package/dist/cjs/src/wavesexchange.js +2 -2
  34. package/dist/cjs/src/woo.js +17 -3
  35. package/dist/cjs/src/woofipro.js +2698 -0
  36. package/js/ccxt.d.ts +8 -2
  37. package/js/ccxt.js +6 -2
  38. package/js/src/abstract/bitget.d.ts +3 -0
  39. package/js/src/abstract/bybit.d.ts +1 -0
  40. package/js/src/abstract/okx.d.ts +1 -0
  41. package/js/src/abstract/woofipro.d.ts +122 -0
  42. package/js/src/abstract/woofipro.js +11 -0
  43. package/js/src/ace.d.ts +2 -2
  44. package/js/src/ascendex.d.ts +5 -15
  45. package/js/src/ascendex.js +3 -4
  46. package/js/src/base/Exchange.d.ts +26 -17
  47. package/js/src/base/Exchange.js +45 -2
  48. package/js/src/base/functions/crypto.d.ts +1 -1
  49. package/js/src/base/functions/crypto.js +10 -3
  50. package/js/src/base/functions/encode.d.ts +1 -1
  51. package/js/src/base/functions/encode.js +6 -3
  52. package/js/src/base/functions/number.d.ts +1 -1
  53. package/js/src/base/functions/number.js +8 -5
  54. package/js/src/base/functions/rsa.js +6 -6
  55. package/js/src/base/types.d.ts +4 -0
  56. package/js/src/bigone.d.ts +4 -14
  57. package/js/src/bigone.js +1 -1
  58. package/js/src/binance.d.ts +13 -71
  59. package/js/src/binancecoinm.d.ts +2 -22
  60. package/js/src/binanceusdm.d.ts +2 -22
  61. package/js/src/bingx.d.ts +4 -14
  62. package/js/src/bit2c.d.ts +2 -2
  63. package/js/src/bitbank.d.ts +2 -2
  64. package/js/src/bitbns.d.ts +2 -2
  65. package/js/src/bitfinex.d.ts +6 -16
  66. package/js/src/bitfinex.js +25 -1
  67. package/js/src/bitfinex2.d.ts +6 -16
  68. package/js/src/bitfinex2.js +59 -51
  69. package/js/src/bitflyer.d.ts +2 -2
  70. package/js/src/bitget.d.ts +7 -17
  71. package/js/src/bitget.js +4 -5
  72. package/js/src/bithumb.d.ts +3 -3
  73. package/js/src/bitmart.d.ts +5 -14
  74. package/js/src/bitmart.js +3 -3
  75. package/js/src/bitmex.d.ts +4 -4
  76. package/js/src/bitopro.d.ts +2 -2
  77. package/js/src/bitrue.d.ts +5 -5
  78. package/js/src/bitso.d.ts +2 -2
  79. package/js/src/bitstamp.d.ts +3 -3
  80. package/js/src/bitstamp.js +1 -3
  81. package/js/src/bitteam.d.ts +2 -2
  82. package/js/src/bitvavo.d.ts +5 -5
  83. package/js/src/bl3p.d.ts +2 -2
  84. package/js/src/blockchaincom.d.ts +2 -2
  85. package/js/src/blofin.d.ts +4 -14
  86. package/js/src/btcalpha.d.ts +2 -2
  87. package/js/src/btcbox.d.ts +2 -2
  88. package/js/src/btcmarkets.d.ts +2 -2
  89. package/js/src/btcturk.d.ts +2 -2
  90. package/js/src/bybit.d.ts +9 -56
  91. package/js/src/bybit.js +39 -9
  92. package/js/src/cex.d.ts +2 -2
  93. package/js/src/coinbase.d.ts +4 -4
  94. package/js/src/coinbasepro.d.ts +3 -3
  95. package/js/src/coincheck.d.ts +2 -2
  96. package/js/src/coinex.d.ts +7 -17
  97. package/js/src/coinex.js +360 -560
  98. package/js/src/coinlist.d.ts +5 -15
  99. package/js/src/coinlist.js +1 -2
  100. package/js/src/coinmate.d.ts +2 -2
  101. package/js/src/coinmetro.d.ts +3 -3
  102. package/js/src/coinone.d.ts +2 -2
  103. package/js/src/coinsph.d.ts +2 -2
  104. package/js/src/coinspot.d.ts +2 -2
  105. package/js/src/cryptocom.d.ts +2 -2
  106. package/js/src/currencycom.d.ts +3 -3
  107. package/js/src/delta.d.ts +5 -43
  108. package/js/src/deribit.d.ts +7 -55
  109. package/js/src/deribit.js +1 -1
  110. package/js/src/digifinex.d.ts +5 -15
  111. package/js/src/exmo.d.ts +2 -2
  112. package/js/src/gate.d.ts +6 -54
  113. package/js/src/gemini.d.ts +2 -2
  114. package/js/src/hitbtc.d.ts +4 -14
  115. package/js/src/hollaex.d.ts +3 -3
  116. package/js/src/hollaex.js +3 -3
  117. package/js/src/htx.d.ts +4 -14
  118. package/js/src/huobijp.d.ts +4 -4
  119. package/js/src/hyperliquid.d.ts +1 -1
  120. package/js/src/idex.d.ts +3 -3
  121. package/js/src/independentreserve.d.ts +2 -2
  122. package/js/src/indodax.d.ts +2 -2
  123. package/js/src/indodax.js +1 -1
  124. package/js/src/kraken.d.ts +4 -14
  125. package/js/src/krakenfutures.d.ts +4 -14
  126. package/js/src/kucoin.d.ts +5 -15
  127. package/js/src/kucoinfutures.d.ts +4 -14
  128. package/js/src/kuna.d.ts +2 -2
  129. package/js/src/latoken.d.ts +5 -15
  130. package/js/src/latoken.js +1 -1
  131. package/js/src/lbank.d.ts +2 -2
  132. package/js/src/luno.d.ts +2 -2
  133. package/js/src/lykke.d.ts +2 -2
  134. package/js/src/mercado.d.ts +2 -2
  135. package/js/src/mexc.d.ts +8 -28
  136. package/js/src/mexc.js +1 -1
  137. package/js/src/ndax.d.ts +2 -2
  138. package/js/src/novadax.d.ts +4 -15
  139. package/js/src/novadax.js +0 -1
  140. package/js/src/okcoin.d.ts +4 -14
  141. package/js/src/okx.d.ts +10 -68
  142. package/js/src/okx.js +17 -0
  143. package/js/src/onetrading.d.ts +2 -2
  144. package/js/src/paymium.d.ts +4 -14
  145. package/js/src/phemex.d.ts +5 -15
  146. package/js/src/phemex.js +17 -6
  147. package/js/src/poloniex.d.ts +3 -13
  148. package/js/src/poloniex.js +1 -2
  149. package/js/src/poloniexfutures.d.ts +2 -2
  150. package/js/src/pro/bitget.js +137 -193
  151. package/js/src/pro/coinbaseinternational.d.ts +3 -3
  152. package/js/src/pro/coinbaseinternational.js +9 -1
  153. package/js/src/pro/htx.js +12 -7
  154. package/js/src/pro/okx.d.ts +4 -1
  155. package/js/src/pro/okx.js +85 -0
  156. package/js/src/pro/woofipro.d.ts +47 -0
  157. package/js/src/pro/woofipro.js +1264 -0
  158. package/js/src/probit.d.ts +3 -3
  159. package/js/src/timex.d.ts +2 -2
  160. package/js/src/tokocrypto.d.ts +3 -3
  161. package/js/src/upbit.d.ts +2 -2
  162. package/js/src/wavesexchange.d.ts +3 -3
  163. package/js/src/wavesexchange.js +2 -2
  164. package/js/src/wazirx.d.ts +2 -2
  165. package/js/src/whitebit.d.ts +3 -13
  166. package/js/src/woo.d.ts +7 -17
  167. package/js/src/woo.js +17 -3
  168. package/js/src/woofipro.d.ts +131 -0
  169. package/js/src/woofipro.js +2699 -0
  170. package/js/src/yobit.d.ts +2 -2
  171. package/js/src/zaif.d.ts +2 -2
  172. package/js/src/zonda.d.ts +4 -14
  173. package/package.json +1 -1
@@ -1141,115 +1141,50 @@ class coinex extends coinex$1 {
1141
1141
  //
1142
1142
  // Spot and Margin fetchMyTrades (private)
1143
1143
  //
1144
- // {
1145
- // "id": 2611520950,
1146
- // "order_id": 63286573298,
1147
- // "account_id": 0,
1148
- // "create_time": 1638990636,
1149
- // "type": "sell",
1150
- // "role": "taker",
1151
- // "price": "192.29",
1152
- // "amount": "0.098",
1153
- // "fee": "0.03768884",
1154
- // "fee_asset": "USDT",
1155
- // "market": "AAVEUSDT",
1156
- // "deal_money": "18.84442"
1157
- // }
1144
+ // {
1145
+ // "amount": "0.00010087",
1146
+ // "created_at": 1714618087585,
1147
+ // "deal_id": 4161200602,
1148
+ // "margin_market": "",
1149
+ // "market": "BTCUSDT",
1150
+ // "order_id": 117654919342,
1151
+ // "price": "57464.04",
1152
+ // "side": "sell"
1153
+ // }
1158
1154
  //
1159
1155
  // Swap fetchMyTrades (private)
1160
1156
  //
1161
1157
  // {
1162
- // "amount": "0.0012",
1163
- // "deal_fee": "0.0237528",
1164
- // "deal_insurance": "0",
1165
- // "deal_margin": "15.8352",
1166
- // "deal_order_id": 17797031903,
1167
- // "deal_profit": "0",
1168
- // "deal_stock": "47.5056",
1169
- // "deal_type": 1,
1170
- // "deal_user_id": 2969195,
1171
- // "fee_asset": "",
1172
- // "fee_discount": "0",
1173
- // "fee_price": "0",
1174
- // "fee_rate": "0.0005",
1175
- // "fee_real_rate": "0.0005",
1176
- // "id": 379044296,
1177
- // "leverage": "3",
1178
- // "margin_amount": "15.8352",
1158
+ // "deal_id": 1180222387,
1159
+ // "created_at": 1714119054558,
1179
1160
  // "market": "BTCUSDT",
1180
- // "open_price": "39588",
1181
- // "order_id": 17797092987,
1182
- // "position_amount": "0.0012",
1183
- // "position_id": 62052321,
1184
- // "position_type": 1,
1185
- // "price": "39588",
1186
- // "role": 2,
1187
- // "side": 2,
1188
- // "time": 1650675936.016103,
1189
- // "user_id": 3620173
1161
+ // "side": "buy",
1162
+ // "order_id": 136915589622,
1163
+ // "price": "64376",
1164
+ // "amount": "0.0001"
1190
1165
  // }
1191
1166
  //
1192
- let timestamp = this.safeTimestamp2(trade, 'create_time', 'time');
1193
- if (timestamp === undefined) {
1194
- timestamp = this.safeInteger(trade, 'created_at');
1167
+ const timestamp = this.safeInteger(trade, 'created_at');
1168
+ let defaultType = this.safeString(this.options, 'defaultType');
1169
+ if (market !== undefined) {
1170
+ defaultType = market['type'];
1195
1171
  }
1196
- const tradeId = this.safeString2(trade, 'id', 'deal_id');
1197
- const orderId = this.safeString(trade, 'order_id');
1198
- const priceString = this.safeString(trade, 'price');
1199
- const amountString = this.safeString(trade, 'amount');
1200
1172
  const marketId = this.safeString(trade, 'market');
1201
- const marketType = this.safeString(trade, 'market_type');
1202
- const defaultType = (marketType === undefined) ? 'spot' : 'swap';
1203
1173
  market = this.safeMarket(marketId, market, undefined, defaultType);
1204
- const symbol = market['symbol'];
1205
- const costString = this.safeString(trade, 'deal_money');
1206
- let fee = undefined;
1207
- const feeCostString = this.safeString2(trade, 'fee', 'deal_fee');
1208
- if (feeCostString !== undefined) {
1209
- const feeCurrencyId = this.safeString(trade, 'fee_asset');
1210
- const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
1211
- fee = {
1212
- 'cost': feeCostString,
1213
- 'currency': feeCurrencyCode,
1214
- };
1215
- }
1216
- let takerOrMaker = this.safeString(trade, 'role');
1217
- if (takerOrMaker === '1') {
1218
- takerOrMaker = 'maker';
1219
- }
1220
- else if (takerOrMaker === '2') {
1221
- takerOrMaker = 'taker';
1222
- }
1223
- let side = undefined;
1224
- if (market['type'] === 'swap') {
1225
- const rawSide = this.safeInteger(trade, 'side');
1226
- if (rawSide === 1) {
1227
- side = 'sell';
1228
- }
1229
- else if (rawSide === 2) {
1230
- side = 'buy';
1231
- }
1232
- if (side === undefined) {
1233
- side = this.safeString2(trade, 'type', 'side');
1234
- }
1235
- }
1236
- else {
1237
- side = this.safeString2(trade, 'type', 'side');
1238
- }
1239
1174
  return this.safeTrade({
1240
1175
  'info': trade,
1241
1176
  'timestamp': timestamp,
1242
1177
  'datetime': this.iso8601(timestamp),
1243
- 'symbol': symbol,
1244
- 'id': tradeId,
1245
- 'order': orderId,
1178
+ 'symbol': market['symbol'],
1179
+ 'id': this.safeString(trade, 'deal_id'),
1180
+ 'order': this.safeString(trade, 'order_id'),
1246
1181
  'type': undefined,
1247
- 'side': side,
1248
- 'takerOrMaker': takerOrMaker,
1249
- 'price': priceString,
1250
- 'amount': amountString,
1251
- 'cost': costString,
1252
- 'fee': fee,
1182
+ 'side': this.safeString(trade, 'side'),
1183
+ 'takerOrMaker': undefined,
1184
+ 'price': this.safeString(trade, 'price'),
1185
+ 'amount': this.safeString(trade, 'amount'),
1186
+ 'cost': this.safeString(trade, 'deal_money'),
1187
+ 'fee': undefined,
1253
1188
  }, market);
1254
1189
  }
1255
1190
  async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
@@ -3827,155 +3762,110 @@ class coinex extends coinex$1 {
3827
3762
  * @method
3828
3763
  * @name coinex#fetchMyTrades
3829
3764
  * @description fetch all trades made by the user
3830
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http013_user_deals
3831
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade014_user_deals
3765
+ * @see https://docs.coinex.com/api/v2/spot/deal/http/list-user-deals
3766
+ * @see https://docs.coinex.com/api/v2/futures/deal/http/list-user-deals
3832
3767
  * @param {string} symbol unified market symbol
3833
3768
  * @param {int} [since] the earliest time in ms to fetch trades for
3834
- * @param {int} [limit] the maximum number of trades structures to retrieve
3769
+ * @param {int} [limit] the maximum number of trade structures to retrieve
3835
3770
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3771
+ * @param {int} [params.until] timestamp in ms of the latest trades
3772
+ * @param {string} [params.side] the side of the trades, either 'buy' or 'sell', required for swap
3836
3773
  * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
3837
3774
  */
3838
- await this.loadMarkets();
3839
- let market = undefined;
3840
- if (limit === undefined) {
3841
- limit = 100;
3775
+ if (symbol === undefined) {
3776
+ throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
3842
3777
  }
3843
- const request = {
3844
- 'limit': limit,
3845
- 'offset': 0, // SWAP, means query from a certain record
3846
- // 'page': 1, // SPOT
3847
- // 'side': 2, // SWAP, 0 for no limit, 1 for sell, 2 for buy
3848
- // 'start_time': since, // SWAP
3849
- // 'end_time': 1524228297, // SWAP
3778
+ await this.loadMarkets();
3779
+ const market = this.market(symbol);
3780
+ let request = {
3781
+ 'market': market['id'],
3850
3782
  };
3851
- if (symbol !== undefined) {
3852
- market = this.market(symbol);
3853
- request['market'] = market['id'];
3854
- }
3855
- let type = undefined;
3856
- [type, params] = this.handleMarketTypeAndParams('fetchMyTrades', market, params);
3857
- if (type !== 'spot' && symbol === undefined) {
3858
- throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument for non-spot markets');
3783
+ if (limit !== undefined) {
3784
+ request['limit'] = limit;
3859
3785
  }
3860
- const swap = (type === 'swap');
3861
- const accountId = this.safeInteger(params, 'account_id');
3862
- let marginMode = undefined;
3863
- [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
3864
- if (marginMode !== undefined) {
3865
- if (accountId === undefined) {
3866
- throw new errors.BadRequest(this.id + ' fetchMyTrades() requires an account_id parameter for margin trades');
3867
- }
3868
- request['account_id'] = accountId;
3869
- params = this.omit(params, 'account_id');
3786
+ if (since !== undefined) {
3787
+ request['start_time'] = since;
3870
3788
  }
3789
+ [request, params] = this.handleUntilOption('end_time', request, params);
3871
3790
  let response = undefined;
3872
- if (swap) {
3873
- if (since !== undefined) {
3874
- request['start_time'] = since;
3875
- }
3876
- request['side'] = 0;
3877
- response = await this.v1PerpetualPrivateGetMarketUserDeals(this.extend(request, params));
3791
+ if (market['swap']) {
3792
+ request['market_type'] = 'FUTURES';
3793
+ response = await this.v2PrivateGetFuturesUserDeals(this.extend(request, params));
3794
+ //
3795
+ // {
3796
+ // "code": 0,
3797
+ // "data": [
3798
+ // {
3799
+ // "deal_id": 1180222387,
3800
+ // "created_at": 1714119054558,
3801
+ // "market": "BTCUSDT",
3802
+ // "side": "buy",
3803
+ // "order_id": 136915589622,
3804
+ // "price": "64376",
3805
+ // "amount": "0.0001"
3806
+ // }
3807
+ // ],
3808
+ // "message": "OK",
3809
+ // "pagination": {
3810
+ // "has_next": true
3811
+ // }
3812
+ // }
3813
+ //
3878
3814
  }
3879
3815
  else {
3880
- request['page'] = 1;
3881
- response = await this.v1PrivateGetOrderUserDeals(this.extend(request, params));
3816
+ let marginMode = undefined;
3817
+ [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
3818
+ if (marginMode !== undefined) {
3819
+ request['market_type'] = 'MARGIN';
3820
+ }
3821
+ else {
3822
+ request['market_type'] = 'SPOT';
3823
+ }
3824
+ response = await this.v2PrivateGetSpotUserDeals(this.extend(request, params));
3825
+ //
3826
+ // {
3827
+ // "code": 0,
3828
+ // "data": [
3829
+ // {
3830
+ // "amount": "0.00010087",
3831
+ // "created_at": 1714618087585,
3832
+ // "deal_id": 4161200602,
3833
+ // "margin_market": "",
3834
+ // "market": "BTCUSDT",
3835
+ // "order_id": 117654919342,
3836
+ // "price": "57464.04",
3837
+ // "side": "sell"
3838
+ // }
3839
+ // ],
3840
+ // "message": "OK",
3841
+ // "pagination": {
3842
+ // "has_next": true
3843
+ // }
3844
+ // }
3845
+ //
3882
3846
  }
3883
- //
3884
- // Spot and Margin
3885
- //
3886
- // {
3887
- // "code": 0,
3888
- // "data": {
3889
- // "data": [
3890
- // {
3891
- // "id": 2611520950,
3892
- // "order_id": 63286573298,
3893
- // "account_id": 0,
3894
- // "create_time": 1638990636,
3895
- // "type": "sell",
3896
- // "role": "taker",
3897
- // "price": "192.29",
3898
- // "amount": "0.098",
3899
- // "fee": "0.03768884",
3900
- // "fee_asset": "USDT",
3901
- // "market": "AAVEUSDT",
3902
- // "deal_money": "18.84442"
3903
- // },
3904
- // ],
3905
- // "curr_page": 1,
3906
- // "has_next": false,
3907
- // "count": 3
3908
- // },
3909
- // "message": "Success"
3910
- // }
3911
- //
3912
- // Swap
3913
- //
3914
- // {
3915
- // "code": 0,
3916
- // "data": {
3917
- // "limit": 100,
3918
- // "offset": 0,
3919
- // "records": [
3920
- // {
3921
- // "amount": "0.0012",
3922
- // "deal_fee": "0.0237528",
3923
- // "deal_insurance": "0",
3924
- // "deal_margin": "15.8352",
3925
- // "deal_order_id": 17797031903,
3926
- // "deal_profit": "0",
3927
- // "deal_stock": "47.5056",
3928
- // "deal_type": 1,
3929
- // "deal_user_id": 2969195,
3930
- // "fee_asset": "",
3931
- // "fee_discount": "0",
3932
- // "fee_price": "0",
3933
- // "fee_rate": "0.0005",
3934
- // "fee_real_rate": "0.0005",
3935
- // "id": 379044296,
3936
- // "leverage": "3",
3937
- // "margin_amount": "15.8352",
3938
- // "market": "BTCUSDT",
3939
- // "open_price": "39588",
3940
- // "order_id": 17797092987,
3941
- // "position_amount": "0.0012",
3942
- // "position_id": 62052321,
3943
- // "position_type": 1,
3944
- // "price": "39588",
3945
- // "role": 2,
3946
- // "side": 2,
3947
- // "time": 1650675936.016103,
3948
- // "user_id": 3620173
3949
- // }
3950
- // ]
3951
- // },
3952
- // "message": "OK"
3953
- // }
3954
- //
3955
- const tradeRequest = swap ? 'records' : 'data';
3956
- const data = this.safeValue(response, 'data');
3957
- const trades = this.safeList(data, tradeRequest, []);
3958
- return this.parseTrades(trades, market, since, limit);
3847
+ const data = this.safeList(response, 'data', []);
3848
+ return this.parseTrades(data, market, since, limit);
3959
3849
  }
3960
3850
  async fetchPositions(symbols = undefined, params = {}) {
3961
3851
  /**
3962
3852
  * @method
3963
3853
  * @name coinex#fetchPositions
3964
3854
  * @description fetch all open positions
3965
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033_pending_position
3966
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033-0_finished_position
3855
+ * @see https://docs.coinex.com/api/v2/futures/position/http/list-pending-position
3856
+ * @see https://docs.coinex.com/api/v2/futures/position/http/list-finished-position
3967
3857
  * @param {string[]} [symbols] list of unified market symbols
3968
3858
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3969
- * @param {string} [params.method] the method to use 'perpetualPrivateGetPositionPending' or 'perpetualPrivateGetPositionFinished' default is 'perpetualPrivateGetPositionPending'
3970
- * @param {int} [params.side] *history endpoint only* 0: All, 1: Sell, 2: Buy, default is 0
3859
+ * @param {string} [params.method] the method to use 'v2PrivateGetFuturesPendingPosition' or 'v2PrivateGetFuturesFinishedPosition' default is 'v2PrivateGetFuturesPendingPosition'
3971
3860
  * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
3972
3861
  */
3973
3862
  await this.loadMarkets();
3974
3863
  let defaultMethod = undefined;
3975
- [defaultMethod, params] = this.handleOptionAndParams(params, 'fetchPositions', 'method', 'v1PerpetualPrivateGetPositionPending');
3976
- const isHistory = (defaultMethod === 'v1PerpetualPrivateGetPositionFinished');
3864
+ [defaultMethod, params] = this.handleOptionAndParams(params, 'fetchPositions', 'method', 'v2PrivateGetFuturesPendingPosition');
3977
3865
  symbols = this.marketSymbols(symbols);
3978
- const request = {};
3866
+ const request = {
3867
+ 'market_type': 'FUTURES',
3868
+ };
3979
3869
  let market = undefined;
3980
3870
  if (symbols !== undefined) {
3981
3871
  let symbol = undefined;
@@ -3992,82 +3882,57 @@ class coinex extends coinex$1 {
3992
3882
  market = this.market(symbol);
3993
3883
  request['market'] = market['id'];
3994
3884
  }
3995
- else {
3996
- if (isHistory) {
3997
- throw new errors.ArgumentsRequired(this.id + ' fetchPositions() requires a symbol argument for closed positions');
3998
- }
3999
- }
4000
- if (isHistory) {
4001
- request['limit'] = 100;
4002
- request['side'] = this.safeInteger(params, 'side', 0); // 0: All, 1: Sell, 2: Buy
4003
- }
4004
3885
  let response = undefined;
4005
- if (defaultMethod === 'v1PerpetualPrivateGetPositionPending') {
4006
- response = await this.v1PerpetualPrivateGetPositionPending(this.extend(request, params));
3886
+ if (defaultMethod === 'v2PrivateGetFuturesPendingPosition') {
3887
+ response = await this.v2PrivateGetFuturesPendingPosition(this.extend(request, params));
4007
3888
  }
4008
3889
  else {
4009
- response = await this.v1PerpetualPrivateGetPositionFinished(this.extend(request, params));
3890
+ response = await this.v2PrivateGetFuturesFinishedPosition(this.extend(request, params));
4010
3891
  }
4011
3892
  //
4012
3893
  // {
4013
3894
  // "code": 0,
4014
3895
  // "data": [
4015
3896
  // {
4016
- // "adl_sort": 3396,
4017
- // "adl_sort_val": "0.00007786",
4018
- // "amount": "0.0005",
4019
- // "amount_max": "0.0005",
4020
- // "amount_max_margin": "6.42101333333333333333",
4021
- // "bkr_price": "25684.05333333333333346175",
4022
- // "bkr_price_imply": "0.00000000000000000000",
4023
- // "close_left": "0.0005",
4024
- // "create_time": 1651294226.110899,
4025
- // "deal_all": "19.26000000000000000000",
4026
- // "deal_asset_fee": "0.00000000000000000000",
4027
- // "fee_asset": "",
4028
- // "finish_type": 1,
4029
- // "first_price": "38526.08",
4030
- // "insurance": "0.00000000000000000000",
4031
- // "latest_price": "38526.08",
4032
- // "leverage": "3",
4033
- // "liq_amount": "0.00000000000000000000",
4034
- // "liq_order_price": "0",
4035
- // "liq_order_time": 0,
4036
- // "liq_price": "25876.68373333333333346175",
4037
- // "liq_price_imply": "0.00000000000000000000",
4038
- // "liq_profit": "0.00000000000000000000",
4039
- // "liq_time": 0,
4040
- // "mainten_margin": "0.005",
4041
- // "mainten_margin_amount": "0.09631520000000000000",
4042
- // "maker_fee": "0.00000000000000000000",
4043
- // "margin_amount": "6.42101333333333333333",
3897
+ // "position_id": 305891033,
4044
3898
  // "market": "BTCUSDT",
4045
- // "open_margin": "0.33333333333333333333",
4046
- // "open_margin_imply": "0.00000000000000000000",
4047
- // "open_price": "38526.08000000000000000000",
4048
- // "open_val": "19.26304000000000000000",
4049
- // "open_val_max": "19.26304000000000000000",
4050
- // "position_id": 65847227,
4051
- // "profit_clearing": "-0.00963152000000000000",
4052
- // "profit_real": "-0.00963152000000000000",
4053
- // "profit_unreal": "0.00",
4054
- // "side": 2,
4055
- // "stop_loss_price": "0.00000000000000000000",
4056
- // "stop_loss_type": 0,
4057
- // "sy s": 0,
4058
- // "take_profit_price": "0.00000000000000000000",
4059
- // "take_profit_type": 0,
4060
- // "taker_fee": "0.00000000000000000000",
4061
- // "total": 4661,
4062
- // "type": 1,
4063
- // "update_time": 1651294226.111196,
4064
- // "user_id": 3620173
4065
- // },
3899
+ // "market_type": "FUTURES",
3900
+ // "side": "long",
3901
+ // "margin_mode": "cross",
3902
+ // "open_interest": "0.0001",
3903
+ // "close_avbl": "0.0001",
3904
+ // "ath_position_amount": "0.0001",
3905
+ // "unrealized_pnl": "0",
3906
+ // "realized_pnl": "-0.00311684",
3907
+ // "avg_entry_price": "62336.8",
3908
+ // "cml_position_value": "6.23368",
3909
+ // "max_position_value": "6.23368",
3910
+ // "created_at": 1715152208041,
3911
+ // "updated_at": 1715152208041,
3912
+ // "take_profit_price": "0",
3913
+ // "stop_loss_price": "0",
3914
+ // "take_profit_type": "",
3915
+ // "stop_loss_type": "",
3916
+ // "settle_price": "62336.8",
3917
+ // "settle_value": "6.23368",
3918
+ // "leverage": "3",
3919
+ // "margin_avbl": "2.07789333",
3920
+ // "ath_margin_size": "2.07789333",
3921
+ // "position_margin_rate": "2.40545879023305655728",
3922
+ // "maintenance_margin_rate": "0.005",
3923
+ // "maintenance_margin_value": "0.03118094",
3924
+ // "liq_price": "0",
3925
+ // "bkr_price": "0",
3926
+ // "adl_level": 1
3927
+ // }
4066
3928
  // ],
4067
- // "message": "OK"
3929
+ // "message": "OK",
3930
+ // "pagination": {
3931
+ // "has_next": false
3932
+ // }
4068
3933
  // }
4069
3934
  //
4070
- const position = this.safeValue(response, 'data', []);
3935
+ const position = this.safeList(response, 'data', []);
4071
3936
  const result = [];
4072
3937
  for (let i = 0; i < position.length; i++) {
4073
3938
  result.push(this.parsePosition(position[i], market));
@@ -4079,215 +3944,129 @@ class coinex extends coinex$1 {
4079
3944
  * @method
4080
3945
  * @name coinex#fetchPosition
4081
3946
  * @description fetch data on a single open contract trade position
4082
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033_pending_position
4083
- * @param {string} symbol unified market symbol of the market the position is held in, default is undefined
3947
+ * @see https://docs.coinex.com/api/v2/futures/position/http/list-pending-position
3948
+ * @param {string} symbol unified market symbol of the market the position is held in
4084
3949
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4085
3950
  * @returns {object} a [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
4086
3951
  */
4087
3952
  await this.loadMarkets();
4088
3953
  const market = this.market(symbol);
4089
3954
  const request = {
3955
+ 'market_type': 'FUTURES',
4090
3956
  'market': market['id'],
4091
3957
  };
4092
- const response = await this.v1PerpetualPrivateGetPositionPending(this.extend(request, params));
3958
+ const response = await this.v2PrivateGetFuturesPendingPosition(this.extend(request, params));
4093
3959
  //
4094
3960
  // {
4095
3961
  // "code": 0,
4096
3962
  // "data": [
4097
3963
  // {
4098
- // "adl_sort": 3396,
4099
- // "adl_sort_val": "0.00007786",
4100
- // "amount": "0.0005",
4101
- // "amount_max": "0.0005",
4102
- // "amount_max_margin": "6.42101333333333333333",
4103
- // "bkr_price": "25684.05333333333333346175",
4104
- // "bkr_price_imply": "0.00000000000000000000",
4105
- // "close_left": "0.0005",
4106
- // "create_time": 1651294226.110899,
4107
- // "deal_all": "19.26000000000000000000",
4108
- // "deal_asset_fee": "0.00000000000000000000",
4109
- // "fee_asset": "",
4110
- // "finish_type": 1,
4111
- // "first_price": "38526.08",
4112
- // "insurance": "0.00000000000000000000",
4113
- // "latest_price": "38526.08",
4114
- // "leverage": "3",
4115
- // "liq_amount": "0.00000000000000000000",
4116
- // "liq_order_price": "0",
4117
- // "liq_order_time": 0,
4118
- // "liq_price": "25876.68373333333333346175",
4119
- // "liq_price_imply": "0.00000000000000000000",
4120
- // "liq_profit": "0.00000000000000000000",
4121
- // "liq_time": 0,
4122
- // "mainten_margin": "0.005",
4123
- // "mainten_margin_amount": "0.09631520000000000000",
4124
- // "maker_fee": "0.00000000000000000000",
4125
- // "margin_amount": "6.42101333333333333333",
3964
+ // "position_id": 305891033,
4126
3965
  // "market": "BTCUSDT",
4127
- // "open_margin": "0.33333333333333333333",
4128
- // "open_margin_imply": "0.00000000000000000000",
4129
- // "open_price": "38526.08000000000000000000",
4130
- // "open_val": "19.26304000000000000000",
4131
- // "open_val_max": "19.26304000000000000000",
4132
- // "position_id": 65847227,
4133
- // "profit_clearing": "-0.00963152000000000000",
4134
- // "profit_real": "-0.00963152000000000000",
4135
- // "profit_unreal": "0.00",
4136
- // "side": 2,
4137
- // "stop_loss_price": "0.00000000000000000000",
4138
- // "stop_loss_type": 0,
4139
- // "s ys": 0,
4140
- // "take_profit_price": "0.00000000000000000000",
4141
- // "take_profit_type": 0,
4142
- // "taker_fee": "0.00000000000000000000",
4143
- // "total": 4661,
4144
- // "type": 1,
4145
- // "update_time": 1651294226.111196,
4146
- // "user_id": 3620173
3966
+ // "market_type": "FUTURES",
3967
+ // "side": "long",
3968
+ // "margin_mode": "cross",
3969
+ // "open_interest": "0.0001",
3970
+ // "close_avbl": "0.0001",
3971
+ // "ath_position_amount": "0.0001",
3972
+ // "unrealized_pnl": "0",
3973
+ // "realized_pnl": "-0.00311684",
3974
+ // "avg_entry_price": "62336.8",
3975
+ // "cml_position_value": "6.23368",
3976
+ // "max_position_value": "6.23368",
3977
+ // "created_at": 1715152208041,
3978
+ // "updated_at": 1715152208041,
3979
+ // "take_profit_price": "0",
3980
+ // "stop_loss_price": "0",
3981
+ // "take_profit_type": "",
3982
+ // "stop_loss_type": "",
3983
+ // "settle_price": "62336.8",
3984
+ // "settle_value": "6.23368",
3985
+ // "leverage": "3",
3986
+ // "margin_avbl": "2.07789333",
3987
+ // "ath_margin_size": "2.07789333",
3988
+ // "position_margin_rate": "2.40545879023305655728",
3989
+ // "maintenance_margin_rate": "0.005",
3990
+ // "maintenance_margin_value": "0.03118094",
3991
+ // "liq_price": "0",
3992
+ // "bkr_price": "0",
3993
+ // "adl_level": 1
4147
3994
  // }
4148
3995
  // ],
4149
- // "message": "OK"
3996
+ // "message": "OK",
3997
+ // "pagination": {
3998
+ // "has_next": false
3999
+ // }
4150
4000
  // }
4151
4001
  //
4152
4002
  const data = this.safeList(response, 'data', []);
4153
4003
  return this.parsePosition(data[0], market);
4154
4004
  }
4155
4005
  parsePosition(position, market = undefined) {
4156
- //
4157
- // fetchPosition
4158
4006
  //
4159
4007
  // {
4160
- // "adl_sort": 3396,
4161
- // "adl_sort_val": "0.00007786",
4162
- // "amount": "0.0005",
4163
- // "amount_max": "0.0005",
4164
- // "amount_max_margin": "6.42101333333333333333",
4165
- // "bkr_price": "25684.05333333333333346175",
4166
- // "bkr_price_imply": "0.00000000000000000000",
4167
- // "close_left": "0.0005",
4168
- // "create_time": 1651294226.110899,
4169
- // "deal_all": "19.26000000000000000000",
4170
- // "deal_asset_fee": "0.00000000000000000000",
4171
- // "fee_asset": "",
4172
- // "finish_type": 1,
4173
- // "first_price": "38526.08",
4174
- // "insurance": "0.00000000000000000000",
4175
- // "latest_price": "38526.08",
4176
- // "leverage": "3",
4177
- // "liq_amount": "0.00000000000000000000",
4178
- // "liq_order_price": "0",
4179
- // "liq_order_time": 0,
4180
- // "liq_price": "25876.68373333333333346175",
4181
- // "liq_price_imply": "0.00000000000000000000",
4182
- // "liq_profit": "0.00000000000000000000",
4183
- // "liq_time": 0,
4184
- // "mainten_margin": "0.005",
4185
- // "mainten_margin_amount": "0.09631520000000000000",
4186
- // "maker_fee": "0.00000000000000000000",
4187
- // "margin_amount": "6.42101333333333333333",
4008
+ // "position_id": 305891033,
4188
4009
  // "market": "BTCUSDT",
4189
- // "open_margin": "0.33333333333333333333",
4190
- // "open_margin_imply": "0.00000000000000000000",
4191
- // "open_price": "38526.08000000000000000000",
4192
- // "open_val": "19.26304000000000000000",
4193
- // "open_val_max": "19.26304000000000000000",
4194
- // "position_id": 65847227,
4195
- // "profit_clearing": "-0.00963152000000000000",
4196
- // "profit_real": "-0.00963152000000000000",
4197
- // "profit_unreal": "0.00",
4198
- // "side": 2,
4199
- // "stop_loss_price": "0.00000000000000000000",
4200
- // "stop_loss_type": 0,
4201
- // "s ys": 0,
4202
- // "take_profit_price": "0.00000000000000000000",
4203
- // "take_profit_type": 0,
4204
- // "taker_fee": "0.00000000000000000000",
4205
- // "total": 4661,
4206
- // "type": 1,
4207
- // "update_time": 1651294226.111196,
4208
- // "user_id": 3620173
4010
+ // "market_type": "FUTURES",
4011
+ // "side": "long",
4012
+ // "margin_mode": "cross",
4013
+ // "open_interest": "0.0001",
4014
+ // "close_avbl": "0.0001",
4015
+ // "ath_position_amount": "0.0001",
4016
+ // "unrealized_pnl": "0",
4017
+ // "realized_pnl": "-0.00311684",
4018
+ // "avg_entry_price": "62336.8",
4019
+ // "cml_position_value": "6.23368",
4020
+ // "max_position_value": "6.23368",
4021
+ // "created_at": 1715152208041,
4022
+ // "updated_at": 1715152208041,
4023
+ // "take_profit_price": "0",
4024
+ // "stop_loss_price": "0",
4025
+ // "take_profit_type": "",
4026
+ // "stop_loss_type": "",
4027
+ // "settle_price": "62336.8",
4028
+ // "settle_value": "6.23368",
4029
+ // "leverage": "3",
4030
+ // "margin_avbl": "2.07789333",
4031
+ // "ath_margin_size": "2.07789333",
4032
+ // "position_margin_rate": "2.40545879023305655728",
4033
+ // "maintenance_margin_rate": "0.005",
4034
+ // "maintenance_margin_value": "0.03118094",
4035
+ // "liq_price": "0",
4036
+ // "bkr_price": "0",
4037
+ // "adl_level": 1
4209
4038
  // }
4210
4039
  //
4211
- //
4212
- // fetchPositionHistory
4213
- //
4214
- // {
4215
- // amount_max: '10',
4216
- // amount_max_margin: '2.03466666666666666666',
4217
- // bkr_price: '0',
4218
- // create_time: '1711150526.2581',
4219
- // deal_all: '12.591',
4220
- // deal_asset_fee: '0',
4221
- // fee_asset: '',
4222
- // finish_type: '5',
4223
- // first_price: '0.6104',
4224
- // latest_price: '0.6487',
4225
- // leverage: '3',
4226
- // liq_amount: '0',
4227
- // liq_price: '0',
4228
- // liq_profit: '0',
4229
- // mainten_margin: '0.01',
4230
- // market: 'XRPUSDT',
4231
- // market_type: '1',
4232
- // open_price: '0.6104',
4233
- // open_val_max: '6.104',
4234
- // position_id: '297371462',
4235
- // profit_real: '0.35702107169',
4236
- // settle_price: '0.6104',
4237
- // settle_val: '0',
4238
- // side: '2',
4239
- // s ys: "0",
4240
- // type: '2',
4241
- // update_time: '1711391446.133233',
4242
- // user_id: '3685860'
4243
- // }
4244
- //
4245
4040
  const marketId = this.safeString(position, 'market');
4246
4041
  market = this.safeMarket(marketId, market, undefined, 'swap');
4247
- const symbol = market['symbol'];
4248
- const positionId = this.safeInteger(position, 'position_id');
4249
- const marginModeInteger = this.safeInteger(position, 'type');
4250
- const marginMode = (marginModeInteger === 1) ? 'isolated' : 'cross';
4251
- const liquidationPrice = this.safeString(position, 'liq_price');
4252
- const entryPrice = this.safeString(position, 'open_price');
4253
- const unrealizedPnl = this.safeString(position, 'profit_unreal');
4254
- const contracts = this.safeNumber(position, 'amount');
4255
- const sideInteger = this.safeInteger(position, 'side');
4256
- const side = (sideInteger === 1) ? 'short' : 'long';
4257
- const timestamp = this.safeTimestamp(position, 'update_time');
4258
- const maintenanceMargin = this.safeString(position, 'mainten_margin_amount');
4259
- const maintenanceMarginPercentage = this.safeString(position, 'mainten_margin');
4260
- const collateral = this.safeString2(position, 'margin_amount', 'amount_max_margin');
4261
- const leverage = this.safeString(position, 'leverage');
4262
- const notional = this.safeString(position, 'open_val');
4263
- const initialMargin = Precise["default"].stringDiv(notional, leverage);
4264
- const initialMarginPercentage = Precise["default"].stringDiv('1', leverage);
4042
+ const timestamp = this.safeInteger(position, 'created_at');
4265
4043
  return this.safePosition({
4266
4044
  'info': position,
4267
- 'id': positionId,
4268
- 'symbol': symbol,
4269
- 'notional': this.parseNumber(notional),
4270
- 'marginMode': marginMode,
4271
- 'liquidationPrice': liquidationPrice,
4272
- 'entryPrice': this.parseNumber(entryPrice),
4273
- 'unrealizedPnl': this.parseNumber(unrealizedPnl),
4045
+ 'id': this.safeInteger(position, 'position_id'),
4046
+ 'symbol': market['symbol'],
4047
+ 'notional': this.safeNumber(position, 'settle_value'),
4048
+ 'marginMode': this.safeString(position, 'margin_mode'),
4049
+ 'liquidationPrice': this.safeNumber(position, 'liq_price'),
4050
+ 'entryPrice': this.safeNumber(position, 'avg_entry_price'),
4051
+ 'unrealizedPnl': this.safeNumber(position, 'unrealized_pnl'),
4052
+ 'realizedPnl': this.safeNumber(position, 'realized_pnl'),
4274
4053
  'percentage': undefined,
4275
- 'contracts': contracts,
4054
+ 'contracts': this.safeNumber(position, 'close_avbl'),
4276
4055
  'contractSize': this.safeNumber(market, 'contractSize'),
4277
4056
  'markPrice': undefined,
4278
4057
  'lastPrice': undefined,
4279
- 'side': side,
4058
+ 'side': this.safeString(position, 'side'),
4280
4059
  'hedged': undefined,
4281
4060
  'timestamp': timestamp,
4282
4061
  'datetime': this.iso8601(timestamp),
4283
- 'lastUpdateTimestamp': undefined,
4284
- 'maintenanceMargin': this.parseNumber(maintenanceMargin),
4285
- 'maintenanceMarginPercentage': this.parseNumber(maintenanceMarginPercentage),
4286
- 'collateral': this.parseNumber(collateral),
4287
- 'initialMargin': this.parseNumber(initialMargin),
4288
- 'initialMarginPercentage': this.parseNumber(initialMarginPercentage),
4289
- 'leverage': this.parseNumber(leverage),
4290
- 'marginRatio': undefined,
4062
+ 'lastUpdateTimestamp': this.safeInteger(position, 'updated_at'),
4063
+ 'maintenanceMargin': this.safeNumber(position, 'maintenance_margin_value'),
4064
+ 'maintenanceMarginPercentage': this.safeNumber(position, 'maintenance_margin_rate'),
4065
+ 'collateral': this.safeNumber(position, 'margin_avbl'),
4066
+ 'initialMargin': undefined,
4067
+ 'initialMarginPercentage': undefined,
4068
+ 'leverage': this.safeNumber(position, 'leverage'),
4069
+ 'marginRatio': this.safeNumber(position, 'position_margin_rate'),
4291
4070
  'stopLossPrice': this.omitZero(this.safeString(position, 'stop_loss_price')),
4292
4071
  'takeProfitPrice': this.omitZero(this.safeString(position, 'take_profit_price')),
4293
4072
  });
@@ -4297,10 +4076,11 @@ class coinex extends coinex$1 {
4297
4076
  * @method
4298
4077
  * @name coinex#setMarginMode
4299
4078
  * @description set margin mode to 'cross' or 'isolated'
4300
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http014_adjust_leverage
4079
+ * @see https://docs.coinex.com/api/v2/futures/position/http/adjust-position-leverage
4301
4080
  * @param {string} marginMode 'cross' or 'isolated'
4302
4081
  * @param {string} symbol unified market symbol
4303
4082
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4083
+ * @param {int} params.leverage the rate of leverage
4304
4084
  * @returns {object} response from the exchange
4305
4085
  */
4306
4086
  if (symbol === undefined) {
@@ -4315,37 +4095,37 @@ class coinex extends coinex$1 {
4315
4095
  if (market['type'] !== 'swap') {
4316
4096
  throw new errors.BadSymbol(this.id + ' setMarginMode() supports swap contracts only');
4317
4097
  }
4318
- let defaultPositionType = undefined;
4319
- if (marginMode === 'isolated') {
4320
- defaultPositionType = 1;
4321
- }
4322
- else if (marginMode === 'cross') {
4323
- defaultPositionType = 2;
4324
- }
4325
4098
  const leverage = this.safeInteger(params, 'leverage');
4326
4099
  const maxLeverage = this.safeInteger(market['limits']['leverage'], 'max', 100);
4327
- const positionType = this.safeInteger(params, 'position_type', defaultPositionType);
4328
4100
  if (leverage === undefined) {
4329
4101
  throw new errors.ArgumentsRequired(this.id + ' setMarginMode() requires a leverage parameter');
4330
4102
  }
4331
- if (positionType === undefined) {
4332
- throw new errors.ArgumentsRequired(this.id + ' setMarginMode() requires a position_type parameter that will transfer margin to the specified trading pair');
4333
- }
4334
- if ((leverage < 3) || (leverage > maxLeverage)) {
4335
- throw new errors.BadRequest(this.id + ' setMarginMode() leverage should be between 3 and ' + maxLeverage.toString() + ' for ' + symbol);
4103
+ if ((leverage < 1) || (leverage > maxLeverage)) {
4104
+ throw new errors.BadRequest(this.id + ' setMarginMode() leverage should be between 1 and ' + maxLeverage.toString() + ' for ' + symbol);
4336
4105
  }
4337
4106
  const request = {
4338
4107
  'market': market['id'],
4339
- 'leverage': leverage.toString(),
4340
- 'position_type': positionType, // 1: isolated, 2: cross
4108
+ 'market_type': 'FUTURES',
4109
+ 'margin_mode': marginMode,
4110
+ 'leverage': leverage,
4341
4111
  };
4342
- return await this.v1PerpetualPrivatePostMarketAdjustLeverage(this.extend(request, params));
4112
+ return await this.v2PrivatePostFuturesAdjustPositionLeverage(this.extend(request, params));
4113
+ //
4114
+ // {
4115
+ // "code": 0,
4116
+ // "data": {
4117
+ // "leverage": 1,
4118
+ // "margin_mode": "isolated"
4119
+ // },
4120
+ // "message": "OK"
4121
+ // }
4122
+ //
4343
4123
  }
4344
4124
  async setLeverage(leverage, symbol = undefined, params = {}) {
4345
4125
  /**
4346
4126
  * @method
4347
4127
  * @name coinex#setLeverage
4348
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http014_adjust_leverage
4128
+ * @see https://docs.coinex.com/api/v2/futures/position/http/adjust-position-leverage
4349
4129
  * @description set the level of leverage for a market
4350
4130
  * @param {float} leverage the rate of leverage
4351
4131
  * @param {string} symbol unified market symbol
@@ -4363,13 +4143,6 @@ class coinex extends coinex$1 {
4363
4143
  }
4364
4144
  let marginMode = undefined;
4365
4145
  [marginMode, params] = this.handleMarginModeAndParams('setLeverage', params, 'cross');
4366
- let positionType = undefined;
4367
- if (marginMode === 'isolated') {
4368
- positionType = 1;
4369
- }
4370
- else if (marginMode === 'cross') {
4371
- positionType = 2;
4372
- }
4373
4146
  const minLeverage = this.safeInteger(market['limits']['leverage'], 'min', 1);
4374
4147
  const maxLeverage = this.safeInteger(market['limits']['leverage'], 'max', 100);
4375
4148
  if ((leverage < minLeverage) || (leverage > maxLeverage)) {
@@ -4377,57 +4150,84 @@ class coinex extends coinex$1 {
4377
4150
  }
4378
4151
  const request = {
4379
4152
  'market': market['id'],
4380
- 'leverage': leverage.toString(),
4381
- 'position_type': positionType, // 1: isolated, 2: cross
4153
+ 'market_type': 'FUTURES',
4154
+ 'margin_mode': marginMode,
4155
+ 'leverage': leverage,
4382
4156
  };
4383
- return await this.v1PerpetualPrivatePostMarketAdjustLeverage(this.extend(request, params));
4157
+ return await this.v2PrivatePostFuturesAdjustPositionLeverage(this.extend(request, params));
4158
+ //
4159
+ // {
4160
+ // "code": 0,
4161
+ // "data": {
4162
+ // "leverage": 1,
4163
+ // "margin_mode": "isolated"
4164
+ // },
4165
+ // "message": "OK"
4166
+ // }
4167
+ //
4384
4168
  }
4385
4169
  async fetchLeverageTiers(symbols = undefined, params = {}) {
4386
4170
  /**
4387
4171
  * @method
4388
4172
  * @name coinex#fetchLeverageTiers
4389
4173
  * @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
4390
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http007_market_limit
4174
+ * @see https://docs.coinex.com/api/v2/futures/market/http/list-market-position-level
4391
4175
  * @param {string[]|undefined} symbols list of unified market symbols
4392
4176
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4393
4177
  * @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}, indexed by market symbols
4394
4178
  */
4395
4179
  await this.loadMarkets();
4396
- const response = await this.v1PerpetualPublicGetMarketLimitConfig(params);
4180
+ const request = {};
4181
+ if (symbols !== undefined) {
4182
+ const marketIds = this.marketIds(symbols);
4183
+ request['market'] = marketIds.join(',');
4184
+ }
4185
+ const response = await this.v2PublicGetFuturesPositionLevel(this.extend(request, params));
4397
4186
  //
4398
4187
  // {
4399
4188
  // "code": 0,
4400
- // "data": {
4401
- // "BTCUSD": [
4402
- // ["500001", "100", "0.005"],
4403
- // ["1000001", "50", "0.01"],
4404
- // ["2000001", "30", "0.015"],
4405
- // ["5000001", "20", "0.02"],
4406
- // ["10000001", "15", "0.025"],
4407
- // ["20000001", "10", "0.03"]
4408
- // ],
4409
- // ...
4410
- // },
4189
+ // "data": [
4190
+ // {
4191
+ // "level": [
4192
+ // {
4193
+ // "amount": "20001",
4194
+ // "leverage": "20",
4195
+ // "maintenance_margin_rate": "0.02",
4196
+ // "min_initial_margin_rate": "0.05"
4197
+ // },
4198
+ // {
4199
+ // "amount": "50001",
4200
+ // "leverage": "10",
4201
+ // "maintenance_margin_rate": "0.04",
4202
+ // "min_initial_margin_rate": "0.1"
4203
+ // },
4204
+ // ],
4205
+ // "market": "MINAUSDT"
4206
+ // },
4207
+ // ],
4411
4208
  // "message": "OK"
4412
4209
  // }
4413
4210
  //
4414
- const data = this.safeValue(response, 'data', {});
4415
- return this.parseLeverageTiers(data, symbols, undefined);
4211
+ const data = this.safeList(response, 'data', []);
4212
+ return this.parseLeverageTiers(data, symbols, 'market');
4416
4213
  }
4417
- parseMarketLeverageTiers(item, market = undefined) {
4214
+ parseMarketLeverageTiers(info, market = undefined) {
4418
4215
  const tiers = [];
4216
+ const brackets = this.safeList(info, 'level', []);
4419
4217
  let minNotional = 0;
4420
- for (let j = 0; j < item.length; j++) {
4421
- const bracket = item[j];
4422
- const maxNotional = this.safeNumber(bracket, 0);
4218
+ for (let i = 0; i < brackets.length; i++) {
4219
+ const tier = brackets[i];
4220
+ const marketId = this.safeString(info, 'market');
4221
+ market = this.safeMarket(marketId, market, undefined, 'swap');
4222
+ const maxNotional = this.safeNumber(tier, 'amount');
4423
4223
  tiers.push({
4424
- 'tier': j + 1,
4224
+ 'tier': this.sum(i, 1),
4425
4225
  'currency': market['linear'] ? market['base'] : market['quote'],
4426
4226
  'minNotional': minNotional,
4427
4227
  'maxNotional': maxNotional,
4428
- 'maintenanceMarginRate': this.safeNumber(bracket, 2),
4429
- 'maxLeverage': this.safeInteger(bracket, 1),
4430
- 'info': bracket,
4228
+ 'maintenanceMarginRate': this.safeNumber(tier, 'maintenance_margin_rate'),
4229
+ 'maxLeverage': this.safeInteger(tier, 'leverage'),
4230
+ 'info': tier,
4431
4231
  });
4432
4232
  minNotional = maxNotional;
4433
4233
  }
@@ -5241,7 +5041,7 @@ class coinex extends coinex$1 {
5241
5041
  const currencyCode = this.safeCurrencyCode(currencyId, currency);
5242
5042
  return {
5243
5043
  'info': transfer,
5244
- 'id': this.safeInteger(transfer, 'id'),
5044
+ 'id': this.safeString(transfer, 'id'),
5245
5045
  'timestamp': timestamp,
5246
5046
  'datetime': this.iso8601(timestamp),
5247
5047
  'currency': currencyCode,
@@ -5936,72 +5736,72 @@ class coinex extends coinex$1 {
5936
5736
  * @method
5937
5737
  * @name coinex#fetchPositionHistory
5938
5738
  * @description fetches historical positions
5939
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033-0_finished_position
5739
+ * @see https://docs.coinex.com/api/v2/futures/position/http/list-finished-position
5940
5740
  * @param {string} symbol unified contract symbol
5941
- * @param {int} [since] not used by coinex fetchPositionHistory
5942
- * @param {int} [limit] the maximum amount of records to fetch, default=1000
5943
- * @param {object} params extra parameters specific to the exchange api endpoint
5944
- *
5945
- * EXCHANGE SPECIFIC PARAMETERS
5946
- * @param {int} [params.side] 0: all 1: sell, 2: buy
5741
+ * @param {int} [since] the earliest time in ms to fetch positions for
5742
+ * @param {int} [limit] the maximum amount of records to fetch, default is 10
5743
+ * @param {object} [params] extra parameters specific to the exchange api endpoint
5744
+ * @param {int} [params.until] the latest time in ms to fetch positions for
5947
5745
  * @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
5948
5746
  */
5949
5747
  await this.loadMarkets();
5950
5748
  const market = this.market(symbol);
5951
- if (limit === undefined) {
5952
- limit = 1000;
5953
- }
5954
- const request = {
5749
+ let request = {
5750
+ 'market_type': 'FUTURES',
5955
5751
  'market': market['id'],
5956
- 'side': 0,
5957
- 'limit': limit,
5958
5752
  };
5959
- const response = await this.v1PerpetualPrivateGetPositionFinished(this.extend(request, params));
5753
+ if (limit !== undefined) {
5754
+ request['limit'] = limit;
5755
+ }
5756
+ if (since !== undefined) {
5757
+ request['start_time'] = since;
5758
+ }
5759
+ [request, params] = this.handleUntilOption('end_time', request, params);
5760
+ const response = await this.v2PrivateGetFuturesFinishedPosition(this.extend(request, params));
5960
5761
  //
5961
- // {
5962
- // code: '0',
5963
- // data: {
5964
- // limit: '1000',
5965
- // offset: '0',
5966
- // records: [
5967
- // {
5968
- // amount_max: '10',
5969
- // amount_max_margin: '2.03466666666666666666',
5970
- // bkr_price: '0',
5971
- // create_time: '1711150526.2581',
5972
- // deal_all: '12.591',
5973
- // deal_asset_fee: '0',
5974
- // fee_asset: '',
5975
- // finish_type: '5',
5976
- // first_price: '0.6104',
5977
- // latest_price: '0.6487',
5978
- // leverage: '3',
5979
- // liq_amount: '0',
5980
- // liq_price: '0',
5981
- // liq_profit: '0',
5982
- // mainten_margin: '0.01',
5983
- // market: 'XRPUSDT',
5984
- // market_type: '1',
5985
- // open_price: '0.6104',
5986
- // open_val_max: '6.104',
5987
- // position_id: '297371462',
5988
- // profit_real: '0.35702107169',
5989
- // settle_price: '0.6104',
5990
- // settle_val: '0',
5991
- // side: '2',
5992
- // sy s: '0',
5993
- // type: '2',
5994
- // update_time: '1711391446.133233',
5995
- // user_id: '3685860'
5996
- // },
5997
- // ...
5998
- // ]
5999
- // },
6000
- // message: 'OK'
6001
- // }
5762
+ // {
5763
+ // "code": 0,
5764
+ // "data": [
5765
+ // {
5766
+ // "position_id": 305891033,
5767
+ // "market": "BTCUSDT",
5768
+ // "market_type": "FUTURES",
5769
+ // "side": "long",
5770
+ // "margin_mode": "cross",
5771
+ // "open_interest": "0.0001",
5772
+ // "close_avbl": "0.0001",
5773
+ // "ath_position_amount": "0.0001",
5774
+ // "unrealized_pnl": "0",
5775
+ // "realized_pnl": "-0.00311684",
5776
+ // "avg_entry_price": "62336.8",
5777
+ // "cml_position_value": "6.23368",
5778
+ // "max_position_value": "6.23368",
5779
+ // "created_at": 1715152208041,
5780
+ // "updated_at": 1715152208041,
5781
+ // "take_profit_price": "0",
5782
+ // "stop_loss_price": "0",
5783
+ // "take_profit_type": "",
5784
+ // "stop_loss_type": "",
5785
+ // "settle_price": "62336.8",
5786
+ // "settle_value": "6.23368",
5787
+ // "leverage": "3",
5788
+ // "margin_avbl": "2.07789333",
5789
+ // "ath_margin_size": "2.07789333",
5790
+ // "position_margin_rate": "2.40545879023305655728",
5791
+ // "maintenance_margin_rate": "0.005",
5792
+ // "maintenance_margin_value": "0.03118094",
5793
+ // "liq_price": "0",
5794
+ // "bkr_price": "0",
5795
+ // "adl_level": 1
5796
+ // }
5797
+ // ],
5798
+ // "message": "OK",
5799
+ // "pagination": {
5800
+ // "has_next": false
5801
+ // }
5802
+ // }
6002
5803
  //
6003
- const data = this.safeDict(response, 'data');
6004
- const records = this.safeList(data, 'records');
5804
+ const records = this.safeList(response, 'data', []);
6005
5805
  const positions = this.parsePositions(records);
6006
5806
  return this.filterBySymbolSinceLimit(positions, symbol, since, limit);
6007
5807
  }