
    ei6                       d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# d dl$m%Z% d dl&m'Z' d dl&m(Z( d dl&m)Z) d d	l&m*Z* d d
l&m+Z+ d dl&m,Z, d dl&m-Z- d dl&m.Z. d dl&m/Z/ d dl&m0Z0 d dl&m1Z1 d dl&m2Z2 d dl&m3Z3 d dl&m4Z4 d dl&m5Z5 d dl6m7Z7 d dl8m9Z9  G d dee          Z:dS )    )Exchange)ImplicitAPIN)AnyBalancesBorrowInterest
CurrenciesCurrencyDepositAddressIntIsolatedBorrowRateLeverageLeverageTierLeverageTiersMarginModificationMarketNumOrderOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeeInterfaceTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)OperationFailed)RateLimitExceeded)ExchangeNotAvailable)RequestTimeout)	TICK_SIZE)Precisec                   X    e Zd Zdef fdZi fdefdZi fdee         fdZ	dee         fdZ
d Zdded	edefd
Zi fdedefdZdi fdedefdZi fdefdZdi fdedefdZdded	edefdZddi fdedededee         fdZi fdedefdZi fdefdZdded	edefdZdd	edefdZ dddi fdededededee         f
dZ!i fdZ"i fd Z#i fd!Z$i fd"Z%i fde&fd#Z'd$e(fd%Z)dd&ed	ede*fd'Z+i fded(e,fd)Z-di fded*e.d+e/d,e,d-e0f
d.Z1di fded*e.d+e/d,e,d-e0f
d/Z2i fd0ee3         dee*         fd1Z4di fd2ee         de(fd3Z5ddi fd4eded*e.d+e/d,e0d-e0fd5Z6i fd0ee3         dee*         fd6Z7di fd4ede(fd7Z8di fde(fd8Z9di fd4ede(fd9Z:dddi fde(dedefd:Z;dddi fde(dededee*         fd;Z<dddi fde(dededee*         fd<Z=i fd=ede>fd>Z?i fd=ede>fd?Z@dd@eAde>fdAZBdddi fde(dedefdBZCdi fdedeeD         fdCZEi fdefdDZFddEed	efdFZGdi fdGede(fdHZHdi fdIeIde(fdJZJdi fdedeKfdKZLdd	edeeM         fdLZNi fdefdMZOddNed	edePfdOZQi fded,e,dePfdPZRi fded,e,dePfdQZSdddi fde(dedefdRZTi fdedeUfdSZVi fdedeUfdTZWdd	edeUfdUZXdV ZYdi fdedeZfdWZ[di fd=ed,e,dXedYe(de\f
dZZ]d$e(fd[Z^dddi fde(dedefd\Z_dd]ed@eAde\fd^Z`i fd=ed,e,d_ed`edeaf
daZbdb Zcddced@eAdeafddZddddi fd=e(dededeea         fdeZedddi fd=e(dededee\         fdfZfdddi fd=e(dededee\         fdgZgddhed	edehfdiZii fdedehfdjZjddddi fd=e(de(dededeek         f
dkZlddhed	edekfdlZmi fded=ed,e,fdmZni fded=efdnZodd@eAfdoZpi fd=efdpZqdi fdqefdrZrdd@eAfdsZsi fdedetfdtZuddIed	edetfduZvddi fdedededeeD         fdvZwdi fded+e/de*fdwZxi df fdx	Zydy Zzg dzi ddfd{Z{d|eId}ed~edededefdZ|ddddi fde(d*e(de0de0deeP         f
dZ} xZ~S )coinexreturnc                    |                      t          t          |                                           i ddddddddgd	d
dddddi dd ddddddddddddddddddddddddddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEddFdGdHddIddJddKddLddMddNddOddPddQddRddSddTdi dUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddeddfdidgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdxdydydzd{d|d}d~ddddddddddddddddddii ddddddddddddddddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddidddddddddddddddd	ddddddddddddd
iddddddddddddddddi ddddddddddddddddddddddddddddddddddddddddddzdi dddddddddddddddddddddddddddddddddddddddddӜii ddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddi ddddddddddddddddddddd ddddddddddddddddi ddddd	dddd
dddddddddddddddddddddddddi ddddddddddddddddddddd d!d"d!d#dd$dd%dd&dd'di d(dd)dd*dd+dd,dd-dd.dd/d!d0d!d1dd2dd3dd4dd5dd6dd7dd8dd9didd:d;d<d=d=d>dfd?d=d=d=d@d@dAidBdCdDd=d dEidFdGdddHdIdidJdKdLdMddddNi dOdOdPdQdRdRdSdSdTdTdUdUdVdVdWdWdXdYdZd[d\d\d]d]d^d_d`d`dadbdcdddedfi dgdhdididjdjdkdkdldldmdmdndndododpdpdqdqdrdrdsdtdududvdvdwdwdxdydzdzd{d|d}d~ddddd dddd dddddddddddddddiddd ddddddddddddddd ddd d d ddddddid	dddddddiddidddiddidd d dddddidt          i dt
          dt          dt          dt          dt          dt          dt          dt          dt
          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt
          dt          dt          dt          dt
          dt          dt          dt           t          t          t          t          t
          dʜt
          t          t"          d˜d̜d͐dΜ          S (  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
editOrders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/premium-index-historyz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/balancezaccount/subs/spot-balancezaccount/trade-fee-ratezaccount/futures-market-settingszaccount/infozassets/spot/balancezassets/futures/balancezassets/margin/balancezassets/financial/balancezassets/amm/liquidityzassets/credit/infozassets/spot/transcation-historyzassets/margin/borrow-historyzassets/margin/interest-limitzassets/deposit-addresszassets/deposit-historyzassets/withdrawzassets/transfer-historyzassets/amm/liquidity-poolzassets/amm/income-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-dealsz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refer/refereezrefer/referee-rebate/recordzrefer/referee-rebate/detailzrefer/agent-referee)zrefer/agent-rebate/recordzrefer/agent-rebate/detailz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/batch-modify-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/cancel-position-stop-lossz#futures/cancel-position-take-profitzfutures/modify-orderzfutures/modify-stop-orderzfutures/batch-modify-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)rE   rF   rG   )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;  )	sandboxrV   rW   r~   r   r   fetchOrdersrc   r   )r*  r.  r/  r*  )extendsrV   r   rc   rC  forDerivatives)r   inverse)rE   rD  rG   rH   commonCurrenciesACMActiniumprecisionMode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broadg     @@)
exceptionsrollingWindowSize)deep_extendsuperr6   describer3   r&   r%   r1   r2   r0   r+   r-   r,   r$   r)   r'   r*   r/   )self	__class__s    W/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/coinex.pyr  zcoinex.describe    s   fd 3 3 < < > > Y
A
(Y
A
HY
A
 tY
A
 $	Y
A
 Y
A
 4Y
A
  !Y
A
"  WWW $W 	W
 %W %W TW $UW 'W "4W tW W $UW  W 'W  /!W" ,U#W W$ 0%W& t'W( )W* (+W, &t-W. "4/W0 (1W2 %d3W4 T5W6 d7W8 9W: &t;W< +E=W> )%?W@ $TAWB 'CWD (EW W WF "4GWH &tIWJ (KWL 1%MWN  OWP *4QWR +DSWT &tUWV 'WWX (YWZ #D[W\ *4]W^ $T_W` "5aWb *4cWd +EeWf  gW W Wh !%iWj %dkWl /mWn +JoWp qWr !%sWt  uWv dwWx "4yWz d{W| !$}W~  W@ 'AWB !$CWD (EWF %eGWH )%IW W WJ tKWL MWN TOWP tQWR "4SWT #DUWV  WWX !$YWZ "5[W\ #D]W^ _W` #EaWb &tcWd teWf  gWh "5iWj DkW Wl DmW W#Y
A
R  SY
A
p ~67'I(J	  075N qY
A
J  *+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  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 Tn   +Q "A  #A  *1	 
 *1  )!  )!  )!  )!  -a  -a  ,Q  ,Q  ,Q  ,Q   3A! " ;A# $ >?67;<56>?BC/     86 *A6 5r6  06  /	6 
 <R6  3A6  86  5b6  >q6  +A6  226  5b6  4Q6  76  3B6   1"!6 " >q#6  6 $ ;B%6 & ;A'6 ( 5b)6 * 5b+6 , .r-6 . 6r/6 0 816 2 836 4 056 6 6q76 8 1!96 : 22;6 < 6q=6 > 7?6 @ .rA6 B /C6 D 3AE6  6  6 F 9!G6 H 4QI6 J 5bK6 L 9!M6 N :2O6 P 1!Q6 R 21S6 T 7U6 V 8W6 X >qY6 Z ?[6 \ ;A]6 ^ >q_6 ` ,Qa6 b :1c6 d :1e6 f 21g6  6 h :;9:k6  6  6 n5!*B5!125! 4R5! /	5!
 4R5! 6r5! 4R5! /5! >r5! 3B5! 225! =b5! .r5! 5b5! .r5!  7!5!" :1#5! 5!$ )&%5!& .v'5!( /)5!* 4Q+5!, 0-5!. 5f/5!0 6v15!2 4Q35!4 055!6 5e75!8 6r95!: ;B;5!< =a=5!> B1?5!@ ,RA5!B 1"C5!D 21E5! 5! 5!F 7G5!H @I5!J B2K5!L 3BM5!N 8O5!P 9"Q5!R 7S5!T 3BU5!V 8W5!X 9"Y5!Z >r[5!\ @]5!^ Ea_5!` 5ba5!b =bc5!d ?e5!f =bg5! 5!h ?i5! 5!qn  n 9K Kmb bKY
A
P "" 
 "$$$% &! !	 QY
A
p   qY
A
| )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 9}Y
A
p $&*(,,0,1).+06:#'#'"&#(	( ( #($)$)+/26/3#')$ $. q% '+!%$(%+*.& & ',#($)*.	# # '+!%#'$)*/( ( $(&*!%$(,0%)#'$)*/	* 	*  #u= =~  &&*)-+/$ $ %e( %e*# #  "#3 "#3 	  ## kY YqY
A
d z!eY
A
j YkY
A
n:*: -: -	:
 -: .: .: ,: ,: +: =: <: <: <: 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 AD "(qY
A
 Y
A
 Y
A
 Y
 Y
 Y
	    c                   K   |                      |           d{V }|                     |dg           }i }t          dt          |                    D ]y}||         }|                     |di           }|                     |dg           }|                     |d          }	|	R|                     |	          }
|                     |d          }|                     |d          }|                     |di           }|                     |                     |d	                    }i }t          dt          |                    D ]>}||         }|                     |d
          }| 	                    ||
          }|:|                     |                     |d	                    }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }||d|o|||| 
                    |          | 
                    |          ddd| 
                    |          dd| 
                    |          ddd|d
}|||<   @|                     |	|
d|o|||d| 
                    |          dddddddddd|d|d          ||
<   {|S )a@  
        fetches all available currencies on an exchange

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        Ndatar   assetchainsccydeposit_enabledwithdraw_enabledwithdrawal_precisionchainwithdrawal_feemin_deposit_amountmin_withdraw_amountr   )r   depositr   )
r9   networkr:   activer  r   fee	precisionr   infocrypto)r9   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_currencieszcoinex.fetch_currencies  s}      GGOOOOOOOOH ~~h33q#d))$$ M	 M	A7DNN4"55E^^D(B77F))%77J!**:66D/@AAJ..0BCCK266J#'#7#78H8HUk8l8l#m#m H1c&kk** %0 %0q	 ,,UG<<	"55iFF$"&"6"6t7G7GOe7f7f"g"g ,,U4DEE	*.*:*:5BV*W*W'+/+;+;ECX+Y+Y("&..8I"J"J#'>>%9K#L#L #* -B2B. 0,,Y77!%!2!2?!C!C $(#'# #
 $(#4#45L#M#M#'$ $
 $(#4#45M#N#N#'% %  "/! !2 )0%%77 $4%'!../CDD  $# 
  $#   
  $#! !  % 39 9  F4LL6 r  c                    K   |                      |          |                     |          g}t          j        |  d{V }|d         }|d         }|                     ||          S )ab  
        retrieves data on all markets for coinex

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nr   r   )fetch_spot_marketsfetch_contract_marketsasynciogatherarray_concat)r  r  promisesUnresolvedpromisesspotMarketsswapMarketss         r  fetch_marketszcoinex.fetch_markets;  s{       ##F++''//
 !);<<<<<<<qkqk  k:::r  c                 4  K   |                      |           d {V }|                     |dg           }g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }	|                     |          }
|                     |	          }|
dz   |z   }|                    i d|d|d	|
d
|dd d|d|	dd ddddd|                     |d          ddddddd|                     |d          dddd d |                     |d          |                     |d          d d d d d | 	                    | 
                    |                     |d                              | 	                    | 
                    |                     |d                              d d d d!|                     |d"          d d!d d d!d d d!d#d |d$           |S )%Nr  r   marketbase_ccy	quote_ccy/r9   symbolbasequotesettlebaseIdquoteIdsettleIdr  rE   TrF   is_margin_availablerG   FrH   rI   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  r9   r  r  r  r  r  s                r  r  zcoinex.fetch_spot_marketsN  s     33F;;;;;;;;. ..6266q#g,,'' :	 :	AQZF!!&(33B%%fj99F&&v{;;G**622D++G44ECZ%'FMM 2b2&2 2 	2
 $2 &2 72 D2 2 2 $..1FGG2 2 %2 %2 $..1KLL2  E!2" $#2$  ))&2BCC))&2BCC $"&""//0D0DTEUEUV\^rEsEs0t0tuu!..t/C/CDDTDTU[]rDsDs/t/tuu   $#! !
  $//EE# 
  $# 
  $#  $  c2 2 2 2 2 2 2f r  c                 (  K   |                      |           d {V }|                     |dg           }g }t          dt          |                    D ]<}||         }| j        }|                     |dg           }|                     |d          }	|	dk    }
|	dk    }|                     |d          }|                     |d          }|                     |d	          }|                     |          }|                     |          }|	dk    rd
n|}|                     |          }|dz   |z   dz   |z   }t          |          }|                    i d|d|d|d|d|d|d|d|dddddddddddddd ddd|
||d         d          |d         d!         |                     d"          d d d d |                     | 	                    |                     |d#                              |                     | 	                    |                     |d$                              d%| 
                    |d          | 
                    ||d&z
            d'| 
                    |d(          d d'd d d'd d d'd)d |d*           >|S )+Nr  r   r4  contract_typer   rE  r  r  r  USDTr  :r9   r  r  r  r  r  r  r  r  rG   rE   FrF   TrH   rI   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  r9   r  r  r  r  r  r  r  leveragesLengths                        r  r  zcoinex.fetch_contract_markets  s     66v>>>>>>>>, ..6266q#g,,'' B	 B	AAJE9Duj"==I&&uo>>G)F)+G!!%22B%%eZ88F&&uk::G**622D++G44E")X"5"5vvFH,,X66FCZ%'#-6F!)nnO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 6"&""//0D0DTEUEUV[]qErEr0s0stt!..t/C/CDDTDTUZ\qDrDr/s/stt   $//	1==#//	?Q;NOO! !
  $//|DD# 
  $# 
  $#  $  c2 2 2 2 2 2 2f r  Ntickerr  c           
         d|v rdnd}|                      |d          }|                     ||d |          }|                     i d|dd dd d|                      |d          d	|                      |d	          d
d d|                      |d          dd d|                      |d          dd d|                      |d          d|                      |d          d|                      |d          dd dd dd dd |                      |d          d |                      |d          |                      |d          |d|          S )N
mark_pricerG   rE   r  r  	timestampdatetimehighlowbid	bidVolume
volume_buyask	askVolumevolume_sellvwapopencloselastpreviousClosechange
percentageaveragevolumeindex_price)
baseVolumequoteVolume	markPrice
indexPricer  )r  safe_symbolsafe_ticker)r  r  r  
marketTypemarketIdr  s         r  parse_tickerzcoinex.parse_ticker  s   H !- 6 6VVV
##FH55!!(FD*EE !
f!
!
 !
 D$$VV44	!

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

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

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/?id=ticker-structure>`
        Nr  r9   rG   r  r   )load_marketsr  v2PublicGetFuturesTickerextendv2PublicGetSpotTickerr  r  r  r  r  r  r  requestr  r  r  s           r  fetch_tickerzcoinex.fetch_tickerC  s      !!!!!!!!!V$$fTl
 &> 	V!::4;;wPV;W;WXXXXXXXXHH!77GV8T8TUUUUUUUUH` ~~h33a,,  000r  symbolsc                   K   |                                   d{V  |                     |          }d}|+|                     |d          }|                     |          }|                     d||          \  }}d}|dk    r|                     |           d{V }n|                     |           d{V }|                     |dg           }|                     ||          S )aj  
        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   rG   r  )	r  market_symbols
safe_valuer  handle_market_type_and_paramsr  r  r  parse_tickers)	r  r"  r  r  r  r  queryr  r  s	            r  fetch_tickerszcoinex.fetch_tickers  s      !!!!!!!!!%%g..__Wa00F[[((F >>~vW]^^
E!::5AAAAAAAAHH!77>>>>>>>>H` ~~h33!!$000r  c                    K   |                      |           d{V }|                     |di           }|                     |d          S )aL  
        fetches the current integer timestamp in milliseconds from the exchange server

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

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

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

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

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

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

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

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

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/?id=fee-structure>` indexed by market symbols
        Nr   rG   r  r   r  r  )
r  r&  r  r  r  r  r  r  rD  rR  )r  r  r  r  r  r  r  r  r  r  r  s              r  fetch_trading_feeszcoinex.fetch_trading_fees  sH      !!!!!!!!!99:LdTZ[[f6>>!::6BBBBBBBBHH. "77????????H* ~~h33q#d))$$ 	C 	CAGE''x88H%%hdDAAFH%F!33E6BBF6NNr  r  c                     |                      |d          }|                     ||          }|||                     |d          |                     |d          dddS )Nr  r  r  T)r  r  r   r   r  	tierBased)r%  r  r  )r  r  r  r  r  s        r  rR  zcoinex.parse_trading_fee6  sm    ??311!!(F33%%c+;<<%%c+;<<
 
 	
r  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr9  r  r  r   r	  value)r,  r  )r  ohlcvr  s      r  parse_ohlcvzcoinex.parse_ohlcvB  s     e\22UF++UF++UE**UG,,UG,,
 	
r  r   	timeframec                   K   |                                   d{V  |                     |          }|d         |                     | j        ||          d}|||d<   d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }	|                     |	||||          S )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
        Nr9   )r  periodr;  rG   r  )	r  r  r  r   v2PublicGetFuturesKliner  v2PublicGetSpotKliner  parse_ohlcvs)
r  r  r\  rK  r;  r  r  r   r  r  s
             r  fetch_ohlcvzcoinex.fetch_ohlcvX  s&      !!!!!!!!!V$$Tl&&t	9MM
 
 $GG&> 	U!99$++gv:V:VWWWWWWWWHH!66t{{7F7S7STTTTTTTTH* ~~h33  vy%GGGr  c                 P  K   |                                   d {V  |                     |           d {V }d|i}|                     |dg           }t          dt	          |                    D ]!}||         }|                     |di           }|                     |di           }|                     |di           }	|                     |di           }
|                                 }|                     |d          }|                     |          }|                     |d          |d	<   |                     |d          |d
<   |                     |	d          }|                     |
d          }t          j
        ||          |d<   |||<   #|                     |          S )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  rh  ri  loanrg  baseAccountbaseCurrencyIdbaseCurrencyCodebaseDebtbaseInterests                   r  fetch_margin_balancezcoinex.fetch_margin_balance  s     !!!!!!!!!==fEEEEEEEE@ )>>(FB77q#h--(( 	3 	3AQKE>>%b99D>>%266D>>%266D~~eZ<<H,,..K!--eZ@@N#66~FF"&"2"24"D"DK"&"2"24"D"DK''j99H++HjAAL")"4X|"L"LK'2F#$$  (((r  c                   K   |                                   d {V  |                     |           d {V }d|i}|                     |dg           }t          dt	          |                    D ]}||         }|                     |d          }|                     |          }|                                 }	|                     |d          |	d<   |                     |d          |	d<   |	||<   |                     |          S 	Nr  r  r   r  rd  rh  re  ri  )	r  v2PrivateGetAssetsSpotBalancer  r  r  r  r  rl  rn  
r  r  r  r  ro  r  r  r  r  rl  s
             r  fetch_spot_balancezcoinex.fetch_spot_balance  s     !!!!!!!!!;;FCCCCCCCC )>>(FB77q#h--(( 	# 	#AQKE))%77J**:66DllnnG"..ukBBGFO"..uh??GFO"F4LL  (((r  c                   K   |                                   d {V  |                     |           d {V }d|i}|                     |dg           }t          dt	          |                    D ]}||         }|                     |d          }|                     |          }|                                 }	|                     |d          |	d<   |                     |d          |	d<   |	||<   |                     |          S rx  )	r   v2PrivateGetAssetsFuturesBalancer  r  r  r  r  rl  rn  rz  s
             r  fetch_swap_balancezcoinex.fetch_swap_balance  s     !!!!!!!!!>>vFFFFFFFF" )>>(FB77q#h--(( 	# 	#AQKE))%77J**:66DllnnG"..ukBBGFO"..uh??GFO"F4LL  (((r  c                   K   |                                   d {V  |                     |           d {V }d|i}|                     |dg           }t          dt	          |                    D ]}||         }|                     |d          }|                     |          }|                                 }	|                     |d          |	d<   |                     |d          |	d<   |	||<   |                     |          S rx  )	r  "v2PrivateGetAssetsFinancialBalancer  r  r  r  r  rl  rn  rz  s
             r  fetch_financial_balancezcoinex.fetch_financial_balance  s     !!!!!!!!!@@HHHHHHHH )>>(FB77q#h--(( 	# 	#AQKE))%77J**:66DllnnG"..ukBBGFO"..uh??GFO"F4LL  (((r  c                 |  K   d}|                      dd|          \  }}d}|                     d|          \  }}|dup|dk    }|dk    r|                     |           d{V S |dk    r|                     |           d{V S |r|                     |           d{V S |                     |           d{V S )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_   rF   rG   	financial)r&  handle_margin_mode_and_paramsr~  r  rv  r{  )r  r  r  r*  isMargins        r  fetch_balancezcoinex.fetch_balance  s      
!??PTV\]]
F
!??PVWW
Fd*G
h0F00888888888;&&55f========= 	9226:::::::::00888888888r  statusc                 B    ddddddd}|                      |||          S )Nrejectedr  closedcanceled)r  r  not_deal	part_dealdonecancelr  r  r  statusess      r  parse_order_statuszcoinex.parse_order_status1  s:    " 
 
 &&999r  rB  c                 X   |                      |d          }|                     |d          }|                     |d          }|dk    r|}|                      |d          }|                      | j        d          }|                     |d|          }|dk    rd	}|d	k    rd	nd
}	|                     ||d |	          }|                      |d          }
|                     |
          }||d         }|                      |d          }|dk    rd}n|dk    rd}|                      |d          }|dk    rd }|                     i d|                     |g d          d|d|                     |          d|d|d| 	                    |          d|d         d|                      |d          dd dd dd d|d|                      |d          d |                      |d!          d"| 
                    |d#          d$| 
                    |d%          d&|                      |d'          |                      |d(          |                      |d)          |                      |d*          |                      |d+          d ||                     |d,d-          d.|d/|          S )0Nr  r9  r2  r   r  r   market_typefuturesrG   rE   r:  r  r?  longbuyshortsell	client_id r9   )position_idr>  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  )r<  r  )r  r   filled	remainingtradesr  r  )r  r,  r   safe_string_lowerrD  r  
safe_ordersafe_string_nrF  r  r  safe_string_2)r  rB  r  	rawStatusr  updatedTimestampr  r   	orderTyper  rH  feeCurrencyr?  r  s                 r  parse_orderzcoinex.parse_order<  sn   ` $$UH55	%%e\::	,,ULAAq  (##E844&&t|]CC**5-MM		!!I )V 3 3VV&
!!(FD*EE((	::--m<< /Kv..6>>DDW__D((<<B M  
$$$U,R,R,RSS 
] 
 Y// 
 	 

 !"2 
 d--i88 
 fX& 
 D$$UF33 
 4 
  
 $ 
 D 
 T%%eW55 
 D,,UODD 
 t//7JKK 
  T--e5FGG! 
" D$$UN;;# 
$ ''/@AA&&uh77&&uo>>))%1BCC'**5+uEE  7 
  
  
8 9  	r  r  c                    K   |                                   d{V  |                     |          }|d         st          | j        dz             d|d<   |                     |dd|d|           d{V S )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>`
        NrE   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr  r  r  )r  r  r.   r9   create_order)r  r  r  r  r  s        r  !create_market_buy_order_with_costz(coinex.create_market_buy_order_with_costB  s       !!!!!!!!!V$$f~ 	ftw)ddeee6;23&&vxdFSSSSSSSSSr  r  r?  r   r  c                    |                      |          }|d         }|                     |dd          }	|                     |dd          }
|                     |d          }|                     |d          }|                     |d          }|d	k    }|                     ||d
k    |          }|                     |d          }|                     |d          }|r+|d         s#t          | j        dz   |d         z   dz             d	|d         i}|	<d}|                     | j        d|          }|dz   | 	                                z   |d<   n|	|d<   |C|A|s||d<   |}|rd
}n||dk    rd}n|dk    rd}|s| 
                    ||          |d<   ||d<   |rd|d<   |s|rn|r5| 
                    ||          |d<   |                     |dd          |d<   n|r3| 
                    ||          |d <   |                     |dd          |d!<   n|                     ||          |d"<   |
3| 
                    ||
          |d#<   |                     |dd          |d$<   nZd }|                     d%|          \  }}|d&|d<   nd'|d<   |d	k    r|d(k    rd)}|                     |d%d*d)          \  }}|                     |d+          }|                     |d+          }|r||t          | j        d,z             |                     |          }|                     |          }|                     t%          j        ||                    }||n|}|                     ||          |d"<   n3|                     ||          |d"<   n|                     ||          |d"<   |
| 
                    ||
          |d#<   |                     |g d-          }|                     ||          S ).NrG   r  r  	stopPricer+  r.  r/  rI   r  
maker_onlyr1  r  z/ createOrder() does not support reduceOnly for r  z> orders, reduceOnly orders are supported for swap markets onlyr9   r   r  -r?  r&  iocr'  fokr  r   r  r  	stop_typelatest_pricestop_loss_typer  take_profit_typer   r  trigger_price_typerV   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,   r9   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  r?  r   r  r  r  rG   r  r+  r.  r/  rI   isMarketOrderr  timeInForceRawr  r   	defaultIdr  requestTyper*  r  r  amountStringpriceStringquoteAmountcostRequests                                r  create_order_requestzcoinex.create_order_requestU  s   V$$f~**6;PP))&+~NN((AA**63DEE!!&(33($$]Fl4JFSS//FF^^FL99
 	t&> t"47-^#^aghnao#o  ss  $s  t  t  tfTl
  %I''j)LLH#+c>DKKMM#AGK  #0GK !(? '"&K (*+!U**"'KK#u,,"'K  J#'#:#:65#I#I )GFO (	Y%.GM" j j  h151H1HQ^1_1_G-.040@0@Vd0e0eG,--$ h373J3J6Sb3c3cG/0262B2B6;Xf2g2gG./$($<$<VV$L$L!+/3/F/Fv|/\/\GO,484D4DV[Zh4i4iG01J!%!C!CMSY!Z!ZJ%)1&&)/&  tu}}481<@<Y<YZ`bo  rU  W[  =\  =\916''7766224 
ODL*47  6q  ,q  r  r  r'+'<'<V'D'D&*&;&;E&B&B&*&;&;G<N|]h<i<i&j&j/3/?ddk,0,B,B6;,W,W))(,(>(>vv(N(NGH%%$($<$<VV$L$L!'+/+B+B6<+X+X(6  $N  $N  $N  O  O{{7F+++r  c                 v  K   |                                   d{V  |                     |          }|                     |d          }|                     |dd          }	|                     |d          }
|                     |d          }|	du}|
du}|du}|p|}|                     ||||||          }d}|d         r:|r|                     |           d{V }n|                     |           d{V }n|r|                     |           d{V }nw|r<|r| 	                    |           d{V }nW|r| 
                    |           d{V }n9|r|                     |           d{V }n|                     |           d{V }|                     |di           }|                     ||          S )	ac  
        create a trade order

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

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: price to trigger stop orders
        :param float [params.stopLossPrice]: price to trigger stop loss orders
        :param float [params.takeProfitPrice]: price to trigger take profit orders
        :param str [params.timeInForce]: 'GTC', 'IOC', 'FOK', 'PO'
        :param boolean [params.postOnly]: set to True if you wish to make a post only order
        :param boolean [params.reduceOnly]: *contract only* indicates if self order is to reduce the size of a position
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr  r  r+  r.  r/  rE   r  )r  r  r  r  r  r  v2PrivatePostSpotStopOrderv2PrivatePostSpotOrderv2PrivatePostFuturesStopOrder'v2PrivatePostFuturesSetPositionStopLoss)v2PrivatePostFuturesSetPositionTakeProfit!v2PrivatePostFuturesClosePositionv2PrivatePostFuturesOrderr  r  )r  r  r  r?  r   r  r  r  r  r+  stopLossTriggerPricetakeProfitTriggerPriceisTriggerOrderisStopLossTriggerOrderisTakeProfitTriggerOrderisStopLossOrTakeProfitTriggerr   r  r  s                      r  r  zcoinex.create_order  ss     4 !!!!!!!!!V$$^^FL99
))&+~NN#//HH!%!1!1&:K!L!L%T1!5T!A#9#E (>(ZBZ%++FD$vVV&> h	M F!%!@!@!I!IIIIIII "&!<!<W!E!EEEEEEE>  |M!%!C!CG!L!LLLLLLL / qM) )]%)%Q%QRY%Z%ZZZZZZZHHN . ]%)%S%ST[%\%\\\\\\\HP  M%)%K%KG%T%TTTTTTTHH< &*%C%CG%L%LLLLLLLH: ~~h33f---r  ordersc           	        K   |                                   d{V  g }d}d}d}d}t          dt          |                    D ]m}||         }	|                     |	d          }
||
}n||
k    rt	          | j        dz             |                     |	d          }|                     |	d          }|                     |	d          }|                     |	d	          }|                     |	d
i           }|dk    rt          | j        dz   |z   dz             |                     |d          }|                     |dd          }| 	                    |d          }| 	                    |d          }|du}|du}|du}|p|}| 
                    |
