
    !:h                       d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# d dl$m%Z% d dl&m'Z' d dl&m(Z( d dl&m)Z) d d	l&m*Z* d d
l&m+Z+ d dl&m,Z, d dl&m-Z- d dl&m.Z. d dl&m/Z/ d dl&m0Z0 d dl&m1Z1 d dl&m2Z2 d dl&m3Z3 d dl&m4Z4 d dl5m6Z6 d dl7m8Z8  G d dee      Z9y)    )Exchange)ImplicitAPIN)AnyBalancesBorrowInterest
CurrenciesCurrencyDepositAddressIntIsolatedBorrowRateLeverageLeverageTierLeverageTiersMarginModificationMarketNumOrderOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeeInterfaceTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)RateLimitExceeded)ExchangeNotAvailable)RequestTimeout)	TICK_SIZE)Precisec                       e Zd Zdef fdZi fdefdZi fdee   fdZ	dee   fdZ
d Zd~ded	edefd
Zi fdedefdZdi fdedefdZi fdefdZdi fdedefdZd~ded	edefdZddi fdedededee   fdZi fdedefdZi fdefdZd~ded	edefdZd~d	edefdZ dddi fdedededee   fdZ!i fdZ"i fdZ#i fd Z$i fd!Z%i fde&fd"Z'd#e(fd$Z)d~d%ed	ede*fd&Z+i fded'e,fd(Z-di fded)e.d*e/d+e,d,e0f
d-Z1di fded)e.d*e/d+e,d,e0f
d.Z2i fd/ee3   dee*   fd0Z4di fde(fd1Z5ddi fd2eded)e.d*e/d+e0d,e0fd3Z6di fd2ede(fd4Z7di fde(fd5Z8di fd2ede(fd6Z9dddi fde(dedefd7Z:dddi fde(dededee*   fd8Z;dddi fde(dededee*   fd9Z<i fd:ede=fd;Z>i fd:ede=fd<Z?d~d=e@de=fd>ZAdddi fde(dedefd?ZBdi fdedeeC   fd@ZDi fdefdAZEd~dBed	efdCZFdi fdDede(fdEZGdi fdFede(fdGZHdi fdedeIfdHZJd~d	edeeK   fdIZLi fdefdJZMd~dKed	edeNfdLZOi fded+e,deNfdMZPi fded+e,deNfdNZQdddi fde(dedefdOZRi fdedeSfdPZTi fdedeSfdQZUd~d	edeSfdRZVdS ZWdi fdedeXfdTZYdi fd:ed+e,dUedeZfdVZ[d#e(fdWZ\dddi fde(dedefdXZ]d~dYed=e@deZfdZZ^i fd:ed+e,d[ed\ede_f
d]Z`d^ Zad~d_ed=e@de_fd`Zbdddi fd:e(dededee_   fdaZcdddi fd:e(dededeeZ   fdbZddddi fd:e(dededeeZ   fdcZed~dded	edeffdeZgi fdedeffdfZhddddi fd:e(de(dededeei   f
dgZjd~dded	edeifdhZki fded:ed+e,fdiZli fded:efdjZmd~d=e@fdkZni fd:efdlZod~d=e@fdmZpi fdedeqfdnZrd~dFed	edeqfdoZsddi fdedededeeC   fdpZtdi fded*e/de*fdqZui df fdr	Zvds Zwg dti ddfduZxdveydwedxedyedzed{efd|Zzddddi fde(d)e(de0de0deeN   f
d}Z{ xZ|S )coinexreturnc                    | j                  t        t        |          i ddddddddgd	d
dddddi dd ddddddddddddddddddddddddddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEdFdGddHddIddJddKddLddMddNddOddPddQddRddSddTdi dUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddeddfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdwdxdxdydzd{d|d}d~dddddddddddddddddii ddddddddddddddddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddidddddddddddddddd	ddddddddddddd
iddddddddddddddddi ddddddddddddddddddddddddddddddddddddddddddydi ddddddddddddddddddddddddddddddddddddddddҜii ddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddd dddddddi ddddddddddd	dd
dddddddddddddddddddddddddddddddddddddddddddedddddddid d!d"dd d#id$d%ddd&d'did(d)d*d+dddd,i d-d-d.d/d0d0d1d1d2d2d3d3d4d4d5d5d6d7d8d9d:d:d;d;d<d=d>d>d?d@dAdBdCdDi dEdFdGdGdHdHdIdIdJdJdKdKdLdLdMdMdNdNdOdOdPdPdQdRdSdSdTdTdUdUdVdWdXdXdYdZd[d\d]dddd dddd ddddd^dddddddd_d`daiddbd dcddddddddeddbddddfd ddbd d d ddddgdhdbidi	dddddjdkdidkdidldmdnidmdnidod d dodpdqdrdsidtt        dui dvt
        dwt        dxt        dyt        dzt        d{t        d|t        d}t        d~t
        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt
        dt        dt        dt        dt
        dt        dt        dt         t        t        t        t        t
        dt
        t        ddi      S (  Nidr5   nameCoinExversionv2	countriesCN	rateLimitg      @proT	certifiedhasCORSspotmarginswapfutureFoption	addMarginborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreateReduceOnlyOrdercreateStopLossOrdercreateStopOrdercreateTakeProfitOrdercreateTriggerOrder	editOrderfetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLeveragesfetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarketLeverageTiersemulatedfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenOrders
fetchOrderfetchOrderBookfetchPositionfetchPositionHistoryfetchPositionsfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransferfetchTransfersfetchWithdrawalfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeveragesetMarginModesetPositionModetransferwithdraw
timeframes1min3min5min15min30min1hour2hour4hour6hour12hour1day3day1week)1m3m5m15m30m1h2h4h6h12h1d3d1wurlszdhttps://user-images.githubusercontent.com/51840849/87182089-1e05fa00-c2ec-11ea-8da9-cc73b45abbbc.jpgzhttps://api.coinex.comz https://api.coinex.com/perpetual)publicprivateperpetualPublicperpetualPrivatezhttps://www.coinex.comzhttps://docs.coinex.com/api/v2zhttps://www.coinex.com/feesz0https://www.coinex.com/register?refer_code=yw5fz)logoapiwwwdocfeesreferralr   get   )z
amm/marketzcommon/currency/ratezcommon/asset/configzcommon/maintain/infozcommon/temp-maintain/infozmargin/marketzmarket/infomarket/listmarket/tickermarket/ticker/allmarket/depthmarket/dealsmarket/klinezmarket/detailzaccount/amm/balance(   zaccount/investment/balancezaccount/balance/historyzaccount/market/feezbalance/coin/depositbalance/coin/withdrawzbalance/info#balance/deposit/address/{coin_type}zcontract/transfer/historyzcredit/infozcredit/balancezinvestment/transfer/historyzmargin/accountzmargin/configzmargin/loan/historyzmargin/transfer/historyzorder/deals   )order/finishedorder/pendingorder/statuszorder/status/batchzorder/user/dealszorder/stop/finishedorder/stop/pendingzorder/user/trade/feezorder/market/trade/infozsub_account/balancezsub_account/transfer/historysub_account/auth/api#sub_account/auth/api/{user_auth_id}zcontract/balance/transferzmargin/flatzmargin/loanzmargin/transferzorder/limit/batchz	order/iocg^I*@zorder/limitzorder/marketzorder/modifyzorder/stop/limitzorder/stop/marketzorder/stop/modifyzsub_account/transferzsub_account/registersub_account/unfrozensub_account/frozenr   )r   r   r   r   zv1/account/settings)	r   zorder/pending/batchr   r   zorder/stop/pending/{id}zorder/pending/by_client_idzorder/stop/pending/by_client_idr   zsub_account/authorize/{id})r   postputdelete)
pingtimer   zmarket/limit_configr   r   r   r   zmarket/funding_historyr   )zmarket/user_dealszasset/queryr   r   zorder/stop_finishedzorder/stop_pendingr   zorder/stop_statuszposition/finishedzposition/pendingzposition/fundingzposition/adl_historymarket/preferencezposition/margin_historyzposition/settle_historyzmarket/adjust_leveragezmarket/position_expectzorder/put_limit   zorder/put_marketzorder/put_stop_limitzorder/put_stop_marketzorder/modify_stopzorder/cancelzorder/cancel_allzorder/cancel_batchzorder/cancel_stopzorder/cancel_stop_allzorder/close_limitzorder/close_marketzposition/adjust_marginzposition/stop_loss)zposition/take_profitzposition/market_closezorder/cancel/by_client_idzorder/cancel_stop/by_client_idr   )r   r   zmaintain/infor   r   zspot/marketzspot/tickerz
spot/depthz
spot/dealsz
spot/klinez
spot/indexzfutures/marketzfutures/tickerzfutures/depthzfutures/dealszfutures/klinezfutures/indexzfutures/funding-ratezfutures/funding-rate-history)zfutures/position-levelzfutures/liquidation-historyzfutures/basis-historyzassets/deposit-withdraw-configz"assets/all-deposit-withdraw-configzaccount/subszaccount/subs/api-detailzaccount/subs/infozaccount/subs/apizaccount/subs/transfer-historyzaccount/subs/spot-balancezaccount/trade-fee-ratezassets/spot/balancezassets/futures/balancezassets/margin/balancezassets/financial/balancezassets/amm/liquidityzassets/credit/infozassets/margin/borrow-historyzassets/margin/interest-limitzassets/deposit-addresszassets/deposit-historyzassets/withdrawzassets/transfer-historyzspot/order-statuszspot/batch-order-statuszspot/pending-orderzspot/finished-orderzspot/pending-stop-orderzspot/finished-stop-orderzspot/user-dealszspot/order-dealszfutures/order-statuszfutures/batch-order-statuszfutures/pending-orderzfutures/finished-orderzfutures/pending-stop-orderzfutures/finished-stop-orderzfutures/user-deals)zfutures/order-dealszfutures/pending-positionzfutures/finished-positionzfutures/position-margin-historyz futures/position-funding-historyzfutures/position-adl-historyzfutures/position-settle-historyzaccount/subs/frozenzaccount/subs/unfrozenzaccount/subs/edit-apizaccount/subs/delete-apizaccount/subs/transferzaccount/settingszassets/margin/borrowzassets/margin/repayzassets/renewal-deposit-addresszassets/cancel-withdrawzassets/transferzassets/amm/add-liquidityzassets/amm/remove-liquidityz
spot/orderzspot/stop-orderzspot/batch-orderzspot/batch-stop-orderzspot/modify-orderzspot/modify-stop-orderzspot/cancel-all-orderzspot/cancel-orderg^I@zspot/cancel-stop-orderzspot/cancel-batch-order
   zspot/cancel-batch-stop-orderzspot/cancel-order-by-client-idz#spot/cancel-stop-order-by-client-idzfutures/orderzfutures/stop-orderzfutures/batch-orderzfutures/batch-stop-orderzfutures/modify-order)zfutures/modify-stop-orderzfutures/cancel-all-orderzfutures/cancel-orderzfutures/cancel-stop-orderzfutures/cancel-batch-orderzfutures/cancel-batch-stop-orderz!futures/cancel-order-by-client-idz&futures/cancel-stop-order-by-client-idzfutures/close-positionzfutures/adjust-position-marginz futures/adjust-position-leveragezfutures/set-position-stop-lossz futures/set-position-take-profit)r   r   )v1r<   r   gMbP?)makertakerg        g-C6?)BCHBTCLTCETHZECDASH)tradingfundinglimitsamountminmaxoptionsx-167673045linearfillResponseFromRequestSPOTMARGINFUTURES)rD   rE   rF   )r   r   r   r   BEP20BSCTRC20ERC20BRC20SOLTONBSVAVAXCAVA_CAVAXXAVASUIACACHZCHILIZADAARBARBITRUMARBNOVAARBITRUM_NOVAOPOPTIMISMAPTAPTOSATOMFTMr   ASTRr   MATICCRONOSr   DOTETCETHWETHPOWFILZILDOGETIACELESTIASEIXRPXMR)r  r  )brokerId!createMarketBuyOrderRequiresPricedefaultTypedefaultSubTypere   accountsByTypeaccountsByIdnetworksfeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergr        i )r(  limitdaysBack	untilDayssymbolRequired)r(  triggerr1  r<  )r(  r9  r=  r1  r<  )r(  r9  r:  daysBackCanceledr;  r=  r1  r<  r9  )	sandboxrU   rV   r|   r   r~   fetchOrdersra   r}   )r(  r,  r-  r(  )extendsrU   r~   ra   rA  forDerivatives)r   inverse)rD   rB  rF   rG   commonCurrenciesACMActiniumprecisionMode
exceptions23242534353621310715860060160260630083109312736003606361036123613361436153616361736183619362036213622362736283629363236333634363540014002400340044005400640074008400940104011401741154117)41234130415842134512)zip not allow visitzservice too busy)exactbroad)deep_extendsuperr5   describer2   r&   r%   r0   r1   r/   r+   r-   r,   r$   r)   r'   r*   )self	__class__s    S/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/async_support/coinex.pyr  zcoinex.describe   s   fd < > D
A
(D
A
HD
A
 tD
A
 $	D
A
 D
A
 4D
A
  !D
A
"  VVV $V 	V
 %V %V TV $UV 'V "4V tV V $UV  V 'V  /!V" ,U#V$ 0%V& t'V( )V* (+V, &t-V. "4/V0 (1V2 %d3V4 T5V6 7V8 &t9V: +E;V< )%=V> $T?V@ 'AVB (CVD "4EVF &tGVH (IVJ 1%KVL  MVN *4OVP +EQVR &tSVT 'UVV (WVX #DYVZ *4[V\ $T]V^ "5_V` *4aVb +EcVd  eVf !%gVh %diVj /kVl +JmVn oVp !%qVr  sVt duVv "4wVx dyVz !${V|  }V~ 'V@ !$AVB (CVD %eEVF )%GVH tIVJ KVL TMVN tOVP "4QVR #DSVT  UVV !$WVX "5YVZ #D[V\ ]V^ #E_V` &taVb tcVd  eVf "5gVh DiVj DkV#D
A
P QD
A
n ~67'I(J	 075NoD
A
H  *+4534459:-.+,+,-.12,-,-,--. & 12 8"  6r  1"	 
 3B  4R  +B  B2  8  *2  -b  :2  -a  ,Q  22   6r! " *2# $ /1-.,-23023523457834<>46CE= @!3R!7! *2! *2	!
 .r! 0! (! *6! +F! +F! /! 0! 0! 3B! 3A!  3B!!" 1"#!$ 3B%!* DF4624CE35  6835-3247=:<?ACE:<
#yG R $%$%+,34-.12,-,-67,- (  23+--..03523,-1213020246137979 "!4a!4a! .r! /	!
 3B! 4R! +B! 0! +B! /! 1"! 0! 4R! 0! 1"!  5b!!" 1"#!$ 57579;>@13-!%*)STn   +Q "A  #A  *1	 
 *1  )!  )!  )!  )!  -a  -a  ,Q  ,Q  ,Q  ,Q   3A! " ;A# $ 78;<56>?BC- 6* *A* 5r*  0*  /	* 
 <R*  8*  5b*  22*  5b*  4Q*  7*  3B*  1"*  ;B*  ;A*   5b!* " 5b#* $ .r%* & 6r'* ( 0)* * 6q+* , 1!-* . 22/* 0 6q1* 2 73* 4 .r5* 6 /7* 8 3A9* : 9!;* < 4Q=* > 5b?* @ 9!A* B :2C* D 1!E* F 458:9:?@@B<=?@S* V0!*B0!120! 4R0! /	0!
 4R0! 6r0! 4R0! /0! 3B0! 220! =b0! .r0! 5b0! .r0! 70!  :1!0!" )&#0!$ .v%0!& /'0!( 4Q)0!* 0+0!, 5f-0!. 4Q/0!0 010!2 5e30!4 6r50!6 ;B70!8 =a90!: B1;0!< ,R=0!> 1"?0!@ 21A0!B 7C0!D 3BE0!F :<89469;:<?AABFG68>@@B>@@B_0!Y] 7ymPID
A
j ""
 "$$$% &!	kD
A
J  KD
A
V )59%"*-t( #&%# #&%!
&5&U& W& W	&
 W& 5& 5& 5& W& U& 5& 5& 8& 5& :&  !&" *#&$ 7%&& F'&( 5)&* 5+&, F-&. 5/&0 W1&2 h3&4 F5&6 57&8 59&: H;&< 5=&> 5?&@ FA&B :C&D 5E&F ! I&%9WD
A
J $&*(,,0,1).+06:#'#'"&#(	( #($)$)+/26/3#')$. q% '+!%$(%+*.& ',#($)*.	# '+!%#'$)*/( $(&*!%$(,0%)#'$)*/	*  #u=~  &&*)-+/$ %e( %e*#  "#3 "#3 	 ##kYKD
A
~ z!D
A
D YED
A
F :*: -: -	:
 -: .: .: ,: ,: +: =: <: <: <: N:  -!:" L#:$ M%:& L':( M):* L+:, L-:. L/:0 L1:2 L3:4 L5:6 L7:8 L9:: L;:< L=:> L?:@ LA:B LC:D LE:F LG:H LI:J LK:L LM:N 0O:P NQ:R MS:T JU:V /W:X /Y:Z ,[:\ /]:^ M_:` Ma:b ,c:d Me:f ,g:h Ii:j .))-,s:x +;(<y@GD
A
 D
 D
	    c                   K   | j                  |       d{   }| j                  |dg       }i }t        dt        |            D ]  }||   }| j	                  |di       }| j                  |dg       }| j                  |d      }	|	D| j                  |	      }
