ccxt 4.3.17__py2.py3-none-any.whl → 4.3.19__py2.py3-none-any.whl

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 (195) hide show
  1. ccxt/__init__.py +3 -1
  2. ccxt/abstract/bybit.py +1 -0
  3. ccxt/abstract/okx.py +1 -0
  4. ccxt/abstract/woofipro.py +119 -0
  5. ccxt/ace.py +1 -1
  6. ccxt/ascendex.py +7 -8
  7. ccxt/async_support/__init__.py +3 -1
  8. ccxt/async_support/ace.py +1 -1
  9. ccxt/async_support/ascendex.py +7 -8
  10. ccxt/async_support/base/exchange.py +23 -2
  11. ccxt/async_support/bigone.py +4 -4
  12. ccxt/async_support/binance.py +34 -17
  13. ccxt/async_support/bingx.py +4 -4
  14. ccxt/async_support/bit2c.py +1 -1
  15. ccxt/async_support/bitbank.py +1 -1
  16. ccxt/async_support/bitbns.py +1 -1
  17. ccxt/async_support/bitfinex.py +28 -4
  18. ccxt/async_support/bitfinex2.py +62 -54
  19. ccxt/async_support/bitflyer.py +1 -1
  20. ccxt/async_support/bitget.py +8 -11
  21. ccxt/async_support/bithumb.py +1 -1
  22. ccxt/async_support/bitmart.py +8 -8
  23. ccxt/async_support/bitmex.py +2 -2
  24. ccxt/async_support/bitopro.py +1 -1
  25. ccxt/async_support/bitrue.py +3 -3
  26. ccxt/async_support/bitso.py +1 -1
  27. ccxt/async_support/bitstamp.py +3 -5
  28. ccxt/async_support/bitteam.py +1 -1
  29. ccxt/async_support/bitvavo.py +1 -1
  30. ccxt/async_support/bl3p.py +1 -1
  31. ccxt/async_support/blockchaincom.py +1 -1
  32. ccxt/async_support/blofin.py +3 -3
  33. ccxt/async_support/btcalpha.py +1 -1
  34. ccxt/async_support/btcbox.py +1 -1
  35. ccxt/async_support/btcmarkets.py +1 -1
  36. ccxt/async_support/btcturk.py +1 -1
  37. ccxt/async_support/bybit.py +9 -8
  38. ccxt/async_support/cex.py +1 -1
  39. ccxt/async_support/coinbase.py +2 -2
  40. ccxt/async_support/coinbasepro.py +1 -1
  41. ccxt/async_support/coincheck.py +1 -1
  42. ccxt/async_support/coinex.py +320 -520
  43. ccxt/async_support/coinlist.py +6 -7
  44. ccxt/async_support/coinmate.py +1 -1
  45. ccxt/async_support/coinmetro.py +1 -1
  46. ccxt/async_support/coinone.py +1 -1
  47. ccxt/async_support/coinsph.py +1 -1
  48. ccxt/async_support/coinspot.py +1 -1
  49. ccxt/async_support/cryptocom.py +1 -1
  50. ccxt/async_support/currencycom.py +2 -2
  51. ccxt/async_support/delta.py +4 -4
  52. ccxt/async_support/deribit.py +8 -8
  53. ccxt/async_support/digifinex.py +5 -5
  54. ccxt/async_support/exmo.py +1 -1
  55. ccxt/async_support/gate.py +5 -5
  56. ccxt/async_support/gemini.py +1 -1
  57. ccxt/async_support/hitbtc.py +3 -3
  58. ccxt/async_support/hollaex.py +4 -4
  59. ccxt/async_support/htx.py +4 -4
  60. ccxt/async_support/huobijp.py +1 -1
  61. ccxt/async_support/idex.py +1 -1
  62. ccxt/async_support/independentreserve.py +1 -1
  63. ccxt/async_support/indodax.py +2 -2
  64. ccxt/async_support/kraken.py +2 -2
  65. ccxt/async_support/krakenfutures.py +3 -3
  66. ccxt/async_support/kucoin.py +3 -3
  67. ccxt/async_support/kucoinfutures.py +3 -3
  68. ccxt/async_support/kuna.py +1 -1
  69. ccxt/async_support/latoken.py +6 -6
  70. ccxt/async_support/lbank.py +1 -1
  71. ccxt/async_support/luno.py +1 -1
  72. ccxt/async_support/lykke.py +1 -1
  73. ccxt/async_support/mercado.py +1 -1
  74. ccxt/async_support/mexc.py +7 -7
  75. ccxt/async_support/ndax.py +1 -1
  76. ccxt/async_support/novadax.py +3 -4
  77. ccxt/async_support/okcoin.py +3 -3
  78. ccxt/async_support/okx.py +27 -10
  79. ccxt/async_support/onetrading.py +1 -1
  80. ccxt/async_support/paymium.py +3 -3
  81. ccxt/async_support/phemex.py +5 -5
  82. ccxt/async_support/poloniex.py +3 -4
  83. ccxt/async_support/poloniexfutures.py +1 -1
  84. ccxt/async_support/probit.py +1 -1
  85. ccxt/async_support/timex.py +1 -1
  86. ccxt/async_support/tokocrypto.py +1 -1
  87. ccxt/async_support/upbit.py +1 -1
  88. ccxt/async_support/wavesexchange.py +3 -3
  89. ccxt/async_support/wazirx.py +1 -1
  90. ccxt/async_support/whitebit.py +2 -2
  91. ccxt/async_support/woo.py +25 -10
  92. ccxt/async_support/woofipro.py +2524 -0
  93. ccxt/async_support/yobit.py +1 -1
  94. ccxt/async_support/zaif.py +1 -1
  95. ccxt/async_support/zonda.py +3 -3
  96. ccxt/base/exchange.py +63 -17
  97. ccxt/base/types.py +20 -0
  98. ccxt/bigone.py +4 -4
  99. ccxt/binance.py +34 -17
  100. ccxt/bingx.py +4 -4
  101. ccxt/bit2c.py +1 -1
  102. ccxt/bitbank.py +1 -1
  103. ccxt/bitbns.py +1 -1
  104. ccxt/bitfinex.py +28 -4
  105. ccxt/bitfinex2.py +62 -54
  106. ccxt/bitflyer.py +1 -1
  107. ccxt/bitget.py +8 -11
  108. ccxt/bithumb.py +1 -1
  109. ccxt/bitmart.py +8 -8
  110. ccxt/bitmex.py +2 -2
  111. ccxt/bitopro.py +1 -1
  112. ccxt/bitrue.py +3 -3
  113. ccxt/bitso.py +1 -1
  114. ccxt/bitstamp.py +3 -5
  115. ccxt/bitteam.py +1 -1
  116. ccxt/bitvavo.py +1 -1
  117. ccxt/bl3p.py +1 -1
  118. ccxt/blockchaincom.py +1 -1
  119. ccxt/blofin.py +3 -3
  120. ccxt/btcalpha.py +1 -1
  121. ccxt/btcbox.py +1 -1
  122. ccxt/btcmarkets.py +1 -1
  123. ccxt/btcturk.py +1 -1
  124. ccxt/bybit.py +9 -8
  125. ccxt/cex.py +1 -1
  126. ccxt/coinbase.py +2 -2
  127. ccxt/coinbasepro.py +1 -1
  128. ccxt/coincheck.py +1 -1
  129. ccxt/coinex.py +320 -520
  130. ccxt/coinlist.py +6 -7
  131. ccxt/coinmate.py +1 -1
  132. ccxt/coinmetro.py +1 -1
  133. ccxt/coinone.py +1 -1
  134. ccxt/coinsph.py +1 -1
  135. ccxt/coinspot.py +1 -1
  136. ccxt/cryptocom.py +1 -1
  137. ccxt/currencycom.py +2 -2
  138. ccxt/delta.py +4 -4
  139. ccxt/deribit.py +8 -8
  140. ccxt/digifinex.py +5 -5
  141. ccxt/exmo.py +1 -1
  142. ccxt/gate.py +5 -5
  143. ccxt/gemini.py +1 -1
  144. ccxt/hitbtc.py +3 -3
  145. ccxt/hollaex.py +4 -4
  146. ccxt/htx.py +4 -4
  147. ccxt/huobijp.py +1 -1
  148. ccxt/idex.py +1 -1
  149. ccxt/independentreserve.py +1 -1
  150. ccxt/indodax.py +2 -2
  151. ccxt/kraken.py +2 -2
  152. ccxt/krakenfutures.py +3 -3
  153. ccxt/kucoin.py +3 -3
  154. ccxt/kucoinfutures.py +3 -3
  155. ccxt/kuna.py +1 -1
  156. ccxt/latoken.py +6 -6
  157. ccxt/lbank.py +1 -1
  158. ccxt/luno.py +1 -1
  159. ccxt/lykke.py +1 -1
  160. ccxt/mercado.py +1 -1
  161. ccxt/mexc.py +7 -7
  162. ccxt/ndax.py +1 -1
  163. ccxt/novadax.py +3 -4
  164. ccxt/okcoin.py +3 -3
  165. ccxt/okx.py +27 -10
  166. ccxt/onetrading.py +1 -1
  167. ccxt/paymium.py +3 -3
  168. ccxt/phemex.py +5 -5
  169. ccxt/poloniex.py +3 -4
  170. ccxt/poloniexfutures.py +1 -1
  171. ccxt/pro/__init__.py +3 -1
  172. ccxt/pro/bitget.py +127 -190
  173. ccxt/pro/bitvavo.py +1 -1
  174. ccxt/pro/bybit.py +4 -3
  175. ccxt/pro/coinbaseinternational.py +11 -4
  176. ccxt/pro/okx.py +79 -1
  177. ccxt/pro/woofipro.py +1183 -0
  178. ccxt/probit.py +1 -1
  179. ccxt/test/test_async.py +31 -1
  180. ccxt/test/test_sync.py +31 -1
  181. ccxt/timex.py +1 -1
  182. ccxt/tokocrypto.py +1 -1
  183. ccxt/upbit.py +1 -1
  184. ccxt/wavesexchange.py +3 -3
  185. ccxt/wazirx.py +1 -1
  186. ccxt/whitebit.py +2 -2
  187. ccxt/woo.py +25 -10
  188. ccxt/woofipro.py +2524 -0
  189. ccxt/yobit.py +1 -1
  190. ccxt/zaif.py +1 -1
  191. ccxt/zonda.py +3 -3
  192. {ccxt-4.3.17.dist-info → ccxt-4.3.19.dist-info}/METADATA +8 -6
  193. {ccxt-4.3.17.dist-info → ccxt-4.3.19.dist-info}/RECORD +195 -191
  194. {ccxt-4.3.17.dist-info → ccxt-4.3.19.dist-info}/WHEEL +0 -0
  195. {ccxt-4.3.17.dist-info → ccxt-4.3.19.dist-info}/top_level.txt +0 -0
