
    E#i                       S SK Jr  S SKJr  S SKJrJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"  S SK#J$r$  S SK%J&r&  S SK%J'r'  S SK%J(r(  S SK%J)r)  S S	K%J*r*  S S
K%J+r+  S SK%J,r,  S SK%J-r-  S SK%J.r.  S SK%J/r/  S SK%J0r0  S SK%J1r1  S SK%J2r2  S SK%J3r3  S SK%J4r4  S SK5J6r6  S SK7J8r8   " S S\\5      r9g)    )Exchange)ImplicitAPI)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)OperationFailed)RateLimitExceeded)ExchangeNotAvailable)RequestTimeout)	TICK_SIZE)Precisec                   	  ^  \ rS rSrS\4U 4S jjr0 4S\4S jjr0 4S\\	   4S jjr
S\\	   4S jrS rSS	\S
\	S\4S jjr0 4S\S\4S jjrS0 4S\S\4S jjr0 4S\4S jjrS0 4S\S\4S jjrSS\S
\	S\4S jjrSS0 4S\S\S\S\\   4S jjr0 4S\S\4S jjr0 4S\4S jjrSS\S
\	S\4S jjrSS
\	S\ 4S jjr!SSS0 4S\S\S\S\S\\    4
S jjr"0 4S  jr#0 4S! jr$0 4S" jr%0 4S# jr&0 4S\'4S$ jjr(S%\)4S& jr*SS'\S
\	S\+4S( jjr,0 4S\S)\-4S* jjr.S0 4S\S+\/S,\0S-\-S.\14
S/ jjr2S0 4S\S+\/S,\0S-\-S.\14
S0 jjr30 4S1\\4   S\\+   4S2 jjr5S0 4S3\\   S\)4S4 jjr6SS0 4S5\S\S+\/S,\0S-\1S.\14S6 jjr7S0 4S5\S\)4S7 jjr8S0 4S\)4S8 jjr9S0 4S5\S\)4S9 jjr:SSS0 4S\)S\S\4S: jjr;SSS0 4S\)S\S\S\\+   4S; jjr<SSS0 4S\)S\S\S\\+   4S< jjr=0 4S=\S\>4S> jjr?0 4S=\S\>4S? jjr@SS@\AS\>4SA jjrBSSS0 4S\)S\S\4SB jjrCS0 4S\S\\D   4SC jjrE0 4S\4SD jjrFSSE\S
\	4SF jjrGS0 4SG\S\)4SH jjrHS0 4SI\IS\)4SJ jjrJS0 4S\S\K4SK jjrLSS
\	S\\M   4SL jjrN0 4S\4SM jjrOSSN\S
\	S\P4SO jjrQ0 4S\S-\-S\P4SP jjrR0 4S\S-\-S\P4SQ jjrSSSS0 4S\)S\S\4SR jjrT0 4S\S\U4SS jjrV0 4S\S\U4ST jjrWSS
\	S\U4SU jjrXSV rYS0 4S\S\Z4SW jjr[S0 4S=\S-\-SX\SY\)S\\4
SZ jjr]S%\)4S[ jr^SSS0 4S\)S\S\4S\ jjr_SS]\S@\AS\\4S^ jjr`0 4S=\S-\-S_\S`\S\a4
Sa jjrbSb rcSSc\S@\AS\a4Sd jjrdSSS0 4S=\)S\S\S\\a   4Se jjreSSS0 4S=\)S\S\S\\\   4Sf jjrfSSS0 4S=\)S\S\S\\\   4Sg jjrgSSh\S
\	S\h4Si jjri0 4S\S\h4Sj jjrjSSSS0 4S=\)S\)S\S\S\\k   4
Sk jjrlSSh\S
\	S\k4Sl jjrm0 4S\S=\S-\-4Sm jjrn0 4S\S=\4Sn jjroSS@\A4So jjrp0 4S=\4Sp jjrqS0 4Sq\4Sr jjrrSS@\A4Ss jjrs0 4S\S\t4St jjruSSI\S
\	S\t4Su jjrvSS0 4S\S\S\S\\D   4Sv jjrwS0 4S\S,\0S\+4Sw jjrx0 S4U 4Sx jjrySy rz/ Sz0 SS4S{ jr{S|\IS}\S~\S\S\S\4S jr|SSSS0 4S\)S+\)S\1S\1S\\P   4
S jjr}Sr~U =r$ )coinex   returnc                   > U R                  [        [        U ]  5       0 SS_SS_SS_SS/_S	S
_SS_SS_S0 SS _SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S_0 S!S_S"S_S#S_S$S_S%S_S&S_S'S_S(S_S)S_S*S_S+S_S,S_S-S_S.S_S/S_S0S_S1S_E0 S2S_S3S_S4S_S5S_S6S_S7S_S8S_S9S_S:S_S;S_S<S_S=S_S>S_S?S_S@S_SAS_SBS_E0 SCS_SDS_SESF_SGS_SHS_SIS_SJS_SKS_SLS_SMS_SNS_SOS_SPS_SQS_SRS_SSS_STS_E0 SUS_SVS_SWS_SXS_SYS_SZS_S[S_S\S_S]S_S^S_S_S_S`S_SaS_SbS_ScS_SdS_SeS_E_SfSgShSiSjSkSlSmSnSoSpSqSrSsSt._SuSvSwSwSxSxSy.SzS{S|S}S~._SSSSSSSSSSSSSSSSS.00 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSSSSSSSSS.E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS0ESSSSSS.SSSSSSSSSS.	S.SSSSSSSSSSSS.
0SSSSSSSSSSSSSSSS.0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSS.ES.Sy.S0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSS.E00 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_ESSSSSSSS.E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_GS S_GSS_GSS_GSS_0 GSS_GSS_GSS_GSS_GSS_GS	S_GS
GS_GSGS_GSGS_GSGS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_ESSGSGSSSSSSSSSSGS.ES.GS.GS._GSGSGSGS.SeGSGSGSGSGSGSGS.0GS ._GS!GS"GSS GS#.0_GS$GS%SSGS&GS'S0GS(GS)GS*GS+.SSSGS,.0 GS-GS-_GS.GS/_GS0GS0_GS1GS1_GS2GS2_GS3GS3_GS4GS4_GS5GS5_GS6GS7_GS8GS9_GS:GS:_GS;GS;_GS<GS=_GS>GS>_GS?GS@_GSAGSB_GSCGSD_0 GSEGSF_GSGGSG_GSHGSH_GSIGSI_GSJGSJ_GSKGSK_GSLGSL_GSMGSM_GSNGSN_GSOGSO_GSPGSP_GSQGSR_GSSGSS_GSTGST_GSUGSU_GSVGSW_GSXGSX_EGSYGSZGS[.EGS\._GS]SSSS SSSS SSSSGS^.SSSSSSSGS_.GS`GSa0SGSbS GScSGSd.SSSSGSe.SGSbSSSGSf.S SGSbS S S SSSGSg.GShGSb0GSi.	SSSSGSj.GSkS0GSkS0GSl.GSmGSn0GSmGSn0GSo.S S GSo.GSp._GSqGSrGSs0_GSt[        _GSu0 GSv[
        _GSw[        _GSx[        _GSy[        _GSz[        _GS{[        _GS|[        _GS}[        _GS~[
        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _E0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[
        _GS[        _GS[        _GS[        _GS[
        _GS[        _GS[        _GS[         _E[        [        [        [        [
        GS.E[
        [        ["        GS.GS.0E5      $ (  Nidr6   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)rF   rG   rH   )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defaultSubTyperg   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*  triggerr3  r>  )r*  r;  r?  r3  r>  )r*  r;  r<  daysBackCanceledr=  r?  r3  r>  r;  )	sandboxrW   rX   r~   r   r   fetchOrdersrc   r   )r*  r.  r/  r*  )extendsrW   r   rc   rC  forDerivatives)r   inverse)rF   rD  rH   rI   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 busyz6Service is not available during funding fee settlement)exactbroad)deep_extendsuperr6   describer3   r&   r%   r1   r2   r0   r+   r-   r,   r$   r)   r'   r*   r/   )self	__class__s    E/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/coinex.pyr  coinex.describe   s   fd < > E
A
(E
A
HE
A
 tE
A
 $	E
A
 E
A
 4E
A
  !E
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 +DQ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#E
A
P QE
A
n ~67'I(J	 075NoE
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E
A
j ""
 "$$$% &!	kE
A
J  KE
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E
A
J $&*(,,0,1).+06:#'#'"&#(	( #($)$)+/26/3#')$. q% '+!%$(%+*.& ',#($)*.	# '+!%#'$)*/( $(&*!%$(,0%)#'$)*/	*  #u=~  &&*)-+/$ %e( %e*#  "#3 "#3 	 ##kYKE
A
~ z!E
A
D YEE
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 +;(<N]yAGE
A
 E
 E
	    c                    U R                  U5      nU R                  US/ 5      n0 n[        S[        U5      5       GH   nX5   nU R	                  US0 5      nU R                  US/ 5      nU R                  US5      n	U	c  ME  U R                  U	5      n
U R                  US5      nU R                  US5      nU R	                  US0 5      nU R                  U R                  US	5      5      n0 n[        S[        U5      5       GH  nUU   nU R                  US
5      nU R                  UU
5      nUc  M2  U R                  U R                  US	5      5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nUUSU=(       a    UUUU R                  U5      U R                  U5      SSS.U R                  U5      SS.U R                  U5      SS.S.US.
nUUU'   GM     U R                  U	U
SU=(       a    UUUSU R                  U5      SSS.SSS.SSS.S.USUS.5      XJ'   GM#     U$ )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
datar   assetchainsccyNdeposit_enabledwithdraw_enabledwithdrawal_precisionchainwithdrawal_feemin_deposit_amountmin_withdraw_amountr   )r   depositr   )
r:   networkr;   activer  r   fee	precisionr   infocrypto)r:   coder;   r  r  r   r  r  r   r$  typer  ))v2PublicGetAssetsAllDepositWithdrawConfig	safe_listrangelen	safe_dictsafe_stringsafe_currency_code	safe_boolparse_precisionnetwork_id_to_codeparse_numbersafe_currency_structure)r  paramsresponser  resulticoinr  r  
currencyIdr  
canDepositcanWithdraw
firstChainfirstPrecisionStringr$  jr  	networkIdnetworkCodeprecisionString	feeStringminNetworkDepositStringminNetworkWithdrawStringcanDepositChaincanWithdrawChainr  s                              r  fetch_currenciescoinex.fetch_currencies  s    AA&IH ~~h3q#d)$A7DNN4"5E^^D(B7F))%7J!**:6D/@AJ..0BCK26J#'#7#78H8HUk8l#m H1c&k*q	 ,,UG<	"55iF$"&"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 )0%K +L  77 $4%'!../CD  $#
  $# 
  $#! % 39 FLg %\ r  c                     U R                  U5      U R                  U5      /nUnUS   nUS   nU R                  XE5      $ )a2  
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
r   r   )fetch_spot_marketsfetch_contract_marketsarray_concat)r  r  promisesUnresolvedpromisesspotMarketsswapMarketss         r  fetch_marketscoinex.fetch_markets&  sR     ##F+''/
 &qkqk  ::r  c                 |   U R                  U5      nU R                  US/ 5      n/ n[        S[        U5      5       GH{  nX5   nU R	                  US5      nU R	                  US5      nU R	                  US5      n	U R                  U5      n
U R                  U	5      nU
S-   U-   nUR                  0 SU_SU_S	U
_S
U_SS _SU_SU	_SS _SS_SS_SU R                  US5      _SS_SS_SS_SU R                  US5      _SS_SS _S U R                  US5      U R                  US5      S S S S S U R                  U R                  U R	                  US5      5      5      U R                  U R                  U R	                  US5      5      5      S .S S S!.U R                  US"5      S S!.S S S!.S S S!.S#.S US$.E5        GM~     U$ )%Nr  r   marketbase_ccy	quote_ccy/r:   symbolbasequotesettlebaseIdquoteIdsettleIdr  rF   TrG   is_margin_availablerH   FrI   rJ   r  is_api_trading_availablecontractr   taker_fee_ratemaker_fee_ratebase_ccy_precisionquote_ccy_precisionr   pricer   
min_amountr4  r   r  costrE  r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper  r   createdr  )v2PublicGetSpotMarketr  r  r  r  r  appendr  safe_numberr  r  )r  r  r  marketsr  r  r  r:   r  r  r  r  r  s                r  r  coinex.fetch_spot_markets9  s   --f5. ..626q#g,'AZF!!&(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 $..1FG2 2 %2 %2 $..1KL2  E!2" $#2$  ))&2BC))&2BC $"&""//0D0DTEUEUV\^rEs0tu!..t/C/CDDTDTU[]rDs/tu  $#!
  $//E#
  $#
  $#$  c2 2 (v r  c                 F   U R                  U5      nU R                  US/ 5      n/ n[        S[        U5      5       GH  nX5   nU R                  nU R                  US/ 5      nU R                  US5      n	U	S:H  n
U	S:H  nU R                  US5      nU R                  US5      nU R                  US	5      nU R                  U5      nU R                  U5      nU	S:X  a  S
OUnU R                  U5      nUS-   U-   S-   U-   n[        U5      nUR                  0 SU_SU_SU_SU_SU_SU_SU_SU_SS_SS_SS_SS_SS_SS_SS _SS_SU
_UUS   S    US   S!   U R                  S"5      S S S S U R                  U R                  U R                  US#5      5      5      U R                  U R                  U R                  US$5      5      5      S%.U R                  US5      U R                  UUS&-
  5      S'.U R                  US(5      S S'.S S S'.S S S'.S).S US*.E5        GM     U$ )+Nr  r   r4  contract_typer   rE  r  r  r  USDTr  :r:   r  r  r  r  r  r  r  r  rH   rF   FrG   TrI   rJ   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   rE  r:   r  r  r  r  r  r  r  leveragesLengths                        r  r  coinex.fetch_contract_markets  s   008, ..626q#g,'AJE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! (F r  Ntickerr  c           
      :   SU;   a  SOSnU R                  US5      nU R                  XBS U5      nU R                  0 SU_SS _SS _SU R                  US5      _S	U R                  US	5      _S
S _SU R                  US5      _SS _SU R                  US5      _SS _SU R                  US5      _SU R                  US5      _SU R                  US5      _SS _SS _SS _SS _U R                  US5      S U R                  US5      U R                  US5      US.EU5      $ )N
mark_pricerH   rF   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_tickercoinex.parse_ticker  s   H !- 6VV
##FH5!!(D*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                 Z   U R                  5         U R                  U5      nSUS   0nSnUS   (       a!  U R                  U R                  XB5      5      nO U R	                  U R                  XB5      5      nU R                  US/ 5      nU R                  US0 5      nU R                  Xs5      $ )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>`
r  r:   NrH   r  r   )load_marketsr  v2PublicGetFuturesTickerextendv2PublicGetSpotTickerr  r  r  r  r  r  r  requestr  r  r  s           r  fetch_tickercoinex.fetch_ticker.  s     	V$fTl
 &>44T[[5QRH11$++g2NOH` ~~h3a,  00r  symbolsc                 Z   U R                  5         U R                  U5      nSnUb#  U R                  US5      nU R                  U5      nU R	                  SX25      u  pVSnUS:X  a  U R                  U5      nOU R                  U5      nU R                  US/ 5      nU R                  X5      $ )a4  
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   rH   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_tickerscoinex.fetch_tickersv  s     	%%g.__Wa0F[[(F >>~v^
44U;H11%8H` ~~h3!!$00r  c                 n    U R                  U5      nU R                  US0 5      nU R                  US5      $ )a$  
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
r  r  )v2PublicGetTimer  safe_integer)r  r  r  r  s       r  
fetch_timecoinex.fetch_time  s;     ''/ ~~h3  {33r  r   r;  c                    U R                  5         U R                  U5      nUc  SnUS   USS.nSnUS   (       a!  U R                  U R                  XS5      5      nO U R	                  U R                  XS5      5      nU R                  US0 5      nU R                  US0 5      nU R                  US	5      n	U R                  XU	5      $ )
aL  
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   r:   0)r  r;  intervalrH   r  depth
updated_at)r  r  v2PublicGetFuturesDepthr   v2PublicGetSpotDepthr  r1  parse_order_book)
r  r  r;  r  r  r#  r  r  r7  r  s
             r  fetch_order_bookcoinex.fetch_order_book  s     	V$=ETl

 &>33DKK4PQH6 00W1MNH4 ~~h3tWb1%%e\:	$$UI>>r  tradec                 z   U R                  US5      nU R                  U R                  S5      nUb  US   nU R                  US5      nU R                  XRS U5      nU R                  US5      nS nUb(  U R                  US5      nU R	                  U5      n	UU	S.nU R                  UUU R                  U5      US   U R                  US	5      U R                  US
5      S U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      US.U5      $ )N
created_atr   r  r  r  fee_ccyr  currencyr  deal_idorder_idsideroler  r   
deal_money)r  r  r   r  r:   orderr  rF  takerOrMakerr  r   r  r  )r1  r  r   safe_marketr  
safe_tradeiso8601)
r  r>  r  r  r   r  feeCostStringr  feeCurrencyIdfeeCurrencyCodes
             r  parse_tradecoinex.parse_trade&  s[   P %%e\:	&&t||]C .K##E84!!(D+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                 &   U R                  5         U R                  U5      nSUS   0nUb  X6S'   SnUS   (       a!  U R                  U R                  Xd5      5      nO U R	                  U R                  Xd5      5      nU R                  US   XRU5      $ )a2  
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>`
r  r:   Nr;  rH   r  )r  r  v2PublicGetFuturesDealsr   v2PublicGetSpotDealsparse_trades)r  r  rS  r;  r  r  r#  r  s           r  fetch_tradescoinex.fetch_tradesm  s     	V$fTl
 $G&>33DKK4PQH00W1MNH$   &!16%HHr  c                 Z   U R                  5         U R                  U5      nSUS   0nSnUS   (       a!  U R                  U R                  XB5      5      nO U R	                  U R                  XB5      5      nU R                  US/ 5      nU R                  US0 5      nU R                  Xs5      $ )ae  
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>`
r  r:   NrF   r  r   )r  r  r  r   r  r  r  parse_trading_feer"  s           r  fetch_trading_feecoinex.fetch_trading_fee  s     	V$fTl
 &>11$++g2NOH, 44T[[5QRH, ~~h3a,%%f55r  c                    U R                  5         SnU R                  SSU5      u  p!SnUS:X  a  U R                  U5      nOU R                  U5      nU R	                  US/ 5      n0 n[        S[        U5      5       HE  nXF   nU R                  US5      nU R                  USSU5      n	U	S   n
U R                  Xy5      XZ'   MG     U$ )am  
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   rH   r  r   r  r  )
r  r*  r  r  r  r  r  r  rK  r[  )r  r  r  r  r  r  r  r  r  r  r  s              r  fetch_trading_feescoinex.fetch_trading_fees  s     	99:LdTZ[6>44V<H. 11&9H* ~~h3q#d)$AGE''x8H%%hdDAFH%F!33EBFN % r  r  c                     U R                  US5      nU R                  X25      nUUU R                  US5      U R                  US5      SSS.$ )Nr  r  r  T)r  r  r   r   r  	tierBased)r)  r  r  )r  r  r  r  r  s        r  r[  coinex.parse_trading_fee!  sZ    ??31!!(3%%c+;<%%c+;<
 	
r  c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Nr@  r
  r  r  r  value)r1  r  )r  ohlcvr  s      r  parse_ohlcvcoinex.parse_ohlcv-  sn     e\2UF+UF+UE*UG,UG,
 	
r  r   	timeframec                 |   U R                  5         U R                  U5      nUS   U R                  U R                  X"5      S.nUb  XGS'   SnUS   (       a!  U R	                  U R                  Xu5      5      nO U R                  U R                  Xu5      5      nU R                  US/ 5      n	U R                  XX#U5      $ )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
r:   )r  periodNr;  rH   r  )	r  r  r  r   v2PublicGetFuturesKliner   v2PublicGetSpotKliner  parse_ohlcvs)
r  r  ri  rS  r;  r  r  r#  r  r  s
             r  fetch_ohlcvcoinex.fetch_ohlcvC  s     	V$Tl&&t	M
 $G&>33DKK4PQH00W1MNH* ~~h3  yGGr  c                    U R                  5         U R                  U5      nSU0nU R                  US/ 5      n[        S[	        U5      5       H  nXE   nU R                  US0 5      nU R                  US0 5      nU R                  US0 5      n	U R                  US0 5      n
U R                  5       nU R                  US5      nU R                  U5      nU R                  US5      US	'   U R                  US5      US
'   U R                  U	S5      nU R                  U
S5      n[        R                  " X5      US'   XU'   M     U R                  U5      $ )Nr  r  r   	availablefrozenrepaidinterestr  freeuseddebt)r  v2PrivateGetAssetsMarginBalancer  r  r  r  accountr  r  r4   
string_addsafe_balance)r  r  r  r  balancesr  r  rv  rw  loanru  baseAccountbaseCurrencyIdbaseCurrencyCodebaseDebtbaseInterests                   r  fetch_margin_balancecoinex.fetch_margin_balanceu  sR   77?@ )>>(FB7q#h-(AKE>>%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'2#$ )   ((r  c                    U R                  5         U R                  U5      nSU0nU R                  US/ 5      n[        S[	        U5      5       Hh  nXE   nU R                  US5      nU R                  U5      nU R                  5       n	U R                  US5      U	S'   U R                  US5      U	S'   XU'   Mj     U R                  U5      $ 	Nr  r  r   r  rr  rv  rs  rw  )	r  v2PrivateGetAssetsSpotBalancer  r  r  r  r  rz  r|  
r  r  r  r  r}  r  r  r  r  rz  s
             r  fetch_spot_balancecoinex.fetch_spot_balance  s    55f= )>>(FB7q#h-(AKE))%7J**:6DllnG"..ukBGFO"..uh?GFO"4L )   ((r  c                    U R                  5         U R                  U5      nSU0nU R                  US/ 5      n[        S[	        U5      5       Hh  nXE   nU R                  US5      nU R                  U5      nU R                  5       n	U R                  US5      U	S'   U R                  US5      U	S'   XU'   Mj     U R                  U5      $ r  )	r   v2PrivateGetAssetsFuturesBalancer  r  r  r  r  rz  r|  r  s
             r  fetch_swap_balancecoinex.fetch_swap_balance  s    88@" )>>(FB7q#h-(AKE))%7J**:6DllnG"..ukBGFO"..uh?GFO"4L )   ((r  c                    U R                  5         U R                  U5      nSU0nU R                  US/ 5      n[        S[	        U5      5       Hh  nXE   nU R                  US5      nU R                  U5      nU R                  5       n	U R                  US5      U	S'   U R                  US5      U	S'   XU'   Mj     U R                  U5      $ r  )	r  "v2PrivateGetAssetsFinancialBalancer  r  r  r  r  rz  r|  r  s
             r  fetch_financial_balancecoinex.fetch_financial_balance  s    ::6B )>>(FB7q#h-(AKE))%7J**:6DllnG"..ukBGFO"..uh?GFO"4L )   ((r  c                 *   SnU R                  SSU5      u  p!SnU R                  SU5      u  p1USL=(       d    US:H  nUS:X  a  U R                  U5      $ US:X  a  U R                  U5      $ U(       a  U R	                  U5      $ U R                  U5      $ )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_   rG   rH   	financial)r*  handle_margin_mode_and_paramsr  r  r  r  )r  r  r  r*  isMargins        r  fetch_balancecoinex.fetch_balance  s     
!??PTV\]

!??PVW
d*G
h0F**622;&//77,,V44**622r  statusc                 8    SSSSSSS.nU R                  X!U5      $ )Nrejectedr
  closedcanceled)r  r
  not_deal	part_dealdonecancelr  r  r  statusess      r  parse_order_statuscoinex.parse_order_status  s0    " 
 &99r  rI  c                    U R                  US5      nU R                  US5      nU R                  US5      nUS:X  a  UnU R                  US5      nU R                  U R                  S5      nU R                  USU5      nUS:X  a  S	nUS	:X  a  S	OS
n	U R	                  XbS U	5      nU R                  US5      n
U R                  U
5      nUc  US   nU R                  US5      nUS:X  a  SnOUS:X  a  SnU R                  US5      nUS:X  a  S nU R                  0 SU R                  U/ SQ5      _SU_SU R                  U5      _SU_SU_SU R                  U5      _SUS   _SU R                  US5      _SS _SS _SS _SU_SU R                  US5      _S U R                  US!5      _S"U R                  US#5      _S$U R                  US%5      _S&U R                  US'5      _U R                  US(5      U R                  US)5      U R                  US*5      U R                  US+5      S UU R                  US,S-5      S..US/.EU5      $ )0Nr  r@  r8  r   r  r   market_typefuturesrH   rF   rA  r  rF  longbuyshortsell	client_id r:   )position_idrE  stop_idclientOrderIdr   r  lastTradeTimestampr  r  r1  postOnly
reduceOnlyr  r+  trigger_pricer/  take_profit_pricer.  stop_loss_pricer  filled_valueavg_entry_pricer   filled_amountunfilled_amount	quote_feer  )rC  r  )r  r   filled	remainingtradesr  r  )r  r1  r   safe_string_lowerrK  r  
safe_ordersafe_string_nrM  r  r  safe_string_2)r  rI  r  	rawStatusr  updatedTimestampr  r   	orderTyper  rO  feeCurrencyrF  r  s                 r  parse_ordercoinex.parse_order'  s   ` $$UH5	%%e\:	,,ULAq (##E84&&t||]C**5-M		!I )V 3V&
!!(D*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                     U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS'   U R	                  USSUSU5      $ )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>`
rF   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr  r  r  N)r  r  r.   r:   create_order)r  r  r  r  r  s        r  !create_market_buy_order_with_cost(coinex.create_market_buy_order_with_cost-  s`     	V$f~tww)ddee6;23  5$fMMr  r  rF  r   r  c                 <   U R                  U5      nUS   nU R                  USS5      n	U R                  USS5      n
U R                  US5      nU R                  US5      nU R                  US5      nUS	:H  nU R                  XS
:H  U5      nU R	                  US5      nU R                  US5      nU(       a+  US   (       d!  [        U R                  S-   US   -   S-   5      eS	US   0nU	c9  SnU R                  U R                  SU5      nUS-   U R                  5       -   US'   OU	US'   UcO  UcL  U(       d  UUS'   UnU(       a  S
nOUb  US:X  a  SnOUS:X  a  SnU(       d  U R                  X5      US'   UUS'   U(       a  SUS'   U(       d  U(       af  U(       a,  U R                  X5      US'   U R                  USS5      US'   GOU(       a*  U R                  X5      US '   U R                  USS5      US!'   GO{U R                  X5      US"'   U
b*  U R                  X5      US#'   U R                  USS5      US$'   GO8S nU R                  S%U5      u  nnUb  S&US'   OS'US'   US	:X  a  US(:X  a  S)nU R                  US%S*S)5      u  nnU R                  US+5      nU R                  US+5      nU(       a  Uc  Uc  [        U R                  S,-   5      eU R!                  U5      nU R!                  U5      nU R#                  [$        R&                  " UU5      5      nUb  UOUnU R)                  UU5      US"'   O)U R)                  X5      US"'   OU R                  X5      US"'   U
b  U R                  X5      US#'   U R                  U/ S-Q5      nU R+                  UU5      $ ).NrH   r  r  	stopPricer+  r.  r/  rJ   r  
maker_onlyr1  r  z/ createOrder() does not support reduceOnly for r  z> orders, reduceOnly orders are supported for swap markets onlyr:   r   r  -rF  r&  iocr'  fokr  r   r  r  	stop_typelatest_pricestop_loss_typer  take_profit_typer   r  trigger_price_typerW   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  r1  r  r  r+  r.  r/  )r  r  r  is_post_onlysafe_string_upperr  r,   r:   r   uuid16price_to_precisionamount_to_precisionr  handle_option_and_paramsr  omitnumber_to_stringparse_to_numericr4   
string_mulcost_to_precisionr   )r  r  r  rF  r   r  r  r  rH   r  r+  r.  r/  rJ   isMarketOrderr  timeInForceRawr  r#  	defaultIdr  requestTyper*  r  r  amountStringpriceStringquoteAmountcostRequests                                r  create_order_requestcoinex.create_order_request@  s   V$f~**6;P))&+~N((A**63DE!!&(3($$]l4JF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 #'#:#:6#I )GFO%.GM" 151H1H1_G-.040@0@Vd0eG,-$373J3J63cG/0262B2B6;Xf2gG./$($<$<V$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)(,(>(>v(NGH%$($<$<V$L!'+/+B+B6+X(6  $N  O{{7F++r  c                    U R                  5         U R                  U5      nU R                  US5      nU R                  USS5      n	U R	                  US5      n
U R	                  US5      nU	SLnU
SLnUSLnU=(       d    UnU R                  XX4XV5      nSnUS   (       a+  U(       a  U R                  U5      nOU R                  U5      nO|U(       a  U R                  U5      nOcU(       a2  U(       a  U R                  U5      nOCU(       a  U R                  U5      nO*U(       a  U R                  U5      nOU R                  U5      nU R                  US0 5      nU R                  UU5      $ )	a  
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>`
r  r  r+  r.  r/  NrF   r  )r  r  r  r  r  r  v2PrivatePostSpotStopOrderv2PrivatePostSpotOrderv2PrivatePostFuturesStopOrder'v2PrivatePostFuturesSetPositionStopLoss)v2PrivatePostFuturesSetPositionTakeProfit!v2PrivatePostFuturesClosePositionv2PrivatePostFuturesOrderr  r  )r  r  r  rF  r   r  r  r  r  r+  stopLossTriggerPricetakeProfitTriggerPriceisTriggerOrderisStopLossTriggerOrderisTakeProfitTriggerOrderisStopLossOrTakeProfitTriggerr#  r  r  s                      r  r  coinex.create_order  sm   4 	V$^^FL9
))&+~N#//H!%!1!1&:K!L%T1!5T!A#9#E (>(ZBZ%++F$V&>::7C  66w?> ==gF /)#KKGTHN .#MMgVHP #EEgNH<  $==gFH: ~~h3f--r  ordersc           	         U R                  5         / nSnSnSnSn[        S[        U5      5       GH@  nX   n	U R                  U	S5      n
Uc  U
nOXJ:w  a  [	        U R
                  S-   5      eU R                  U	S5      nU R                  U	S5      nU R                  U	S5      nU R                  U	S	5      nU R                  U	S
0 5      nUS:w  a  [        U R
                  S-   U-   S-   5      eU R                  US5      nU R                  USS5      nU R                  US5      nU R                  US5      nUSLnUSLnUSLnU=(       d    UnU R                  XXX5      nUR                  U5        GMC     U R                  U5      nUS   US.nSnUS   (       a+  U(       a  U R                  U5      nOzU R                  U5      nOhU(       a  U R                  U5      nOOU(       a  [        U R
                  S-   5      eU(       a  [        U R
                  S-   5      eU R!                  U5      nU R#                  US/ 5      n/ n[        S[        U5      5       H  nUU   nSnU R%                  US5      nUb  US:w  a  SnOSnU R'                  US0 5      nSnUS   (       a  U(       d  UUS'   U R)                  UU5      nOUUS'   U R)                  UU5      nUR                  U5        M     U$ )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  rF  r   r  r  r;  z! createOrders() does not support z' orders, only limit orders are acceptedr  r  r+  r.  r/  r:   )r  r  rF   zH createOrders() does not support stopLossPrice or takeProfitPrice ordersz2 createOrders() does not support reduceOnly ordersr  r  r  r
  r  )r  r  r  r  r)   r:   r)  r.   safe_number_2r  r  r  r  v2PrivatePostSpotBatchStopOrderv2PrivatePostSpotBatchOrder"v2PrivatePostFuturesBatchStopOrderv2PrivatePostFuturesBatchOrderr  r1  r  r  ) r  r  r  ordersRequestsr  r  r  r  r  rawOrderr  r  rF  r   r  orderParamsr+  r  r  r  r  orderRequestr  r#  r  r  resultsr  r  r  	innerDatarI  s                                    r  create_orderscoinex.create_orders	  s    	
(-%q#f+&AyH''(;H~!%$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4XTSXfL!!,/1 '2 V$Tl$
 &>??H"  ;;GDL BB7K  /"477-w#wxx&tww1e'eff#BB7KHF ~~h3q#d)$AGEF$$UF3D19'F#Fufb9IEf~n"(h((7&,	(#((F;NN5!# %$ r  idsc                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nU R	                  USS5      nU R                  USS/5      nSn/ n[        S[        U5      5       H  n	UR                  [        X   5      5        M!     U(       a  XS'   OXS	'   US
   (       aI  U(       a!  U R                  U R                  XS5      5      nOnU R                  U R                  XS5      5      nOMSUS'   U(       a!  U R                  U R                  XS5      5      nO U R                  U R                  XS5      5      nU R                  US/ 5      n
/ n[        S[        U
5      5       H<  n	X   nU R!                  US0 5      nU R#                  X5      nUR                  U5        M>     U$ )ae  
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  r:   stopr?  r   stop_ids	order_idsrF   r   r  r  )r(   r:   r  r  safe_bool_2r  r  r  r  int%v2PrivatePostSpotCancelBatchStopOrderr   !v2PrivatePostSpotCancelBatchOrder(v2PrivatePostFuturesCancelBatchStopOrder$v2PrivatePostFuturesCancelBatchOrderr  r  r  )r  r  r  r  r  r#  r?  r  
requestIdsr  r  r
  r  itemrI  s                  r  cancel_orderscoinex.cancel_orders;
  s    >#DGG.Z$Z[[V$fTl
 ""669=6FI#67
q#c(#Ac#&k* $",J#-K &>EEdkkRYFbc<  AA$++gB^_J &/GM"HHU\Ief:  DDT[[QXEabF ~~h3q#d)$AGE>>%4D$$T2ENN5!	 %
 r  r:   c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0n	Ub  U R	                  X%5      U	S'   Ub  U R                  X&5      U	S'   Sn
U R                  U/ SQ5      nU R                  USS	/5      nUSLnU(       a)  U R                  X+5      U	S
'   U R                  U5      U	S'   OU R                  U5      U	S'   SnU R                  SU5      u  pUS   (       aW  Ub  SU	S'   OSU	S'   U(       a!  U R                  U R                  X5      5      n
OnU R                  U R                  X5      5      n
OMSU	S'   U(       a!  U R                  U R                  X5      5      n
O U R                  U R                  X5      5      n
U R                  U
S0 5      nU R!                  X5      $ )at  
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  r:   r   r  )r  r+  r  r  r+  r  r  rE  r^   rF   r   r  r   r   r  )r(   r:   r  r  r  r  r  r  r  r   v2PrivatePostSpotModifyStopOrderr   v2PrivatePostSpotModifyOrder#v2PrivatePostFuturesModifyStopOrderv2PrivatePostFuturesModifyOrderr  r  )r  r:   r  r  rF  r   r  r  r  r#  r  r+  r  r*  r  s                  r  
edit_ordercoinex.edit_order
  s   & >#DGG.W$WXXV$fTl
  $ 8 8 HGH#66vEGG))&2`a6K#@A%T1'+'>'>v'TGO$!%!6!6r!:GI"&"7"7";GJ
!??VT
&>%)1&)/&@@WA]^  <<T[[=YZ@ &/GM"CCDKKPWD`a  ??G@\]: ~~h3--r  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nU R	                  USS5      nUS   nSUS   0nSnU R                  SU5      u  pU(       a  S	US
'   OUb  SUS
'   OSUS
'   U R                  USS5      n	U R                  U/ SQ5      nSn
U	b  XS'   U(       aK  U(       a"  U R                  U R                  Xs5      5      n
GO+U R                  U R                  Xs5      5      n
GO	U(       a!  U R                  U R                  Xs5      5      n
OU R                  U R                  Xs5      5      n
OU(       a]  U R                  U5      US'   U(       a!  U R                  U R                  Xs5      5      n
O}U R                  U R                  Xs5      5      n
O\U R                  U5      US'   U(       a!  U R!                  U R                  Xs5      5      n
O U R#                  U R                  Xs5      5      n
SnU	b*  U R%                  U
S/ 5      nU R'                  US   S0 5      nOU R'                  U
S0 5      nU R)                  X5      $ )a  
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?  rH   r  r:   rO   r   r  r   r   r  r  )r  r?  r  r  rE  r  r   )r(   r:   r  r  r  r  r  r  -v2PrivatePostFuturesCancelStopOrderByClientIdr   *v2PrivatePostSpotCancelStopOrderByClientId)v2PrivatePostFuturesCancelOrderByClientId&v2PrivatePostSpotCancelOrderByClientIdr  #v2PrivatePostFuturesCancelStopOrder v2PrivatePostSpotCancelStopOrderv2PrivatePostFuturesCancelOrderv2PrivatePostSpotCancelOrderr  r  r  )r  r:   r  r  r  r  rH   r#  r*  r  r  r  rowss                r  cancel_ordercoinex.cancel_orderr  sV   ( >#DGG.Y$YZZV$))&&)Df~fTl
 
!??vV
%.GM"%)1&)/&**6;P6#GH$#0K #QQRVR]R]^eRnoH6  $NNt{{[bOklH8 #MMdkkZaNjkHD  $JJ4;;W^KghHF %)%:%:2%>	"#GGT[HdeH,  $DDT[[QXEabH, '+&;&;B&?
##CCDKKPWD`aH8  $@@WA]^H8 $>>(FB7D>>$q'626D>>(FB7D--r  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nSnUS   (       a&  SUS'   U R	                  U R                  XB5      5      nODSnU R                  SU5      u  pbUb  S	US'   OS
US'   U R                  U R                  XB5      5      nU R                  SU05      /$ )a  
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  r:   rH   r   r  rN   r   r   r  )	r(   r:   r  r  "v2PrivatePostFuturesCancelAllOrderr   r  v2PrivatePostSpotCancelAllOrderr  )r  r  r  r  r#  r  r*  s          r  cancel_all_orderscoinex.cancel_all_orders  s     >#DGG.]$]^^V$fTl
 &>%.GM">>t{{7?[\H
 J!%!C!CDUW]!^J%)1&)/&;;DKK<XYH
 OO 
 	
r  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUS   U R	                  U5      S.nSnUS   (       a!  U R                  U R                  XS5      5      nO U R                  U R                  XS5      5      nU R                  US0 5      nU R                  Xt5      $ )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 argumentr:   )r  rE  rH   r  )
r(   r:   r  r  r  v2PrivateGetFuturesOrderStatusr   v2PrivateGetSpotOrderStatusr  r  )r  r:   r  r  r  r#  r  r  s           r  fetch_ordercoinex.fetch_order  s     >#DGG.X$XYYV$Tl--b1
 &>::4;;w;WXH> 77G8TUH> ~~h3--r  c                 Z   U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  XFS'   U R                  USS5      nU R                  USS/5      nSn	U R	                  SXu5      u  pSn
US:H  =(       d    US	:H  nUS
:H  =(       d    US:H  nU	S:X  a  SUS'   U(       aK  U(       a"  U R                  U R                  Xe5      5      n
GO4U R                  U R                  Xe5      5      n
GOU(       aH  U(       a!  U R                  U R                  Xe5      5      n
OU R                  U R                  Xe5      5      n
OSnU R                  SU5      u  pUb  SUS'   OSUS'   U(       aI  U(       a!  U R                  U R                  Xe5      5      n
OoU R                  U R                  Xe5      5      n
ONUS
:X  aH  U(       a!  U R                  U R                  Xe5      5      n
O U R                  U R                  Xe5      5      n
U R                  U
S/ 5      nU R!                  XX45      $ )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>`
Nr:   r  r;  r  r?  fetchOrdersByStatusfinishedr  pendingr
  rH   r   r  r   r   r  )r  r  r  r  r*  $v2PrivateGetFuturesFinishedStopOrderr    v2PrivateGetFuturesFinishedOrder#v2PrivateGetFuturesPendingStopOrderv2PrivateGetFuturesPendingOrderr  !v2PrivateGetSpotFinishedStopOrderv2PrivateGetSpotFinishedOrder v2PrivateGetSpotPendingStopOrderv2PrivateGetSpotPendingOrderr  parse_orders)r  r  r  rS  r;  r  r#  r  r?  r  r  isClosedisOpenr*  r  s                  r  fetch_orders_by_statuscoinex.fetch_orders_by_status  s(   $ 	[[(F &tGH$G""669=6FI#67
!??@UW]f
j(Af.@I%<6V+;%.GM"#HHU\IefH8  $DDT[[QXEabH> #GGT[HdeH:  $CCDKKPWD`aHH J!%!C!CDY[a!bJ%)1&)/&#EEdkkRYFbcH:  $AA$++gB^_HB 9$#DDT[[QXEabH<  $@@WA]^HH ~~h3  u<<r  c                 r    U R                  SXX45      n[        S[        U5      5       H
  nSXV   S'   M     U$ )aG  
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=  r   r
  r  )rI  r  r  )r  r  rS  r;  r  
openOrdersr  s          r  fetch_open_orderscoinex.fetch_open_orders?  s?    " 00F5Y
q#j/*A&,JM(# +r  c                 (    U R                  SXX45      $ )ay  
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<  )rI  )r  r  rS  r;  r  s        r  fetch_closed_orderscoinex.fetch_closed_ordersU  s    " **:veTTr  r  c                    U R                  5         U R                  U5      nU R                  USS5      nUc  [        U R                  S-   5      eU R                  US5      nUS   U R                  XCS   5      S.nU R                  U R                  XR5      5      nU R                  US0 5      nU R                  Xs5      $ )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>`
r  r  z4 createDepositAddress() requires a network parameterr:   r  )r  r  r  )r  rC  r  r(   r:   r  network_code_to_id(v2PrivatePostAssetsRenewalDepositAddressr   r  parse_deposit_address)r  r  r  rC  r  r#  r  r  s           r  create_deposit_addresscoinex.create_deposit_addressh  s     	==&$$VWi@?#DGG.d$dee69-D>,,Wv6FG
 @@WA]^ ~~h3))$99r  c                 b   U R                  5         U R                  U5      nSUS   0nSnU R                  U5      u  pRUc  [        U R                  S-   5      eU R                  U5      US'   U R                  U R                  XB5      5      nU R                  US0 5      nU R                  Xs5      $ )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>`
r  r:   Nz5 fetchDepositAddress() requires a "network" parameterr  r  )
r  rC  handle_network_code_and_paramsr(   r:   rS   v2PrivateGetAssetsDepositAddressr   r  rU  )r  r  r  rC  r#  r  r  r  s           r  fetch_deposit_addresscoinex.fetch_deposit_address  s     	==&8D>
 "AA&I#DGG.e$eff22;?88W9UV ~~h3))$99r  rC  c           	          U R                  US5      nUR                  S5      nS nS n[        U5      nUS:  a  US   S:w  a  US   nUS   nOUnUU R                  S U5      S UU R                  USU5      S.$ )Naddressr  r   r   cfxmemo)r  rC  r  r^  tag)r  splitr  r  )r  depositAddressrC  coinAddresspartsr^  ra  partsLengths           r  rU  coinex.parse_deposit_address  s     &&~yA!!#&%j?uQx50AhG(C!G"//h?##NFC@
 	
r  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nUb  X6S'   Ub  X&S'   U R	                  SXd5      u  pdSnUS   (       a&  S	US
'   U R                  U R                  Xd5      5      nODSnU R                  SU5      u  pUb  SUS
'   OSUS
'   U R                  U R                  Xd5      5      nU R                  US/ 5      n	U R                  XX#5      $ )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  r:   r;  
start_timeend_timerH   r   r  r~   r   r   r  )r(   r:   r  r  handle_until_optionv2PrivateGetFuturesUserDealsr   r  v2PrivateGetSpotUserDealsr  rW  )
r  r  rS  r;  r  r  r#  r  r*  r  s
             r  fetch_my_tradescoinex.fetch_my_trades  s     >#DGG.[$[\\V$fTl
 $G$)L!22:wO&>%.GM"88W9UVH, J!%!C!COU[!\J%)1&)/&55dkk'6RSH, ~~h3  u<<r  c                    U R                  5         SnU R                  USSS5      u  p2U R                  U5      nSS0nSnUba  Sn[        U[        5      (       a/  [        U5      nUS:  a  [        U R                  S-   5      eUS	   nOUnU R                  U5      nUS
   US'   SnUS:X  a!  U R                  U R                  XB5      5      nO U R                  U R                  XB5      5      nU R                  US/ 5      n	/ n
[        S	[        U	5      5       H&  nU
R                  U R                  X   U5      5        M(     U R!                  U
SUS5      $ )aD  
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   r:   r  r  r  F)r  r  r(  
isinstancelistr  r)   r:   r  rr  r   #v2PrivateGetFuturesFinishedPositionr  r  r  parse_positionfilter_by_array_positions)r  r&  r  defaultMethodr#  r  r  symbolsLengthr  positionr  r  s               r  fetch_positionscoinex.fetch_positions  sd    	 $ = =fFVX`  cG  !H%%g.9
 F'4(( #G 1$$TWW/u%uvv  [[(F &tGH@@>>t{{7?[\H??G@\]HX >>(FB7q#h-(AMM$--hk6BC )--fhOOr  c                     U R                  5         U R                  U5      nSUS   S.nU R                  U R                  XB5      5      nU R	                  US/ 5      nU R                  US   U5      $ )au  
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>`
r   r:   r  r  r  r   )r  r  rr  r   r  rv  )r  r  r  r  r#  r  r  s          r  fetch_positioncoinex.fetch_positiono  sv     	V$$Tl
 ::4;;w;WXX ~~h3""47F33r  rz  c                    U R                  US5      nU R                  X2S S5      nU R                  US5      nU R                  0 SU_SU R                  US5      _SUS   _SU R	                  US	5      _S
U R                  US5      _SU R	                  US5      _SU R	                  US5      _SU R	                  US5      _SU R	                  US5      _SS _SU R	                  US5      _SU R	                  US5      _SS _SS _SU R                  US5      _SS _SU_U R                  U5      U R                  US5      U R	                  US5      U R	                  US5      U R	                  US 5      S S U R	                  US!5      U R	                  US"5      U R                  U R                  US#5      5      U R                  U R                  US$5      5      S%.E5      $ )&Nr  rH   r@  r  r:   r  r  notionalsettle_valuer*  margin_modeliquidationPrice	liq_price
entryPricer  unrealizedPnlunrealized_pnlrealizedPnlrealized_pnlr  	contracts
close_avblr  r  	lastPricerF  r2  r  r8  maintenance_margin_valuemaintenance_margin_ratemargin_avblr4  position_margin_rater  r  )r   lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager4  marginRatior.  r/  )r  rK  r1  safe_positionr  rM  	omit_zero)r  rz  r  r  r  s        r  rv  coinex.parse_position  sV   F ##Hh7!!(D&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                 n   Uc  [        U R                  S-   5      eUR                  5       nUS:w  a  US:w  a  [        U R                  S-   5      eU R	                  5         U R                  U5      nUS   S:w  a  [        U R                  S-   5      eU R                  US5      nU R                  US	   S   S
S5      nUc  [        U R                  S-   5      eUS:  d  XV:  a*  [        U R                  S-   [        U5      -   S-   U-   5      eUS   SUUS.nU R                  U R                  Xs5      5      $ )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
z+ setMarginMode() requires a symbol argumentisolatedcrossz@ setMarginMode() marginMode argument should be isolated or crossr  rH   z- setMarginMode() supports swap contracts onlyr4  r   r   d   z. setMarginMode() requires a leverage parameterr   z2 setMarginMode() leverage should be between 1 and  for r:   r   r  r  r  r4  )r(   r:   lowerr)   r  r  r*   r1  str*v2PrivatePostFuturesAdjustPositionLeverager   )r  r*  r  r  r  r4  maxLeverager#  s           r  set_margin_modecoinex.set_margin_mode  sO    >#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$% 	
 >>t{{7?[\\r  r4  c                 *   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUS   (       d  [	        U R                  S-   5      eSnU R                  SUS5      u  pSU R                  US   S   S	S
5      nU R                  US   S   SS5      nX:  d  X:  a9  [        U R                  S-   [        U5      -   S-   [        U5      -   S-   U-   5      eUS   SUUS.nU R                  U R                  X5      5      $ )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 argumentrH   z+ setLeverage() supports swap contracts onlyr   r  r   r4  r   r   r   r  z* setLeverage() leverage should be between z and r  r:   r   r  )r(   r:   r  r  r*   r  r1  r)   r  r  r   )	r  r4  r  r  r  r*  minLeverager  r#  s	            r  set_leveragecoinex.set_leverage   sI    >#DGG.Y$YZZV$f~DGG&SSTT
!??vW^_
''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$% 	
 >>t{{7?[\\r  c                     U R                  5         0 nUb%  U R                  U5      nSR                  U5      US'   U R                  U R	                  X25      5      nU R                  US/ 5      nU R                  XaS5      $ )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
,r  r  )r  
market_idsjoinv2PublicGetFuturesPositionLevelr   r  parse_leverage_tiers)r  r&  r  r#  	marketIdsr  r  s          r  fetch_leverage_tierscoinex.fetch_leverage_tiersJ  s|     	0I # 3GH77G8TU4 ~~h3((AAr  c                    / nU R                  US/ 5      nSn[        S[        U5      5       H  nXF   nU R                  US5      nU R	                  XS S5      nU R                  US5      n	UR                  U R                  US5      U R                  XS S5      US   (       a  US   OUS	   UU	U R                  US
5      U R                  US5      US.5        U	nM     U$ )Nlevelr   r  rH   r   r   r   r  r  r  r4  )tierr  rC  minNotionalmaxNotionalmaintenanceMarginRater  r  )
r  r  r  r  rK  r  r  sumr  r1  )
r  r  r  tiersbracketsr  r  r  r  r  s
             r  parse_market_leverage_tiers"coinex.parse_market_leverage_tiersv  s    >>$4q#h-(A;D''h7H%%hfEF**4:KLLA**8T6J.4X.>F6NF7O**)-)9)9$@Y)Z#00zB	 	 &K )  r  c                    U R                  5         U R                  U5      nU R                  X5      nUnUS:X  a  [        R                  " U5      nUS   SUS.nU R                  U R                  X5      5      n	U R                  U	S5      n
U R                  U	S5      nUS:X  a  SOSnU R                  U R                  X5      UU R                  U5      US.5      $ )	Nreducer:   r   )r  r  r   r  messageadd)r  r   r  )r  r  r  r4   
string_neg(v2PrivatePostFuturesAdjustPositionMarginr   r  r  parse_margin_modificationr  )r  r  r   addOrReducer  r  	rawAmountrequestAmountr#  r  r  r  r  s                r  modify_margin_helpercoinex.modify_margin_helper  s    V$,,V<	!("#..y9MTl$#

 @@WA]^N ~~h/'')<'83x%{{499$G''/J
  	r  r  c                 6   U R                  US5      nU R                  USS5      nU R                  US5      nUU R                  X2S S5      S SU R                  [        R
                  " U5      5      U R                  US5      US   S UU R                  U5      S	.
$ )
Nr  r8  r@  margin_changerH   r  r  r  )
r  r  r  r*  r   totalr  r  r  r   )r  safe_integer_2r  r  r4   
string_absr  rM  )r  r  r  r  r  r  s         r  r   coinex.parse_margin_modification  s    l ##D(3''lLI	!!$8&&xvF$''(:(:6(BC%%dM:7O"Y/
 	
r  c                 (    U R                  XSU5      $ )aT  
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  r  r  r  r   r  s       r  
add_margincoinex.add_margin  s     ((GGr  c                 (    U R                  XSU5      $ )aq  
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  r  r  s       r  reduce_margincoinex.reduce_margin  s     ((6JJr  c                 v   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUS   SS.nU R	                  SXd5      u  pdUb  X&S'   Ub  X6S'   U R                  U R                  Xd5      5      nU R                  US/ 5      n/ n	[        S	[        U5      5       H  n
X   nU R                  US
5      nU R                  US5      nU R                  U5      nU	R                  UUUUU R                  U5      U R                  US5      U R                  US5      S.5        M     U	$ )a  
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>`
z1 fetchFundingHistory() requires a symbol argumentr:   r   )r  r  rj  ri  r;  r  r   r@  r  r  funding_value)r  r  r  r  r   r:   r   )r(   r:   r  r  rk  )v2PrivateGetFuturesPositionFundingHistoryr   r  r  r  r1  r  r  r  rM  r  )r  r  rS  r;  r  r  r#  r  r  r  r  r  r  r  r  s                  r  fetch_funding_historycoinex.fetch_funding_history(  sM    >#DGG.a$abbV$Tl$
 22:wO$)L!$GAA$++gB^_, ~~h3q#d)$AGE))%>I))%7J**:6DMM & LL3&&um<**5/B  % r  c                 D   U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      nU R                  US/ 5      nU R                  US0 5      nU R                  Xs5      $ )aC  
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>`
rH   z0 fetchFundingRate() supports swap contracts onlyr  r:   r  r   )	r  r  r*   r:   v2PublicGetFuturesFundingRater   r  r  parse_funding_rate)r  r  r  r  r#  r  r  firsts           r  fetch_funding_ratecoinex.fetch_funding_ratei  s     	V$f~DGG&XXYYfTl
 55dkk'6RS& ~~h3tQ+&&u55r  c                 $    U R                  X5      $ )aL  
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>`
)r  )r  r  r  s      r  fetch_funding_intervalcoinex.fetch_funding_interval  s     &&v66r  c                 0   U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n[        R                  " Xe5      nU R                  US5      n0 SU_SU R	                  XS S5      _SU R                  US5      _S	S _S
S _SS _SS _SS _SU R                  US5      _SU_SU R                  U5      _SU R                  US5      _SU_SU R                  U5      _SS _SS _SS _SU R                  U5      0E$ )Nlatest_funding_timenext_funding_timer  r  r  rH   r  r  r  interestRateestimatedSettlePricer  r   fundingRatelatest_funding_ratefundingTimestampfundingDatetimenextFundingRatenext_funding_ratenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer6  )r1  r  r4   
string_subr  r  rM  parse_funding_interval)	r  r  r  currentFundingTimestampfutureFundingTimestampfundingTimeStringnextFundingTimeStringmillisecondsIntervalr  s	            r  r  coinex.parse_funding_rate  s    #'"3"3H>S"T!%!2!28=P!Q ,,X7LM $ 0 0;N O&112G[##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                 6    SSSSSS.nU R                  X!U5      $ )Nr   r   8h16h24h)360000014400000288000005760000086400000r  )r  r6  	intervalss      r  r  coinex.parse_funding_interval  s-    
	 	X>>r  c                    U R                  5         U R                  U5      n0 nSnUbj  U R                  US5      nU R                  U5      nUS   (       d  [	        U R
                  S-   5      eU R                  U5      nSR                  U5      US'   U R                  U R                  X25      5      nU R                  US/ 5      nU R                  X5      $ )aj  
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   rH   z1 fetchFundingRates() supports swap contracts onlyr  r  r  )r  r(  r)  r  r*   r:   r  r  r  r   r  parse_funding_rates)	r  r&  r  r#  r  r  r  r  r  s	            r  fetch_funding_ratescoinex.fetch_funding_rates  s     	%%g.__Wa0F[[(F&>*] ]^^0I # 3GH55dkk'6RS& ~~h3''66r  r^  ra  c                    U R                  XE5      u  pEU R                  U5        U R                  5         U R                  U5      nUS   UU R	                  X5      S.nUb  XGS'   SnU R                  U5      u  pUb  U R                  U5      US'   U R                  U R                  Xu5      5      n	U R                  U	S0 5      n
U R                  X5      $ )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]: memo
: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>`
r:   )r  
to_addressr   Nr`  r  r  )handle_withdraw_tag_and_paramscheck_addressr  rC  currency_to_precisionrY  rS  v2PrivatePostAssetsWithdrawr   r  parse_transaction)r  r  r   r^  ra  r  rC  r#  r  r  transactions              r  r   coinex.withdraw  s     99#F7#==&D>!00>

 ?!FO"AA&I"#66{CGG33DKK4PQ6 nnXvr:%%k<<r  c                 @    SSSSSSSSSSS.