| j                  |d      }| j                  |d      }| j	                  |di       }| j                  | j                  |d	            }i }t        dt        |            D ]  }||   }| j                  |d
      }|| j                  | j                  |d	            }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }||d|xr |||| j                  |      | j                  |      ddd| j                  |      dd| j                  |      ddd|d
}|||<    | j                  |	|
d|xr |||d| j                  |      ddddddddddi d|d      ||
<     |S 7 2w)a@  
        fetches all available currencies on an exchange

        https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/list-all-deposit-withdrawal-config

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        Ndatar   assetchainsccydeposit_enabledwithdraw_enabledwithdrawal_precisionchainwithdrawal_feemin_deposit_amountmin_withdraw_amountr   )r   depositr   )
r8   networkr9   activer  r   fee	precisionr   infocrypto)r8   coder9   r  r  r   r  r  r   r"  typer  ))v2PublicGetAssetsAllDepositWithdrawConfig	safe_listrangelen	safe_dictsafe_stringsafe_currency_code	safe_boolparse_precisionparse_numbersafe_currency_structure)r  paramsresponser  resulticoinr  r  
currencyIdr  
canDepositcanWithdraw
firstChainfirstPrecisionStringr"  jr  	networkIdprecisionString	feeStringminNetworkDepositStringminNetworkWithdrawStringcanDepositChaincanWithdrawChainr  s                             r  fetch_currencieszcoinex.fetch_currencies  s     GGOOH ~~h3q#d)$ L	A7DNN4"5E^^D(B7F))%7J!**:6D/@AJ..0BCK26J#'#7#78H8HUk8l#m H1c&k* $.q	 ,,UG<	$"&"6"6t7G7GOe7f"g ,,U4DE	*.*:*:5BV*W'+/+;+;ECX+Y("&..8I"J#'>>%9K#L #( -B2B. 0,,Y7!%!2!2?!C $(#'#
 $(#4#45L#M#'$
 $(#4#45M#N#'% "/!2 '.#I$.J  77 $4%'!../CD  $#
  $# 
  $#!  39 F4LeL	Z g Ps   II	H2Ic                    K   | j                  |      | j                  |      g}t        j                  |  d{   }|d   }|d   }| j	                  ||      S 7  w)ab  
        retrieves data on all markets for coinex

        https://docs.coinex.com/api/v2/spot/market/http/list-market
        https://docs.coinex.com/api/v2/futures/market/http/list-market

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nr   r   )fetch_spot_marketsfetch_contract_marketsasynciogatherarray_concat)r  r  promisesUnresolvedpromisesspotMarketsswapMarketss         r  fetch_marketszcoinex.fetch_markets$  sj      ##F+''/
 !);<<qkqk  k:: =s   8AA!Ac                 X  K   | j                  |       d {   }| j                  |dg       }g }t        dt        |            D ][  }||   }| j	                  |d      }| j	                  |d      }| j	                  |d      }	| j                  |      }
| j                  |	      }|
dz   |z   }|j                  i d|d|d	|
d
|dd d|d|	dd dddddd dddddddd dddd d | j                  |d      | j                  |d      d d d d d | j                  | j                  | j	                  |d                  | j                  | j                  | j	                  |d                  dd d d| j                  |d       d dd d dd d dd!d |d"       ^ |S 7 w)#Nr  r   marketbase_ccy	quote_ccy/r8   symbolbasequotesettlebaseIdquoteIdsettleIdr  rD   TrE   rF   FrG   rH   r  contractr   taker_fee_ratemaker_fee_ratebase_ccy_precisionquote_ccy_precisionr   pricer   
min_amountr2  r   r  costrC  r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper  r   createdr  )
v2PublicGetSpotMarketr  r  r  r  r  appendsafe_numberr  r  )r  r  r  marketsr  r  r  r8   r  r  r  r  r  s                r  r  zcoinex.fetch_spot_markets7  s    33F;;* ..626q#g,' :	AQZF!!&(3B%%fj9F&&v{;G**62D++G4ECZ%'FMM 2b2&2 2 	2
 $2 &2 72 D2 2 2 $2 2 %2 %2 $2  E!2" $#2$  ))&2BC))&2BC $"&""//0D0DTEUEUV\^rEs0tu!..t/C/CDDTDTU[]rDs/tu  $#!
  $//E#
  $#
  $#$  c2 2:	v e <s   F*F'FF*c                 `  K   | j                  |       d {   }| j                  |dg       }g }t        dt        |            D ]  }||   }| j                  }| j                  |dg       }| j                  |d      }	|	dk(  }
|	dk(  }| j                  |d      }| j                  |d      }| j                  |d	      }| j                  |      }| j                  |      }|	dk(  rd
n|}| j                  |      }|dz   |z   dz   |z   }t        |      }|j                  i d|d|d|d|d|d|d|d|dddddddddddddd ddd|
||d   d    |d   d!   | j                  d"      d d d d | j                  | j                  | j                  |d#                  | j                  | j                  | j                  |d$                  d%| j                  |d      | j                  ||d&z
        d'| j                  |d(      d d'd d d'd d d'd)d |d*        |S 7 w)+Nr  r   r2  contract_typer   rC  r  r  r  USDTr  :r8   r  r  r  r  r  r  r  r  rF   rD   FrE   TrG   rH   r  r  r   r   r   1r  r  r  r   r   r  r  r  )v2PublicGetFuturesMarketr  r  r  r   r  r  r  r  r  r  )r  r  r  r  r  r  entryr   	leveragessubTyper   rC  r8   r  r  r  r  r  r  r  leveragesLengths                        r  r  zcoinex.fetch_contract_markets  s    66v>>, ..626q#g,' B	AAJE99Duj"=I&&uo>G)F)+G!!%2B%%eZ8F&&uk:G**62D++G4E")X"5vFH,,X6FCZ%'#-6F!)nOMM 2b2&2 2 	2
 &2 &2 72 H2 2 2 %2 2 %2 %2 $2  D!2" &#2$ #i1i1 $ 1 1# 6"&""//0D0DTEUEUV[]qEr0st!..t/C/CDDTDTUZ\qDr/st  $//	1=#//	?Q;NO!
  $//|D#
  $#
  $#$  c2 2!B	F w ?s   H.H+HH.Ntickerr  c           
      8   d|v rdnd}| j                  |d      }| j                  ||d |      }| j                  i d|dd dd d| j                  |d      d	| j                  |d	      d
d d| j                  |d      dd d| j                  |d      dd d| j                  |d      d| j                  |d      d| j                  |d      dd dd dd dd | j                  |d      d | j                  |d      | j                  |d      |d|      S )N
mark_pricerF   rD   r  r  	timestampdatetimehighlowbid	bidVolume
volume_buyask	askVolumevolume_sellvwapopencloselastpreviousClosechange
percentageaveragevolumeindex_price)
baseVolumequoteVolume	markPrice
indexPricer  )r  safe_symbolsafe_ticker)r  r  r  
marketTypemarketIdr  s         r  parse_tickerzcoinex.parse_ticker  s   H !- 6VV
##FH5!!(FD*E !
f!
!
 !
 D$$VV4	!

 4##FE2!
 4!
 ))&,?!
 4!
 ))&-@!
 D!
 D$$VV4!
 T%%fg6!
 D$$VV4!
 T!
 d!
  $!!
" t#!
$ **68<))&,?**6=A-!
. / 	r  r  c                   K   | j                          d{    | j                  |      }d|d   i}d}|d   r*| j                  | j                  ||             d{   }n)| j	                  | j                  ||             d{   }| j                  |dg       }| j                  |di       }| j                  ||      S 7 7 h7 @w)a+  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://docs.coinex.com/api/v2/spot/market/http/list-market-ticker
        https://docs.coinex.com/api/v2/futures/market/http/list-market-ticker

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr  r8   rF   r  r   )load_marketsr  v2PublicGetFuturesTickerextendv2PublicGetSpotTickerr  r  r  r  r  r  r  requestr  r  r  s           r  fetch_tickerzcoinex.fetch_ticker*  s      !!!V$fTl
 &>!::4;;wPV;WXXH!77GV8TUUH` ~~h3a,  00w 	" YU4   CCACC)CC		=CC	Csymbolsc                   K   | j                          d{    | j                  |      }d}|#| j                  |d      }| j                  |      }| j	                  d||      \  }}d}|dk(  r| j                  |       d{   }n| j                  |       d{   }| j                  |dg       }| j                  ||      S 7 7 E7 -w)al  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://docs.coinex.com/api/v2/spot/market/http/list-market-ticker
        https://docs.coinex.com/api/v2/futures/market/http/list-market-ticker

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr   r   rF   r  )	r  market_symbols
safe_valuer  handle_market_type_and_paramsr  r  r  parse_tickers)	r  r  r  r  r  r  queryr  r  s	            r  fetch_tickerszcoinex.fetch_tickersr  s      !!!%%g.__Wa0F[[(F >>~vW]^
E!::5AAH!77>>H` ~~h3!!$00y 	" B>s4   CCA-CC
CC*C
CCc                    K   | j                  |       d{   }| j                  |di       }| j                  |d      S 7 )w)aL  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://docs.coinex.com/api/v2/common/http/time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        Nr  r  )v2PublicGetTimer  safe_integer)r  r  r  r  s       r  
fetch_timezcoinex.fetch_time  sG      --f55 ~~h3  {33 6s   AA*Ar   r9  c                   K   | j                          d{    | j                  |      }|d}|d   |dd}d}|d   r*| j                  | j                  ||             d{   }n)| j	                  | j                  ||             d{   }| j                  |di       }| j                  |di       }| j                  |d	      }	| j                  |||	      S 7 7 {7 Sw)
a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://docs.coinex.com/api/v2/spot/market/http/list-market-depth
        https://docs.coinex.com/api/v2/futures/market/http/list-market-depth

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        Nr   r8   0)r  r9  intervalrF   r  depth
updated_at)r  r  v2PublicGetFuturesDepthr  v2PublicGetSpotDepthr  r&  parse_order_book)
r  r  r9  r  r  r  r  r  r+  r  s
             r  fetch_order_bookzcoinex.fetch_order_book  s      !!!V$=ETl

 &>!99$++gv:VWWH6 "66t{{7F7STTH4 ~~h3tWb1%%e\:	$$UFI>>G 	" X6 Us5   C$CAC$$C %)C$C"AC$ C$"C$tradec                 x   | j                  |d      }| j                  | j                  d      }||d   }| j                  |d      }| j                  ||d |      }| j                  |d      }d }|(| j                  |d      }| j	                  |      }	||	d}| j                  ||| j                  |      |d   | j                  |d	      | j                  |d
      d | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      |d|      S )N