ccxt/coinex.py CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  from ccxt.base.exchange import Exchange
7
7
  from ccxt.abstract.coinex import ImplicitAPI
8
- from ccxt.base.types import Balances, Currencies, Currency, Int, IsolatedBorrowRate, IsolatedBorrowRates, Leverage, Leverages, MarginModification, Market, Num, Order, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry
8
+ from ccxt.base.types import Balances, Currencies, Currency, Int, IsolatedBorrowRate, IsolatedBorrowRates, Leverage, Leverages, MarginModification, Market, Num, Order, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry, TransferEntries
9
9
  from typing import List
10
10
  from ccxt.base.errors import ExchangeError
11
11
  from ccxt.base.errors import AuthenticationError
@@ -811,7 +811,7 @@ class coinex(Exchange, ImplicitAPI):
811
811
  })
812
812
  return result
813
813
 
814
- def parse_ticker(self, ticker, market: Market = None) -> Ticker:
814
+ def parse_ticker(self, ticker: dict, market: Market = None) -> Ticker:
815
815
  #
816
816
  # Spot fetchTicker, fetchTickers
817
817
  #
@@ -1127,106 +1127,49 @@ class coinex(Exchange, ImplicitAPI):
1127
1127
  #
1128
1128
  # Spot and Margin fetchMyTrades(private)
1129
1129
  #
1130
- # {
1131
- # "id": 2611520950,
1132
- # "order_id": 63286573298,
1133
- # "account_id": 0,
1134
- # "create_time": 1638990636,
1135
- # "type": "sell",
1136
- # "role": "taker",
1137
- # "price": "192.29",
1138
- # "amount": "0.098",
1139
- # "fee": "0.03768884",
1140
- # "fee_asset": "USDT",
1141
- # "market": "AAVEUSDT",
1142
- # "deal_money": "18.84442"
1143
- # }
1130
+ # {
1131
+ # "amount": "0.00010087",
1132
+ # "created_at": 1714618087585,
1133
+ # "deal_id": 4161200602,
1134
+ # "margin_market": "",
1135
+ # "market": "BTCUSDT",
1136
+ # "order_id": 117654919342,
1137
+ # "price": "57464.04",
1138
+ # "side": "sell"
1139
+ # }
1144
1140
  #
1145
1141
  # Swap fetchMyTrades(private)
1146
1142
  #
1147
1143
  # {
1148
- # "amount": "0.0012",
1149
- # "deal_fee": "0.0237528",
1150
- # "deal_insurance": "0",
1151
- # "deal_margin": "15.8352",
1152
- # "deal_order_id": 17797031903,
1153
- # "deal_profit": "0",
1154
- # "deal_stock": "47.5056",
1155
- # "deal_type": 1,
1156
- # "deal_user_id": 2969195,
1157
- # "fee_asset": "",
1158
- # "fee_discount": "0",
1159
- # "fee_price": "0",
1160
- # "fee_rate": "0.0005",
1161
- # "fee_real_rate": "0.0005",
1162
- # "id": 379044296,
1163
- # "leverage": "3",
1164
- # "margin_amount": "15.8352",
1144
+ # "deal_id": 1180222387,
1145
+ # "created_at": 1714119054558,
1165
1146
  # "market": "BTCUSDT",
1166
- # "open_price": "39588",
1167
- # "order_id": 17797092987,
1168
- # "position_amount": "0.0012",
1169
- # "position_id": 62052321,
1170
- # "position_type": 1,
1171
- # "price": "39588",
1172
- # "role": 2,
1173
- # "side": 2,
1174
- # "time": 1650675936.016103,
1175
- # "user_id": 3620173
1147
+ # "side": "buy",
1148
+ # "order_id": 136915589622,
1149
+ # "price": "64376",
1150
+ # "amount": "0.0001"
1176
1151
  # }
1177
1152
  #
1178
- timestamp = self.safe_timestamp_2(trade, 'create_time', 'time')
1179
- if timestamp is None:
1180
- timestamp = self.safe_integer(trade, 'created_at')
1181
- tradeId = self.safe_string_2(trade, 'id', 'deal_id')
1182
- orderId = self.safe_string(trade, 'order_id')
1183
- priceString = self.safe_string(trade, 'price')
1184
- amountString = self.safe_string(trade, 'amount')
1153
+ timestamp = self.safe_integer(trade, 'created_at')
1154
+ defaultType = self.safe_string(self.options, 'defaultType')
1155
+ if market is not None:
1156
+ defaultType = market['type']
1185
1157
  marketId = self.safe_string(trade, 'market')