nU R                  X!U5      $ )Nr=  failedr  ok)
auditpassaudit_required
processing
confirmingnot_passr  finishr<  failr  r  s      r  parse_transaction_statuscoinex.parse_transaction_status7  s<    '##  
 &99r  c           
         Uc  [        U R                  S-   5      eU R                  5         SnU R                  USS5      u  pTU(       a  U R	                  SXUSUS5      $ U R                  U5      nSUS	   0nUb  X'S
'   Ub  X7S'   U R                  SXt5      u  ptU R                  U R                  Xt5      5      nU R                  US/ 5      n	/ n
[        S[        U	5      5       Ht  nX   nU R                  US5      nU R                  XSS5      nU R                  US5      nU
R                  UUU R!                  US5      UU R#                  U5      S.5        Mv     U R%                  U
S5      nU R'                  UUS   X#5      $ )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 argumentFrq   paginater  r:  r  r:   ri  r;  rj  r  r   rH   funding_timeactual_funding_rate)r  r  r  r  r   r  r  )r(   r:   r  r  "fetch_paginated_call_deterministicr  rk  $v2PublicGetFuturesFundingRateHistoryr   r  r  r  r  r  r1  r  r  rM  sort_byfilter_by_symbol_since_limit)r  r  rS  r;  r  r'  r  r#  r  r  ratesr  r  r  symbolInnerr  sorteds                    r  fetch_funding_rate_history!coinex.fetch_funding_rate_historyF  s    >#DGG.e$eff88AZ\fg::;TV\ejlprxz~V$fTl
 $)L!$G22:wO<<T[[=YZ$ ~~h3q#d)$AGE''x8H**8T6JK))%@ILL%#//7LM& LL3  % e[1009I5XXr  r  c                    U R                  US5      nU R                  US5      nUb  [        U5      S:  a  S nU R                  US5      nUb  [        U5      S:  a  S nU R                  US5      nUb  [        U5      S:  a  S nU R                  US5      nU R                  Xr5      nU R                  US5      n	SU;   a  S	OS
n
U R                  US5      nU R                  US5      nU R	                  USS5      nUS:H  nU R                  US5      nUc  U R                  US5      nU
S
:X  a  SnU R                  US5      nU R                  U5      U R                  U5      S.n0 SU_SU R                  USS5      _SU_SU	_SU R                  U	5      _SU R                  U5      _SU_SU_SS _SU_S S _S!S _S"U
_SU_S#U_S$U R                  U R                  US$5      5      _S%S _UUUS&.E$ )'Nr  r`  r   remarktx_idr  r@  withdraw_id
withdrawalr  r  tx_feewithdraw_methoddeposit_methodlocalactual_amountr   r5  	fee_assetrB  r  r:   
deposit_idtxidr  r   r  r^  	addressToaddressFromra  tagTotagFromr  rC  r  updated)r  commentinternal)r  r  r  r1  safe_string_lower_2r  r  r  rM  r  r$  )r  r  rC  r^  ra  r4  r?  r  r  r  r  r  feeCosttransferMethodrF  r   rO  r  s                     r  r  coinex.parse_transaction  s   Z "";={F3?3x!|!!+x86{QW54y1}%%k59
&&z<%%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                    U R                  5         U R                  U5      nU R                  X5      nU R                  U R                  S0 5      nU R                  XU5      n	U R                  XU5      n
US   UU	U
S.nUS:X  d  US:X  aS  U R                  US5      nUc  [        U R                  S-   5      eU R                  US5      nU R                  U5      US'   US:w  a  US:w  a  [        U R                  S	-   5      eU R                  U R                  X5      5      nU R                  U R                  X5      U R                  U5      UUS
.5      $ )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>`
r"  r:   )r  r   from_account_typeto_account_typerG   r  zE transfer() the symbol parameter must be defined for a margin accountr  rF   zs transfer() can only be between spot and swap, or spot and margin, either the fromAccount or toAccount must be spot)r   rK  rL  )r  rC  r  r  r   r  r(   r:   r  	market_idr)   v2PrivatePostAssetsTransferr   parse_transferr  )r  r  r   rK  rL  r  rC  amountToPrecisionr"  fromIdtoIdr#  r  r  s                 r  r   coinex.transfer  se    	==& 66tD6FK!!.{K9ED>'!'#	
 8#h)>%%fh7F~'2y(yzzYYvx0F $v 6GH6!	V(;TWW  (]  ]  ^  ^33DKK4PQ {{4..xB''(9:&"E
  	r  c                 6    SSSSSS.nU R                  X!U5      $ )Nr  )r5  SUCCESSOKr<  FINISHEDr  r  s      r  parse_transfer_statuscoinex.parse_transfer_status  s-    
 &99r  r   c                    U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  U R                  S0 5      nS UU R	                  U5      U R                  XB5      U R                  US5      U R                  XuU5      U R                  XvU5      U R                  U R                  USS5      5      S	.$ )
Nr@  r  rN  rO  r#  r   r  r  )r:   r  r   rC  r   rK  rL  r  )	r1  r  r)  r   rM  r  r  r[  r  )r  r   rC  r  r  rT  rU  r#  s           r  rR  coinex.parse_transfer$  s    %%h=	%%h6
!!(,?@*;<t||^RH"Y///
E&&x:++L&I)),dC001C1CHfV^1_`	
 		
r  c                    U R                  5         Uc  [        U R                  S-   5      eU R                  U5      nSUS   0nSnU R	                  SU5      u  ptUb  SUS'   OSUS'   Ub  X&S	'   Ub  X6S
'   U R                  SXd5      u  pdU R                  U R                  Xd5      5      nU R                  US/ 5      n	U R                  XX#5      $ )ar  
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  r:   r   r   transfer_typer   ri  r;  rj  r  )
r  r(   r:   rC  r  rk  !v2PrivateGetAssetsTransferHistoryr   r  parse_transfers)
r  r  rS  r;  r  rC  r#  r*  r  r  s
             r  fetch_transferscoinex.fetch_transfers5  s     	<#DGG.Z$Z[[==&8D>
 
!??@PRXY
!'/GO$'0GO$$)L!$G22:wO99$++g:VW* ~~h3##DEAAr  c                     U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X5S'   U R                  U R                  XT5      5      nU R	                  US/ 5      nU R                  XX#5      $ )a  
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>`
Nr:   r  r;  r  )r  rC  v2PrivateGetAssetsWithdrawr   r  parse_transactions	r  r  rS  r;  r  r#  rC  r  r  s	            r  fetch_withdrawalscoinex.fetch_withdrawalsl  s     	}}T*H%d^GEN$G224;;w3OPB ~~h3&&tuDDr  c                     U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X5S'   U R                  U R                  XT5      5      nU R	                  US/ 5      nU R                  XX#5      $ )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>`
Nr:   r  r;  r  )r  rC   v2PrivateGetAssetsDepositHistoryr   r  rg  rh  s	            r  fetch_depositscoinex.fetch_deposits  s     	}}T*H%d^GEN$G88W9UV< ~~h3&&tuDDr  r  c           
          U R                  US5      nU R                  X2S S5      nU R                  US5      nU R                  US5      nS nS nXBS   :X  a  UnO