created_atr  r  r  r  fee_ccyr  currencyr  deal_idorder_idsideroler  r   
deal_money)r  r  r  r  r8   orderr  r9  takerOrMakerr  r   r  r  )r&  r  r   safe_marketr  
safe_tradeiso8601)
r  r1  r  r  r  r  feeCostStringr  feeCurrencyIdfeeCurrencyCodes
             r  parse_tradezcoinex.parse_trade"  s]   P %%e\:	&&t||]C .K##E84!!(FD+F((6$ ,,UI>M"55mDO%+C "Y/X&""5)4%%eZ8$$UF3 ,,UF;%%eW5&&uh7$$UL9 
  	r  sincec                 f  K   | j                          d{    | j                  |      }d|d   i}|||d<   d}|d   r*| j                  | j                  ||             d{   }n)| j	                  | j                  ||             d{   }| j                  |d   |||      S 7 7 G7 w)az  
        get the list of the most recent trades for a particular symbol

        https://docs.coinex.com/api/v2/spot/market/http/list-market-deals
        https://docs.coinex.com/api/v2/futures/market/http/list-market-deals

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Nr  r8   r9  rF   r  )r  r  v2PublicGetFuturesDealsr  v2PublicGetSpotDealsparse_trades)r  r  rE  r9  r  r  r  r  s           r  fetch_tradeszcoinex.fetch_tradesi  s      !!!V$fTl
 $GG&>!99$++gv:VWWH!66t{{7F7STTH$   &!165%HH= 	" XTs4   B1B+AB1%B-&)B1B/B1-B1/B1c                   K   | j                          d{    | j                  |      }d|d   i}d}|d   r*| j                  | j                  ||             d{   }n)| j	                  | j                  ||             d{   }| j                  |dg       }| j                  |di       }| j                  ||      S 7 7 h7 @w)a  
        fetch the trading fees for a market

        https://docs.coinex.com/api/v2/spot/market/http/list-market
        https://docs.coinex.com/api/v2/futures/market/http/list-market

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        Nr  r8   rD   r  r   )r  r  r  r  r  r  r  parse_trading_feer  s           r  fetch_trading_feezcoinex.fetch_trading_fee  s      !!!V$fTl
 &>!77GV8TUUH, "::4;;wPV;WXXH, ~~h3a,%%ff55k 	" V, Yr  c                   K   | j                          d{    d}| j                  dd|      \  }}d}|dk(  r| j                  |       d{   }n| j                  |       d{   }| j	                  |dg       }i }t        dt        |            D ]G  }||   }| j                  |d      }| j                  |dd|      }	|	d   }
| j                  ||	      ||
<   I |S 7 7 7 ~w)a  
        fetch the trading fees for multiple markets

        https://docs.coinex.com/api/v2/spot/market/http/list-market
        https://docs.coinex.com/api/v2/futures/market/http/list-market

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        Nr   rF   r  r   r  r  )
r  r   r  r  r  r  r  r  r>  rL  )r  r  r  r  r  r  r  r  r  r  r  s              r  fetch_trading_feeszcoinex.fetch_trading_fees  s     !!!99:LdTZ[f6>!::6BBH. "77??H* ~~h3q#d)$ 	CAGE''x8H%%hdDAFH%F!33E6BF6N	C s 	"
 C. @s4   C)C#7C)C%C)(C')A;C)%C)'C)r  c                     | j                  |d      }| j                  ||      }||| j                  |d      | j                  |d      dddS )Nr  r  r  T)r  r  r   r   r  	tierBased)r  r  r  )r  r  r  r  r  s        r  rL  zcoinex.parse_trading_fee  s\    ??31!!(F3%%c+;<%%c+;<
 	
r  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr3  r  r  r  r  value)r&  r  )r  ohlcvr  s      r  parse_ohlcvzcoinex.parse_ohlcv)  sn     e\2UF+UF+UE*UG,UG,
 	
r  r   c                   K   | j                          d{    | j                  |      }|d   | j                  | j                  ||      d}|||d<   d}|d   r*| j	                  | j                  ||             d{   }n)| j                  | j                  ||             d{   }| j                  |dg       }	| j                  |	||||      S 7 7 X7 0w)a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://docs.coinex.com/api/v2/spot/market/http/list-market-kline
        https://docs.coinex.com/api/v2/futures/market/http/list-market-kline

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr8   )r  periodr9  rF   r  )	r  r  r  r   v2PublicGetFuturesKliner  v2PublicGetSpotKliner  parse_ohlcvs)
r  r  	timeframerE  r9  r  r  r  r  r  s
             r  fetch_ohlcvzcoinex.fetch_ohlcv?  s      !!!V$Tl&&t	9M
 $GG&>!99$++gv:VWWH!66t{{7F7STTH* ~~h3  vy%GGE 	" XTs4   CCA*CC)C+C,-CCCc                   K   | j                          d {    | j                  |       d {   }d|i}| j                  |dg       }t        dt	        |            D ]  }||   }| j                  |di       }| j                  |di       }| j                  |di       }	| j                  |di       }
| j                         }| j                  |d      }| j                  |      }| j                  |d      |d	<   | j                  |d      |d
<   | j                  |	d      }| j                  |
d      }t        j                  ||      |d<   |||<    | j                  |      S 7 P7 :w)Nr  r  r   	availablefrozenrepaidinterestr  freeuseddebt)r  v2PrivateGetAssetsMarginBalancer  r  r  r  accountr  r  r3   
string_addsafe_balance)r  r  r  r  balancesr  r  rb  rc  loanra  baseAccountbaseCurrencyIdbaseCurrencyCodebaseDebtbaseInterests                   r  fetch_margin_balancezcoinex.fetch_margin_balanceq  st    !!!==fEE@ )>>(FB7q#h-( 	3AQKE>>%b9D>>%26D>>%26D~~eZ<H,,.K!--eZ@N#66~F"&"2"24"DK"&"2"24"DK''j9H++HjAL")"4"4X|"LK'2F#$	3   ((e 	"Es    E,E&E,E)D7E,)E,c                   K   | j                          d {    | j                  |       d {   }d|i}| j                  |dg       }t        dt	        |            D ]i  }||   }| j                  |d      }| j                  |      }| j                         }	| j                  |d      |	d<   | j                  |d      |	d<   |	||<   k | j                  |      S 7 7 w	Nr  r  r   r  r^  rb  r_  rc  )	r  v2PrivateGetAssetsSpotBalancer  r  r  r  r  rf  rh  
r  r  r  r  ri  r  r  r  r  rf  s
             r  fetch_spot_balancezcoinex.fetch_spot_balance  s     !!!;;FCC )>>(FB7q#h-( 	#AQKE))%7J**:6DllnG"..ukBGFO"..uh?GFO"F4L	#   ((3 	"C    C!CC!CB.C!C!c                   K   | j                          d {    | j                  |       d {   }d|i}| j                  |dg       }t        dt	        |            D ]i  }||   }| j                  |d      }| j                  |      }| j                         }	| j                  |d      |	d<   | j                  |d      |	d<   |	||<   k | j                  |      S 7 7 wrr  )	r   v2PrivateGetAssetsFuturesBalancer  r  r  r  r  rf  rh  rt  s
             r  fetch_swap_balancezcoinex.fetch_swap_balance  s     !!!>>vFF" )>>(FB7q#h-( 	#AQKE))%7J**:6DllnG"..ukBGFO"..uh?GFO"F4L	#   ((9 	"Frv  c                   K   | j                          d {    | j                  |       d {   }d|i}| j                  |dg       }t        dt	        |            D ]i  }||   }| j                  |d      }| j                  |      }| j                         }	| j                  |d      |	d<   | j                  |d      |	d<   |	||<   k | j                  |      S 7 7 wrr  )	r  "v2PrivateGetAssetsFinancialBalancer  r  r  r  r  rf  rh  rt  s
             r  fetch_financial_balancezcoinex.fetch_financial_balance  s     !!!@@HH )>>(FB7q#h-( 	#AQKE))%7J**:6DllnG"..ukBGFO"..uh?GFO"F4L	#   ((3 	"Hrv  c                 n  K   d}| j                  dd|      \  }}d}| j                  d|      \  }}|duxs |dk(  }|dk(  r| j                  |       d{   S |dk(  r| j                  |       d{   S |r| j	                  |       d{   S | j                  |       d{   S 7 V7 :7 !7 
w)a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://docs.coinex.com/api/v2/assets/balance/http/get-spot-balance         # spot
        https://docs.coinex.com/api/v2/assets/balance/http/get-futures-balance      # swap
        https://docs.coinex.com/api/v2/assets/balance/http/get-marigin-balance      # margin
        https://docs.coinex.com/api/v2/assets/balance/http/get-financial-balance    # financial

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: 'margin', 'swap', 'financial', or 'spot'
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nr]   rE   rF   	financial)r   handle_margin_mode_and_paramsry  r|  rp  ru  )r  r  r  r(  isMargins        r  fetch_balancezcoinex.fetch_balance  s      
!??PTV\]
F
!??PVW
Fd*G
h0F00888;&55f===226:::00888 9=:8sH   AB5B-B54B/5B5B1B5(B3)B5/B51B53B5statusc                 :    ddddddd}| j                  |||      S )Nrejectedr  closedcanceled)r  r  not_deal	part_dealdonecancelr  r  r  statusess      r  parse_order_statuszcoinex.parse_order_status  s2    " 
 &&99r  r<  c                 z   | j                  |d      }| j                  |d      }| j                  |d      }|dk(  r|}| j                  |d      }| j                  | j                  d      }| j                  |d|      }|dk(  rd	}|d	k(  rd	nd
}	| j	                  ||d |	      }| j                  |d      }
| j                  |
      }||d   }| j                  |d      }|dk(  rd}n|dk(  rd}| j                  |d      }|dk(  rd }| j                  i d| j                  |g d      d|d| j                  |      d|d|d| j                  |      d|d   d| j                  |d      dd dd dd d|d| j                  |d      d | j                  |d!      d"| j                  |d#      d$| j                  |d%      d&| j                  |d'      | j                  |d(      | j                  |d)      | j                  |d*      | j                  |d+      d || j                  |d,d-      d.|d/|      S )0Nr  r3  r,  r   r  r  market_typefuturesrF   rD   r4  r  r9  longbuyshortsell	client_id r8   )position_idr8  stop_idclientOrderIdr  r  lastTradeTimestampr  r  r/  postOnly
reduceOnlyr  r)  trigger_pricer-  take_profit_pricer,  stop_loss_pricer  filled_valueavg_entry_pricer   filled_amountunfilled_amount	quote_feer  )r6  r  )r  r   filled	remainingtradesr  r  )r  r&  r   safe_string_lowerr>  r  
safe_ordersafe_string_nr@  r  r  safe_string_2)r  r<  r  	rawStatusr  updatedTimestampr  r  	orderTyper  rB  feeCurrencyr9  r  s                 r  parse_orderzcoinex.parse_order#  s   ` $$UH5	%%e\:	,,ULAq (##E84&&t||]C**5-M		!I )V 3V&
!!(FD*E((	:--m< /Kv.6>DW_D((<B M  
$$$U,RS 
] 
 Y/ 
 	 

 !"2 
 d--i8 
 fX& 
 D$$UF3 
 4 
  
 $ 
 D 
 T%%eW5 
 D,,UOD 
 t//7JK 
  T--e5FG! 
" D$$UN;# 
$ ''/@A&&uh7&&uo>))%1BC'**5+uE 7 
8 9 	r  r  c                    K   | j                          d{    | j                  |      }|d   st        | j                  dz         d|d<   | j	                  |dd|d|       d{   S 7 U7 w)a<  
        create a market buy order by providing the symbol and cost

        https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade003_market_order
        https://docs.coinex.com/api/v2/spot/order/http/put-order

        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        NrD   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr  r  r  )r  r  r.   r8   create_order)r  r  r  r  r  s        r  !create_market_buy_order_with_costz(coinex.create_market_buy_order_with_cost)  sy      !!!V$f~tww)ddee6;23&&vxdFSSS 	"
 Ts"   A0A,AA0'A.(A0.A0r  r9  r   r  c                    | j                  |      }|d   }| j                  |dd      }	| j                  |dd      }
| j                  |d      }| j                  |d      }| j                  |d      }|d	k(  }| j                  ||d
k(  |      }| j	                  |d      }| j                  |d      }|r&|d   s!t        | j                  dz   |d   z   dz         d	|d   i}|	9d}| j                  | j                  d|      }|dz   | j                         z   |d<   n|	|d<   |=|;|s||d<   |}|rd
}n||dk(  rd}n|dk(  rd}|s| j                  ||      |d<   ||d<   |rd|d<   |s|r_|r-| j                  ||      |d<   | j                  |dd      |d<   n|r| j                  ||      |d <   | j                  |dd      |d!<   ns| j                  ||      |d"<   |
[| j                  ||
      |d#<   | j                  |dd      |d$<   n.d }| j                  d%|      \  }}|d&|d<   nd'|d<   |d	k(  r|d(k(  rd)}| j                  |d%d*d)      \  }}| j                  |d+      }| j                  |d+      }|r||t        | j                  d,z         | j!                  |      }| j!                  |      }| j#                  t%        j&                  ||            }||n|}| j)                  ||      |d"<   n+| j)                  ||      |d"<   n| j                  ||      |d"<   |
| j                  ||
      |d#<   | j                  |g d-      }| j+                  ||      S ).NrF   r  r  	stopPricer)  r,  r-  rH   r  
maker_onlyr/  r  z/ createOrder() does not support reduceOnly for r  z> orders, reduceOnly orders are supported for swap markets onlyr8   r   r  -r9  r$  iocr%  fokr  r   r  r  	stop_typelatest_pricestop_loss_typer  take_profit_typer   r  trigger_price_typerU   r   r   r  Tr  r  z createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argument)r  r/  r  r  r)  r,  r-  )r  r  r  is_post_onlysafe_string_upperr  r,   r8   r   uuid16price_to_precisionamount_to_precisionr  handle_option_and_paramsr  omitnumber_to_stringparse_to_numericr3   
string_mulcost_to_precisionr  )r  r  r  r9  r   r  r  r  rF   r  r)  r,  r-  rH   isMarketOrderr  timeInForceRawr  r  	defaultIdr  requestTyper(  r  r  amountStringpriceStringquoteAmountcostRequests                                r  create_order_requestzcoinex.create_order_request<  s"   V$f~**6;P))&+~N((A**63DE!!&(3($$]Fl4JFS//F^^FL9
&>"477-^#^aghnao#o  ss  $s  t  tfTl
  %I''j)LH#+c>DKKM#AGK #0GK !(?"&K*+!U*"'K#u,"'K #'#:#:65#I )GFO%.GM" 151H1HQ^1_G-.040@0@Vd0eG,-$373J3J6Sb3cG/0262B2B6;Xf2gG./$($<$<VV$L!+/3/F/Fv|/\GO,484D4DV[Zh4iG01J!%!C!CMSY!ZJ%)1&)/& tu}481<@<Y<YZ`bo  rU  W[  =\916''76624DL*477  6q  ,q  r  r'+'<'<V'D&*&;&;E&B&*&;&;G<N<N|]h<i&j/3/?dk,0,B,B6;,W)(,(>(>vv(NGH%$($<$<VV$L!'+/+B+B6<+X(6  $N  O{{7F++r  c                 :  K   | j                          d{    | j                  |      }| j                  |d      }| j                  |dd      }	| j	                  |d      }