|||||          }|                    |           o|                     |          }|d         |d}d}|d         r:|r|                     |           d{V }n|                     |           d{V }nk|r|                     |           d{V }nM|rt          | j        dz             |rt          | j        dz             |                     |           d{V }|                     |dg           }g }t          dt          |                    D ]}||         }d}|                     |d          }||dk    rd}nd}|                     |di           }d}|d         r|s||d<   |                     ||          }n||d<   |                     ||          }|                    |           |S )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  r?  r   r  r  r;  z! createOrders() does not support z' orders, only limit orders are acceptedr  r  r+  r.  r/  r9   )r  r  rE   zH createOrders() does not support stopLossPrice or takeProfitPrice ordersz2 createOrders() does not support reduceOnly ordersr  r  r  r  r  )r  r  r  r  r)   r9   r%  r.   safe_number_2r  r  r  r  v2PrivatePostSpotBatchStopOrderv2PrivatePostSpotBatchOrder"v2PrivatePostFuturesBatchStopOrderv2PrivatePostFuturesBatchOrderr  r,  r  r  ) r  r  r  ordersRequestsr  r  r  r  r  rawOrderr  r  r?  r   r  orderParamsr+  r  r  r  r  orderRequestr  r   r  r  resultsr  r  r  	innerDatarB  s                                    r  create_orderszcoinex.create_orders	  s6      !!!!!!!!!
(-%q#f++&& 	0 	0AayH''(;;H~!X%%$TW/l%lmmm##Hf55D##Hf55D__Xx88FOOHg66E//(HbAAKw"47-P#PSW#W  [D  $D  E  E  ElCCJ--k;WWL#'#3#3K#Q#Q %)%5%5kCT%U%U")5N%9%E"'=T'I$,B,^F^)44XtT6SXZeffL!!,////V$$Tl$
 
 &> P	R K!%!E!Eg!N!NNNNNNN" "&!A!A'!J!JJJJJJJL  R!%!H!H!Q!QQQQQQQ  / R"47-w#wxxx R&tw1e'efff%)%H%H%Q%QQQQQQQHF ~~h33q#d))$$ 	" 	"AGEF$$UF33D199'FF#Fufb99IEf~ <n <"(h((77&,	(#((F;;NN5!!!!r  idsc                 d  K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|                     |dd          }|                     |ddg          }d}g }t          dt          |                    D ]*}	|                    t          ||	                              +|r||d<   n||d	<   |d
         rb|r0| 
                    |                     ||                     d{V }n|                     |                     ||                     d{V }nfd|d<   |r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }
g }t          dt          |
                    D ]L}	|
|	         }|                     |di           }|                     ||          }|                    |           M|S )a  
        cancel multiple orders

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

        :param str[] ids: order ids
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: set to True for canceling stop orders
        :returns dict: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nz* cancelOrders() requires a symbol argumentr  r9   stopr?  r   stop_ids	order_idsrE   r   r  r  )r(   r9   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  itemrB  s                  r  cancel_orderszcoinex.cancel_ordersP
  s      >#DG.Z$Z[[[!!!!!!!!!V$$fTl
 ""669==6FI#677
q#c((## 	+ 	+Ac#a&kk**** 	.",GJ#-GK &> d	i f!%!K!KDKKX_agLhLh!i!iiiiiii< "&!G!GT[]cHdHd!e!eeeeeeeJ &/GM" i!%!N!Nt{{[bdjOkOk!l!lllllll: "&!J!J4;;W^`fKgKg!h!hhhhhhhF ~~h33q#d))$$ 	" 	"AGE>>%44D$$T622ENN5!!!!r  r9   c                 d  K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}	||                     ||          |	d<   ||                     ||          |	d<   d}
|                     |g d          }|                     |dd	g          }|du}|r2|                     ||          |	d
<   |                     |          |	d<   n|                     |          |	d<   d}| 	                    d|          \  }}|d         ro|d|	d<   nd|	d<   |r0| 
                    |                     |	|                     d{V }