XBS   :X  a  UnUS   US   UUS	   US
S S US.	$ )Nr  rF   r  daily_interest_rater  r  r  r  r  i \&)	r  r  baseRater  	quoteRaterk  r  r   r  )r  rK  r  )r  r  r  r  rC  raterq  rr  s           r  parse_isolated_borrow_rate!coinex.parse_isolated_borrow_rate  s     ##D(3!!(D&A##D%0&;<	h''H	**IX&6N G_"

 
	
r  c                    U R                  5         U R                  US5      nUc  [        U R                  S-   5      eU R	                  US5      nU R                  U5      nU R                  U5      nUS   US   S.nU R                  U R                  Xb5      5      nU R                  US0 5      nU R                  X5      $ )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>`
r  z4 fetchIsolatedBorrowRate() requires a code parameterr:   r  r  r  )r  r  r(   r:   r  rC  r  %v2PrivateGetAssetsMarginInterestLimitr   r  rt  	r  r  r  r  rC  r  r#  r  r  s	            r  fetch_isolated_borrow_rate!coinex.fetch_isolated_borrow_rate  s     	/<#DGG.d$dee66*==&V$TlD>
 ==dkk'>Z[ ~~h3..t<<r  c                    U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  XFS'   U R                  U R                  Xe5      5      nU R	                  US/ 5      n	U R                  X5      n
U R                  XX45      $ )ae  
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>`
Nr:   r  r;  r  )r  r  %v2PrivateGetAssetsMarginBorrowHistoryr   r)  parse_borrow_interestsfilter_by_currency_since_limit)r  r  r  rS  r;  r  r#  r  r  r-  ru  s              r  fetch_borrow_interestcoinex.fetch_borrow_interest"  s     	[[(F &tGH$G==dkk'>Z[2 x4..t<2285PPr  c                 J   U R                  US5      nU R                  X2S S5      nU R                  US5      nUUS   U R                  U R                  US5      5      U R	                  US5      U R	                  US5      U R	                  US5      S	UU R                  U5      S
.	$ )Nr  rF   
expired_atr  r  to_repaied_amountrp  borrow_amountr  )	r  r  rC  ru  r  amountBorrowedr*  r  r   )r  rK  r1  r  r  rM  )r  r  r  r  r  s        r  parse_borrow_interestcoinex.parse_borrow_interestT  s     ##D(3!!(D&A%%dL9	X&//0@0@u0MN((/BC ,,T3HI"..t_E$"Y/

 
	