| j	                  |d      }|	du}|
du}|du}|xs |}| j                  ||||||      }d}|d   r6|r| j                  |       d{   }n| j                  |       d{   }n|r| j                  |       d{   }no|r8|r| j                  |       d{   }nQ|rO| j                  |       d{   }n5|r| j                  |       d{   }n| j                  |       d{   }| j                  |di       }| j                  ||      S 7 t7 7 7 7 7 j7 P7 8w)	ae  
        create a trade order

        https://docs.coinex.com/api/v2/spot/order/http/put-order
        https://docs.coinex.com/api/v2/spot/order/http/put-stop-order
        https://docs.coinex.com/api/v2/futures/order/http/put-order
        https://docs.coinex.com/api/v2/futures/order/http/put-stop-order
        https://docs.coinex.com/api/v2/futures/position/http/close-position
        https://docs.coinex.com/api/v2/futures/position/http/set-position-stop-loss
        https://docs.coinex.com/api/v2/futures/position/http/set-position-take-profit

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: price to trigger stop orders
        :param float [params.stopLossPrice]: price to trigger stop loss orders
        :param float [params.takeProfitPrice]: price to trigger take profit orders
        :param str [params.timeInForce]: 'GTC', 'IOC', 'FOK', 'PO'
        :param boolean [params.postOnly]: set to True if you wish to make a post only order
        :param boolean [params.reduceOnly]: *contract only* indicates if self order is to reduce the size of a position
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  r  r)  r,  r-  rD   r  )r  r  r  r  r  r  v2PrivatePostSpotStopOrderv2PrivatePostSpotOrderv2PrivatePostFuturesStopOrder'v2PrivatePostFuturesSetPositionStopLoss)v2PrivatePostFuturesSetPositionTakeProfit!v2PrivatePostFuturesClosePositionv2PrivatePostFuturesOrderr  r  )r  r  r  r9  r   r  r  r  r  r)  stopLossTriggerPricetakeProfitTriggerPriceisTriggerOrderisStopLossTriggerOrderisTakeProfitTriggerOrderisStopLossOrTakeProfitTriggerr  r  r  s                      r  r  zcoinex.create_order  s    4 !!!V$^^FL9
))&+~N#//H!%!1!1&:K!L%T1!5T!A#9#E (>(ZBZ%++FD$vV&>!%!@!@!II "&!<!<W!EE> !%!C!CG!LL /)%)%Q%QRY%ZZHN .%)%S%ST[%\\HP %)%K%KG%TTH< &*%C%CG%LLH: ~~h3f--e 	" J F@ M  [P  ]R  U<  Ms   FF
B#F:F;FFF0F1FFF*F+FFF F!*FFFFFFFFordersc           	        K   | j                          d{    g }d}d}d}d}t        dt        |            D ]<  }||   }	| j                  |	d      }
||
}n||
k7  rt	        | j
                  dz         | j                  |	d      }| j                  |	d      }| j                  |	d      }| j                  |	d	      }| j                  |	d
i       }|dk7  rt        | j
                  dz   |z   dz         | j                  |d      }| j                  |dd      }| j                  |d      }| j                  |d      }|du}|du}|du}|xs |}| j                  |
|||||      }|j                  |       ? | j                  |      }|d   |d}d}|d   r6|r| j                  |       d{   }n| j                  |       d{   }ni|r| j                  |       d{   }nM|rt        | j
                  dz         |rt        | j
                  dz         | j!                  |       d{   }| j#                  |dg       }g }t        dt        |            D ]  }||   }d}| j%                  |d      }|
|dk7  rd}nd}| j'                  |di       }d}|d   r|s||d<   | j)                  ||      }n||d<   | j)                  ||      }|j                  |        |S 7 7 >7 '7 7 ­w)a  
        create a list of trade orders(all orders should be of the same symbol)

        https://docs.coinex.com/api/v2/spot/order/http/put-multi-order
        https://docs.coinex.com/api/v2/spot/order/http/put-multi-stop-order
        https://docs.coinex.com/api/v2/futures/order/http/put-multi-order
        https://docs.coinex.com/api/v2/futures/order/http/put-multi-stop-order

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the api endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        NFr   r  z; createOrders() requires all orders to have the same symbolr  r9  r   r  r  r9  z! createOrders() does not support z' orders, only limit orders are acceptedr  r  r)  r,  r-  r8   )r  r  rD   zH createOrders() does not support stopLossPrice or takeProfitPrice ordersz2 createOrders() does not support reduceOnly ordersr  r  r  r  r  )r  r  r  r  r)   r8   r  r.   safe_number_2r  r  r  r  v2PrivatePostSpotBatchStopOrderv2PrivatePostSpotBatchOrder"v2PrivatePostFuturesBatchStopOrderv2PrivatePostFuturesBatchOrderr  r&  r  r  ) r  r  r  ordersRequestsr  r  r  r  r  rawOrderr  r  r9  r   r  orderParamsr)  r  r  r  r  orderRequestr  r  r  r  resultsr  r  r  	innerDatar<  s                                    r  create_orderszcoinex.create_orders|	  sm     !!!
(-%q#f+& 	0AayH''(;H~!X%$TWW/l%lmm##Hf5D##Hf5D__Xx8FOOHg6E//(HbAKw"477-P#PSW#W  [D  $D  E  ElCJ--k;WL#'#3#3K#Q %)%5%5kCT%U")5N%9%E"'=T'I$,B,^F^)44XtT6SXZefL!!,/1	02 V$Tl$
 &>!%!E!Eg!NN" "&!A!A'!JJL !%!H!H!QQ  /"477-w#wxx&tww1e'eff%)%H%H%QQHF ~~h3q#d)$ 	"AGEF$$UF3D19'F#Fufb9IEf~n"(h((7&,	(#((F;NN5!#	"$ Y 	"N O" KN R,  RsZ   K9K+FK90K.1K9
K1K9&K4'AK94K75B7K9.K91K94K97K9c                   K   |t        | j                  dz         | j                          d{    | j                  |      }d|d   i}| j	                  |dd      }| j                  |ddg      }d}g }t        dt        |            D ]  }	|j                  t        ||	                ! |r||d<   n||d	<   |d
   rV|r*| j                  | j                  ||             d{   }n| j                  | j                  ||             d{   }nZd|d<   |r*| j                  | j                  ||             d{   }n)| j                  | j                  ||             d{   }| j                  |dg       }
g }t        dt        |
            D ]=  }	|
|	   }| j!                  |di       }| j#                  ||      }|j                  |       ? |S 7 7 7 7 7 yw)a  
        cancel multiple orders

        https://docs.coinex.com/api/v2/spot/order/http/cancel-batch-order
        https://docs.coinex.com/api/v2/spot/order/http/cancel-batch-stop-order
        https://docs.coinex.com/api/v2/futures/order/http/cancel-batch-order
        https://docs.coinex.com/api/v2/futures/order/http/cancel-batch-stop-order

        :param str[] ids: order ids
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: set to True for canceling stop orders
        :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz* cancelOrders() requires a symbol argumentr  r8   stopr=  r   stop_ids	order_idsrD   r   r  r  )r(   r8   r  r  safe_bool_2r  r  r  r  int%v2PrivatePostSpotCancelBatchStopOrderr  !v2PrivatePostSpotCancelBatchOrder(v2PrivatePostFuturesCancelBatchStopOrder$v2PrivatePostFuturesCancelBatchOrderr  r  r  )r  idsr  r  r  r  r=  r  
requestIdsr  r  r  r  itemr<  s                  r  cancel_orderszcoinex.cancel_orders7
  s     >#DGG.Z$Z[[!!!V$fTl
 ""669=6FI#67
q#c(# 	+Ac#a&k*	+",GJ#-GK &>!%!K!KDKKX_agLh!ii< "&!G!GT[]cHd!eeJ &/GM"!%!N!Nt{{[bdjOk!ll: "&!J!J4;;W^`fKg!hhF ~~h3q#d)$ 	"AGE>>%4D$$T62ENN5!		"
 { 	"" j< fN m: isY   .G(GB6G('G ()G(G"0G(G$)G(,G&-A1G( G("G($G(&G(r8   c                   K   |t        | j                  dz         | j                          d{    | j                  |      }d|d   i}	|| j	                  ||      |	d<   || j                  ||      |	d<   d}
| j                  |g d      }| j                  |dd	g      }|du}|r*| j                  ||      |	d
<   | j                  |      |	d<   n| j                  |      |	d<   d}| j                  d|      \  }}|d   rc|d|	d<   nd|	d<   |r*| j                  | j                  |	|             d{   }
n| j                  | j                  |	|             d{   }
nZd|	d<   |r*| j                  | j                  |	|             d{   }
n)| j                  | j                  |	|             d{   }
| j                  |
di       }| j!                  ||      S 7 7 7 7 Z7 2w)a  
        edit a trade order

        https://docs.coinex.com/api/v2/spot/order/http/edit-order
        https://docs.coinex.com/api/v2/spot/order/http/edit-stop-order
        https://docs.coinex.com/api/v2/futures/order/http/edit-order
        https://docs.coinex.com/api/v2/futures/order/http/edit-stop-order

        :param str id: order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of the currency you want to trade in units of the base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: the price to trigger stop orders
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz' editOrder() requires a symbol argumentr  r8   r   r  )r  r)  r  r  r)  r  r  r8  r\   rD   r   r  r   r   r  )r(   r8   r  r  r  r  r  r  r  r   v2PrivatePostSpotModifyStopOrderr  v2PrivatePostSpotModifyOrder#v2PrivatePostFuturesModifyStopOrderv2PrivatePostFuturesModifyOrderr  r  )r  r8   r  r  r9  r   r  r  r  r  r  r)  r  r(  r  s                  r  
edit_orderzcoinex.edit_order
  s&    & >#DGG.W$WXX!!!V$fTl
  $ 8 8 HGH#66vuEGG))&2`a6K#@A%T1'+'>'>v|'TGO$!%!6!6r!:GI"&"7"7";GJ
!??VT
F&>%)1&)/&!%!F!Ft{{SZ\bGc!dd "&!B!B4;;wX^C_!``@ &/GM"!%!I!I$++V]_eJf!gg "&!E!EdkkRY[aFb!cc: ~~h3f--a 	"4 e aD h dsX   .G2G'DG28G*9)G2"G,#0G2G.)G2=G0>*G2*G2,G2.G20G2c                 d  K   |t        | j                  dz         | j                          d{    | j                  |      }| j	                  |dd      }|d   }d|d   i}d}| j                  d|      \  }}|rd	|d
<   n|d|d
<   nd|d
<   | j                  |dd      }	| j                  |g d      }d}
|	|	|d<   |rX|r+| j                  | j                  ||             d{   }
nV| j                  | j                  ||             d{   }
n+|r*| j                  | j                  ||             d{   }
n| j                  | j                  ||             d{   }
n|rj| j                  |      |d<   |r*| j                  | j                  ||             d{   }
n| j                  | j                  ||             d{   }
ni| j                  |      |d<   |r*| j!                  | j                  ||             d{   }
n)| j#                  | j                  ||             d{   }
d}|	*| j%                  |
dg       }| j'                  |d   di       }n| j'                  |
di       }| j)                  ||      S 7 i7 7 7 a7 :7 7 7 7 lw)af  
        cancels an open order

        https://docs.coinex.com/api/v2/spot/order/http/cancel-order
        https://docs.coinex.com/api/v2/spot/order/http/cancel-stop-order
        https://docs.coinex.com/api/v2/spot/order/http/cancel-order-by-client-id
        https://docs.coinex.com/api/v2/spot/order/http/cancel-stop-order-by-client-id
        https://docs.coinex.com/api/v2/futures/order/http/cancel-order
        https://docs.coinex.com/api/v2/futures/order/http/cancel-stop-order
        https://docs.coinex.com/api/v2/futures/order/http/cancel-order-by-client-id
        https://docs.coinex.com/api/v2/futures/order/http/cancel-stop-order-by-client-id

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.clientOrderId]: client order id, defaults to id if not passed
        :param boolean [params.trigger]: set to True for canceling a trigger order
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentr  r=  rF   r  r8   rM   r   r  r   r   r  r  )r  r=  r  r  r8  r  r   )r(   r8   r  r  r  r  r  r  -v2PrivatePostFuturesCancelStopOrderByClientIdr  *v2PrivatePostSpotCancelStopOrderByClientId)v2PrivatePostFuturesCancelOrderByClientId&v2PrivatePostSpotCancelOrderByClientIdr  #v2PrivatePostFuturesCancelStopOrder v2PrivatePostSpotCancelStopOrderv2PrivatePostFuturesCancelOrderv2PrivatePostSpotCancelOrderr  r  r  )r  r8   r  r  r  r  rF   r  r(  r  r  r  rowss                r  cancel_orderzcoinex.cancel_ordern  s    ( >#DGG.Y$YZZ!!!V$))&&)Df~fTl
 
