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