r  c                    U R                  5         U R                  U5      nU R                  U5      nU R                  USSS5      nU R	                  US5      nUS   US   U R                  X#5      US.nU R                  U R                  X5      5      n	U R                  U	S0 5      n
U R                  X5      nU R                  UUUS.5      $ )a%  
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>`
isAutoRenewis_auto_renewFr:   )r  r  r  r  r  r   r  )
r  r  rC  r  r  r  v2PrivatePostAssetsMarginBorrowr   r  parse_margin_loan)r  r  r  r   r  r  rC  r  r#  r  r  r  s               r  borrow_isolated_margincoinex.borrow_isolated_marginr  s     	V$==&&&v}ouU6=1TlD>!77E(	
 77G8TU" ~~h3,,T<{{;)
  	r  c                 N   U R                  5         U R                  U5      nU R                  U5      nUS   US   U R                  X#5      S.nU R	                  U R                  Xt5      5      nU R                  US0 5      n	U R                  X5      n
U R                  U
UUS.5      $ )a  
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>`
r:   )r  r  r   r  r  )r  r  rC  r  v2PrivatePostAssetsMarginRepayr   r  r  )r  r  r  r   r  r  rC  r#  r  r  r  s              r  repay_isolated_margincoinex.repay_isolated_margin  s     	V$==&TlD>00>

 66t{{77ST ~~h3,,T<{{;)
  	r  c           	      "   U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      U R                  X25      U R                  US5      U R                  US S S5      UU R	                  U5      US.$ )Nr  r  r  	borrow_idr  rF   )r:   rC  r   r  r  r   r  )r  r1  r  r  rM  )r  r  rC  r  r  r  s         r  r  coinex.parse_margin_loan  s     %%dE2
##D(3%%dL9	##D+6//
E&&t_=&&xtVD"Y/
 	
r  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US0 5      nU R                  Xc5      $ )aK  
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>`
r  r:   r  )r  rC  &v2PublicGetAssetsDepositWithdrawConfigr   r  parse_deposit_withdraw_fee)r  r  r  rC  r#  r  r  s          r  fetch_deposit_withdraw_fee!coinex.fetch_deposit_withdraw_fee  so     	==&8D>
 >>t{{7?[\D ~~h3..t>>r  codesc                    U R                  5         U R                  U5      nU R                  US/ 5      n0 n[        S[	        U5      5       Hp  nXF   nU R                  US0 5      nU R                  US5      n	U	c  M1  U R                  U	5      n
Ub  U R                  X5      (       d  M]  U R                  U5      XZ'   Mr     U$ )ai  
       fetch the fees for deposits and withdrawals

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

@param codes
       :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>`
       r  r   r  r  )
r  r  r  r  r  r  r  r  in_arrayr  )r  r  r  r  r  r  r  r  r  r  r  s              r  fetch_deposit_withdraw_fees"coinex.fetch_deposit_withdraw_fees  s     	AA&IH ~~h3q#d)$A7DNN4"5E))%7J!**:6D}d : :#>>tD % r  c                    US S S.S S S.0 S.nU R                  US/ 5      nU R                  US0 5      n[        S[        U5      5       H  nXF   nU R	                  US5      nU(       d  M"  U R                  US5      US   S	'   S
US   S'   U R                  US5      n	U	(       d  M]  U R                  XR                  US5      5      n
U R                  US5      S
S.S S S.S.US   U
'   M     U$ )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  rC  r  r  r  r  r  isWithdrawEnabledr  r  s              r  r  !coinex.parse_deposit_withdraw_feeP  s'   > "
 " 
 Xr2sGR0q#f+&AIE $u6H I  ,0,<,<UDT,Uz"5)38z"<0 ,,UG<	9"&"9"9)EUEUV[]bEc"dK $(#3#3E;K#L*/%
 $(*.$	7F:&{3 '& r  c                    U R                  5         U R                  US5      nUc  [        U R                  S-   5      eU R	                  US5      nU R                  U5      nU R                  U5      nUS   US   S.nU R                  U R                  Xb5      5      nU R                  US0 5      nU R                  X5      $ )au  
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>`
r  z* fetchLeverage() requires a code parameterr:   rw  r  )r  r  r(   r:   r  rC  r  rx  r   r  parse_leveragery  s	            r  fetch_leveragecoinex.fetch_leverage  s     	/<#DGG.Z$Z[[66*==&V$TlD>
 ==dkk'>Z[ ~~h3""400r  c                 |    U R                  US5      nU R                  US5      nUU R                  X2S S5      SUUS.$ )Nr  r4  rF   r  )r  r  r*  longLeverageshortLeverage)r  r1  r  )r  r4  r  r  leverageValues        r  r  coinex.parse_leverage  sP     ##Hh7))(J?&&xvF$)*
 	
r  c                 D   U R                  5         U R                  U5      nSUS   S.nUb  X6S'   Ub  X&S'   U R                  SXd5      u  pdU R                  U R	                  Xd5      5      nU R                  US/ 5      nU R                  U5      n	U R                  XX#5      $ )a  
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>`
r   r:   r~  r;  ri  rj  r  )r  r  rk  ru  r   r  parse_positionsr-  )
r  r  rS  r;  r  r  r#  r  records	positionss
             r  fetch_position_historycoinex.fetch_position_history  s     	V$$Tl
 $G$)L!22:wO;;DKK<XYX ..626((1	00EQQr  c                 \   U R                  5         U R                  U5      nU R                  USS5      nUS   SUS.nU R                  USS5      nUb  XvS'   U R	                  US5      nU R                  U R                  Xc5      5      nU R                  US0 5      n	U R                  X5      $ )	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>`
r  r  r:   r   )r  r  r  r  r  r  )	r  r  r  r  r  r  r   r  r  )
r  r  rF  r  r  r  r#  r  r  r  s
             r  close_positioncoinex.close_position  s     	V$9Tl$

 **6;P$#0K 6?399$++g:VW: ~~h3--r  c                    > U R                  U R                  S5      nU R                  USS5      nSn[        [        U ]  XU5      u  pbUc  US:X  d  USL a  SnXb/$ )aK  