!??vV
F%.GM"%)1&)/&**6;P6#GH$#0GK %)%W%WX\XcXcdkmsXt%uuH6 &*%T%TUYU`U`ahjpUq%rrH8 %)%S%STXT_T_`gioTp%qqHD &*%P%PQUQ\Q\]dflQm%nnHF %)%:%:2%>	"%)%M%MdkkZaciNj%kkH, &*%J%J4;;W^`fKg%hhH, '+&;&;B&?
#%)%I%I$++V]_eJf%ggH8 &*%F%Ft{{SZ\bGc%ddH8 $>>(FB7D>>$q'626D>>(FB7Df--G 	".  v6  s:  rD  oL  l,  i0  h8  es   .J0JB8J0)J**J0J,J0J")J0+J%,AJ0-J(.)J0J*?J0J,)J0J.AJ0J0J0"J0%J0(J0*J0,J0.J0c                   K   |t        | j                  dz         | j                          d{    | j                  |      }d|d   i}d}|d   r/d|d<   | j	                  | j                  ||             d{   }nMd}| j                  d|      \  }}|d	|d<   nd
|d<   | j                  | j                  ||             d{   }| j                  d|i      gS 7 7 h7 w)a4  
        cancel all open orders in a market

        https://docs.coinex.com/api/v2/spot/order/http/cancel-all-order
        https://docs.coinex.com/api/v2/futures/order/http/cancel-all-order

        :param str symbol: unified market symbol of the market to cancel orders in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' for canceling spot margin orders
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz- cancelAllOrders() requires a symbol argumentr  r8   rF   r   r  rL   r   r   r  )	r(   r8   r  r  "v2PrivatePostFuturesCancelAllOrderr  r  v2PrivatePostSpotCancelAllOrderr  )r  r  r  r  r  r  r(  s          r  cancel_all_orderszcoinex.cancel_all_orders  s     >#DGG.]$]^^!!!V$fTl
 &>%.GM"!DDT[[QXZ`EabbH
 J!%!C!CDUW]!^J%)1&)/&!AA$++gW]B^__H
 OO 
 	
/ 	" c `s5   .C*C$AC*=C&>AC*C(C*&C*(C*c                   K   |t        | j                  dz         | j                          d{    | j                  |      }|d   | j	                  |      d}d}|d   r*| j                  | j                  ||             d{   }n)| j                  | j                  ||             d{   }| j                  |di       }| j                  ||      S 7 7 U7 -w)a  
        fetches information on an order made by the user

        https://docs.coinex.com/api/v2/spot/order/http/get-order-status
        https://docs.coinex.com/api/v2/futures/order/http/get-order-status

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( fetchOrder() requires a symbol argumentr8   )r  r8  rF   r  )
r(   r8   r  r  r  v2PrivateGetFuturesOrderStatusr  v2PrivateGetSpotOrderStatusr  r  )r  r8   r  r  r  r  r  r  s           r  fetch_orderzcoinex.fetch_order  s      >#DGG.X$XYY!!!V$Tl--b1
 &>!@@WV\A]^^H> "==dkk'SY>Z[[H> ~~h3f--O 	" _> \s4   .C"CAC"C	)C"2C 3*C"C" C"c                   K   | j                          d{    i }d}|| j                  |      }|d   |d<   |||d<   | j                  |dd      }| j                  |ddg      }d}	| j	                  d||      \  }	}d}
|dk(  xs |d	k(  }|d
k(  xs |dk(  }|	dk(  rd|d<   |rX|r+| j                  | j                  ||             d{   }
n[| j                  | j                  ||             d{   }
n0|r-|r+| j                  | j                  ||             d{   }
n | j                  | j                  ||             d{   }
nd}| j                  d|      \  }}|d|d<   nd|d<   |rV|r*| j                  | j                  ||             d{   }
n| j                  | j                  ||             d{   }
nZ|d
k(  rU|r*| j                  | j                  ||             d{   }
n)| j                  | j                  ||             d{   }
| j                  |
dg       }| j!                  ||||      S 7 ?7 7 d7 77 7 7 7 h7 @w)a  
        fetch a list of orders

        https://docs.coinex.com/api/v2/spot/order/http/list-finished-order
        https://docs.coinex.com/api/v2/spot/order/http/list-finished-stop-order
        https://docs.coinex.com/api/v2/futures/order/http/list-finished-order
        https://docs.coinex.com/api/v2/futures/order/http/list-finished-stop-order

        :param str status: order status to fetch for
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: set to True for fetching trigger orders
        :param str [params.marginMode]: 'cross' or 'isolated' for fetching spot margin orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr8   r  r9  r  r=  fetchOrdersByStatusfinishedr  pendingr  rF   r   r  r   r   r  )r  r  r  r  r   $v2PrivateGetFuturesFinishedStopOrderr   v2PrivateGetFuturesFinishedOrder#v2PrivateGetFuturesPendingStopOrderv2PrivateGetFuturesPendingOrderr  !v2PrivateGetSpotFinishedStopOrderv2PrivateGetSpotFinishedOrder v2PrivateGetSpotPendingStopOrderv2PrivateGetSpotPendingOrderr  parse_orders)r  r  r  rE  r9  r  r  r  r=  r  r  isClosedisOpenr(  r  s                  r  fetch_orders_by_statuszcoinex.fetch_orders_by_status  s    $ !!![[(F &tGH$GG""669=6FI#67
!??@UW]_ef
Fj(Af.@I%<6V+;%.GM"%)%N%Nt{{[bdjOk%llH8 &*%J%J4;;W^`fKg%hhH> %)%M%MdkkZaciNj%kkH: &*%I%I$++V]_eJf%ggHH J!%!C!CDY[a!bJ%)1&)/&%)%K%KDKKX_agLh%iiH: &*%G%GT[]cHd%eeHB 9$%)%J%J4;;W^`fKg%hhH< &*%F%Ft{{SZ\bGc%ddHH ~~h3  vue<<y 	"&  m8  iB  l:  hX  j:  fF  i<  es   I,IB5I,I*I,7I8/I,'I(*I,I!AI,$I$%)I,I&0I,?I( )I,)I**,I,I,I,I,!I,$I,&I,(I,*I,c                    K   | j                  d||||       d{   }t        dt        |            D ]
  }d||   d<    |S 7 (w)a  
        fetch all unfilled currently open orders

        https://docs.coinex.com/api/v2/spot/order/http/list-pending-order
        https://docs.coinex.com/api/v2/spot/order/http/list-pending-stop-order
        https://docs.coinex.com/api/v2/futures/order/http/list-pending-order
        https://docs.coinex.com/api/v2/futures/order/http/list-pending-stop-order

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of open order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: set to True for fetching trigger orders
        :param str [params.marginMode]: 'cross' or 'isolated' for fetching spot margin orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  Nr   r  r  )r&  r  r  )r  r  rE  r9  r  
openOrdersr  s          r  fetch_open_orderszcoinex.fetch_open_orders;  sY     "  66y&%QVX^__
q#j/* 	-A&,JqM(#	- `s   AA)Ac                 H   K   | j                  d||||       d{   S 7 w)a  
        fetches information on multiple closed orders made by the user

        https://docs.coinex.com/api/v2/spot/order/http/list-finished-order
        https://docs.coinex.com/api/v2/spot/order/http/list-finished-stop-order
        https://docs.coinex.com/api/v2/futures/order/http/list-finished-order
        https://docs.coinex.com/api/v2/futures/order/http/list-finished-stop-order

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: set to True for fetching trigger orders
        :param str [params.marginMode]: 'cross' or 'isolated' for fetching spot margin orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  N)r&  )r  r  rE  r9  r  s        r  fetch_closed_orderszcoinex.fetch_closed_ordersQ  s(     " 00VUESYZZZZs   " "r  c                   K   | j                          d{    | j                  |      }| j                  |dd      }|t        | j                  dz         | j                  |d      }|d   | j                  ||d         d}| j                  | j                  ||             d{   }| j                  |di       }| j                  ||      S 7 7 +w)	a  
        create a currency deposit address

        https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/update-deposit-address

        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: the blockchain network to create a deposit address on
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nr  r  z4 createDepositAddress() requires a network parameterr8   r  )r  r  r  )r  r6  r  r(   r8   r  network_code_to_id(v2PrivatePostAssetsRenewalDepositAddressr  r  parse_deposit_address)r  r  r  r6  r  r  r  r  s           r  create_deposit_addresszcoinex.create_deposit_addressd  s      !!!==&$$VWi@?#DGG.d$dee69-D>,,Whv6FG
 FFt{{SZ\bGcdd ~~h3))$99- 	" e"   CCBC*C+*CCc                   K   | j                          d{    | j                  |      }d|d   i}d}| j                  |      \  }}|t        | j                  dz         | j                  |      |d<   | j                  | j                  ||             d{   }| j                  |di       }| j                  ||      S 7 7 +w)a  
        fetch the deposit address for a currency associated with self account

        https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/get-deposit-address

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: the blockchain network to create a deposit address on
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nr  r8   z5 fetchDepositAddress() requires a "network" parameterr  r  )
r  r6  handle_network_code_and_paramsr(   r8   r-   v2PrivateGetAssetsDepositAddressr  r  r/  )r  r  r  r6  r  networkCoder  r  s           r  fetch_deposit_addresszcoinex.fetch_deposit_address  s      !!!==&8D>
 "AA&IV#DGG.e$eff22;?>>t{{7TZ?[\\ ~~h3))$99- 	" ]s"   C	CBC	C*C	C	r6  c           	          | j                  |d      }|j                  d      }d }d }t        |      }|dkD  r|d   dk7  r|d   }|d   }n|}|| j                  d |      d || j                  |d|      dS )Naddressr  r   r   cfxmemo)r  r6  r  r8  tag)r  splitr  r  )r  depositAddressr6  coinAddresspartsr8  r;  partsLengths           r  r/  zcoinex.parse_deposit_address  s     &&~yA!!#&%j?uQx50AhG(C!G"//h?##NFC@
 	
r  c                 F  K   |t        | j                  dz         | j                          d{    | j                  |      }d|d   i}|||d<   |||d<   | j	                  d||      \  }}d}|d   r/d	|d
<   | j                  | j                  ||             d{   }nMd}| j                  d|      \  }}|d|d
<   nd|d
<   | j                  | j                  ||             d{   }| j                  |dg       }	| j                  |	|||      S 7 7 {7 /w)a  
        fetch all trades made by the user

        https://docs.coinex.com/api/v2/spot/deal/http/list-user-deals
        https://docs.coinex.com/api/v2/futures/deal/http/list-user-deals

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trade structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest trades
        :param str [params.side]: the side of the trades, either 'buy' or 'sell', required for swap
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nz+ fetchMyTrades() requires a symbol argumentr  r8   r9  
start_timeend_timerF   r   r  r|   r   r   r  )r(   r8   r  r  handle_until_optionv2PrivateGetFuturesUserDealsr  r  v2PrivateGetSpotUserDealsr  rI  )
r  r  rE  r9  r  r  r  r  r(  r  s
             r  fetch_my_tradeszcoinex.fetch_my_trades  sX     >#DGG.[$[\\!!!V$fTl
 $GG$)GL!22:wO&>%.GM"!>>t{{7TZ?[\\H, J!%!C!COU[!\J%)1&)/&!;;DKKQW<XYYH, ~~h3  vue<<A 	" ]8 Zs5   .D!DA0D!!D"AD!/D0,D!D!D!c                   K   | j                          d{    d}| j                  |ddd      \  }}| j                  |      }ddi}d}|[d}t        |t              r.t        |      }|dkD  rt        | j                  dz         |d	   }n|}| j                  |      }|d
   |d<   d}|dk(  r*| j                  | j                  ||             d{   }n)| j                  | j                  ||             d{   }| j                  |dg       }	g }
t        d	t        |	            D ]&  }|
j                  | j                  |	|   |             ( | j!                  |
d|d      S 7 S7 7 pw)a  
        fetch all open positions

        https://docs.coinex.com/api/v2/futures/position/http/list-pending-position
        https://docs.coinex.com/api/v2/futures/position/http/list-finished-position

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.method]: the method to use 'v2PrivateGetFuturesPendingPosition' or 'v2PrivateGetFuturesFinishedPosition' default is 'v2PrivateGetFuturesPendingPosition'
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nr   method"v2PrivateGetFuturesPendingPositionr  r   r   zD fetchPositions() symbols argument cannot contain more than 1 symbolr   r8   r  r  r  F)r  r  r  
isinstancelistr  r)   r8   r  rJ  r  #v2PrivateGetFuturesFinishedPositionr  r  r  parse_positionfilter_by_array_positions)r  r  r  defaultMethodr  r  r  symbolsLengthr  positionr  r  s               r  fetch_positionszcoinex.fetch_positions  s     !!! $ = =fFVX`  cG  !Hv%%g.9
 F'4( #G 1$$TWW/u%uvv  [[(F &tGH@@!DDT[[QXZ`EabbH!EEdkkRY[aFbccHX >>(FB7q#h-( 	DAMM$--hqk6BC	D--fhOOO 	"* ccs5   E0E)B<E0E,)E0=E.>A,E0,E0.E0c                   K   | j                          d{    | j                  |      }d|d   d}| j                  | j                  ||             d{   }| j	                  |dg       }| j                  |d   |      S 7 n7 .w)a  
        fetch data on a single open contract trade position

        https://docs.coinex.com/api/v2/futures/position/http/list-pending-position

        :param str symbol: unified market symbol of the market the position is held in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nr   r8   r  r  r  r   )r  r  rJ  r  r  rN  )r  r  r  r  r  r  r  s          r  fetch_positionzcoinex.fetch_positionk  s      !!!V$$Tl
 @@WV\A]^^X ~~h3""47F33g 	" _s"   B	BAB	B-B	B	rR  c                    | j                  |d      }| j                  ||d d      }| j                  |d      }| j                  i d|d| j                  |d      d|d   d| j	                  |d	      d