n|                     |                     |	|                     d{V }
nfd|	d<   |r0|                     |                     |	|                     d{V }
n/|                     |                     |	|                     d{V }
|                     |
di           }|                     ||          S )a  
        edit a trade order

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

        :param str id: order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of the currency you want to trade in units of the base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: the price to trigger stop orders
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nz' editOrder() requires a symbol argumentr  r9   r   r  )r  r+  r  r  r+  r  r  r>  r]   rE   r   r  r   r   r  )r(   r9   r  r  r  r  r  r  r  r   v2PrivatePostSpotModifyStopOrderr  v2PrivatePostSpotModifyOrder#v2PrivatePostFuturesModifyStopOrderv2PrivatePostFuturesModifyOrderr  r  )r  r9   r  r  r?  r   r  r  r  r   r  r+  r  r*  r  s                  r  
edit_orderzcoinex.edit_order   s     & >#DG.W$WXXX!!!!!!!!!V$$fTl
  $ 8 8 H HGH#66vuEEGG))&2`2`2`aa6K#@AA%T1 	<'+'>'>v|'T'TGO$!%!6!6r!:!:GI"&"7"7";";GJ
!??VTT
F&> >	d%)1&&)/& a!%!F!Ft{{SZ\bGcGc!d!ddddddd "&!B!B4;;wX^C_C_!`!```````@ &/GM" d!%!I!I$++V]_eJfJf!g!ggggggg "&!E!EdkkRY[aFbFb!c!ccccccc: ~~h33f---r  c                   K   |                                   d{V  g }g }t          dt          |                    D ]N}||         }|                     |d          }|                     |          }|                    |           |                     |d          }	|                     |d          }
|                     |d          }|                     |di           }d}|                     d|          \  }}d	}|d
         rd}n|d}| 	                    |	          |d         |d}|
| 
                    ||
          |d<   ||                     ||          |d<   |                    |                     ||                     P|                     |dddd          }|                     |d          }|                     |          }d|i}d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|dk    s&|dk    r|dk    rz|                                dk    rb|s`| j        dz   |z   }|                     | j        d         ||           |                     | j        d         ||           t-          |          |                     |di           }|                     |          }|                    |           |S )a  
        edit a list of trade orders

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

        :param Array orders: list of orders to edit, each object should contain the parameters required by editOrder, namely id, symbol, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr   r  r9   r   r  r  r^   r   rG   r   r   )r>  r  r  FTr  rE   r  r  messager/  Success	Succeededok r  r  )r  r  r  r  r  r  r%  r  r  r  r  r  r  r$  !v2PrivatePostSpotBatchModifyOrder$v2PrivatePostFuturesBatchModifyOrderr  lowerr9   throw_broadly_matched_exceptionr  throw_exactly_matched_exceptionr$   r  )r  r  r  r  orderSymbolsr  r  r  r  r9   r   r  r  r*  r  r  firstSymbolfirstMarketr   r  r  r  r  r  r
  feedbackr  rB  s                               r  edit_orderszcoinex.edit_orders  s      !!!!!!!!!q#f++&& 	J 	JAayH''(;;H[[**F)))!!(D11B__Xx88FOOHg66E..8R@@KJ&*&H&HWb&c&c#J Kf~ '''& 11"55 ,*" "L
 !)-)A)A(F)S)SX& (,(?(?%(P(PW%!!$++lK"H"HIIII**<udDQQ&&|Q77kk+..n
 v 	e!CCDKKPWY_D`D`aaaaaaaaHH!FFt{{SZ\bGcGcddddddddH~~h33q#d))$$ 	! 	!AGE##E622D&&ui88G'Y"6"6W=S=SZaZgZgZiZimqZqZq{Zq7S=7244T_W5MwX`aaa44T_W5MtU]^^^#H--->>%44D$$T**EMM%    r  c                    K   |t          | j        dz             |                                  d{V  |                     |          }|                     |dd          }|d         }d|d         i}d}|                     d|          \  }}|rd	|d
<   n|d|d
<   nd|d
<   |                     |dd          }	|                     |g d          }d}
|	|	|d<   |rd|r1|                     | 	                    ||                     d{V }
n| 
                    | 	                    ||                     d{V }