1186
- marketType = self.safe_string(trade, 'market_type')
1187
- defaultType = 'spot' if (marketType is None) else 'swap'
1188
1158
  market = self.safe_market(marketId, market, None, defaultType)
1189
- symbol = market['symbol']
1190
- costString = self.safe_string(trade, 'deal_money')
1191
- fee = None
1192
- feeCostString = self.safe_string_2(trade, 'fee', 'deal_fee')
1193
- if feeCostString is not None:
1194
- feeCurrencyId = self.safe_string(trade, 'fee_asset')
1195
- feeCurrencyCode = self.safe_currency_code(feeCurrencyId)
1196
- fee = {
1197
- 'cost': feeCostString,
1198
- 'currency': feeCurrencyCode,
1199
- }
1200
- takerOrMaker = self.safe_string(trade, 'role')
1201
- if takerOrMaker == '1':
1202
- takerOrMaker = 'maker'
1203
- elif takerOrMaker == '2':
1204
- takerOrMaker = 'taker'
1205
- side: Str = None
1206
- if market['type'] == 'swap':
1207
- rawSide = self.safe_integer(trade, 'side')
1208
- if rawSide == 1:
1209
- side = 'sell'
1210
- elif rawSide == 2:
1211
- side = 'buy'
1212
- if side is None:
1213
- side = self.safe_string_2(trade, 'type', 'side')
1214
- else:
1215
- side = self.safe_string_2(trade, 'type', 'side')
1216
1159
  return self.safe_trade({
1217
1160
  'info': trade,
1218
1161
  'timestamp': timestamp,
1219
1162
  'datetime': self.iso8601(timestamp),
1220
- 'symbol': symbol,
1221
- 'id': tradeId,
1222
- 'order': orderId,
1163
+ 'symbol': market['symbol'],
1164
+ 'id': self.safe_string(trade, 'deal_id'),
1165
+ 'order': self.safe_string(trade, 'order_id'),
1223
1166
  'type': None,
1224
- 'side': side,
1225
- 'takerOrMaker': takerOrMaker,
1226
- 'price': priceString,
1227
- 'amount': amountString,
1228
- 'cost': costString,
1229
- 'fee': fee,
1167
+ 'side': self.safe_string(trade, 'side'),
1168
+ 'takerOrMaker': None,
1169
+ 'price': self.safe_string(trade, 'price'),
1170
+ 'amount': self.safe_string(trade, 'amount'),
1171
+ 'cost': self.safe_string(trade, 'deal_money'),
1172
+ 'fee': None,
1230
1173
  }, market)
1231
1174
 
1232
1175
  def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
@@ -3604,145 +3547,101 @@ class coinex(Exchange, ImplicitAPI):
3604
3547
  def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
3605
3548
  """
3606
3549
  fetch all trades made by the user
3607
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http013_user_deals
3608
- :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade014_user_deals
3550
+ :see: https://docs.coinex.com/api/v2/spot/deal/http/list-user-deals
3551
+ :see: https://docs.coinex.com/api/v2/futures/deal/http/list-user-deals
3609
3552
  :param str symbol: unified market symbol
3610
3553
  :param int [since]: the earliest time in ms to fetch trades for
3611
- :param int [limit]: the maximum number of trades structures to retrieve
3554
+ :param int [limit]: the maximum number of trade structures to retrieve
3612
3555
  :param dict [params]: extra parameters specific to the exchange API endpoint
3556
+ :param int [params.until]: timestamp in ms of the latest trades
3557
+ :param str [params.side]: the side of the trades, either 'buy' or 'sell', required for swap
3613
3558
  :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
3614
3559
  """
3560
+ if symbol is None:
3561
+ raise ArgumentsRequired(self.id + ' fetchMyTrades() requires a symbol argument')
3615
3562
  self.load_markets()
3616
- market = None
3617
- if limit is None:
3618
- limit = 100
3563
+ market = self.market(symbol)
3619
3564
  request = {
3620
- 'limit': limit, # SPOT and SWAP
3621
- 'offset': 0, # SWAP, means query from a certain record
3622
- # 'page': 1, # SPOT
3623
- # 'side': 2, # SWAP, 0 for no limit, 1 for sell, 2 for buy
3624
- # 'start_time': since, # SWAP
3625
- # 'end_time': 1524228297, # SWAP
3565
+ 'market': market['id'],
3626
3566
  }
3627
- if symbol is not None:
3628
- market = self.market(symbol)
3629
- request['market'] = market['id']
3630
- type = None
3631
- type, params = self.handle_market_type_and_params('fetchMyTrades', market, params)
3632
- if type != 'spot' and symbol is None:
3633
- raise ArgumentsRequired(self.id + ' fetchMyTrades() requires a symbol argument for non-spot markets')
3634
- swap = (type == 'swap')
3635
- accountId = self.safe_integer(params, 'account_id')
3636
- marginMode = None
3637
- marginMode, params = self.handle_margin_mode_and_params('fetchMyTrades', params)
3638
- if marginMode is not None:
3639
- if accountId is None:
3640
- raise BadRequest(self.id + ' fetchMyTrades() requires an account_id parameter for margin trades')
3641
- request['account_id'] = accountId
3642
- params = self.omit(params, 'account_id')
3567
+ if limit is not None:
3568
+ request['limit'] = limit
3569
+ if since is not None:
3570
+ request['start_time'] = since
3571
+ request, params = self.handle_until_option('end_time', request, params)
3643
3572
  response = None
3644
- if swap:
3645
- if since is not None:
3646
- request['start_time'] = since
3647
- request['side'] = 0
3648
- response = self.v1PerpetualPrivateGetMarketUserDeals(self.extend(request, params))
3573
+ if market['swap']:
3574
+ request['market_type'] = 'FUTURES'
3575
+ response = self.v2PrivateGetFuturesUserDeals(self.extend(request, params))
3576
+ #
3577
+ # {
3578
+ # "code": 0,
3579
+ # "data": [
3580
+ # {
3581
+ # "deal_id": 1180222387,
3582
+ # "created_at": 1714119054558,
3583
+ # "market": "BTCUSDT",
3584
+ # "side": "buy",
3585
+ # "order_id": 136915589622,
3586
+ # "price": "64376",
3587
+ # "amount": "0.0001"
3588
+ # }
3589
+ # ],
3590
+ # "message": "OK",
3591
+ # "pagination": {
3592
+ # "has_next": True
3593
+ # }
3594
+ # }
3595
+ #
3649
3596
  else:
3650
- request['page'] = 1
3651
- response = self.v1PrivateGetOrderUserDeals(self.extend(request, params))
3652
- #
3653
- # Spot and Margin
3654
- #
3655
- # {
3656
- # "code": 0,
3657
- # "data": {
3658
- # "data": [
3659
- # {
3660
- # "id": 2611520950,
3661
- # "order_id": 63286573298,
3662
- # "account_id": 0,
3663
- # "create_time": 1638990636,
3664
- # "type": "sell",
3665
- # "role": "taker",
3666
- # "price": "192.29",
3667
- # "amount": "0.098",
3668
- # "fee": "0.03768884",
3669
- # "fee_asset": "USDT",
3670
- # "market": "AAVEUSDT",
3671
- # "deal_money": "18.84442"
3672
- # },
3673
- # ],
3674
- # "curr_page": 1,
3675
- # "has_next": False,
3676
- # "count": 3
3677
- # },
3678
- # "message": "Success"
3679
- # }
3680
- #
3681
- # Swap
3682
- #
3683
- # {
3684
- # "code": 0,
3685
- # "data": {
3686
- # "limit": 100,
3687
- # "offset": 0,
3688
- # "records": [
3689
- # {
3690
- # "amount": "0.0012",
3691
- # "deal_fee": "0.0237528",
3692
- # "deal_insurance": "0",
3693
- # "deal_margin": "15.8352",
3694
- # "deal_order_id": 17797031903,
3695
- # "deal_profit": "0",
3696
- # "deal_stock": "47.5056",
3697
- # "deal_type": 1,
3698
- # "deal_user_id": 2969195,
3699
- # "fee_asset": "",
3700
- # "fee_discount": "0",
3701
- # "fee_price": "0",
3702
- # "fee_rate": "0.0005",
3703
- # "fee_real_rate": "0.0005",
3704
- # "id": 379044296,
3705
- # "leverage": "3",
3706
- # "margin_amount": "15.8352",
3707
- # "market": "BTCUSDT",
3708
- # "open_price": "39588",
3709
- # "order_id": 17797092987,
3710
- # "position_amount": "0.0012",
3711
- # "position_id": 62052321,
3712
- # "position_type": 1,
3713
- # "price": "39588",
3714
- # "role": 2,
3715
- # "side": 2,
3716
- # "time": 1650675936.016103,
3717
- # "user_id": 3620173
3718
- # }
3719
- # ]
3720
- # },
3721
- # "message": "OK"
3722
- # }
3723
- #
3724
- tradeRequest = 'records' if swap else 'data'
3725
- data = self.safe_value(response, 'data')
3726
- trades = self.safe_list(data, tradeRequest, [])
3727
- return self.parse_trades(trades, market, since, limit)
3597
+ marginMode = None
3598
+ marginMode, params = self.handle_margin_mode_and_params('fetchMyTrades', params)
3599
+ if marginMode is not None:
3600
+ request['market_type'] = 'MARGIN'
3601
+ else:
3602
+ request['market_type'] = 'SPOT'
3603
+ response = self.v2PrivateGetSpotUserDeals(self.extend(request, params))
3604
+ #
3605
+ # {
3606
+ # "code": 0,
3607
+ # "data": [
3608
+ # {
3609
+ # "amount": "0.00010087",
3610
+ # "created_at": 1714618087585,
3611
+ # "deal_id": 4161200602,
3612
+ # "margin_market": "",
3613
+ # "market": "BTCUSDT",
3614
+ # "order_id": 117654919342,
3615
+ # "price": "57464.04",
3616
+ # "side": "sell"
3617
+ # }
3618
+ # ],
3619
+ # "message": "OK",
3620
+ # "pagination": {
3621
+ # "has_next": True
3622
+ # }
3623
+ # }
3624
+ #
3625
+ data = self.safe_list(response, 'data', [])
3626
+ return self.parse_trades(data, market, since, limit)
3728
3627
 
3729
3628
  def fetch_positions(self, symbols: Strings = None, params={}):
3730
3629
  """
3731
3630
  fetch all open positions
3732
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033_pending_position
3733
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033-0_finished_position
3631
+ :see: https://docs.coinex.com/api/v2/futures/position/http/list-pending-position
3632
+ :see: https://docs.coinex.com/api/v2/futures/position/http/list-finished-position
3734
3633
  :param str[] [symbols]: list of unified market symbols
3735
3634
  :param dict [params]: extra parameters specific to the exchange API endpoint
3736
- :param str [params.method]: the method to use 'perpetualPrivateGetPositionPending' or 'perpetualPrivateGetPositionFinished' default is 'perpetualPrivateGetPositionPending'
3737
- :param int [params.side]: *history endpoint only* 0: All, 1: Sell, 2: Buy, default is 0
3635
+ :param str [params.method]: the method to use 'v2PrivateGetFuturesPendingPosition' or 'v2PrivateGetFuturesFinishedPosition' default is 'v2PrivateGetFuturesPendingPosition'
3738
3636
  :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
3739
3637
  """
3740
3638
  self.load_markets()
3741
3639
  defaultMethod = None
3742
- defaultMethod, params = self.handle_option_and_params(params, 'fetchPositions', 'method', 'v1PerpetualPrivateGetPositionPending')
3743
- isHistory = (defaultMethod == 'v1PerpetualPrivateGetPositionFinished')
3640
+ defaultMethod, params = self.handle_option_and_params(params, 'fetchPositions', 'method', 'v2PrivateGetFuturesPendingPosition')
3744
3641
  symbols = self.market_symbols(symbols)
3745
- request = {}
3642
+ request = {
3643
+ 'market_type': 'FUTURES',
3644
+ }
3746
3645
  market = None
3747
3646
  if symbols is not None:
3748
3647
  symbol = None
@@ -3755,77 +3654,55 @@ class coinex(Exchange, ImplicitAPI):
3755
3654
  symbol = symbols
3756
3655
  market = self.market(symbol)
3757
3656
  request['market'] = market['id']
3758
- else:
3759
- if isHistory:
3760
- raise ArgumentsRequired(self.id + ' fetchPositions() requires a symbol argument for closed positions')
3761
- if isHistory:
3762
- request['limit'] = 100
3763
- request['side'] = self.safe_integer(params, 'side', 0) # 0: All, 1: Sell, 2: Buy
3764
3657
  response = None
3765
- if defaultMethod == 'v1PerpetualPrivateGetPositionPending':
3766
- response = self.v1PerpetualPrivateGetPositionPending(self.extend(request, params))
3658
+ if defaultMethod == 'v2PrivateGetFuturesPendingPosition':
3659
+ response = self.v2PrivateGetFuturesPendingPosition(self.extend(request, params))
3767
3660
  else:
3768
- response = self.v1PerpetualPrivateGetPositionFinished(self.extend(request, params))
3661
+ response = self.v2PrivateGetFuturesFinishedPosition(self.extend(request, params))
3769
3662
  #
3770
3663
  # {
3771
3664
  # "code": 0,
3772
3665
  # "data": [
3773
3666
  # {
3774
- # "adl_sort": 3396,
3775
- # "adl_sort_val": "0.00007786",
3776
- # "amount": "0.0005",
3777
- # "amount_max": "0.0005",
3778
- # "amount_max_margin": "6.42101333333333333333",
3779
- # "bkr_price": "25684.05333333333333346175",
3780
- # "bkr_price_imply": "0.00000000000000000000",
3781
- # "close_left": "0.0005",
3782
- # "create_time": 1651294226.110899,
3783
- # "deal_all": "19.26000000000000000000",
3784
- # "deal_asset_fee": "0.00000000000000000000",
3785
- # "fee_asset": "",
3786
- # "finish_type": 1,
3787
- # "first_price": "38526.08",
3788
- # "insurance": "0.00000000000000000000",
3789
- # "latest_price": "38526.08",
3790
- # "leverage": "3",
3791
- # "liq_amount": "0.00000000000000000000",
3792
- # "liq_order_price": "0",
3793
- # "liq_order_time": 0,
3794
- # "liq_price": "25876.68373333333333346175",
3795
- # "liq_price_imply": "0.00000000000000000000",
3796
- # "liq_profit": "0.00000000000000000000",
3797
- # "liq_time": 0,
3798
- # "mainten_margin": "0.005",
3799
- # "mainten_margin_amount": "0.09631520000000000000",
3800
- # "maker_fee": "0.00000000000000000000",
3801
- # "margin_amount": "6.42101333333333333333",
3667
+ # "position_id": 305891033,
3802
3668
  # "market": "BTCUSDT",