| j                  |d      d| j	                  |d      d| j	                  |d      d| j	                  |d      d| j	                  |d      dd d| j	                  |d      d| j	                  |d      dd dd d| j                  |d      dd d|| j                  |      | j                  |d      | j	                  |d      | j	                  |d      | j	                  |d       d d | j	                  |d!      | j	                  |d"      | j                  | j                  |d#            | j                  | j                  |d$            d%      S )&Nr  rF   r3  r  r8   r  r  notionalsettle_valuer(  margin_modeliquidationPrice	liq_price
entryPricer  unrealizedPnlunrealized_pnlrealizedPnlrealized_pnlr  	contracts
close_avblr  r  	lastPricer9  r0  r  r,  maintenance_margin_valuemaintenance_margin_ratemargin_avblr2  position_margin_rater  r  )r  lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager2  marginRatior,  r-  )r  r>  r&  safe_positionr  r@  	omit_zero)r  rR  r  r  r  s        r  rN  zcoinex.parse_position  sX   F ##Hh7!!(FD&A%%h=	!! #
H#
$##Hm<#
 fX&#
 ((>B	#

 $**8]C#
  0 0; G#
 $**85FG#
 T--h8HI#
 4++HnE#
 $#
 ))(LA#
 D,,V^D#
 #
 #
 D$$Xv6#
  d!#
" ##
$ Y/#'#4#4X|#L!%!1!1(<V!W+/+;+;HF_+`**8]C!'+((:>++H6LM!^^D,<,<XGX,YZ#~~d.>.>xI\.]^9#
  	r  r(  c                   K   |t        | j                  dz         |j                         }|dk7  r|dk7  rt        | j                  dz         | j	                          d{    | j                  |      }|d   dk7  rt        | j                  dz         | j                  |d	      }| j                  |d
   d	   dd      }|t        | j                  dz         |dk  s||kD  r*t        | j                  dz   t        |      z   dz   |z         |d   d||d}| j                  | j                  ||             d{   S 7 7 w)a  
        set margin mode to 'cross' or 'isolated'

        https://docs.coinex.com/api/v2/futures/position/http/adjust-position-leverage

        :param str marginMode: 'cross' or 'isolated'
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int params['leverage']: the rate of leverage
        :returns dict: response from the exchange
        Nz+ setMarginMode() requires a symbol argumentisolatedcrossz@ setMarginMode() marginMode argument should be isolated or crossr  rF   z- setMarginMode() supports swap contracts onlyr2  r   r   d   z. setMarginMode() requires a leverage parameterr   z2 setMarginMode() leverage should be between 1 and  for r8   r   r  r  rZ  r2  )r(   r8   lowerr)   r  r  r*   r&  str*v2PrivatePostFuturesAdjustPositionLeverager  )r  r(  r  r  r  r2  maxLeverager  s           r  set_margin_modezcoinex.set_margin_mode  sn     >#DGG.[$[\\%%'
#
g(=TWW'iijj!!!V$&>V#DGG&UUVV$$VZ8''x(8(DeSQ#DGG.^$^__qLh4TWW'[[^abm^nnqxx  |B  B  C  CTl$% 	
 DDT[[QXZ`Eabbb! 	"  cs%   A E"E#CE?E EEr2  c                 R  K   |t        | j                  dz         | j                          d{    | j                  |      }|d   st	        | j                  dz         d}| j                  d|d      \  }}| j                  |d   d   d	d
      }| j                  |d   d   dd      }||k  s||kD  r9t        | j                  dz   t        |      z   dz   t        |      z   dz   |z         |d   d||d}| j                  | j                  ||             d{   S 7 7 w)a  

        https://docs.coinex.com/api/v2/futures/position/http/adjust-position-leverage

        set the level of leverage for a market
        :param float leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated'(default is 'cross')
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentrF   z+ setLeverage() supports swap contracts onlyr   rt  r   r2  r   r   r   ru  z* setLeverage() leverage should be between z and rv  r8   r   rw  )r(   r8   r  r  r*   r  r&  r)   ry  rz  r  )	r  r2  r  r  r  r(  minLeverager{  r  s	            r  set_leveragezcoinex.set_leverage  sl     >#DGG.Y$YZZ!!!V$f~DGG&SSTT
!??vW^_
F''x(8(DeQO''x(8(DeSQ{";(>TWW'SSVYZeVffippsv  xC  tD  D  GN  N  QW  W  X  XTl$% 	
 DDT[[QXZ`Eabbb! 	"  cs"   .D'D#C-D'D%D'%D'c                 2  K   | j                          d{    i }|%| j                  |      }dj                  |      |d<   | j                  | j	                  ||             d{   }| j                  |dg       }| j                  ||d      S 7 |7 ,w)a  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes

        https://docs.coinex.com/api/v2/futures/market/http/list-market-position-level

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`, indexed by market symbols
        N,r  r  )r  
market_idsjoinv2PublicGetFuturesPositionLevelr  r  parse_leverage_tiers)r  r  r  r  	marketIdsr  r  s          r  fetch_leverage_tierszcoinex.fetch_leverage_tiersF  s      !!!0I # 3GH==dkk'SY>Z[[4 ~~h3((wAAA 	"
 \s"   BBAB(B)+BBc                    g }| j                  |dg       }d}t        dt        |            D ]  }||   }| j                  |d      }| j	                  ||d d      }| j                  |d      }	|j                  | j                  |d      | j                  ||d d      |d   r|d   n|d	   ||	| j                  |d
      | j                  |d      |d       |	} |S )Nlevelr   r  rF   r   r   r   r  r  rf  r2  )tierr  r6  minNotionalmaxNotionalmaintenanceMarginRater{  r  )
r  r  r  r  r>  r  r  sumr  r&  )
r  r  r  tiersbracketsr  r  r  r  r  s
             r  parse_market_leverage_tiersz"coinex.parse_market_leverage_tiersr  s    >>$4q#h-( 	&AA;D''h7H%%hfEF**4:KLLA**8VT6J.4X.>F6NF7O**)-)9)9$@Y)Z#00zB	 	 &K	&  r  c                   K   | j                          d {    | j                  |      }| j                  ||      }|}|dk(  rt        j                  |      }|d   d|d}| j                  | j                  ||             d {   }	| j                  |	d      }
| j                  |	d      }|dk(  rdnd}| j                  | j                  |
|      || j                  |      |d      S 7 7 hw)	Nreducer8   r   )r  r  r   r  messageadd)r  r   r  )r  r  r  r3   
string_neg(v2PrivatePostFuturesAdjustPositionMarginr  r  r  parse_margin_modificationr  )r  r  r   addOrReducer  r  	rawAmountrequestAmountr  r  r  r  r  s                r  modify_margin_helperzcoinex.modify_margin_helper  s    !!!V$,,VV<	!("#..y9MTl$#

 FFt{{SZ\bGcddN ~~h/'')<'83x%{{499$G''/J
  	k 	" es#   C2C.A0C2C0A'C20C2r  c                 6   | j                  |d      }| j                  |dd      }| j                  |d      }|| j                  ||d d      d d| j                  t	        j
                  |            | j                  |d      |d   d || j                  |      d	
S )
Nr  r,  r3  margin_changerF   rs  rg  r  )
r  r  r  r(  r   totalr  r  r  r  )r  safe_integer_2r  r  r3   
string_absr  r@  )r  r  r  r  r  r  s         r  r  z coinex.parse_margin_modification  s    l ##D(3''lLI	!!$8&&xvF$''(:(:6(BC%%dM:7O"Y/
 	
r  c                 F   K   | j                  ||d|       d{   S 7 w)a  
        add margin

        https://docs.coinex.com/api/v2/futures/position/http/adjust-position-margin

        :param str symbol: unified market symbol
        :param float amount: amount of margin to add
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
        r  Nr  r  r  r   r  s       r  
add_marginzcoinex.add_margin
  s%      ..vvufMMMM   !!c                 F   K   | j                  ||d|       d{   S 7 w)a  
        remove margin from a position

        https://docs.coinex.com/api/v2/futures/position/http/adjust-position-margin

        :param str symbol: unified market symbol
        :param float amount: the amount of margin to remove
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
        r  Nr  r  s       r  reduce_marginzcoinex.reduce_margin  s%      ..vvxPPPPr  c                   K   |t        | j                  dz         | j                          d{    | j                  |      }|d   dd}| j	                  d||      \  }}|||d<   |||d<   | j                  | j                  ||             d{   }| j                  |d	g       }g }	t        d
t        |            D ]  }
||
   }| j                  |d      }| j                  |d      }| j                  |      }|	j                  ||||| j                  |      | j                  |d      | j                  |d      d        |	S 7 7 w)aW  
        fetch the history of funding fee payments paid and received on self account

        https://docs.coinex.com/api/v2/futures/position/http/list-position-funding-history

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
        Nz1 fetchFundingHistory() requires a symbol argumentr8   r   )r  r  rC  rB  r9  r  r   r3  r  r  funding_value)r  r  r  r  r  r8   r   )r(   r8   r  r  rD  )v2PrivateGetFuturesPositionFundingHistoryr  r  r  r  r&  r  r  r  r@  r  )r  r  rE  r9  r  r  r  r  r  r  r  r  r  r  r  s                  r  fetch_funding_historyzcoinex.fetch_funding_history$  sz     >#DGG.a$abb!!!V$Tl$
 22:wO$)GL!$GGGGT[]cHdee, ~~h3q#d)$ 	AGE))%>I))%7J**:6DMM & LL3&&um<**5/B 	 c 	" fs#   .EEA%EEB8EEc                 n  K   | j                          d{    | j                  |      }|d   st        | j                  dz         d|d   i}| j	                  | j                  ||             d{   }| j                  |dg       }| j                  |di       }| j                  ||      S 7 7 >w)as  
        fetch the current funding rate

        https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        NrF   z0 fetchFundingRate() supports swap contracts onlyr  r8   r  r   )	r  r  r*   r8   v2PublicGetFuturesFundingRater  r  r  parse_funding_rate)r  r  r  r  r  r  r  firsts           r  fetch_funding_ratezcoinex.fetch_funding_ratee  s      !!!V$f~DGG&XXYYfTl
 ;;DKKQW<XYY& ~~h3tQ+&&uf559 	" Zs"   B5B1AB54B35=B53B5c                 B   K   | j                  ||       d{   S 7 w)a|  
        fetch the current funding rate interval

        https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        N)r  )r  r  r  s      r  fetch_funding_intervalzcoinex.fetch_funding_interval  s!      ,,VV<<<<s   c                 2   | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }t        j                  ||      }| j                  |d      }i d|d| j	                  ||d d      d| j                  |d      d	d d
d dd dd dd d| j                  |d      d|d| j                  |      d| j                  |d      d|d| j                  |      dd dd dd d| j                  |      iS )Nlatest_funding_timenext_funding_timer  r  r  rF   r  r  r  interestRateestimatedSettlePricer  r  fundingRatelatest_funding_ratefundingTimestampfundingDatetimenextFundingRatenext_funding_ratenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer*  )r&  r  r3   
string_subr  r  r@  parse_funding_interval)	r  r  r  currentFundingTimestampfutureFundingTimestampfundingTimeStringnextFundingTimeStringmillisecondsIntervalr  s	            r  r  zcoinex.parse_funding_rate  s    #'"3"3H>S"T!%!2!28=P!Q ,,X7LM $ 0 0;N O&112GIZ[##Hh7
H
d&&xvF
 ))(LA
 $	

 D
 #D
 
 
 4++H6KL
  7
 t||,CD
 t//:MN
 #$:
 "4<<0F#G
 "4
  '!
" &t#
$ 334HI%
 	
r  c                 8    dddddd}| j                  |||      S )Nr   r   8h16h24h)360000014400000288000005760000086400000r  )r  r*  	intervalss      r  r  zcoinex.parse_funding_interval  s/    
	 	8X>>r  c                   K   | j                          d{    | j                  |      }i }d}|e| j                  |d      }| j                  |      }|d   st	        | j
                  dz         | j                  |      }dj                  |      |d<   | j                  | j                  ||             d{   }| j                  |dg       }| j                  ||      S 7 7 +w)a  
        fetch the current funding rates for multiple markets

        https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate

        :param str[] symbols: unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        Nr   rF   z1 fetchFundingRates() supports swap contracts onlyr  r  r  )r  r  r  r  r*   r8   r  r  r  r  r  parse_funding_rates)	r  r  r  r  r  r  r  r  r  s	            r  fetch_funding_rateszcoinex.fetch_funding_rates  s      !!!%%g.__Wa0F[[(F&>*] ]^^0I # 3GH;;DKKQW<XYY& ~~h3''g66? 	" Zs"   C)C%B$C);C'<*C)'C)r8  c                   K   | j                  ||      \  }}| j                  |       | j                          d{    | j                  |      }|d   || j	                  ||      d}|||d<   d}| j                  |      \  }}|| j                  |      |d<   | j                  | j                  ||             d{   }	| j                  |	di       }
| j                  |
|      S 7 7 +w)a  
        make a withdrawal

        https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/withdrawal

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: unified network code
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr8   )r  
to_addressr   r:  r  r  )handle_withdraw_tag_and_paramscheck_addressr  r6  currency_to_precisionr3  r-  v2PrivatePostAssetsWithdrawr  r  parse_transaction)r  r  r   r8  r;  r  r6  r  r5  r  transactions              r  r   zcoinex.withdraw  s     99#vFV7#!!!==&D>!00v>

 ?!GFO"AA&IV"#66{CGG99$++gv:VWW6 nnXvr:%%k8<<S 	" Xs"   :C0C,BC0C.*C0.C0c                 B    ddddddddddd
}| j                  |||      S )Nr  failedr  ok)
auditpassaudit_required
processing
confirmingnot_passr  finishr  failr  r  s      r  parse_transaction_statuszcoinex.parse_transaction_status3  s>    '##  
 &&99r  c           
      P  K   |t        | j                  dz         | j                          d{    d}| j                  |dd      \  }}|r| j	                  d|||d|d       d{   S | j                  |      }d|d	   i}|||d
<   |||d<   | j                  d||      \  }}| j                  | j                  ||             d{   }| j                  |dg       }	g }
t        dt        |	            D ]u  }|	|   }| j                  |d      }| j                  ||dd      }| j                  |d      }|
j                  ||| j!                  |d      || j#                  |      d       w | j%                  |
d      }| j'                  ||d   ||      S 7 n7 87 խw)a  
        fetches historical funding rate prices

        https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate-history

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: timestamp in ms of the earliest funding rate to fetch
        :param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param int [params.until]: timestamp in ms of the latest funding rate
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentFro   paginater  r8  r  r8   rB  r9  rC  r  r   rF   funding_timeactual_funding_rate)r  r  r  r  r  r  r  )r(   r8   r  r  "fetch_paginated_call_deterministicr  rD  $v2PublicGetFuturesFundingRateHistoryr  r  r  r  r  r  r&  r  r  r@  sort_byfilter_by_symbol_since_limit)r  r  rE  r9  r  r  r  r  r  r  ratesr  r  r  symbolInnerr  sorteds                    r  fetch_funding_rate_historyz!coinex.fetch_funding_rate_historyB  s     >#DGG.e$eff!!!88AZ\fg&@@AZ\bdikprvx~  AE  F  F  FV$fTl
 $)GL!$GG22:wOBB4;;wX^C_``$ ~~h3q#d)$ 	AGE''x8H**8VT6JK))%@ILL%#//7LM& LL3 	 e[1009I5RWXX_ 	" F as5   .F&F8F&)F!*A$F&F$CF&!F&$F&r  c                    | j                  |d      }| j                  |d      }|t        |      dk  rd }| j                  |d      }|t        |      dk  rd }| j                  |d      }|t        |      dk  rd }| j                  |d      }| j                  ||      }| j                  |d      }	d|v rd	nd
}
| j                  |d      }| j                  |d      }| j	                  |dd      }|dk(  }| j                  |d      }|| j                  |d      }|
d
k(  rd}| j                  |d      }| j                  |      | j                  |      d}i d|d| j                  |dd      d|d|	d| j                  |	      d| j                  |      d|d|dd d|d d d!d d"|
d|d#|d$| j                  | j                  |d$            d%d |||d&S )'Nr  r:  r   remarktx_idr  r3  withdraw_id
withdrawalr  r  tx_feewithdraw_methoddeposit_methodlocalactual_amountr   r)  	fee_assetr5  r  r8   
deposit_idtxidr  r  r  r8  	addressToaddressFromr;  tagTotagFromr  r6  r  updated)r  commentinternal)r  r  r  r&  safe_string_lower_2r  r  r  r@  network_id_to_coder  )r  r  r6  r8  r;  r  r  r  r  r  r  r  feeCosttransferMethodr  r   rB  r  s                     r  r  zcoinex.parse_transaction  s   Z "";={F3?3x!|!!+x86{QW54y1}%%k59
&&z8<%%k<@	 - <|9$$[':	"";911+?PRbc!W,!!+?>%%k8<F9G((kB%%g.//>

K
$$$[-N
 D
 	

 Y/
 t..y9
 w
 
 4
 3
 T
 t
 D
 f
 
  d33D4D4D[RZ4[\!
" t#
$  )
 	
r  fromAccount	toAccountc                   K   | j                          d{    | j                  |      }| j                  ||      }| j                  | j                  di       }| j                  |||      }	| j                  |||      }
|d   ||	|
d}|dk(  s|dk(  rR| j                  |d      }|t        | j                  dz         | j                  |d      }| j                  |      |d<   |d	k7  r|d	k7  rt        | j                  d
z         | j                  | j                  ||             d{   }| j                  | j                  ||      | j                  |      ||d      S 7 Q7 <w)a  
        transfer currency internally between wallets on the same account

        https://docs.coinex.com/api/v2/assets/transfer/http/transfer

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.symbol]: unified ccxt symbol, required when either the fromAccount or toAccount is margin
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        Nr   r8   )r  r   from_account_typeto_account_typerE   r  zE transfer() the symbol parameter must be defined for a margin accountr  rD   zs transfer() can only be between spot and swap, or spot and margin, either the fromAccount or toAccount must be spot)r   r  r  )r  r6  r  r  r   r  r(   r8   r  	market_idr)   v2PrivatePostAssetsTransferr  parse_transferr  )r  r  r   r  r  r  r6  amountToPrecisionr   fromIdtoIdr  r  r  s                 r  r   zcoinex.transfer  s     !!!==& 66tVD6FK!!.+{K	9ED>'!'#	
 8#h)>%%fh7F~'2y(yzzYYvx0F $v 6GH6!	V(;TWW  (]  ]  ^  ^99$++gv:VWW {{4..xB''(9:&"E
  	9 	"( Xs"   E,E'DE,-E*.:E,*E,c                 8    dddddd}| j                  |||      S )Nr  )r)  SUCCESSOKr  FINISHEDr  r  s      r  parse_transfer_statuszcoinex.parse_transfer_status  s/    
 &&99r  r   c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  | j                  di       }d || j	                  |      | j                  ||      | j                  |d      | j                  |||      | j                  |||      | j                  | j                  |dd            d	S )
Nr3  r  r  r  r!  r   r  r  )r8   r  r  r6  r   r  r  r  )	r&  r  r  r   r@  r  r  r  r  )r  r   r6  r  r  r  r  r!  s           r  r  zcoinex.parse_transfer   s    %%h=	%%h6
!!(,?@*;<t||^RH"Y///
HE&&x:++L&&I)),dC001C1CHfV^1_`	
 		
r  c                   K   | j                          d{    |t        | j                  dz         | j                  |      }d|d   i}d}| j	                  d|      \  }}|d|d<   nd|d<   |||d	<   |||d
<   | j                  d||      \  }}| j                  | j                  ||             d{   }| j                  |dg       }	| j                  |	|||      S 7 7 -w)a  
        fetch a history of internal transfers made on an account

        https://docs.coinex.com/api/v2/assets/transfer/http/list-transfer-history

        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of transfer structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' for fetching transfers to and from your margin account
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
        Nz* fetchTransfers() requires a code argumentr  r8   r   r   transfer_typer   rB  r9  rC  r  )