nX|r1|                     | 	                    ||                     d{V }
n%|                     | 	                    ||                     d{V }
n|rz|                     |          |d<   |r0|                     | 	                    ||                     d{V }
n|                     | 	                    ||                     d{V }
ny|                     |          |d<   |r0|                     | 	                    ||                     d{V }
n/|                     | 	                    ||                     d{V }
d}|	5|                     |
dg           }|                     |d         di           }n|                     |
di           }|                     ||          S )ad  
        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?  rG   r  r9   rN   r   r  r   r   r  r  )r  r?  r  r  r>  r  r   )r(   r9   r  r  r  r  r  r  -v2PrivatePostFuturesCancelStopOrderByClientIdr  *v2PrivatePostSpotCancelStopOrderByClientId)v2PrivatePostFuturesCancelOrderByClientId&v2PrivatePostSpotCancelOrderByClientIdr  #v2PrivatePostFuturesCancelStopOrder v2PrivatePostSpotCancelStopOrderv2PrivatePostFuturesCancelOrderv2PrivatePostSpotCancelOrderr  r  r  )r  r9   r  r  r  r  rG   r   r*  r  r  r  rowss                r  cancel_orderzcoinex.cancel_order  s     ( >#DG.Y$YZZZ!!!!!!!!!V$$))&&)DDf~fTl
 
!??vVV
F 	0%.GM""%)1&&)/&**6;PP6#G#G#GHH$#0GK  \o s%)%W%WX\XcXcdkmsXtXt%u%uuuuuuuHH6 &*%T%TUYU`U`ahjpUqUq%r%rrrrrrrHH8  #o%)%S%STXT_T_`gioTpTp%q%qqqqqqqHHD &*%P%PQUQ\Q\]dflQmQm%n%nnnnnnnHHF  Me%)%:%:2%>%>	" i%)%M%MdkkZaciNjNj%k%kkkkkkkHH, &*%J%J4;;W^`fKgKg%h%hhhhhhhHH, '+&;&;B&?&?
# e%)%I%I$++V]_eJfJf%g%gggggggHH8 &*%F%Ft{{SZ\bGcGc%d%dddddddH8 $>>(FB77D>>$q'6266DD>>(FB77Df---r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}d}|d         r5d|d<   |                     |                     ||                     d{V }nWd}|                     d|          \  }}|d	|d<   nd
|d<   |                     |                     ||                     d{V }|                     d|i          gS )a2  
        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  r9   rG   r   r  rM   r   r   r  )	r(   r9   r  r  "v2PrivatePostFuturesCancelAllOrderr  r  v2PrivatePostSpotCancelAllOrderr  )r  r  r  r  r   r  r*  s          r  cancel_all_orderszcoinex.cancel_all_orders  sX      >#DG.]$]^^^!!!!!!!!!V$$fTl
 &> 	`%.GM"!DDT[[QXZ`EaEabbbbbbbbHH
 J!%!C!CDUW]!^!^J%)1&&)/&!AA$++gW]B^B^________H
 OO  
 	
r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }|d         |                     |          d}d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |di           }| 	                    ||          S )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 argumentr9   )r  r>  rG   r  )
r(   r9   r  r  r  v2PrivateGetFuturesOrderStatusr  v2PrivateGetSpotOrderStatusr  r  )r  r9   r  r  r  r   r  r  s           r  fetch_orderzcoinex.fetch_order  s)      >#DG.X$XYYY!!!!!!!!!V$$Tl--b11
 
 &>  	\!@@WV\A]A]^^^^^^^^HH> "==dkk'SY>Z>Z[[[[[[[[H> ~~h33f---r  c                 N  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |                     |dd          }|                     |ddg          }d}	|                     d||          \  }	}d}
|dk    p|d	k    }|d
k    p|dk    }|	dk    rd|d<   |rd|r1|                     |                     ||                     d{V }
n|                     |                     ||                     d{V }
nX|rb|r1|                     |                     ||                     d{V }
n#| 	                    |                     ||                     d{V }
nd}| 
                    d|          \  }}|d|d<   nd|d<   |rb|r0|                     |                     ||                     d{V }
n|                     |                     ||                     d{V }
ng|d
k    ra|r0|                     |                     ||                     d{V }
n/|                     |                     ||                     d{V }
|                     |
dg           }|                     ||||          S )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>`
        Nr9   r  r;  r  r?  fetchOrdersByStatusfinishedr  pendingr  rG   r   r  r   r   r  )r  r  r  r  r&  $v2PrivateGetFuturesFinishedStopOrderr   v2PrivateGetFuturesFinishedOrder#v2PrivateGetFuturesPendingStopOrderv2PrivateGetFuturesPendingOrderr  !v2PrivateGetSpotFinishedStopOrderv2PrivateGetSpotFinishedOrder v2PrivateGetSpotPendingStopOrderv2PrivateGetSpotPendingOrderr  parse_orders)r  r  r  rK  r;  r  r   r  r?  r  r  isClosedisOpenr*  r  s                  r  fetch_orders_by_statuszcoinex.fetch_orders_by_statusg  s     $ !!!!!!!!![[((F &tGH$GG""669==6FI#677
!??@UW]_eff
Fj(Af.@I%<6V+;%.GM" \h i%)%N%Nt{{[bdjOkOk%l%lllllllHH8 &*%J%J4;;W^`fKgKg%h%hhhhhhhHH>  h h%)%M%MdkkZaciNjNj%k%kkkkkkkHH: &*%I%I$++V]_eJfJf%g%gggggggHH J!%!C!CDY[a!b!bJ%)1&&)/& `e f%)%K%KDKKX_agLhLh%i%iiiiiiiHH: &*%G%GT[]cHdHd%e%eeeeeeeHHB 9$$ e%)%J%J4;;W^`fKgKg%h%hhhhhhhHH< &*%F%Ft{{SZ\bGcGc%d%dddddddHH ~~h33  vue<<<r  c                    K   |                      d||||           d{V }t          dt          |                    D ]}d||         d<   |S )a  
        fetch all unfilled currently open orders

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

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

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

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

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

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

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

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: the blockchain network to create a deposit address on
        :returns dict: an `address structure <https://docs.ccxt.com/?id=address-structure>`
        Nr  r9   z5 fetchDepositAddress() requires a "network" parameterr  r  )
r  r<  handle_network_code_and_paramsr(   r9   rB   v2PrivateGetAssetsDepositAddressr  r  rD  )r  r  r  r<  r   r  r  r  s           r  fetch_deposit_addresszcoinex.fetch_deposit_address  s      !!!!!!!!!==&&8D>
 "AA&IIV#DG.e$efff22;??>>t{{7TZ?[?[\\\\\\\\ ~~h33))$999r  r<  c           	      *   |                      |d          }|                    d          }d }d }t          |          }|dk    r|d         dk    r|d         }|d         }n|}||                     d |          d ||                      |d|          dS )Naddressr  r   r   cfxmemo)r  r<  r  rK  tag)r  splitr  r  )r  depositAddressr<  coinAddresspartsrK  rN  partsLengths           r  rD  zcoinex.parse_deposit_address  s     &&~yAA!!#&&%jj??uQx500AhG(CC!G"//h??##NFC@@
 
 	
r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|||d<   |||d<   |                     d||          \  }}d}|d         r5d	|d
<   |                     |                     ||                     d{V }nWd}|                     d|          \  }}|d|d
<   nd|d
<   |                     |                     ||                     d{V }| 	                    |dg           }	| 
                    |	|||          S )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  r9   r;  
start_timeend_timerG   r   r  r~   r   r   r  )r(   r9   r  r  handle_until_optionv2PrivateGetFuturesUserDealsr  r  v2PrivateGetSpotUserDealsr  rO  )
r  r  rK  r;  r  r  r   r  r*  r  s
             r  fetch_my_tradeszcoinex.fetch_my_trades  s      >#DG.[$[\\\!!!!!!!!!V$$fTl
 $GG$)GL!22:wOO&> 	Z%.GM"!>>t{{7TZ?[?[\\\\\\\\HH, J!%!C!COU[!\!\J%)1&&)/&!;;DKKQW<X<XYYYYYYYYH, ~~h33  vue<<<r  c                 X  K   |                                   d{V  d}|                     |ddd          \  }}|                     |          }ddi}d}|nd}t          |t                    r5t          |          }|dk    rt          | j        dz             |d	         }n|}|                     |          }|d
         |d<   d}|dk    r0| 	                    | 
                    ||                     d{V }n/|                     | 
                    ||                     d{V }|                     |dg           }	g }
t          d	t          |	                    D ]1}|
                    |                     |	|         |                     2|                     |
d|d          S )a  
        fetch all open positions

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

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

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

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

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

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

        :param str marginMode: 'cross' or 'isolated'
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int params['leverage']: the rate of leverage
        :returns dict: response from the exchange
        Nz+ setMarginMode() requires a symbol argumentisolatedcrossz@ setMarginMode() marginMode argument should be isolated or crossr  rG   z- setMarginMode() supports swap contracts onlyr4  r   r   d   z. setMarginMode() requires a leverage parameterr   z2 setMarginMode() leverage should be between 1 and  for r9   r   r  r  rm  r4  )r(   r9   r  r)   r  r  r*   r,  str*v2PrivatePostFuturesAdjustPositionLeverager  )r  r*  r  r  r  r4  maxLeverager   s           r  set_margin_modezcoinex.set_margin_modeK  s      >#DG.[$[\\\%%''