3803
- # "open_margin": "0.33333333333333333333",
3804
- # "open_margin_imply": "0.00000000000000000000",
3805
- # "open_price": "38526.08000000000000000000",
3806
- # "open_val": "19.26304000000000000000",
3807
- # "open_val_max": "19.26304000000000000000",
3808
- # "position_id": 65847227,
3809
- # "profit_clearing": "-0.00963152000000000000",
3810
- # "profit_real": "-0.00963152000000000000",
3811
- # "profit_unreal": "0.00",
3812
- # "side": 2,
3813
- # "stop_loss_price": "0.00000000000000000000",
3814
- # "stop_loss_type": 0,
3815
- # "sy s": 0,
3816
- # "take_profit_price": "0.00000000000000000000",
3817
- # "take_profit_type": 0,
3818
- # "taker_fee": "0.00000000000000000000",
3819
- # "total": 4661,
3820
- # "type": 1,
3821
- # "update_time": 1651294226.111196,
3822
- # "user_id": 3620173
3823
- # },
3669
+ # "market_type": "FUTURES",
3670
+ # "side": "long",
3671
+ # "margin_mode": "cross",
3672
+ # "open_interest": "0.0001",
3673
+ # "close_avbl": "0.0001",
3674
+ # "ath_position_amount": "0.0001",
3675
+ # "unrealized_pnl": "0",
3676
+ # "realized_pnl": "-0.00311684",
3677
+ # "avg_entry_price": "62336.8",
3678
+ # "cml_position_value": "6.23368",
3679
+ # "max_position_value": "6.23368",
3680
+ # "created_at": 1715152208041,
3681
+ # "updated_at": 1715152208041,
3682
+ # "take_profit_price": "0",
3683
+ # "stop_loss_price": "0",
3684
+ # "take_profit_type": "",
3685
+ # "stop_loss_type": "",
3686
+ # "settle_price": "62336.8",
3687
+ # "settle_value": "6.23368",
3688
+ # "leverage": "3",
3689
+ # "margin_avbl": "2.07789333",
3690
+ # "ath_margin_size": "2.07789333",
3691
+ # "position_margin_rate": "2.40545879023305655728",
3692
+ # "maintenance_margin_rate": "0.005",
3693
+ # "maintenance_margin_value": "0.03118094",
3694
+ # "liq_price": "0",
3695
+ # "bkr_price": "0",
3696
+ # "adl_level": 1
3697
+ # }
3824
3698
  # ],
3825
- # "message": "OK"
3699
+ # "message": "OK",
3700
+ # "pagination": {
3701
+ # "has_next": False
3702
+ # }
3826
3703
  # }
3827
3704
  #
3828
- position = self.safe_value(response, 'data', [])
3705
+ position = self.safe_list(response, 'data', [])
3829
3706
  result = []
3830
3707
  for i in range(0, len(position)):
3831
3708
  result.append(self.parse_position(position[i], market))
@@ -3834,215 +3711,129 @@ class coinex(Exchange, ImplicitAPI):
3834
3711
  def fetch_position(self, symbol: str, params={}):
3835
3712
  """
3836
3713
  fetch data on a single open contract trade position
3837
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033_pending_position
3838
- :param str symbol: unified market symbol of the market the position is held in, default is None
3714
+ :see: https://docs.coinex.com/api/v2/futures/position/http/list-pending-position
3715
+ :param str symbol: unified market symbol of the market the position is held in
3839
3716
  :param dict [params]: extra parameters specific to the exchange API endpoint
3840
3717
  :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
3841
3718
  """
3842
3719
  self.load_markets()
3843
3720
  market = self.market(symbol)
3844
3721
  request = {
3722
+ 'market_type': 'FUTURES',
3845
3723
  'market': market['id'],
3846
3724
  }
3847
- response = self.v1PerpetualPrivateGetPositionPending(self.extend(request, params))
3725
+ response = self.v2PrivateGetFuturesPendingPosition(self.extend(request, params))
3848
3726
  #
3849
3727
  # {
3850
3728
  # "code": 0,
3851
3729
  # "data": [
3852
3730
  # {
3853
- # "adl_sort": 3396,
3854
- # "adl_sort_val": "0.00007786",
3855
- # "amount": "0.0005",
3856
- # "amount_max": "0.0005",
3857
- # "amount_max_margin": "6.42101333333333333333",
3858
- # "bkr_price": "25684.05333333333333346175",
3859
- # "bkr_price_imply": "0.00000000000000000000",
3860
- # "close_left": "0.0005",
3861
- # "create_time": 1651294226.110899,
3862
- # "deal_all": "19.26000000000000000000",
3863
- # "deal_asset_fee": "0.00000000000000000000",
3864
- # "fee_asset": "",
3865
- # "finish_type": 1,
3866
- # "first_price": "38526.08",
3867
- # "insurance": "0.00000000000000000000",
3868
- # "latest_price": "38526.08",
3869
- # "leverage": "3",
3870
- # "liq_amount": "0.00000000000000000000",
3871
- # "liq_order_price": "0",
3872
- # "liq_order_time": 0,
3873
- # "liq_price": "25876.68373333333333346175",
3874
- # "liq_price_imply": "0.00000000000000000000",
3875
- # "liq_profit": "0.00000000000000000000",
3876
- # "liq_time": 0,
3877
- # "mainten_margin": "0.005",
3878
- # "mainten_margin_amount": "0.09631520000000000000",
3879
- # "maker_fee": "0.00000000000000000000",
3880
- # "margin_amount": "6.42101333333333333333",
3731
+ # "position_id": 305891033,
3881
3732
  # "market": "BTCUSDT",
3882
- # "open_margin": "0.33333333333333333333",
3883
- # "open_margin_imply": "0.00000000000000000000",
3884
- # "open_price": "38526.08000000000000000000",
3885
- # "open_val": "19.26304000000000000000",
3886
- # "open_val_max": "19.26304000000000000000",
3887
- # "position_id": 65847227,
3888
- # "profit_clearing": "-0.00963152000000000000",
3889
- # "profit_real": "-0.00963152000000000000",
3890
- # "profit_unreal": "0.00",
3891
- # "side": 2,
3892
- # "stop_loss_price": "0.00000000000000000000",
3893
- # "stop_loss_type": 0,
3894
- # "s ys": 0,
3895
- # "take_profit_price": "0.00000000000000000000",
3896
- # "take_profit_type": 0,
3897
- # "taker_fee": "0.00000000000000000000",
3898
- # "total": 4661,
3899
- # "type": 1,
3900
- # "update_time": 1651294226.111196,
3901
- # "user_id": 3620173
3733
+ # "market_type": "FUTURES",
3734
+ # "side": "long",
3735
+ # "margin_mode": "cross",
3736
+ # "open_interest": "0.0001",
3737
+ # "close_avbl": "0.0001",
3738
+ # "ath_position_amount": "0.0001",
3739
+ # "unrealized_pnl": "0",
3740
+ # "realized_pnl": "-0.00311684",
3741
+ # "avg_entry_price": "62336.8",
3742
+ # "cml_position_value": "6.23368",
3743
+ # "max_position_value": "6.23368",
3744
+ # "created_at": 1715152208041,
3745
+ # "updated_at": 1715152208041,
3746
+ # "take_profit_price": "0",
3747
+ # "stop_loss_price": "0",
3748
+ # "take_profit_type": "",
3749
+ # "stop_loss_type": "",
3750
+ # "settle_price": "62336.8",
3751
+ # "settle_value": "6.23368",
3752
+ # "leverage": "3",
3753
+ # "margin_avbl": "2.07789333",
3754
+ # "ath_margin_size": "2.07789333",
3755
+ # "position_margin_rate": "2.40545879023305655728",
3756
+ # "maintenance_margin_rate": "0.005",
3757
+ # "maintenance_margin_value": "0.03118094",
3758
+ # "liq_price": "0",
3759
+ # "bkr_price": "0",
3760
+ # "adl_level": 1
3902
3761
  # }
3903
3762
  # ],
3904
- # "message": "OK"
3763
+ # "message": "OK",
3764
+ # "pagination": {
3765
+ # "has_next": False
3766
+ # }
3905
3767
  # }