r  r(   r8   r6  r  rD  !v2PrivateGetAssetsTransferHistoryr  r  parse_transfers)
r  r  rE  r9  r  r6  r  r(  r  r  s
             r  fetch_transferszcoinex.fetch_transfers1  s     !!!<#DGG.Z$Z[[==&8D>
 
!??@PRXY
F!'/GO$'0GO$$)GL!$GG22:wO??GU[@\]]* ~~h3##D(E5AAQ 	"$ ^s"   C)C%B"C)9C':,C)'C)c                 .  K   | j                          d{    i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||             d{   }| j	                  |dg       }| j                  ||||      S 7 z7 -w)a3  
        fetch all withdrawals made from an account

        https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/list-withdrawal-history

        :param str [code]: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawal structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr8   r  r9  r  )r  r6  v2PrivateGetAssetsWithdrawr  r  parse_transactions	r  r  rE  r9  r  r  r6  r  r  s	            r  fetch_withdrawalszcoinex.fetch_withdrawalsh  s      !!!}}T*H%d^GEN$GG88Wf9UVVB ~~h3&&tXueDDU 	" W"   BBAB%B&,BBc                 .  K   | j                          d{    i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||             d{   }| j	                  |dg       }| j                  ||||      S 7 z7 -w)a%  
        fetch all deposits made to an account

        https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/list-deposit-history

        :param str [code]: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposit structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr8   r  r9  r  )r  r6   v2PrivateGetAssetsDepositHistoryr  r  r(  r)  s	            r  fetch_depositszcoinex.fetch_deposits  s      !!!}}T*H%d^GEN$GG>>t{{7TZ?[\\< ~~h3&&tXueDDO 	" ]r+  r  c           
          | j                  |d      }| j                  ||d d      }| j                  |d      }| j                  |d      }d }d }||d   k(  r|}n
||d   k(  r|}|d   |d   ||d	   |d
d d |d	S )Nr  rD   r  daily_interest_rater  r  r  r  r  i \&)	r  r  baseRater  	quoteRaterW  r  r  r  )r  r>  r  )r  r  r  r  r6  rater1  r2  s           r  parse_isolated_borrow_ratez!coinex.parse_isolated_borrow_rate  s     ##D(3!!(FD&A##D%0&;<	vh''H	**IX&6N G_"

 
	
r  c                   K   | j                          d{    | j                  |d      }|t        | j                  dz         | j	                  |d      }| j                  |      }| j                  |      }|d   |d   d}| j                  | j                  ||             d{   }| j                  |di       }| j                  ||      S 7 7 +w)a	  
        fetch the rate of interest to borrow a currency for margin trading

        https://docs.coinex.com/api/v2/assets/loan-flat/http/list-margin-interest-limit

        :param str symbol: unified symbol of the market to fetch the borrow rate for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['code']: unified currency code
        :returns dict: an `isolated borrow rate structure <https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure>`
        Nr  z4 fetchIsolatedBorrowRate() requires a code parameterr8   r  r  r  )r  r  r(   r8   r  r6  r  %v2PrivateGetAssetsMarginInterestLimitr  r  r4  	r  r  r  r  r6  r  r  r  r  s	            r  fetch_isolated_borrow_ratez!coinex.fetch_isolated_borrow_rate  s      !!!/<#DGG.d$dee66*==&V$TlD>
 CCDKKPWY_D`aa ~~h3..tV<<7 	" br1  c                 R  K   | j                          d{    i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||             d{   }| j	                  |dg       }	| j                  |	|      }
| j                  |
|||      S 7 7 ?w)a  
        fetch the interest owed by the user for borrowing currency for margin trading

        https://docs.coinex.com/api/v2/assets/loan-flat/http/list-margin-borrow-history

        :param str [code]: unified currency code
        :param str [symbol]: unified market symbol when fetch interest in isolated markets
        :param int [since]: the earliest time in ms to fetch borrrow interest for
        :param int [limit]: the maximum number of structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
        Nr8   r  r9  r  )r  r  %v2PrivateGetAssetsMarginBorrowHistoryr  r  parse_borrow_interestsfilter_by_currency_since_limit)r  r  r  rE  r9  r  r  r  r  r  ra  s              r  fetch_borrow_interestzcoinex.fetch_borrow_interest  s      !!![[(F &tGH$GGCCDKKPWY_D`aa2 x4..tV<228T5%PPG 	" bs"   B'B#AB'%B%&>B'%B'c                 L   | j                  |d      }| j                  ||d d      }| j                  |d      }||d   | j                  | j                  |d            | j	                  |d      | j	                  |d      | j	                  |d      d	|| j                  |      d
	S )Nr  rD   
expired_atr  r  to_repaied_amountr0  borrow_amountrs  )	r  r  r6  ra  r  amountBorrowedr(  r  r  )r  r>  r&  r  r  r@  )r  r  r  r  r  s        r  parse_borrow_interestzcoinex.parse_borrow_interestP  s     ##D(3!!(FD&A%%dL9	X&//0@0@u0MN((/BC ,,T3HI"..t_E$"Y/

 
	
r  c                   K   | j                          d{    | j                  |      }| j                  |      }| j                  |ddd      }| j	                  |d      }|d   |d   | j                  ||      |d}| j                  | j                  ||             d{   }	| j                  |	di       }
| j                  |
|      }| j                  |||d      S 7 7 @w)	am  
        create a loan to borrow margin

        https://docs.coinex.com/api/v2/assets/loan-flat/http/margin-borrow

        :param str symbol: unified market symbol, required for coinex
        :param str code: unified currency code of the currency to borrow
        :param float amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.isAutoRenew]: whether to renew the margin loan automatically or not, default is False
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        NisAutoRenewis_auto_renewFr8   )r  r  rB  rG  r  r   r  )
r  r  r6  r  r  r  v2PrivatePostAssetsMarginBorrowr  r  parse_margin_loan)r  r  r  r   r  r  r6  rF  r  r  r  r  s               r  borrow_isolated_marginzcoinex.borrow_isolated_marginn  s      !!!V$==&&&v}ouU6=1TlD>!77fE(	
 ==dkk'SY>Z[[" ~~h3,,T8<{{;)
  	= 	" \s"   C'C#BC'$C%%?C'%C'c                   K   | j                          d{    | j                  |      }| j                  |      }|d   |d   | j                  ||      d}| j	                  | j                  ||             d{   }| j                  |di       }	| j                  |	|      }
| j                  |
||d      S 7 7 @w)aE  
        repay borrowed margin and interest

        https://docs.coinex.com/api/v2/assets/loan-flat/http/margin-repay

        :param str symbol: unified market symbol, required for coinex
        :param str code: unified currency code of the currency to repay
        :param float amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.borrow_id]: extra parameter that is not required
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        Nr8   )r  r  r   r  rH  )r  r  r6  r  v2PrivatePostAssetsMarginRepayr  r  rJ  )r  r  r  r   r  r  r6  r  r  r  r  s              r  repay_isolated_marginzcoinex.repay_isolated_margin  s      !!!V$==&TlD>00v>

 <<T[[RX=YZZ ~~h3,,T8<{{;)
  	% 	" [s"   C B<A&C =B>>?C >C c           	      $   | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      | j                  ||      | j                  |d      | j                  |d d d      || j	                  |      |dS )Nr  r  r@  	borrow_idrB  rD   )r8   r6  r   r  r  r  r  )r  r&  r  r  r@  )r  r  r6  r  r  r  s         r  rJ  zcoinex.parse_margin_loan  s     %%dE2
##D(3%%dL9	##D+6//
HE&&t_=&&xtVD"Y/
 	