##
g(=(=TW'iijjj!!!!!!!!!V$$&>V##DG&UUVVV$$VZ88''x(8(DeSQQ#DG.^$^___qLLh44TW'[[^abm^n^nnqxx  |B  B  C  C  CTl$% 	
 
 DDT[[QXZ`EaEabbbbbbbbbr  r4  c                   K   |t          | j        dz             |                                  d{V  |                     |          }|d         st	          | j        dz             d}|                     d|d          \  }}|                     |d         d         d	d
          }|                     |d         d         dd          }||k     s||k    r@t          | j        dz   t          |          z   dz   t          |          z   dz   |z             |d         d||d}| 	                    | 
                    ||                     d{V S )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 argumentrG   z+ setLeverage() supports swap contracts onlyr   r  r   r4  r   r   r   r  z* setLeverage() leverage should be between z and r  r9   r   r  )r(   r9   r  r  r*   r  r,  r)   r  r  r  )	r  r4  r  r  r  r*  minLeverager  r   s	            r  set_leveragezcoinex.set_leveragex  s      >#DG.Y$YZZZ!!!!!!!!!V$$f~ 	UDG&SSTTT
!??vW^__
F''x(8(DeQOO''x(8(DeSQQ{"";(>(>TW'SSVYZeVfVffippsv  xC  tD  tD  D  GN  N  QW  W  X  X  XTl$% 	
 
 DDT[[QXZ`EaEabbbbbbbbbr  c                 V  K   |                                   d{V  i }|-|                     |          }d                    |          |d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||d          S )a  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes

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

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/?id=leverage-tiers-structure>`, indexed by market symbols
        N,r  r  )r  
market_idsjoinv2PublicGetFuturesPositionLevelr  r  parse_leverage_tiers)r  r"  r  r   	marketIdsr  r  s          r  fetch_leverage_tierszcoinex.fetch_leverage_tiers  s       !!!!!!!!!00I # 3 3GH==dkk'SY>Z>Z[[[[[[[[4 ~~h33((wAAAr  c                 $   g }|                      |dg           }d}t          dt          |                    D ]}||         }|                     |d          }|                     ||d d          }|                     |d          }	|                    |                     |d          |                     ||d d          |d         r|d         n|d	         ||	|                     |d
          | 	                    |d          |d           |	}|S )Nlevelr   r  rG   r   r   r   r  r  ry  r4  )tierr  r<  minNotionalmaxNotionalmaintenanceMarginRater  r  )
r  r  r  r  rD  r  r  sumr  r,  )
r  r  r  tiersbracketsr  r  r  r  r  s
             r  parse_market_leverage_tiersz"coinex.parse_market_leverage_tiers  s)   >>$44q#h--(( 	& 	&AA;D''h77H%%hfEEF**4::KLLA**8VT6JJ.4X.>SF6NNF7O**)-)9)9$@Y)Z)Z#00zBB	 	 	 	 	 &KKr  c                 ,  K   |                                   d {V  |                     |          }|                     ||          }|}|dk    rt          j        |          }|d         d|d}|                     |                     ||                     d {V }	|                     |	d          }
|                     |	d          }|dk    rdnd}|                     | 	                    |
|          || 
                    |          |d          S )	Nreducer9   r   )r  r  r   r  r
  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_helperzcoinex.modify_margin_helper  sI     !!!!!!!!!V$$,,VV<<	!(""#.y99MTl$#
 

 FFt{{SZ\bGcGcddddddddN ~~h//'')<<'833xx%{{499$GG''//J
 J
   	r  r  c                 r   |                      |d          }|                     |dd          }|                      |d          }||                     ||d d          d d|                     t	          j        |                    |                     |d          |d         d ||                     |          d	
S )
Nr  r2  r9  margin_changerG   r  rz  r  )
r  r  r  r*  r   totalr  r  r  r  )r  safe_integer_2r  r  r4   
string_absr  rF  )r  r  r  r  r  r  s         r  r  z coinex.parse_margin_modification   s    l ##D(33''lLII	!!$88&&xvFF$''(:6(B(BCC%%dM::7O"Y//
 
 	
r  c                 B   K   |                      ||d|           d{V S )a  
        add margin

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

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

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

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

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

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding history structure <https://docs.ccxt.com/?id=funding-history-structure>`
        Nz1 fetchFundingHistory() requires a symbol argumentr9   r   )r  r  rV  rU  r;  r  r   r9  r  r  funding_value)r  r  r  r  r  r9   r   )r(   r9   r  r  rW  )v2PrivateGetFuturesPositionFundingHistoryr  r  r  r  r,  r  r  r  rF  r  )r  r  rK  r;  r  r  r   r  r  r  r  r  r  r  r  s                  r  fetch_funding_historyzcoinex.fetch_funding_history  s      >#DG.a$abbb!!!!!!!!!V$$Tl$
 
 22:wOO$)GL!$GGGGT[]cHdHdeeeeeeee, ~~h33q#d))$$ 	 	AGE))%>>I))%77J**:66DMM & LL33&&um<<**5/BB      r  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     ||          S )aq  
        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>`
        NrG   z0 fetchFundingRate() supports swap contracts onlyr  r9   r  r   )	r  r  r*   r9   v2PublicGetFuturesFundingRater  r  r  parse_funding_rate)r  r  r  r  r   r  r  firsts           r  fetch_funding_ratezcoinex.fetch_funding_rate  s       !!!!!!!!!V$$f~ 	ZDG&XXYYYfTl
 ;;DKKQW<X<XYYYYYYYY& ~~h33tQ++&&uf555r  c                 >   K   |                      ||           d{V S )az  
        fetch the current funding rate interval

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

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

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

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

        :param str[] symbols: unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-structure>`
        Nr   rG   z1 fetchFundingRates() supports swap contracts onlyr  r  r  )r  r$  r%  r  r*   r9   r  r  r  r  r  parse_funding_rates)	r  r"  r  r   r  r  r  r  r  s	            r  fetch_funding_rateszcoinex.fetch_funding_rates)  s      !!!!!!!!!%%g..__Wa00F[[((F&> _*] ]^^^00I # 3 3GH;;DKKQW<X<XYYYYYYYY& ~~h33''g666r  rK  rN  c                 .  K   |                      ||          \  }}|                     |           |                                  d{V  |                     |          }|d         ||                     ||          d}|||d<   d}|                     |          \  }}||                     |          |d<   |                     |                     ||                     d{V }	| 	                    |	di           }
| 
                    |
|          S )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>`
        Nr9   )r  
to_addressr   rM  r  r  )handle_withdraw_tag_and_paramscheck_addressr  r<  currency_to_precisionrG  rB  v2PrivatePostAssetsWithdrawr  r  parse_transaction)r  r  r   rK  rN  r  r<  r   r  r  transactions              r  r   zcoinex.withdrawT  s>      99#vFFV7###!!!!!!!!!==&&D>!00v>>
 

 ?!GFO"AA&IIV"#66{CCGG99$++gv:V:VWWWWWWWW6 nnXvr::%%k8<<<r  c                 J    ddddddddddd
}|                      |||          S )Nr/  failedr  r  )
auditpassaudit_required
processing
confirmingnot_passr  finishr.  failr  r  s      r  parse_transaction_statuszcoinex.parse_transaction_status  sF    '##  
 
 &&999r  c           
        K   |t          | j        dz             |                                  d{V  d}|                     |dd          \  }}|r!|                     d|||d|d           d{V S |                     |          }d|d	         i}|||d
<   |||d<   |                     d||          \  }}|                     |                     ||                     d{V }| 	                    |dg           }	g }
t          dt          |	                    D ]}|	|         }|                     |d          }|                     ||dd          }|                     |d          }|
                    |||                     |d          ||                     |          d           |                     |
d          }|                     ||d         ||          S )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  r9   rU  r;  rV  r  r   rG   funding_timeactual_funding_rate)r  r  r  r  r  r  r  )r(   r9   r  r  "fetch_paginated_call_deterministicr  rW  $v2PublicGetFuturesFundingRateHistoryr  r  r  r  r  r  r,  r  r  rF  sort_byfilter_by_symbol_since_limit)r  r  rK  r;  r  r  r  r   r  r  ratesr  r  r  symbolInnerr  sorteds                    r  fetch_funding_rate_historyz!coinex.fetch_funding_rate_history  sj      >#DG.e$efff!!!!!!!!!88AZ\fgg& 	F@@AZ\bdikprvx~  AE  F  F  F  F  F  F  F  F  FV$$fTl
 $)GL!$GG22:wOOBB4;;wX^C_C_````````$ ~~h33q#d))$$ 	 	AGE''x88H**8VT6JJK))%@@ILL%#//7LMM& LL33      e[11009I5RWXXXr  r  c                    |                      |d          }|                      |d          }|t          |          dk     rd }|                      |d          }|t          |          dk     rd }|                      |d          }|t          |          dk     rd }|                      |d          }|                     ||          }|                     |d          }	d|v rd	nd
}
|                      |d          }|                      |d          }|                     |dd          }|dk    }|                     |d          }||                     |d          }|
d
k    rd}|                      |d          }|                     |          |                     |          d}i d|d|                     |dd          d|d|	d|                     |	          d| 	                    |          d|d|dd d|d d d!d d"|
d|d#|d$| 
                    |                      |d$                    d%d |||d&S )'Nr  rM  r   remarktx_idr  r9  withdraw_id
withdrawalr  r  tx_feewithdraw_methoddeposit_methodlocalactual_amountr   r/  	fee_assetr;  r  r9   
deposit_idtxidr  r  r  rK  	addressToaddressFromrN  tagTotagFromr  r<  r  updated)r  commentinternal)r  r  r  r,  safe_string_lower_2r  r  r  rF  r  r  )r  r  r<  rK  rN  r  r  r  r  r  r  r  feeCosttransferMethodr  r   rH  r  s                     r  r  zcoinex.parse_transaction  s   Z "";=={F33?3xx!||!!+x886{{QW554yy1}}%%k599
&&z8<<%%k<@@	 - < <||9$$['::	"";9911+?PRbcc!W,!!+??>%%k8<<F9G((kBB%%g..//>>
 

K
$$$[-NN
 D
 	

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

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

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

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

        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of transfer structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' for fetching transfers to and from your margin account
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/?id=transfer-structure>`
        Nz* fetchTransfers() requires a code argumentr  r9   r   r   transfer_typer   rU  r;  rV  r  )