@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   rG   FNTr  )r  r   r  r  r6   r  )r  
methodNamer  defaultValuer   r  r*  r  s          r  r  $coinex.handle_margin_mode_and_paramsQ  sl     &&t||]C>>&(E:
"64Nzcop
x'X-='
##r  c                 "    U R                  5       $ N)milliseconds)r  s    r  noncecoinex.noncea  s      ""r  GETc                    U R                  X5      nUS   nUS   nU R                  S   U   S-   U-   S-   U-   n	U R                  X@R                  U5      5      n
[	        U R                  5       5      nUS:X  a  UR                  S5      nU R                  USS5      n[        U5      nU R                  XS-
  S5      nUR                  S5      n[        U5      nU R                  UUS-
  S5      nUS:X  aY  US	:X  d  US
:X  aM  U R                  US5      nUc8  SnU R                  U R                  SU5      nUS-   U R                  5       -   U
S'   US:X  a  U R                  5         U R                  U R                  US.U
5      n
U R                  U
5      n
U R!                  U
5      nU R#                  U R%                  US-   U R&                  -   5      S5      nUR)                  5       U R                  S.nUS:X  d  US:X  a
  U	SU-   -  n	GOSUS'   UnGOUS:X  d  US:X  a   U
(       a  U	SU R+                  U
5      -   -  n	GOUS:X  a  U R                  5         U R                  U R                  US.U
5      n
U R                  U
5      n
U R!                  U
5      nU R#                  U R%                  US-   U R&                  -   5      S5      nUR-                  5       SS.nUS:X  d  US:X  d  US:X  a	  U	SU-   -  n	OU R/                  U
5      nOUS :X  a  U R                  5         U R                  U
5      n
U R!                  U
5      nUS-   U-   S-   U-   nUS:X  a  U R/                  U
5      nUU-  nOU(       a  USU-   -  nUXR&                  -   -  nU R#                  U R%                  U5      S5      nSSU R                  UUS!.nUS:w  a  U(       a  U	SU-   -  n	XXeS".$ )#Nr   r   r   r  POSTr  _rI  r;  r  r  r   r  r   )	access_idr  z&secret_key=sha256)AuthorizationAccessIdr  PUT?z!application/x-www-form-urlencodedContent-Typer   r   r   )r  toncemd5zapplication/json)r  r  DELETEr>   )r  AcceptzX-COINEX-KEYzX-COINEX-SIGNzX-COINEX-TIMESTAMP)urlrq  bodyheaders)implode_paramsr   r  extract_paramsr  r  rb  r  r  r)  r   r  check_required_credentialsr   apiKeykeysort	rawencodehashencodesecretr  	urlencodeupperjson)r  pathr   rq  r  r  r  r=   
requestUrlr  r,  r  re  	firstPartnumPartslastPart	lastWordsnumWordslastWordr  r  r  
urlencoded	signaturepreparedStrings                            r  signcoinex.signd  s   ""40a&V
iiz*S07:S@4G		&"5"5d";<DJJL!VJJsOE((26I5zH''!|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//dOOr  httpCodereasonr  rq  r  r  c
                    Uc  g U R                  US5      n
U R                  US5      nU R                  US5      nU
S:w  d'  US:w  a|  US:w  av  UR                  5       S:w  ab  U(       d[  U R                  S-   U-   nU R	                  U R
                  S	   X5        U R                  U R
                  S
   X5        [        U5      eg )Nr  r  r  r5  Success	Succeededr   r  r  )r  r)  r  r:   throw_broadly_matched_exceptionrJ  throw_exactly_matched_exceptionr$   )r  r  r  r  rq  r  r  r  requestHeadersrequestBodyr  r  r  feedbacks                 r  handle_errorscoinex.handle_errors  s    &1x0""8Y7CKg2K9OV]VcVcVeimVmw{ww}w.H001I7]001I4Z))r  c                    U R                  5         Uc  [        U R                  S-   5      eU R                  USS5      nU R	                  US5      nUc  [        U R                  S-   5      eU R                  U5      nUS   SUS.nU R                  S	X5      u  pUb  X8S
'   Ub  XHS'   U R                  U R                  X5      5      n	U R                  U	S/ 5      n
U R                  U
SSS5      nU R                  XX45      $ )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 parameterr:   r   )r  r  r  rj  ri  r;  r  r  rH   )r  r(   r:   r  r  r  rk  (v2PrivateGetFuturesPositionMarginHistoryr   r  parse_margin_modificationsr-  )r  r  r  rS  r;  r  r  r  r#  r  r  modificationss               r  fetch_margin_adjustment_history&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$)L!$G@@WA]^4 ~~h377dHfU00UUr   r  )__name__
__module____qualname____firstlineno__r   r  r   r  r#   r   r  r  r  dictr   r  r  r$  r   r   r-  r   r2  r<  r   rQ  rX  r   r\  r    r_  r[  rt  rg  ro  r  r  r  r  r   r  r   r  r   r  floatr  r   r   r   r  r  r   r  r  r"  r.  r3  r8  rI  rM  rP  r
   rV  r[  r	   rU  rn  r   r{  r  rv  r  r  r  r   r  r   r  r  r   r  r  r  r  r   r  r  r  r  r   r  r!   r   r$  r1  r  r"   r   r[  rR  rc  ri  rm  r   rt  rz  r   r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  __static_attributes____classcell__)r  s   @r  r6   r6      s
   F
# F
P ') }Z }~ $& ;$v, ;&UDL Un\|>4 > >6 >@ 02 F13 F1f F1P 04B G1W G17 G1R !# 4s 4, :<B O?s O?3 O?bE Ev E EN 6:UW +I3 +Is +I# +I\`af\g +IZ 57 @6 @6;N @6D )+ C{ CJ

T 

6 

EX 


 
4 
, 9=4^bkm 0H# 0H# 0HS 0HX[ 0Hrvw{r| 0Hd +- 3)j )+ )8 )+ )> .0 )8 $& 3( 36	: 	:D Dv D DL RT N N5 N& os{} P,3 P,i P,y P,Z_ P,hk P,d gksu l.3 l.i l.y l.RW l.`c l.\ @B yD$6 yd5k yv ;?r nc nC n` `drv  @B E.S E.# E.Y E.i E.Y\ E.lo E.N 37r Y.s Y.C Y.v /32 )
 )
V 26b U.c U.3 U.n <@daenp n=S n= n=[^ n=`	 /3TXac  3 c hlmrhs , 154VZce U# US UPS Ujnotju U& 8: !:3 !:n !:F 79 !:# !:^ !:F
h 
R` 
2 -1tRV_a Q=c Q= Q=C Q=f 26b SPw SPT(^ SPj 24 =4S =4~Ct CV CJ >B" !]# !]s !]Z 9=R ]S ]# ]T 7;2 *BG *B- *BX $|J\ , MO :3 :xD
d D
F D
N` D
L =? H He HCU H @B KC K KFX K 37TX\eg ?C ?s ?RU ?B 68 &6 &6K &6P :< 
7S 
7 
7(
6 (
[ (
T? 6:" )77 )7 )7V KOWY 9=S 9=% 9=# 9=C 9=^i 9=v:s : 8<$]ajl ?Y ?YC ?YWZ ?YBa
T a
X a
Q\ a
F [] .S .% .c .c .an .`:
t 
x 
= 
" +/TPT]_ 5BC 5Bs 5B# 5Bdhivdw 5Bn -1tRV_a 6Ec 6E 6EC 6Efjkvfw 6Ep *.Dt\^ 3E3 3Ec 3E 3Ecghsct 3Ej
t 
V 
Oa 
B >@ &= &=DV &=P 15DW[jnwy 0Q# 0Qc 0QQT 0Qdg 0Q  C  DR  S 0Qd
$ 
 
. 
< TV .S . .U .` LN "C "s "H
 
4 <> 2?s 2?h <@ : :x? ?B 24 &1S &1 &1P
t 
V 
x 
* @DRV_a FRS FR FRC FRfjksft FRP =A 9.S 9.	 9.PU 9.v @BPT $ #  b$T [Pzc 3 S # X\ dg  =Adaetx  BD =Vc =V =V[^ =Vnq =V  IM  N`  Ia =V =Vr  r6   N):ccxt.base.exchanger   ccxt.abstract.coinexr   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   r2   ccxt.base.decimal_to_precisionr3   ccxt.base.preciser4   r6   r  r  r  <module>r     s    ( , u  u  u  u  u  u  u  u  * 0 - - . ' & . ) * ) , . 1 + 4 %n[VX{ n[Vr  