3906
3768
  #
3907
3769
  data = self.safe_list(response, 'data', [])
3908
3770
  return self.parse_position(data[0], market)
3909
3771
 
3910
3772
  def parse_position(self, position, market: Market = None):
3911
- #
3912
- # fetchPosition
3913
3773
  #
3914
3774
  # {
3915
- # "adl_sort": 3396,
3916
- # "adl_sort_val": "0.00007786",
3917
- # "amount": "0.0005",
3918
- # "amount_max": "0.0005",
3919
- # "amount_max_margin": "6.42101333333333333333",
3920
- # "bkr_price": "25684.05333333333333346175",
3921
- # "bkr_price_imply": "0.00000000000000000000",
3922
- # "close_left": "0.0005",
3923
- # "create_time": 1651294226.110899,
3924
- # "deal_all": "19.26000000000000000000",
3925
- # "deal_asset_fee": "0.00000000000000000000",
3926
- # "fee_asset": "",
3927
- # "finish_type": 1,
3928
- # "first_price": "38526.08",
3929
- # "insurance": "0.00000000000000000000",
3930
- # "latest_price": "38526.08",
3931
- # "leverage": "3",
3932
- # "liq_amount": "0.00000000000000000000",
3933
- # "liq_order_price": "0",
3934
- # "liq_order_time": 0,
3935
- # "liq_price": "25876.68373333333333346175",
3936
- # "liq_price_imply": "0.00000000000000000000",
3937
- # "liq_profit": "0.00000000000000000000",
3938
- # "liq_time": 0,
3939
- # "mainten_margin": "0.005",
3940
- # "mainten_margin_amount": "0.09631520000000000000",
3941
- # "maker_fee": "0.00000000000000000000",
3942
- # "margin_amount": "6.42101333333333333333",
3775
+ # "position_id": 305891033,
3943
3776
  # "market": "BTCUSDT",
3944
- # "open_margin": "0.33333333333333333333",
3945
- # "open_margin_imply": "0.00000000000000000000",
3946
- # "open_price": "38526.08000000000000000000",
3947
- # "open_val": "19.26304000000000000000",
3948
- # "open_val_max": "19.26304000000000000000",
3949
- # "position_id": 65847227,
3950
- # "profit_clearing": "-0.00963152000000000000",
3951
- # "profit_real": "-0.00963152000000000000",
3952
- # "profit_unreal": "0.00",
3953
- # "side": 2,
3954
- # "stop_loss_price": "0.00000000000000000000",
3955
- # "stop_loss_type": 0,
3956
- # "s ys": 0,
3957
- # "take_profit_price": "0.00000000000000000000",
3958
- # "take_profit_type": 0,
3959
- # "taker_fee": "0.00000000000000000000",
3960
- # "total": 4661,
3961
- # "type": 1,
3962
- # "update_time": 1651294226.111196,
3963
- # "user_id": 3620173
3777
+ # "market_type": "FUTURES",
3778
+ # "side": "long",
3779
+ # "margin_mode": "cross",
3780
+ # "open_interest": "0.0001",
3781
+ # "close_avbl": "0.0001",
3782
+ # "ath_position_amount": "0.0001",
3783
+ # "unrealized_pnl": "0",
3784
+ # "realized_pnl": "-0.00311684",
3785
+ # "avg_entry_price": "62336.8",
3786
+ # "cml_position_value": "6.23368",
3787
+ # "max_position_value": "6.23368",
3788
+ # "created_at": 1715152208041,
3789
+ # "updated_at": 1715152208041,
3790
+ # "take_profit_price": "0",
3791
+ # "stop_loss_price": "0",
3792
+ # "take_profit_type": "",
3793
+ # "stop_loss_type": "",
3794
+ # "settle_price": "62336.8",
3795
+ # "settle_value": "6.23368",
3796
+ # "leverage": "3",
3797
+ # "margin_avbl": "2.07789333",
3798
+ # "ath_margin_size": "2.07789333",
3799
+ # "position_margin_rate": "2.40545879023305655728",
3800
+ # "maintenance_margin_rate": "0.005",
3801
+ # "maintenance_margin_value": "0.03118094",
3802
+ # "liq_price": "0",
3803
+ # "bkr_price": "0",
3804
+ # "adl_level": 1
3964
3805
  # }
3965
3806
  #
3966
- #
3967
- # fetchPositionHistory
3968
- #
3969
- # {
3970
- # amount_max: '10',
3971
- # amount_max_margin: '2.03466666666666666666',
3972
- # bkr_price: '0',
3973
- # create_time: '1711150526.2581',
3974
- # deal_all: '12.591',
3975
- # deal_asset_fee: '0',
3976
- # fee_asset: '',
3977
- # finish_type: '5',
3978
- # first_price: '0.6104',
3979
- # latest_price: '0.6487',
3980
- # leverage: '3',
3981
- # liq_amount: '0',
3982
- # liq_price: '0',
3983
- # liq_profit: '0',
3984
- # mainten_margin: '0.01',
3985
- # market: 'XRPUSDT',
3986
- # market_type: '1',
3987
- # open_price: '0.6104',
3988
- # open_val_max: '6.104',
3989
- # position_id: '297371462',
3990
- # profit_real: '0.35702107169',
3991
- # settle_price: '0.6104',
3992
- # settle_val: '0',
3993
- # side: '2',
3994
- # s ys: "0",
3995
- # type: '2',
3996
- # update_time: '1711391446.133233',
3997
- # user_id: '3685860'
3998
- # }
3999
- #
4000
3807
  marketId = self.safe_string(position, 'market')
4001
3808
  market = self.safe_market(marketId, market, None, 'swap')
