ccxt 4.3.18 → 4.3.19

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