r  r(   r9   r<  r  rW  !v2PrivateGetAssetsTransferHistoryr  r  parse_transfers)
r  r  rK  r;  r  r<  r   r*  r  r  s
             r  fetch_transferszcoinex.fetch_transfers  sH      !!!!!!!!!<#DG.Z$Z[[[==&&8D>
 
!??@PRXYY
F!'/GO$$'0GO$$)GL!$GG22:wOO??GU[@\@\]]]]]]]]* ~~h33##D(E5AAAr  c                 P  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )a1  
        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>`
        Nr9   r  r;  r  )r  r<  v2PrivateGetAssetsWithdrawr  r  parse_transactions	r  r  rK  r;  r  r   r<  r  r  s	            r  fetch_withdrawalszcoinex.fetch_withdrawals  s       !!!!!!!!!}}T**H%d^GEN$GG88Wf9U9UVVVVVVVVB ~~h33&&tXueDDDr  c                 P  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )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>`
        Nr9   r  r;  r  )r  r<   v2PrivateGetAssetsDepositHistoryr  r  r6  r7  s	            r  fetch_depositszcoinex.fetch_deposits  s       !!!!!!!!!}}T**H%d^GEN$GG>>t{{7TZ?[?[\\\\\\\\< ~~h33&&tXueDDDr  r  c           
      4   |                      |d          }|                     ||d d          }|                      |d          }|                     |d          }d }d }||d         k    r|}n||d         k    r|}|d         |d         ||d	         |d
d d |d	S )Nr  rE   r  daily_interest_rater  r  r  r  r  i \&)	r  r  baseRater  	quoteRater^  r  r  r  )r  rD  r  )r  r  r  r  r<  rater>  r?  s           r  parse_isolated_borrow_ratez!coinex.parse_isolated_borrow_rate1  s     ##D(33!!(FD&AA##D%00&;<<	vh'''HH	***IX&6N G_"

 

 
	
r  c                   K   |                                   d{V  |                     |d          }|t          | j        dz             |                     |d          }|                     |          }|                     |          }|d         |d         d}|                     |                     ||                     d{V }| 	                    |di           }| 
                    ||          S )a  
        fetch the rate of interest to borrow a currency for margin trading

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

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

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

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

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

        :param str symbol: unified market symbol, required for coinex
        :param str code: unified currency code of the currency to borrow
        :param float amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.isAutoRenew]: whether to renew the margin loan automatically or not, default is False
        :returns dict: a `margin loan structure <https://docs.ccxt.com/?id=margin-loan-structure>`
        NisAutoRenewis_auto_renewFr9   )r  r  rO  rT  r  r   r  )
r  r  r<  r  r  r  v2PrivatePostAssetsMarginBorrowr  r  parse_margin_loan)r  r  r  r   r  r  r<  rS  r   r  r  r  s               r  borrow_isolated_marginzcoinex.borrow_isolated_margin  s4      !!!!!!!!!V$$==&&&&v}ouUU6=11TlD>!77fEE(	
 
 ==dkk'SY>Z>Z[[[[[[[[" ~~h33,,T8<<{{;)
 )
   	r  c                   K   |                                   d{V  |                     |          }|                     |          }|d         |d         |                     ||          d}|                     |                     ||                     d{V }|                     |di           }	|                     |	|          }
|                     |
||d          S )aC  
        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>`
        Nr9   )r  r  r   r  rU  )r  r  r<  r  v2PrivatePostAssetsMarginRepayr  r  rW  )r  r  r  r   r  r  r<  r   r  r  r  s              r  repay_isolated_marginzcoinex.repay_isolated_margin  s      !!!!!!!!!V$$==&&TlD>00v>>
 

 <<T[[RX=Y=YZZZZZZZZ ~~h33,,T8<<{{;)
 )
   	r  c           	      d   |                      |d          }|                      |d          }|                     |d          }|                     |d          |                     ||          |                      |d          |                     |d d d          ||                     |          |dS )Nr  r  rM  	borrow_idrO  rE   )r9   r<  r   r  r  r  r  )r  r,  r  r  rF  )r  r  r<  r  r  r  s         r  rW  zcoinex.parse_margin_loan  s     %%dE22
##D(33%%dL99	##D+66//
HEE&&t_==&&xtVDD"Y//
 
 	
r  c                 0  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )ay  
        fetch the fee for deposits and withdrawals

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

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/?id=fee-structure>`
        Nr  r9   r  )r  r<  &v2PublicGetAssetsDepositWithdrawConfigr  r  parse_deposit_withdraw_fee)r  r  r  r<  r   r  r  s          r  fetch_deposit_withdraw_feez!coinex.fetch_deposit_withdraw_fee8  s       !!!!!!!!!==&&8D>
 DDT[[QXZ`EaEabbbbbbbbD ~~h33..tX>>>r  codesc                   K   |                                   d{V  |                     |           d{V }|                     |dg           }i }t          dt	          |                    D ]}||         }|                     |di           }|                     |d          }	|	:|                     |	          }
||                     |
|          r| 	                    |          ||
<   |S )am  
        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>`
        Nr  r   r  r  )
r  r  r  r  r  r  r  r  in_arrayr`  )r  rb  r  r  r  r  r  r  r  r  r  s              r  fetch_deposit_withdraw_feesz"coinex.fetch_deposit_withdraw_feesl  s      !!!!!!!!!GGOOOOOOOOH ~~h33q#d))$$ 	E 	EA7DNN4"55E))%77J!**:66D}dE : :}#>>tDDtr  c                 $   |d d dd d di d}|                      |dg           }|                     |di           }t          dt          |                    D ]}||         }|                     |d          }|r|                     |d          |d         d	<   d
|d         d<   |                     |d          }	|	rR|                     |	|                     |d                    }
|                     |d          d
dd d dd|d         |
<   |S )N)r  r  )r  r   r  r$  r  r  r   r  r  r   r  Fr  r  r  )r   r  r$  )r  r  r  r  r  r  r  r  )r  r  r<  r  r  r  r  r  isWithdrawEnabledr  r  s              r  r`  z!coinex.parse_deposit_withdraw_fee  sq   > " 
 "  
 
 Xr22sGR00q#f++&& 	 	A1IE $u6H I I  ,0,<,<UDT,U,Uz"5)38z"<0 ,,UG<<	 "&"9"9)TEUEUV[]bEcEc"d"dK $(#3#3E;K#L#L*/% %
 $(*.$ $	7 	7F:&{3 r  c                   K   |                                   d{V  |                     |d          }|t          | j        dz             |                     |d          }|                     |          }|                     |          }|d         |d         d}|                     |                     ||                     d{V }| 	                    |di           }| 
                    ||          S )a  
        fetch the set leverage for a market

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

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['code']: unified currency code
        :returns dict: a `leverage structure <https://docs.ccxt.com/?id=leverage-structure>`
        Nr  z* fetchLeverage() requires a code parameterr9   rC  r  )r  r  r(   r9   r  r<  r  rD  r  r  parse_leveragerE  s	            r  fetch_leveragezcoinex.fetch_leverage  s      !!!!!!!!!//<#DG.Z$Z[[[66**==&&V$$TlD>
 
 CCDKKPWY_D`D`aaaaaaaa ~~h33""4000r  c                     |                      |d          }|                     |d          }||                     ||d d          d||dS )Nr  r4  rE   r  )r  r  r*  longLeverageshortLeverage)r  r,  r  )r  r4  r  r  leverageValues        r  ri  zcoinex.parse_leverage  s`     ##Hh77))(J??&&xvFF$)*
 
 	
r  c                   K   |                                   d{V  |                     |          }d|d         d}|||d<   |||d<   |                     d||          \  }}|                     |                     ||                     d{V }|                     |dg           }|                     |          }	|                     |	|||          S )	aa  
        fetches historical positions

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

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

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

        :param str symbol: unified CCXT market symbol
        :param str [side]: buy or sell, not used by coinex
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['type']: required by coinex, one of: limit, market, maker_only, ioc or fok, default is *market*
        :param str [params.price]: the price to fulfill the order, ignored in market orders
        :param str [params.amount]: the amount to trade in units of the base currency
        :param str [params.clientOrderId]: the client id of the order
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr  r  r9   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  s
             r  close_positionzcoinex.close_positionn  s
      !!!!!!!!!V$$99Tl$
 

 **6;PP$#0GK 6?33??GU[@\@\]]]]]]]]: ~~h33f---r  c                     |                      | j        d          }|                     |dd          }d}t          t          |                               |||          \  }}||dk    s|du rd}||gS )aP  
 @ignore
        marginMode specified by params["marginMode"], self.options["marginMode"], self.options["defaultMarginMode"], params["margin"] = True or self.options["defaultType"] = 'margin'
        :param dict params: extra parameters specific to the exchange api endpoint
        :returns Array: the marginMode in lowercase
        r   rF   FNTr  )r  r   r  r  r6   r  )r  
methodNamer  defaultValuer   r  r*  r  s          r  r  z$coinex.handle_margin_mode_and_params  s     &&t|]CC>>&(E::
"6400NNz[acopp
Fx''X-=-='
F##r  c                 *    |                                  S N)milliseconds)r  s    r  noncezcoinex.nonce  s      """r  GETc                 ~   |                      ||          }|d         }|d         }| j        d         |         dz   |z   dz   |z   }	|                     ||                     |                    }
t	          |                                           }|dk    r|                    d          }|                     |dd          }t          |          }|                     ||dz
  d          }|                    d          }t          |          }|                     ||dz
  d          }|dk    r_|d	k    s|d
k    rS|                     |d          }|;d}| 	                    | j
        d|          }|dz   |                                 z   |
d<   |dk    r|                                  |                     | j        |d|
          }
|                     |
          }
|                     |
          }|                     |                     |dz   | j        z             d          }|                                | j        d}|dk    s|dk    r
|	d|z   z  }	nd|d<   |}n|dk    s|dk    r|
r|	d|                     |
          z   z  }	n|dk    r|                                  |                     | j        |d|
          }
|                     |
          }
|                     |
          }|                     |                     |dz   | j        z             d          }|                                dd}|dk    s|dk    s|dk    r	|	d|z   z  }	n|                     |
          }n|d k    r|                                  |                     |
          }
|                     |
          }|dz   |z   dz   |z   }|dk    r|                     |
          }||z  }n
|r|d|z   z  }||| j        z   z  }|                     |                     |          d          }dd| j        ||d!}|dk    r
|r|	d|z   z  }	|	|||d"S )#Nr   r   r   r  POSTr  _rB  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)urlr\  bodyheaders)implode_paramsr   r  extract_paramsr  r|  rO  r  r  r%  r   r  check_required_credentialsr  apiKeykeysort	rawencodehashencodesecretr  	urlencodeupperjson)r  pathr   r\  r  r  r  r<   
requestUrlr  r(  r|  rR  	firstPartnumPartslastPart	lastWordsnumWordslastWordr  r  r  
urlencoded	signaturepreparedStrings                            r  signzcoinex.sign  s   ""400a&V
iz*S07:S@4G		&$"5"5d";";<<DJJLL!!VJJsOOE((266I5zzH''x!|R@@H s++I9~~H''	8a<DDHW$$8w+>+>(hBVBV !% 0 0 E E ( -I#t|ZSSH)1C$++--)GE+&+++++---KK!["! !  E LL''E..J		$++j>.IDK.W"X"XZbccI!*!2!2 K G %Vu__sZ''*M'!8##z5F'F'F 3sT^^E2222$//111!%"% %   U++!^^E22
 IIdkk*~2MPTP[2[&\&\^cdd	%.__%6%6$6  eOO8););53++CC99U++DDD//111U++!^^E22
!'#!7#!=!DV##99U++D"d*NN 7"cJ&66N%$+"55 IIdkk.&A&A8LL	$60$(K%.*/  V##! 0sZ//fdwOOOr  httpCodereasonr  r\  r  r  c
                    |d S |                      |d          }
|                     |d          }|                      |d          }|
dk    s&|dk    r|dk    rz|                                dk    rb|s`| j        dz   |z   }|                     | j        d	         ||           |                     | j        d
         |