4002
- symbol = market['symbol']
4003
- positionId = self.safe_integer(position, 'position_id')
4004
- marginModeInteger = self.safe_integer(position, 'type')
4005
- marginMode = 'isolated' if (marginModeInteger == 1) else 'cross'
4006
- liquidationPrice = self.safe_string(position, 'liq_price')
4007
- entryPrice = self.safe_string(position, 'open_price')
4008
- unrealizedPnl = self.safe_string(position, 'profit_unreal')
4009
- contracts = self.safe_number(position, 'amount')
4010
- sideInteger = self.safe_integer(position, 'side')
4011
- side = 'short' if (sideInteger == 1) else 'long'
4012
- timestamp = self.safe_timestamp(position, 'update_time')
4013
- maintenanceMargin = self.safe_string(position, 'mainten_margin_amount')
4014
- maintenanceMarginPercentage = self.safe_string(position, 'mainten_margin')
4015
- collateral = self.safe_string_2(position, 'margin_amount', 'amount_max_margin')
4016
- leverage = self.safe_string(position, 'leverage')
4017
- notional = self.safe_string(position, 'open_val')
4018
- initialMargin = Precise.string_div(notional, leverage)
4019
- initialMarginPercentage = Precise.string_div('1', leverage)
3809
+ timestamp = self.safe_integer(position, 'created_at')
4020
3810
  return self.safe_position({
4021
3811
  'info': position,
4022
- 'id': positionId,
4023
- 'symbol': symbol,
4024
- 'notional': self.parse_number(notional),
4025
- 'marginMode': marginMode,
4026
- 'liquidationPrice': liquidationPrice,
4027
- 'entryPrice': self.parse_number(entryPrice),
4028
- 'unrealizedPnl': self.parse_number(unrealizedPnl),
3812
+ 'id': self.safe_integer(position, 'position_id'),
3813
+ 'symbol': market['symbol'],
3814
+ 'notional': self.safe_number(position, 'settle_value'),
3815
+ 'marginMode': self.safe_string(position, 'margin_mode'),
3816
+ 'liquidationPrice': self.safe_number(position, 'liq_price'),
3817
+ 'entryPrice': self.safe_number(position, 'avg_entry_price'),
3818
+ 'unrealizedPnl': self.safe_number(position, 'unrealized_pnl'),
3819
+ 'realizedPnl': self.safe_number(position, 'realized_pnl'),
4029
3820
  'percentage': None,
4030
- 'contracts': contracts,
3821
+ 'contracts': self.safe_number(position, 'close_avbl'),
4031
3822
  'contractSize': self.safe_number(market, 'contractSize'),
4032
3823
  'markPrice': None,
4033
3824
  'lastPrice': None,
4034
- 'side': side,
3825
+ 'side': self.safe_string(position, 'side'),
4035
3826
  'hedged': None,
4036
3827
  'timestamp': timestamp,
4037
3828
  'datetime': self.iso8601(timestamp),
4038
- 'lastUpdateTimestamp': None,
4039
- 'maintenanceMargin': self.parse_number(maintenanceMargin),
4040
- 'maintenanceMarginPercentage': self.parse_number(maintenanceMarginPercentage),
4041
- 'collateral': self.parse_number(collateral),
4042
- 'initialMargin': self.parse_number(initialMargin),
4043
- 'initialMarginPercentage': self.parse_number(initialMarginPercentage),
4044
- 'leverage': self.parse_number(leverage),
4045
- 'marginRatio': None,
3829
+ 'lastUpdateTimestamp': self.safe_integer(position, 'updated_at'),
3830
+ 'maintenanceMargin': self.safe_number(position, 'maintenance_margin_value'),
3831
+ 'maintenanceMarginPercentage': self.safe_number(position, 'maintenance_margin_rate'),
3832
+ 'collateral': self.safe_number(position, 'margin_avbl'),
3833
+ 'initialMargin': None,
3834
+ 'initialMarginPercentage': None,
3835
+ 'leverage': self.safe_number(position, 'leverage'),
3836
+ 'marginRatio': self.safe_number(position, 'position_margin_rate'),
4046
3837
  'stopLossPrice': self.omit_zero(self.safe_string(position, 'stop_loss_price')),
4047
3838
  'takeProfitPrice': self.omit_zero(self.safe_string(position, 'take_profit_price')),
4048
3839
  })
@@ -4050,10 +3841,11 @@ class coinex(Exchange, ImplicitAPI):
4050
3841
  def set_margin_mode(self, marginMode: str, symbol: Str = None, params={}):
4051
3842
  """
4052
3843
  set margin mode to 'cross' or 'isolated'
4053
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http014_adjust_leverage
3844
+ :see: https://docs.coinex.com/api/v2/futures/position/http/adjust-position-leverage
4054
3845
  :param str marginMode: 'cross' or 'isolated'
4055
3846
  :param str symbol: unified market symbol
4056
3847
  :param dict [params]: extra parameters specific to the exchange API endpoint
3848
+ :param int params['leverage']: the rate of leverage
4057
3849
  :returns dict: response from the exchange
4058
3850
  """
4059
3851
  if symbol is None:
@@ -4065,30 +3857,33 @@ class coinex(Exchange, ImplicitAPI):
4065
3857
  market = self.market(symbol)
4066
3858
  if market['type'] != 'swap':
4067
3859
  raise BadSymbol(self.id + ' setMarginMode() supports swap contracts only')
4068
- defaultPositionType = None
4069
- if marginMode == 'isolated':
4070
- defaultPositionType = 1
4071
- elif marginMode == 'cross':
4072
- defaultPositionType = 2
4073
3860
  leverage = self.safe_integer(params, 'leverage')
4074
3861
  maxLeverage = self.safe_integer(market['limits']['leverage'], 'max', 100)
4075
- positionType = self.safe_integer(params, 'position_type', defaultPositionType)
4076
3862
  if leverage is None:
4077
3863
  raise ArgumentsRequired(self.id + ' setMarginMode() requires a leverage parameter')
4078
- if positionType is None:
4079
- raise ArgumentsRequired(self.id + ' setMarginMode() requires a position_type parameter that will transfer margin to the specified trading pair')
4080
- if (leverage < 3) or (leverage > maxLeverage):
4081
- raise BadRequest(self.id + ' setMarginMode() leverage should be between 3 and ' + str(maxLeverage) + ' for ' + symbol)
3864
+ if (leverage < 1) or (leverage > maxLeverage):
3865
+ raise BadRequest(self.id + ' setMarginMode() leverage should be between 1 and ' + str(maxLeverage) + ' for ' + symbol)
4082
3866
  request = {
4083
3867
  'market': market['id'],
4084
- 'leverage': str(leverage),
4085
- 'position_type': positionType, # 1: isolated, 2: cross
3868
+ 'market_type': 'FUTURES',
3869
+ 'margin_mode': marginMode,
3870
+ 'leverage': leverage,
4086
3871
  }
4087
- return self.v1PerpetualPrivatePostMarketAdjustLeverage(self.extend(request, params))
3872
+ return self.v2PrivatePostFuturesAdjustPositionLeverage(self.extend(request, params))
3873
+ #
3874
+ # {
3875
+ # "code": 0,
3876
+ # "data": {
3877
+ # "leverage": 1,
3878
+ # "margin_mode": "isolated"
3879
+ # },
3880
+ # "message": "OK"
3881
+ # }
3882
+ #
4088
3883
 
4089
3884
  def set_leverage(self, leverage: Int, symbol: Str = None, params={}):
4090
3885
  """
4091
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http014_adjust_leverage
3886
+ :see: https://docs.coinex.com/api/v2/futures/position/http/adjust-position-leverage
4092
3887
  set the level of leverage for a market
4093
3888
  :param float leverage: the rate of leverage
4094
3889
  :param str symbol: unified market symbol
@@ -4104,21 +3899,27 @@ class coinex(Exchange, ImplicitAPI):
4104
3899
  raise BadSymbol(self.id + ' setLeverage() supports swap contracts only')
4105
3900
  marginMode = None
4106
3901
  marginMode, params = self.handle_margin_mode_and_params('setLeverage', params, 'cross')
4107
- positionType = None
4108
- if marginMode == 'isolated':
4109
- positionType = 1
4110
- elif marginMode == 'cross':
4111
- positionType = 2
4112
3902
  minLeverage = self.safe_integer(market['limits']['leverage'], 'min', 1)
4113
3903
  maxLeverage = self.safe_integer(market['limits']['leverage'], 'max', 100)
4114
3904
  if (leverage < minLeverage) or (leverage > maxLeverage):
4115
3905
  raise BadRequest(self.id + ' setLeverage() leverage should be between ' + str(minLeverage) + ' and ' + str(maxLeverage) + ' for ' + symbol)
4116
3906
  request = {
4117
3907
  'market': market['id'],
4118
- 'leverage': str(leverage),
4119
- 'position_type': positionType, # 1: isolated, 2: cross
3908
+ 'market_type': 'FUTURES',
3909
+ 'margin_mode': marginMode,
3910
+ 'leverage': leverage,
4120
3911
  }
4121
- return self.v1PerpetualPrivatePostMarketAdjustLeverage(self.extend(request, params))
3912
+ return self.v2PrivatePostFuturesAdjustPositionLeverage(self.extend(request, params))
3913
+ #
3914
+ # {
3915
+ # "code": 0,
3916
+ # "data": {
3917
+ # "leverage": 1,
3918
+ # "margin_mode": "isolated"
3919
+ # },
3920
+ # "message": "OK"
3921
+ # }
3922
+ #
4122
3923
 
4123
3924
  def fetch_leverage_tiers(self, symbols: Strings = None, params={}):
4124
3925
  """