r  c                   K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |di       }| j                  ||      S 7 j7 +w)a{  
        fetch the fee for deposits and withdrawals

        https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/get-deposit-withdrawal-config

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        Nr  r8   r  )r  r6  &v2PublicGetAssetsDepositWithdrawConfigr  r  parse_deposit_withdraw_fee)r  r  r  r6  r  r  r  s          r  fetch_deposit_withdraw_feez!coinex.fetch_deposit_withdraw_fee  s      !!!==&8D>
 DDT[[QXZ`EabbD ~~h3..tX>>Q 	"
 cs"   BBA BB*BBc                    |d d dd d di d}| j                  |dg       }| j                  |di       }t        dt        |            D ]  }||   }| j	                  |d      }|s| j                  |d      |d   d	<   d
|d   d<   | j                  |d      }	|	sR| j                  |	| j                  |d            }
| j                  |d      d
dd d dd|d   |
<    |S )N)r  r  )r  r   r  r"  r  r  r   r  r  r   r  Fr  r  r  )r   r  r"  )r  r  r  r  r  r  r  r  )r  r  r6  r  r  r  r  r  isWithdrawEnabledr  r5  s              r  rS  z!coinex.parse_deposit_withdraw_fee  s+   > "
 " 
 Xr2sGR0q#f+& 	A1IE $u6H I ,0,<,<UDT,Uz"5)38z"<0 ,,UG<	"&"9"9)TEUEUV[]bEc"dK $(#3#3E;K#L*/%
 $(*.$	7F:&{3	& r  c                   K   | j                          d{    | j                  |d      }|t        | j                  dz         | j	                  |d      }| j                  |      }| j                  |      }|d   |d   d}| j                  | j                  ||             d{   }| j                  |di       }| j                  ||      S 7 7 +w)a  
        fetch the set leverage for a market

        https://docs.coinex.com/api/v2/assets/loan-flat/http/list-margin-interest-limit

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['code']: unified currency code
        :returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
        Nr  z* fetchLeverage() requires a code parameterr8   r6  r  )r  r  r(   r8   r  r6  r  r7  r  r  parse_leverager8  s	            r  fetch_leveragezcoinex.fetch_leverageQ  s      !!!/<#DGG.Z$Z[[66*==&V$TlD>
 CCDKKPWY_D`aa ~~h3""4007 	" br1  c                 ~    | j                  |d      }| j                  |d      }|| j                  ||d d      d||dS )Nr  r2  rD   rs  )r  r  r(  longLeverageshortLeverage)r  r&  r  )r  r2  r  r  leverageValues        r  rX  zcoinex.parse_leveragey  sR     ##Hh7))(J?&&xvF$)*
 	
r  c                 ~  K   | j                          d{    | j                  |      }d|d   d}|||d<   |||d<   | j                  d||      \  }}| j                  | j	                  ||             d{   }| j                  |dg       }| j                  |      }	| j                  |	|||      S 7 7 >w)	ac  
        fetches historical positions

        https://docs.coinex.com/api/v2/futures/position/http/list-finished-position

        :param str symbol: unified contract symbol
        :param int [since]: the earliest time in ms to fetch positions for
        :param int [limit]: the maximum amount of records to fetch, default is 10
        :param dict [params]: extra parameters specific to the exchange api endpoint
        :param int [params.until]: the latest time in ms to fetch positions for
        :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
        Nr   r8   rU  r9  rB  rC  r  )r  r  rD  rM  r  r  parse_positionsr  )
r  r  rE  r9  r  r  r  r  records	positionss
             r  fetch_position_historyzcoinex.fetch_position_history  s      !!!V$$Tl
 $GG$)GL!22:wOAA$++gW]B^__X ..626((1	00FE5QQs 	" `s"   B=B9A%B=<B;==B=;B=c                   K   | j                          d{    | j                  |      }| j                  |dd      }|d   d|d}| j                  |dd      }|||d<   | j	                  |d      }| j                  | j                  ||             d{   }| j                  |d	i       }	| j                  |	|      S 7 7 +w)
a  
        closes an open position for a market

        https://docs.coinex.com/api/v2/futures/position/http/close-position

        :param str symbol: unified CCXT market symbol
        :param str [side]: buy or sell, not used by coinex
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['type']: required by coinex, one of: limit, market, maker_only, ioc or fok, default is *market*
        :param str [params.price]: the price to fulfill the order, ignored in market orders
        :param str [params.amount]: the amount to trade in units of the base currency
        :param str [params.clientOrderId]: the client id of the order
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  r  r8   r   )r  r  r  r  r  r  )	r  r  r  r  r  r  r  r  r  )
r  r  r9  r  r  r  r  r  r  r  s
             r  close_positionzcoinex.close_position  s      !!!V$9Tl$

 **6;P$#0GK 6?3??GU[@\]]: ~~h3f--U 	" ^s"   CCBCC*CCc                     | j                  | j                  d      }| j                  |dd      }d}t        t        |   |||      \  }}||dk(  s|du rd}||gS )aP  
 @ignore
        marginMode specified by params["marginMode"], self.options["marginMode"], self.options["defaultMarginMode"], params["margin"] = True or self.options["defaultType"] = 'margin'
        :param dict params: extra parameters specific to the exchange api endpoint
        :returns Array: the marginMode in lowercase
        r  rE   FNTrs  )r  r   r  r  r5   r  )r  
methodNamer  defaultValuer  r  r(  r  s          r  r  z$coinex.handle_margin_mode_and_params  ss     &&t||]C>>&(E:
"64Nz[acop
Fx'X-='
F##r  c                 "    | j                         S N)milliseconds)r  s    r  noncezcoinex.nonce!  s      ""r  GETc                 z   | j                  ||      }|d   }|d   }| j                  d   |   dz   |z   dz   |z   }	| j                  || j                  |            }
t	        | j                               }|dk(  r|j                  d      }| j                  |dd      }t        |      }| j                  ||dz
  d      }|j                  d      }t        |      }| j                  ||dz
  d      }|dk(  rV|d	k(  s|d
k(  rL| j                  |d      }|8d}| j                  | j                  d|      }|dz   | j                         z   |
d<   |dk(  r| j                          | j                  | j                  |d|
      }
| j                  |
      }
| j!                  |
      }| j#                  | j%                  |dz   | j&                  z         d      }|j)                         | j                  d}|dk(  s|dk(  r
|	d|z   z  }	nd|d<   |}n|dk(  s|dk(  r|
r|	d| j+                  |
      z   z  }	n|dk(  r| j                          | j                  | j                  |d|
      }
| j                  |
      }
| j!                  |
      }| j#                  | j%                  |dz   | j&                  z         d      }|j-                         dd}|dk(  s
|dk(  s|dk(  r	|	d|z   z  }	n| j/                  |
      }n|d k(  r| j                          | j                  |
      }
| j!                  |
      }|dz   |z   dz   |z   }|dk(  r| j/                  |
      }||z  }n
|r|d|z   z  }||| j&                  z   z  }| j#                  | j%                  |      d      }dd| j                  ||d!}|dk7  r
|r|	d|z   z  }	|	|||d"S )#Nr   r   r   r  POSTr  _r<  r9  r  r  r   r  r   )	access_idr  z&secret_key=sha256)AuthorizationAccessIdrl  PUT?z!application/x-www-form-urlencodedContent-Typer   r   r   )rp  toncemd5zapplication/json)rr  rv  DELETEr<   )rv  AcceptzX-COINEX-KEYzX-COINEX-SIGNzX-COINEX-TIMESTAMP)urlrI  bodyheaders)implode_paramsr   r  extract_paramsry  rk  r<  r  r  r  r   r  check_required_credentialsr  apiKeykeysort	rawencodehashencodesecretrx  	urlencodeupperjson)r  pathr   rI  r  r}  r|  r;   
requestUrlr{  r"  rk  r?  	firstPartnumPartslastPart	lastWordsnumWordslastWordr  r  r  
urlencoded	signaturepreparedStrings                            r  signzcoinex.sign$  s   ""40a&V
iiz*S07:S@4G		&$"5"5d";<DJJL!VJJsOE((26I5zH''x!|R@H s+I9~H''	8a<DHW$8w+>(hBV !% 0 0 E ( -I#t||ZSH)1C$++-)GE+&++++-KK![["! E LL'E.J		$++j>.IDKK.W"XZbcI!*!2 KKG %Vu_sZ''*M'!8#z5F'FsT^^E222$//1!%"%  U+!^^E2
 IIdkk*~2MPTP[P[2[&\^cd	%.__%6$6 eO8);53++C99U+DD//1U+!^^E2
!'#!7#!=!DV#99U+D"d*N"cJ&66N%$++"55 IIdkk.&A8L	$60$(KK%.*/ V#!sZ//fdwOOr  httpCodereasonr{  rI  r}  r|  c
                 x   |y | j                  |d      }
| j                  |d      }| j                  |d      }|
dk7  s|dk7  rw|dk7  rr|j                         dk7  r_|s]| j                  dz   |z   }| j	                  | j
                  d	   ||       | j                  | j
                  d
   |
|       t        |      y )Nr  r  r  r)  Success	Succeededr   r  r  )r  r  rx  r8   throw_broadly_matched_exceptionrH  throw_exactly_matched_exceptionr$   )r  r  r  r{  rI  r}  r|  r  requestHeadersrequestBodyr  r  r  feedbacks                 r  handle_errorszcoinex.handle_errors  s    &1x0""8Y7CKg2K9OV]VcVcVeimVmw{ww}w.H001I7T\]001I4QYZ))r  c                 8  K   | j                          d{    |t        | j                  dz         | j                  |dd      }| j	                  |d      }|t        | j                  dz         | j                  |      }|d   d|d}| j                  d	||      \  }}|||d
<   |||d<   | j                  | j                  ||             d{   }	| j                  |	dg       }
| j                  |
ddd      }| j                  ||||      S 7 7 Aw)a]  
        fetches the history of margin added or reduced from contract isolated positions

        https://docs.coinex.com/api/v2/futures/position/http/list-position-margin-history

        :param str symbol: unified market symbol
        :param str [type]: not used by coinex fetchMarginAdjustmentHistory
        :param int [since]: timestamp in ms of the earliest change to fetch
        :param int [limit]: the maximum amount of changes to fetch, default is 10
        :param dict params: extra parameters specific to the exchange api endpoint
        :param int [params.until]: timestamp in ms of the latest change to fetch
        :param int [params.positionId]: the id of the position that you want to retrieve margin adjustment history for
        :returns dict[]: a list of `margin structures <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        Nz: fetchMarginAdjustmentHistory() requires a symbol argument
positionIdr  z? fetchMarginAdjustmentHistory() requires a positionId parameterr8   r   )r  r  r  rC  rB  r9  r  r  rF   )r  r(   r8   r  r  r  rD  (v2PrivateGetFuturesPositionMarginHistoryr  r  parse_margin_modificationsr  )r  r  r  rE  r9  r  r  r  r  r  r  modificationss               r  fetch_margin_adjustment_historyz&coinex.fetch_margin_adjustment_history  s=     !!!>#DGG.j$jkk((}M
6<0#DGG.o$oppV$Tl$%

 22:wO$)GL!$GGFFt{{SZ\bGcdd4 ~~h377dHfU00uUU] 	"$ es#   DDB?DDA DDri  )}__name__
__module____qualname__r   r  r   r  r#   r   r  r  r  dictr   r  ry  r  r   r   r#  r   r'  r0  r   rD  rJ  r   rM  r    rO  rL  rL  rU  r\  rp  ru  ry  r|  r   r  r   r  r   r  floatr  r   r   r   r  r  r   r  r  r  r  r  r  r&  r)  r+  r
   r0  r6  r	   r/  rG  r   rS  rV  rN  r|  r  r   r  r   r  r  r   r  r  r  r  r   r  r  r  r  r   r  r!   r   r  r  r  r"   r   r  r  r%  r*  r.  r   r4  r9  r   r>  rD  rK  rN  rJ  rT  rS  r   rY  rX  rb  rd  r  rk  r  r  r  r  __classcell__)r  s   @r  r5   r5      st
   E
# E
N -/ |: || *, ;V ;&S$v, Sj\|>4 > >6 >@ 68 F1 F1F F1P 6:" G17 G1 G1R ') 4S 4, @B" O?S O? O?bE Ev E EN <@d[] +I +IS +I +Ibfglbm +IZ ;= @6c @6AT @6D /1 C[ CJ

T 

6 

EX 


 
4 
, 8<$]ajl 0H 0HC 0HWZ 0Hquvzq{ 0Hd 13 3)j /1 )8 /1 )> 46 )8 *, 9 96	: 	:D Dv D DL XZ Tc T T& os{} P,3 P,i P,y P,Z_ P,hk P,d mqy{ l. l.I l.Y l.X] l.fi l.\ FH y$|*< yDQVK yv 6:" ns n` fjx|  FH E.3 E. E.9 E.I E._b E.ru E.N 9=R Y.S Y.# Y.v 59 )
c )
V 8<B U.C U. U.n BFTXgktv n=3 n=c n=ad n=`	 59tZ^gi c  TW nrsxny , 7;\`ik [ [3 [VY [ptuzp{ [& >@ !: !:N !:F =? !: !:> !:F
h 
R` 
2 37TX\eg Q=C Q=s Q=RU Q=f 8<B SPW SP4PX> SPj 8: =43 =4~Ct CV CJ DHPR !c !cS !cZ ?C2 c3 c cT =A *B' *BP] *BX $|J\ , SU : :xD
d D
F D
N` D
L CE Ns NE NI[ N FH Q# Qu QL^ Q 9=4^bkm ?# ?S ?X[ ?B <> &6s &6+ &6P @B 
=3 
=k 
=(
6 (
[ (
T? <@ )7 )7| )7V JNVX 9=3 9= 9= 9=]h 9=v:s : >BPTcgpr ?Ys ?Y# ?Y]` ?YBa
T a
X a
Q\ a
F ac .3 . .C .TW .gt .`:
t 
x 
= 
" 154VZce 5B# 5BS 5BPS 5Bjno|j} 5Bn 37TX\eg 6EC 6Es 6ERU 6Elpq|l} 6Ep 04$UYbd 3E 3EC 3Es 3Eimnyiz 3Ej
t 
V 
Oa 
B DF &=s &=J\ &=P 7;$]apt} 0Q 0QC 0QWZ 0Qjm 0Q  EI  JX  EY 0Qd
$ 
 
. 
< Z\ .3 .c .5 .` RT "# "S "H
 
4 BD 2?S 2?h? ?B 8: &13 &1h &1P
t 
V 
x 
* FJX\eg FR3 FRs FRRU FRlpqylz FRP CGr 9.3 9.i 9.V[ 9.v @BPT $ #  b$T [Pzc 3 S # X\ dg  CGTXgkz~  HJ =VC =Vc =Vad =Vtw =V  OS  Tf  Og =Vr  r5   ): ccxt.async_support.base.exchanger   ccxt.abstract.coinexr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   typingr#   ccxt.base.errorsr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   ccxt.base.decimal_to_precisionr2   ccxt.base.preciser3   r5    r  r  <module>r     s    6 ,  u  u  u  u  u  u  u  u  * 0 - - . ' & . ) * ) . 1 + 4 %nZVX{ nZVr  