|           t          |          d S )Nr  r  r
  r/  r  r  r  r  r  r  )r  r%  r  r9   r  r  r  r$   )r  r  r  r  r\  r  r  r  requestHeadersrequestBodyr  r  r
  r  s                 r  handle_errorszcoinex.handle_errors  s    4&11x00""8Y77CKKg22K9O9OV]VcVcVeVeimVmVmw{Vmw}w.H001I7T\]]]001I4QYZZZ)))tr  c                 v  K   |                                   d{V  |t          | j        dz             |                     |dd          }|                     |d          }|t          | j        dz             |                     |          }|d         d|d}|                     d	||          \  }}|||d
<   |||d<   |                     |                     ||                     d{V }	| 	                    |	dg           }
| 
                    |
ddd          }|                     ||||          S )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 parameterr9   r   )r  r  r  rV  rU  r;  r  r  rG   )r  r(   r9   r  r  r  rW  (v2PrivateGetFuturesPositionMarginHistoryr  r  parse_margin_modificationsr  )r  r  r  rK  r;  r  r  r  r   r  r  modificationss               r  fetch_margin_adjustment_historyz&coinex.fetch_margin_adjustment_history&  ss      !!!!!!!!!>#DG.j$jkkk((}MM
6<00#DG.o$opppV$$Tl$%
 

 22:wOO$)GL!$GGFFt{{SZ\bGcGcdddddddd4 ~~h3377dHfUU00uUUUr  rz  )__name__
__module____qualname__r   r  r   r  r#   r   r  r  r  dictr   r  r  r!  r   r   r)  r   r-  r6  r   rJ  rP  r   rS  r    rU  rR  r_  r[  rb  rv  r{  r~  r  r   r  r   r  r   r  floatr  r   r   r   r  r  r   r  r  r  r  r#  r'  r+  r;  r>  r@  r
   rE  rI  r	   rD  rZ  r   rf  ri  ra  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%  r3  r8  r;  r   rA  rF  r   rK  rQ  rX  r[  rW  ra  re  r`  r   rj  ri  rs  ru  r  r|  r  r  r  __classcell__)r  s   @r  r6   r6      s)       Z
# Z
 Z
 Z
 Z
 Z
 Z
x -/ } }: } } } }~ *, ; ;V ; ; ; ;&U$v, U U U Un\ \ \|> >4 > >6 > > > >@ 68 F1 F1 F1F F1 F1 F1 F1P 6:" G1 G17 G1 G1 G1 G1 G1R ') 4 4S 4 4 4 4, @B" O? O?S O? O? O? O? O?bE E Ev E E E E EN <@d[] +I +I +IS +I +Ibfglbm +I +I +I +IZ ;= @6 @6c @6AT @6 @6 @6 @6D /1 C C[ C C C CJ

 

T 

6 

EX 

 

 

 


 
 
4 
 
 
 
, ?CQUdhqs 0H 0H 0H 0H3 0H^a 0Hx|  ~B  yC 0H 0H 0H 0Hd 13 3) 3) 3) 3)j /1 ) ) ) )8 /1 ) ) ) )> 46 ) ) ) )8 *, 9 9 9 9 9 96	: 	: 	: 	: 	:D D Dv D D D D DL XZ T Tc T T T T T& os{} P, P,3 P,i P,y P,Z_ P,hk P, P, P, P,d mqy{ l. l. l.I l.Y l.X] l.fi l. l. l. l.\ FH y y$|*< yDQVK y y y yv AER n ntCy n# n n n n` fjx|  FH E. E.3 E. E.9 E.I E._b E.ru E. E. E. E.N DF A A\(: A$u+ A A A AF 9=R Y. Y.S Y.# Y. Y. Y. Y.v 59 )
 )
c )
 )
 )
 )
V 8<B U. U.C U. U. U. U. U.n BFTXgktv n= n=3 n=c n=ad n= n= n= n=`	 59tZ^gi  c  TW nrsxny    , 7;\`ik [ [ [3 [VY [ptuzp{ [ [ [ [& >@ !: !: !:N !: !: !: !:F =? !: !: !:> !: !: !: !:F
 
h 
R` 
 
 
 
2 37TX\eg Q= Q=C Q=s Q=RU Q= Q= Q= Q=f 8<B SP SPW SP4PX> SP SP SP SPj 8: =4 =43 =4 =4 =4 =4~C Ct CV C C C CJ DHPR !c !c !cS !c !c !c !cZ ?C2 c c3 c c c c cT =A *B *B' *BP] *B *B *B *BX  $|J\    , SU : : : : : :xD
 D
d D
F D
N` D
 D
 D
 D
L CE N Ns NE NI[ N N N N FH Q Q# Qu QL^ Q Q Q Q 9=4^bkm ? ?# ?S ?X[ ? ? ? ?B <> &6 &6s &6+ &6 &6 &6 &6P @B 
= 
=3 
=k 
= 
= 
= 
=(
 (
6 (
[ (
 (
 (
 (
T? ? ? <@ )7 )7 )7| )7 )7 )7 )7V QU]_ 9= 9=3 9= 9= 9=# 9=do 9= 9= 9= 9=v:s : : : : >BPTcgpr ?Y ?Ys ?Y# ?Y]` ?Y ?Y ?Y ?YBa
 a
T a
X a
Q\ a
 a
 a
 a
F ac . .3 . .C .TW .gt . . . .`: : :
 
t 
x 
= 
 
 
 
" 154VZce 5B 5B# 5BS 5BPS 5Bjno|j} 5B 5B 5B 5Bn 37TX\eg 6E 6EC 6Es 6ERU 6Elpq|l} 6E 6E 6E 6Ep 04$UYbd 3E 3E 3EC 3Es 3Eimnyiz 3E 3E 3E 3Ej
 
t 
V 
Oa 
 
 
 
B DF &= &=s &=J\ &= &= &= &=P 7;$]apt} 0Q 0Q 0QC 0QWZ 0Qjm 0Q  EI  JX  EY 0Q 0Q 0Q 0Qd
 
$ 
 
. 
 
 
 
< Z\ . .3 .c .5 . . . .` RT " "# "S " " " "H
 
 
 
 
 
4 BD 2? 2?S 2? 2? 2? 2?h BFb : :w : : : :x? ? ? ? ? ?B 8: &1 &13 &1h &1 &1 &1 &1P
 
t 
V 
x 
 
 
 
* FJX\eg FR FR3 FRs FRRU FRlpqylz FR FR FR FRP CGr 9. 9.3 9.i 9.V[ 9. 9. 9. 9.v @BPT $ $ $ $ $ $ # # #  b$T [P [P [P [Pzc 3 S # X\ dg     CGTXgkz~  HJ =V =VC =Vc =Vad =Vtw =V  OS  Tf  Og =V =V =V =V =V =V =V =Vr  r6   ); ccxt.async_support.base.exchanger   ccxt.abstract.coinexr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   typingr#   ccxt.base.errorsr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   ccxt.base.decimal_to_precisionr3   ccxt.base.preciser4   r6    r  r  <module>r     sL   6 5 5 5 5 5 , , , , , ,  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) , , , , , , . . . . . . 1 1 1 1 1 1 + + + + + + 4 4 4 4 4 4 % % % % % %E]V E]V E]V E]V E]VX{ E]V E]V E]V E]V E]Vr  