@@ -4878,14 +4679,14 @@ class coinex(Exchange, ImplicitAPI):
4878
4679
  'toAccount': toAccount,
4879
4680
  })
4880
4681
 
4881
- def parse_transfer_status(self, status):
4682
+ def parse_transfer_status(self, status: Str) -> Str:
4882
4683
  statuses = {
4883
4684
  '0': 'ok',
4884
4685
  'SUCCESS': 'ok',
4885
4686
  }
4886
4687
  return self.safe_string(statuses, status, status)
4887
4688
 
4888
- def parse_transfer(self, transfer, currency: Currency = None):
4689
+ def parse_transfer(self, transfer: dict, currency: Currency = None) -> TransferEntry:
4889
4690
  #
4890
4691
  # fetchTransfers Swap
4891
4692
  #
@@ -4932,7 +4733,7 @@ class coinex(Exchange, ImplicitAPI):
4932
4733
  currencyCode = self.safe_currency_code(currencyId, currency)
4933
4734
  return {
4934
4735
  'info': transfer,
4935
- 'id': self.safe_integer(transfer, 'id'),
4736
+ 'id': self.safe_string(transfer, 'id'),
4936
4737
  'timestamp': timestamp,
4937
4738
  'datetime': self.iso8601(timestamp),
4938
4739
  'currency': currencyCode,
@@ -4942,7 +4743,7 @@ class coinex(Exchange, ImplicitAPI):
4942
4743
  'status': self.parse_transfer_status(self.safe_string_2(transfer, 'code', 'status')),
4943
4744
  }
4944
4745
 
4945
- def fetch_transfers(self, code: Str = None, since: Int = None, limit: Int = None, params={}):
4746
+ def fetch_transfers(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> TransferEntries:
4946
4747
  """
4947
4748
  fetch a history of internal transfers made on an account
4948
4749
  :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account025_margin_transfer_history
@@ -5567,7 +5368,7 @@ class coinex(Exchange, ImplicitAPI):
5567
5368
  leverages = self.safe_list(response, 'data', [])
5568
5369
  return self.parse_leverages(leverages, symbols, 'market', marketType)
5569
5370
 
5570
- def parse_leverage(self, leverage, market=None) -> Leverage:
5371
+ def parse_leverage(self, leverage: dict, market: Market = None) -> Leverage:
5571
5372
  marketId = self.safe_string(leverage, 'market')
5572
5373
  leverageValue = self.safe_integer(leverage, 'leverage')
5573
5374
  return {
@@ -5581,71 +5382,70 @@ class coinex(Exchange, ImplicitAPI):
5581
5382
  def fetch_position_history(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> Position:
5582
5383
  """
5583
5384
  fetches historical positions
5584
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033-0_finished_position
5385
+ :see: https://docs.coinex.com/api/v2/futures/position/http/list-finished-position
5585
5386
  :param str symbol: unified contract symbol
5586
- :param int [since]: not used by coinex fetchPositionHistory
5587
- :param int [limit]: the maximum amount of records to fetch, default=1000
5588
- :param dict params: extra parameters specific to the exchange api endpoint
5589
- *
5590
- * EXCHANGE SPECIFIC PARAMETERS
5591
- :param int [params.side]: 0: all 1: sell, 2: buy
5387
+ :param int [since]: the earliest time in ms to fetch positions for
5388
+ :param int [limit]: the maximum amount of records to fetch, default is 10
5389
+ :param dict [params]: extra parameters specific to the exchange api endpoint
5390
+ :param int [params.until]: the latest time in ms to fetch positions for
5592
5391
  :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
5593
5392
  """
5594
5393
  self.load_markets()
5595
5394
  market = self.market(symbol)
5596
- if limit is None:
5597
- limit = 1000
5598
5395
  request = {
5396
+ 'market_type': 'FUTURES',
5599
5397
  'market': market['id'],
5600
- 'side': 0,
5601
- 'limit': limit,
5602
5398
  }
5603
- response = self.v1PerpetualPrivateGetPositionFinished(self.extend(request, params))
5399
+ if limit is not None:
5400
+ request['limit'] = limit
5401
+ if since is not None:
5402
+ request['start_time'] = since
5403
+ request, params = self.handle_until_option('end_time', request, params)
5404
+ response = self.v2PrivateGetFuturesFinishedPosition(self.extend(request, params))
5604
5405
  #
5605
- # {
5606
- # code: '0',
5607
- # data: {
5608
- # limit: '1000',
5609
- # offset: '0',
5610
- # records: [
5611
- # {
5612
- # amount_max: '10',
5613
- # amount_max_margin: '2.03466666666666666666',
5614
- # bkr_price: '0',
5615
- # create_time: '1711150526.2581',
5616
- # deal_all: '12.591',
5617
- # deal_asset_fee: '0',
5618
- # fee_asset: '',
5619
- # finish_type: '5',
5620
- # first_price: '0.6104',
5621
- # latest_price: '0.6487',
5622
- # leverage: '3',
5623
- # liq_amount: '0',
5624
- # liq_price: '0',
5625
- # liq_profit: '0',
5626
- # mainten_margin: '0.01',
5627
- # market: 'XRPUSDT',
5628
- # market_type: '1',
5629
- # open_price: '0.6104',
5630
- # open_val_max: '6.104',
5631
- # position_id: '297371462',
5632
- # profit_real: '0.35702107169',
5633
- # settle_price: '0.6104',
5634
- # settle_val: '0',
5635
- # side: '2',
5636
- # sy s: '0',
5637
- # type: '2',
5638
- # update_time: '1711391446.133233',
5639
- # user_id: '3685860'
5640
- # },
5641
- # ...
5642
- # ]
5643
- # },
5644
- # message: 'OK'
5645
- # }
5406
+ # {
5407
+ # "code": 0,
5408
+ # "data": [
5409
+ # {
5410
+ # "position_id": 305891033,
5411
+ # "market": "BTCUSDT",
5412
+ # "market_type": "FUTURES",
5413
+ # "side": "long",
5414
+ # "margin_mode": "cross",
5415
+ # "open_interest": "0.0001",
5416
+ # "close_avbl": "0.0001",
5417
+ # "ath_position_amount": "0.0001",
5418
+ # "unrealized_pnl": "0",
5419
+ # "realized_pnl": "-0.00311684",
5420
+ # "avg_entry_price": "62336.8",
5421
+ # "cml_position_value": "6.23368",
5422
+ # "max_position_value": "6.23368",
5423
+ # "created_at": 1715152208041,
5424
+ # "updated_at": 1715152208041,
5425
+ # "take_profit_price": "0",
5426
+ # "stop_loss_price": "0",
5427
+ # "take_profit_type": "",
5428
+ # "stop_loss_type": "",
5429
+ # "settle_price": "62336.8",
5430
+ # "settle_value": "6.23368",
5431
+ # "leverage": "3",
5432
+ # "margin_avbl": "2.07789333",
5433
+ # "ath_margin_size": "2.07789333",
5434
+ # "position_margin_rate": "2.40545879023305655728",
5435
+ # "maintenance_margin_rate": "0.005",
5436
+ # "maintenance_margin_value": "0.03118094",
5437
+ # "liq_price": "0",
5438
+ # "bkr_price": "0",
5439
+ # "adl_level": 1
5440
+ # }
5441
+ # ],
5442
+ # "message": "OK",
5443
+ # "pagination": {
5444
+ # "has_next": False
5445
+ # }
5446
+ # }
5646
5447
  #
5647
- data = self.safe_dict(response, 'data')
5648
- records = self.safe_list(data, 'records')
5448
+ records = self.safe_list(response, 'data', [])
5649
5449
  positions = self.parse_positions(records)
5650
5450
  return self.filter_by_symbol_since_limit(positions, symbol, since, limit)
5651
5451