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

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        datar   assetchainsccyNdeposit_enabledwithdraw_enabledwithdrawal_precisionchainwithdrawal_feemin_deposit_amountmin_withdraw_amountr   )r   depositr   )
r8   networkr9   activer  r   fee	precisionr   infocrypto)r8   coder9   r  r  r   r  r  r   r"  typer  ))v2PublicGetAssetsAllDepositWithdrawConfig	safe_listrangelen	safe_dictsafe_stringsafe_currency_code	safe_boolparse_precisionparse_numbersafe_currency_structure)r  paramsresponser  resulticoinr  r  
currencyIdr  
canDepositcanWithdraw
firstChainfirstPrecisionStringr"  jr  	networkIdprecisionString	feeStringminNetworkDepositStringminNetworkWithdrawStringcanDepositChaincanWithdrawChainr  s                             r  fetch_currencieszcoinex.fetch_currencies  s    AA&IH ~~h3q#d)$ L	A7DNN4"5E^^D(B7F))%7J!**:6D/@AJ..0BCK26J#'#7#78H8HUk8l#m H1c&k* $.q	 ,,UG<	$"&"6"6t7G7GOe7f"g ,,U4DE	*.*:*:5BV*W'+/+;+;ECX+Y("&..8I"J#'>>%9K#L #( -B2B. 0,,Y7!%!2!2?!C $(#'#
 $(#4#45L#M#'$
 $(#4#45M#N#'% "/!2 '.#I$.J  77 $4%'!../CD  $#
  $# 
  $#!  39 F4LeL	Z r  c                     | j                  |      | j                  |      g}|}|d   }|d   }| j                  ||      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
        r   r   )fetch_spot_marketsfetch_contract_marketsarray_concat)r  r  promisesUnresolvedpromisesspotMarketsswapMarketss         r  fetch_marketszcoinex.fetch_markets#  sT     ##F+''/
 &qkqk  k::r  c                 :   | j                  |      }| j                  |dg       }g }t        dt        |            D ][  }||   }| j	                  |d      }| j	                  |d      }| j	                  |d      }	| j                  |      }
| j                  |	      }|
dz   |z   }|j                  i d|d|d	|
d
|dd d|d|	dd dddddd dddddddd dddd d | j                  |d      | j                  |d      d d d d d | j                  | j                  | j	                  |d                  | j                  | j                  | j	                  |d                  dd d d| j                  |d       d dd d dd d dd!d |d"       ^ |S )#Nr  r   marketbase_ccy	quote_ccy/r8   symbolbasequotesettlebaseIdquoteIdsettleIdr  rD   TrE   rF   FrG   rH   r  contractr   taker_fee_ratemaker_fee_ratebase_ccy_precisionquote_ccy_precisionr   pricer   
min_amountr2  r   r  costrC  r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper  r   createdr  )
v2PublicGetSpotMarketr  r  r  r  r  appendsafe_numberr  r  )r  r  r  marketsr  r  r  r8   r  r  r  r  r  s                r  r  zcoinex.fetch_spot_markets6  sr   --f5* ..626q#g,' :	AQZF!!&(3B%%fj9F&&v{;G**62D++G4ECZ%'FMM 2b2&2 2 	2
 $2 &2 72 D2 2 2 $2 2 %2 %2 $2  E!2" $#2$  ))&2BC))&2BC $"&""//0D0DTEUEUV\^rEs0tu!..t/C/CDDTDTU[]rDs/tu  $#!
  $//E#
  $#
  $#$  c2 2:	v r  c                 B   | j                  |      }| j                  |dg       }g }t        dt        |            D ]  }||   }| j                  }| j                  |dg       }| j                  |d      }	|	dk(  }
|	dk(  }| j                  |d      }| j                  |d      }| j                  |d	      }| j                  |      }| j                  |      }|	dk(  rd
n|}| j                  |      }|dz   |z   dz   |z   }t        |      }|j                  i d|d|d|d|d|d|d|d|dddddddddddddd ddd|
||d   d    |d   d!   | j                  d"      d d d d | j                  | j                  | j                  |d#                  | j                  | j                  | j                  |d$                  d%| j                  |d      | j                  ||d&z
        d'| j                  |d(      d d'd d d'd d d'd)d |d*        |S )+Nr  r   r2  contract_typer   rC  r  r  r  USDTr  :r8   r  r  r  r  r  r  r  r  rF   rD   FrE   TrG   rH   r  r  r   r   r   1r  r  r  r   r   r  r  r  )v2PublicGetFuturesMarketr  r  r  r   r  r  r  r  r  r  )r  r  r  r  r  r  entryr   	leveragessubTyper   rC  r8   r  r  r  r  r  r  r  leveragesLengths                        r  r  zcoinex.fetch_contract_markets  s   008, ..626q#g,' B	AAJE99Duj"=I&&uo>G)F)+G!!%2B%%eZ8F&&uk:G**62D++G4E")X"5vFH,,X6FCZ%'#-6F!)nOMM 2b2&2 2 	2
 &2 &2 72 H2 2 2 %2 2 %2 %2 $2  D!2" &#2$ #i1i1 $ 1 1# 6"&""//0D0DTEUEUV[]qEr0st!..t/C/CDDTDTUZ\qDr/st  $//	1=#//	?Q;NO!
  $//|D#
  $#
  $#$  c2 2!B	F r  Ntickerr  c           
      8   d|v rdnd}| j                  |d      }| j                  ||d |      }| j                  i d|dd dd d| j                  |d      d	| j                  |d	      d
d d| j                  |d      dd d| j                  |d      dd d| j                  |d      d| j                  |d      d| j                  |d      dd dd dd dd | j                  |d      d | j                  |d      | j                  |d      |d|      S )N
mark_pricerF   rD   r  r  	timestampdatetimehighlowbid	bidVolume
volume_buyask	askVolumevolume_sellvwapopencloselastpreviousClosechange
percentageaveragevolumeindex_price)
baseVolumequoteVolume	markPrice
indexPricer  )r  safe_symbolsafe_ticker)r  r  r  
marketTypemarketIdr  s         r  parse_tickerzcoinex.parse_ticker  s   H !- 6VV
##FH5!!(FD*E !
f!
!
 !
 D$$VV4	!

 4##FE2!
 4!
 ))&,?!
 4!
 ))&-@!
 D!
 D$$VV4!
 T%%fg6!
 D$$VV4!
 T!
 d!
  $!!
" t#!
$ **68<))&,?**6=A-!
. / 	r  r  c                 V   | j                          | j                  |      }d|d   i}d}|d   r"| j                  | j                  ||            }n!| j	                  | j                  ||            }| j                  |dg       }| j                  |di       }| j                  ||      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>`
        r  r8   NrF   r  r   )load_marketsr  v2PublicGetFuturesTickerextendv2PublicGetSpotTickerr  r  r  r  r  r  r  requestr  r  r  s           r  fetch_tickerzcoinex.fetch_ticker)  s     	V$fTl
 &>44T[[&5QRH11$++gv2NOH` ~~h3a,  00r  symbolsc                 \   | j                          | j                  |      }d}|#| j                  |d      }| j                  |      }| j	                  d||      \  }}d}|dk(  r| j                  |      }n| j                  |      }| j                  |dg       }| j                  ||      S )al  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

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

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr   r   rF   r  )	r  market_symbols
safe_valuer  handle_market_type_and_paramsr  r  r  parse_tickers)	r  r  r  r  r  r  queryr  r  s	            r  fetch_tickerszcoinex.fetch_tickersq  s     	%%g.__Wa0F[[(F >>~vW]^
E44U;H11%8H` ~~h3!!$00r  c                 n    | j                  |      }| j                  |di       }| j                  |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
        r  r  )v2PublicGetTimer  safe_integer)r  r  r  r  s       r  
fetch_timezcoinex.fetch_time  s;     ''/ ~~h3  {33r  r   r9  c                    | j                          | j                  |      }|d}|d   |dd}d}|d   r"| j                  | j                  ||            }n!| j	                  | j                  ||            }| j                  |di       }| j                  |di       }| j                  |d	      }	| j                  |||	      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   r8   0)r  r9  intervalrF   r  depth
updated_at)r  r  v2PublicGetFuturesDepthr  v2PublicGetSpotDepthr  r#  parse_order_book)
r  r  r9  r  r  r  r  r  r(  r  s
             r  fetch_order_bookzcoinex.fetch_order_book  s     	V$=ETl

 &>33DKK4PQH6 00Wf1MNH4 ~~h3tWb1%%e\:	$$UFI>>r  tradec                 x   | j                  |d      }| j                  | j                  d      }||d   }| j                  |d      }| j                  ||d |      }| j                  |d      }d }|(| j                  |d      }| j	                  |      }	||	d}| j                  ||| j                  |      |d   | j                  |d	      | j                  |d
      d | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      |d|      S )N
created_atr  r  r  r  fee_ccyr  currencyr  deal_idorder_idsideroler  r   
deal_money)r  r  r  r  r8   orderr  r6  takerOrMakerr  r   r  r  )r#  r  r   safe_marketr  
safe_tradeiso8601)
r  r.  r  r  r  r  feeCostStringr  feeCurrencyIdfeeCurrencyCodes
             r  parse_tradezcoinex.parse_trade!  s]   P %%e\:	&&t||]C .K##E84!!(FD+F((6$ ,,UI>M"55mDO%+C "Y/X&""5)4%%eZ8$$UF3 ,,UF;%%eW5&&uh7$$UL9 
  	r  sincec                 "   | j                          | j                  |      }d|d   i}|||d<   d}|d   r"| j                  | j                  ||            }n!| j	                  | j                  ||            }| j                  |d   |||      S )az  
        get the list of the most recent trades for a particular symbol

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

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r  r8   Nr9  rF   r  )r  r  v2PublicGetFuturesDealsr  v2PublicGetSpotDealsparse_trades)r  r  rB  r9  r  r  r  r  s           r  fetch_tradeszcoinex.fetch_tradesh  s     	V$fTl
 $GG&>33DKK4PQH00Wf1MNH$   &!165%HHr  c                 V   | j                          | j                  |      }d|d   i}d}|d   r"| j                  | j                  ||            }n!| j	                  | j                  ||            }| j                  |dg       }| j                  |di       }| j                  ||      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>`
        r  r8   NrD   r  r   )r  r  r  r  r  r  r  parse_trading_feer  s           r  fetch_trading_feezcoinex.fetch_trading_fee  s     	V$fTl
 &>11$++gv2NOH, 44T[[&5QRH, ~~h3a,%%ff55r  c                    | j                          d}| j                  dd|      \  }}d}|dk(  r| j                  |      }n| j                  |      }| j	                  |dg       }i }t        dt        |            D ]G  }||   }| j                  |d      }| j                  |dd|      }	|	d   }
| j                  ||	      ||
<   I |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   rF   r  r   r  r  )
r  r  r  r  r  r  r  r  r;  rI  )r  r  r  r  r  r  r  r  r  r  r  s              r  fetch_trading_feeszcoinex.fetch_trading_fees  s     	99:LdTZ[f6>44V<H. 11&9H* ~~h3q#d)$ 	CAGE''x8H%%hdDAFH%F!33E6BF6N	C r  r  c                     | j                  |d      }| j                  ||      }||| j                  |d      | j                  |d      dddS )Nr  r  r  T)r  r  r   r   r  	tierBased)r  r  r  )r  r  r  r  r  s        r  rI  zcoinex.parse_trading_fee  s\    ??31!!(F3%%c+;<%%c+;<
 	
r  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr0  r  r  r  r   value)r#  r  )r  ohlcvr  s      r  parse_ohlcvzcoinex.parse_ohlcv(  sn     e\2UF+UF+UE*UG,UG,
 	
r  r   c                 |   | j                          | j                  |      }|d   | j                  | j                  ||      d}|||d<   d}|d   r"| j	                  | j                  ||            }n!| j                  | j                  ||            }| j                  |dg       }	| j                  |	||||      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
        r8   )r  periodNr9  rF   r  )	r  r  r  r   v2PublicGetFuturesKliner  v2PublicGetSpotKliner  parse_ohlcvs)
r  r  	timeframerB  r9  r  r  r  r  r  s
             r  fetch_ohlcvzcoinex.fetch_ohlcv>  s     	V$Tl&&t	9M
 $GG&>33DKK4PQH00Wf1MNH* ~~h3  vy%GGr  c                    | j                          | j                  |      }d|i}| j                  |dg       }t        dt	        |            D ]  }||   }| j                  |di       }| j                  |di       }| j                  |di       }	| j                  |di       }
| j                         }| j                  |d      }| j                  |      }| j                  |d      |d	<   | j                  |d      |d
<   | j                  |	d      }| j                  |
d      }t        j                  ||      |d<   |||<    | j                  |      S )Nr  r  r   	availablefrozenrepaidinterestr  freeuseddebt)r  v2PrivateGetAssetsMarginBalancer  r  r  r  accountr  r  r3   
string_addsafe_balance)r  r  r  r  balancesr  r  r_  r`  loanr^  baseAccountbaseCurrencyIdbaseCurrencyCodebaseDebtbaseInterests                   r  fetch_margin_balancezcoinex.fetch_margin_balancep  s]   77?@ )>>(FB7q#h-( 	3AQKE>>%b9D>>%26D>>%26D~~eZ<H,,.K!--eZ@N#66~F"&"2"24"DK"&"2"24"DK''j9H++HjAL")"4"4X|"LK'2F#$	3   ((r  c                    | j                          | j                  |      }d|i}| j                  |dg       }t        dt	        |            D ]i  }||   }| j                  |d      }| j                  |      }| j                         }	| j                  |d      |	d<   | j                  |d      |	d<   |	||<   k | j                  |      S 	Nr  r  r   r  r[  r_  r\  r`  )	r  v2PrivateGetAssetsSpotBalancer  r  r  r  r  rc  re  
r  r  r  r  rf  r  r  r  r  rc  s
             r  fetch_spot_balancezcoinex.fetch_spot_balance  s    55f= )>>(FB7q#h-( 	#AQKE))%7J**:6DllnG"..ukBGFO"..uh?GFO"F4L	#   ((r  c                    | j                          | j                  |      }d|i}| j                  |dg       }t        dt	        |            D ]i  }||   }| j                  |d      }| j                  |      }| j                         }	| j                  |d      |	d<   | j                  |d      |	d<   |	||<   k | j                  |      S ro  )	r   v2PrivateGetAssetsFuturesBalancer  r  r  r  r  rc  re  rq  s
             r  fetch_swap_balancezcoinex.fetch_swap_balance  s    88@" )>>(FB7q#h-( 	#AQKE))%7J**:6DllnG"..ukBGFO"..uh?GFO"F4L	#   ((r  c                    | j                          | j                  |      }d|i}| j                  |dg       }t        dt	        |            D ]i  }||   }| j                  |d      }| j                  |      }| j                         }	| j                  |d      |	d<   | j                  |d      |	d<   |	||<   k | j                  |      S ro  )	r  "v2PrivateGetAssetsFinancialBalancer  r  r  r  r  rc  re  rq  s
             r  fetch_financial_balancezcoinex.fetch_financial_balance  s    ::6B )>>(FB7q#h-( 	#AQKE))%7J**:6DllnG"..ukBGFO"..uh?GFO"F4L	#   ((r  c                    d}| j                  dd|      \  }}d}| j                  d|      \  }}|duxs |dk(  }|dk(  r| j                  |      S |dk(  r| j                  |      S |r| j	                  |      S | j                  |      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]   rE   rF   	financial)r  handle_margin_mode_and_paramsru  rx  rm  rr  )r  r  r  r(  isMargins        r  fetch_balancezcoinex.fetch_balance  s     
!??PTV\]
F
!??PVW
Fd*G
h0F**622;&//77,,V44**622r  statusc                 :    ddddddd}| j                  |||      S )Nrejectedr  closedcanceled)r  r  not_deal	part_dealdonecancelr  r  r~  statusess      r  parse_order_statuszcoinex.parse_order_status  s2    " 
 &&99r  r9  c                 z   | j                  |d      }| j                  |d      }| j                  |d      }|dk(  r|}| j                  |d      }| j                  | j                  d      }| j                  |d|      }|dk(  rd	}|d	k(  rd	nd
}	| j	                  ||d |	      }| j                  |d      }
| j                  |
      }||d   }| j                  |d      }|dk(  rd}n|dk(  rd}| j                  |d      }|dk(  rd }| j                  i d| j                  |g d      d|d| j                  |      d|d|d| j                  |      d|d   d| j                  |d      dd dd dd d|d| j                  |d      d | j                  |d!      d"| j                  |d#      d$| j                  |d%      d&| j                  |d'      | j                  |d(      | j                  |d)      | j                  |d*      | j                  |d+      d || j                  |d,d-      d.|d/|      S )0Nr~  r0  r)  r   r  r  market_typefuturesrF   rD   r1  r  r6  longbuyshortsell	client_id r8   )position_idr5  stop_idclientOrderIdr  r  lastTradeTimestampr  r  r/  postOnly
reduceOnlyr  r)  trigger_pricer-  take_profit_pricer,  stop_loss_pricer  filled_valueavg_entry_pricer   filled_amountunfilled_amount	quote_feer  )r3  r  )r  r   filled	remainingtradesr  r  )r  r#  r   safe_string_lowerr;  r  
safe_ordersafe_string_nr=  r  r  safe_string_2)r  r9  r  	rawStatusr  updatedTimestampr  r  	orderTyper  r?  feeCurrencyr6  r  s                 r  parse_orderzcoinex.parse_order"  s   ` $$UH5	%%e\:	,,ULAq (##E84&&t||]C**5-M		!I )V 3V&
!!(FD*E((	:--m< /Kv.6>DW_D((<B M  
$$$U,RS 
] 
 Y/ 
 	 

 !"2 
 d--i8 
 fX& 
 D$$UF3 
 4 
  
 $ 
 D 
 T%%eW5 
 D,,UOD 
 t//7JK 
  T--e5FG! 
" D$$UN;# 
$ ''/@A&&uh7&&uo>))%1BC'**5+uE 7 
8 9 	r  r  c                     | j                          | j                  |      }|d   st        | j                  dz         d|d<   | j	                  |dd|d|      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>`
        rD   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr  r  r  N)r  r  r.   r8   create_order)r  r  r  r  r  s        r  !create_market_buy_order_with_costz(coinex.create_market_buy_order_with_cost(  s`     	V$f~tww)ddee6;23  5$fMMr  r  r6  r   r  c                    | j                  |      }|d   }| j                  |dd      }	| j                  |dd      }
| j                  |d      }| j                  |d      }| j                  |d      }|d	k(  }| j                  ||d
k(  |      }| j	                  |d      }| j                  |d      }|r&|d   s!t        | j                  dz   |d   z   dz         d	|d   i}|	9d}| j                  | j                  d|      }|dz   | j                         z   |d<   n|	|d<   |=|;|s||d<   |}|rd
}n||dk(  rd}n|dk(  rd}|s| j                  ||      |d<   ||d<   |rd|d<   |s|r_|r-| j                  ||      |d<   | j                  |dd      |d<   n|r| j                  ||      |d <   | j                  |dd      |d!<   ns| j                  ||      |d"<   |
[| j                  ||
      |d#<   | j                  |dd      |d$<   n.d }| j                  d%|      \  }}|d&|d<   nd'|d<   |d	k(  r|d(k(  rd)}| j                  |d%d*d)      \  }}| j                  |d+      }| j                  |d+      }|r||t        | j                  d,z         | j!                  |      }| j!                  |      }| j#                  t%        j&                  ||            }||n|}| j)                  ||      |d"<   n+| j)                  ||      |d"<   n| j                  ||      |d"<   |
| j                  ||
      |d#<   | j                  |g d-      }| j+                  ||      S ).NrF   r  r  	stopPricer)  r,  r-  rH   r  
maker_onlyr/  r  z/ createOrder() does not support reduceOnly for r  z> orders, reduceOnly orders are supported for swap markets onlyr8   r   r  -r6  r$  iocr%  fokr  r   r  r  	stop_typelatest_pricestop_loss_typer  take_profit_typer   r  trigger_price_typerU   r   r   r  Tr  r  z createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argument)r  r/  r  r  r)  r,  r-  )r  r  r  is_post_onlysafe_string_upperr  r,   r8   r   uuid16price_to_precisionamount_to_precisionr{  handle_option_and_paramsr  omitnumber_to_stringparse_to_numericr3   
string_mulcost_to_precisionr  )r  r  r  r6  r   r  r  r  rF   r  r)  r,  r-  rH   isMarketOrderr  timeInForceRawr  r  	defaultIdr  requestTyper(  r  r  amountStringpriceStringquoteAmountcostRequests                                r  create_order_requestzcoinex.create_order_request;  s"   V$f~**6;P))&+~N((A**63DE!!&(3($$]Fl4JFS//F^^FL9
&>"477-^#^aghnao#o  ss  $s  t  tfTl
  %I''j)LH#+c>DKKM#AGK #0GK !(?"&K*+!U*"'K#u,"'K #'#:#:65#I )GFO%.GM" 151H1HQ^1_G-.040@0@Vd0eG,-$373J3J6Sb3cG/0262B2B6;Xf2gG./$($<$<VV$L!+/3/F/Fv|/\GO,484D4DV[Zh4iG01J!%!C!CMSY!ZJ%)1&)/& tu}481<@<Y<YZ`bo  rU  W[  =\916''76624DL*477  6q  ,q  r  r'+'<'<V'D&*&;&;E&B&*&;&;G<N<N|]h<i&j/3/?dk,0,B,B6;,W)(,(>(>vv(NGH%$($<$<VV$L!'+/+B+B6<+X(6  $N  O{{7F++r  c                    | j                          | j                  |      }| j                  |d      }| j                  |dd      }	| j	                  |d      }
| j	                  |d      }|	du}|
du}|du}|xs |}| j                  ||||||      }d}|d   r&|r| j                  |      }nu| j                  |      }nc|r| j                  |      }nO|r(|r| j                  |      }n9|r7| j                  |      }n%|r| j                  |      }n| j                  |      }| j                  |di       }| j                  ||      S )	ae  
        create a trade order

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

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: price to trigger stop orders
        :param float [params.stopLossPrice]: price to trigger stop loss orders
        :param float [params.takeProfitPrice]: price to trigger take profit orders
        :param str [params.timeInForce]: 'GTC', 'IOC', 'FOK', 'PO'
        :param boolean [params.postOnly]: set to True if you wish to make a post only order
        :param boolean [params.reduceOnly]: *contract only* indicates if self order is to reduce the size of a position
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  r)  r,  r-  NrD   r  )r  r  r  r  r  r  v2PrivatePostSpotStopOrderv2PrivatePostSpotOrderv2PrivatePostFuturesStopOrder'v2PrivatePostFuturesSetPositionStopLoss)v2PrivatePostFuturesSetPositionTakeProfit!v2PrivatePostFuturesClosePositionv2PrivatePostFuturesOrderr  r  )r  r  r  r6  r   r  r  r  r  r)  stopLossTriggerPricetakeProfitTriggerPriceisTriggerOrderisStopLossTriggerOrderisTakeProfitTriggerOrderisStopLossOrTakeProfitTriggerr  r  r  s                      r  r  zcoinex.create_order  sr   4 	V$^^FL9
))&+~N#//H!%!1!1&:K!L%T1!5T!A#9#E (>(ZBZ%++FD$vV&>::7C  66w?> ==gF /)#KKGTHN .#MMgVHP #EEgNH<  $==gFH: ~~h3f--r  ordersc           	         | j                          g }d}d}d}d}t        dt        |            D ]<  }||   }	| j                  |	d      }
||
}n||
k7  rt	        | j
                  dz         | j                  |	d      }| j                  |	d      }| j                  |	d      }| j                  |	d	      }| j                  |	d
i       }|dk7  rt        | j
                  dz   |z   dz         | j                  |d      }| j                  |dd      }| j                  |d      }| j                  |d      }|du}|du}|du}|xs |}| j                  |
|||||      }|j                  |       ? | j                  |      }|d   |d}d}|d   r&|r| j                  |      }nk| j                  |      }nY|r| j                  |      }nE|rt        | j
                  dz         |rt        | j
                  dz         | j!                  |      }| j#                  |dg       }g }t        dt        |            D ]  }||   }d}| j%                  |d      }|
|dk7  rd}nd}| j'                  |di       }d}|d   r|s||d<   | j)                  ||      }n||d<   | j)                  ||      }|j                  |        |S )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  r6  r   r  r  r9  z! createOrders() does not support z' orders, only limit orders are acceptedr  r  r)  r,  r-  r8   )r  r  rD   zH createOrders() does not support stopLossPrice or takeProfitPrice ordersz2 createOrders() does not support reduceOnly ordersr  r  r  r  r~  )r  r  r  r  r)   r8   r  r.   safe_number_2r  r  r  r  v2PrivatePostSpotBatchStopOrderv2PrivatePostSpotBatchOrder"v2PrivatePostFuturesBatchStopOrderv2PrivatePostFuturesBatchOrderr  r#  r  r  ) r  r  r  ordersRequestsr  r  r  r  r  rawOrderr  r  r6  r   r  orderParamsr)  r  r  r  r  orderRequestr  r  r  r  resultsr  r~  r  	innerDatar9  s                                    r  create_orderszcoinex.create_orders{	  s3    	
(-%q#f+& 	0AayH''(;H~!X%$TWW/l%lmm##Hf5D##Hf5D__Xx8FOOHg6E//(HbAKw"477-P#PSW#W  [D  $D  E  ElCJ--k;WL#'#3#3K#Q %)%5%5kCT%U")5N%9%E"'=T'I$,B,^F^)44XtT6SXZefL!!,/1	02 V$Tl$
 &>??H"  ;;GDL BB7K  /"477-w#wxx&tww1e'eff#BB7KHF ~~h3q#d)$ 	"AGEF$$UF3D19'F#Fufb9IEf~n"(h((7&,	(#((F;NN5!#	"$ r  c                 f   |t        | j                  dz         | j                          | j                  |      }d|d   i}| j	                  |dd      }| j                  |ddg      }d}g }t        dt        |            D ]  }	|j                  t        ||	                ! |r||d<   n||d	<   |d
   rF|r"| j                  | j                  ||            }nl| j                  | j                  ||            }nJd|d<   |r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |dg       }
g }t        dt        |
            D ]=  }	|
|	   }| j!                  |di       }| j#                  ||      }|j                  |       ? |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  r8   stopr=  r   stop_ids	order_idsrD   r   r  r  )r(   r8   r  r  safe_bool_2r  r  r  r  int%v2PrivatePostSpotCancelBatchStopOrderr  !v2PrivatePostSpotCancelBatchOrder(v2PrivatePostFuturesCancelBatchStopOrder$v2PrivatePostFuturesCancelBatchOrderr  r  r  )r  idsr  r  r  r  r=  r  
requestIdsr  r  r  r  itemr9  s                  r  cancel_orderszcoinex.cancel_orders6
  s    >#DGG.Z$Z[[V$fTl
 ""669=6FI#67
q#c(# 	+Ac#a&k*	+",GJ#-GK &>EEdkkRY[aFbc<  AA$++gW]B^_J &/GM"HHU\^dIef:  DDT[[QXZ`EabF ~~h3q#d)$ 	"AGE>>%4D$$T62ENN5!		"
 r  r8   c                 z   |t        | j                  dz         | j                          | j                  |      }d|d   i}	|| j	                  ||      |	d<   || j                  ||      |	d<   d}
| j                  |g d      }| j                  |dd	g      }|du}|r*| j                  ||      |	d
<   | j                  |      |	d<   n| j                  |      |	d<   d}| j                  d|      \  }}|d   rS|d|	d<   nd|	d<   |r"| j                  | j                  |	|            }
nl| j                  | j                  |	|            }
nJd|	d<   |r"| j                  | j                  |	|            }
n!| j                  | j                  |	|            }
| j                  |
di       }| j!                  ||      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  r8   r   r  )r  r)  r  r  r)  r  r  r5  r\   rD   r   r  r   r   r  )r(   r8   r  r  r  r  r  r  r  r{   v2PrivatePostSpotModifyStopOrderr  v2PrivatePostSpotModifyOrder#v2PrivatePostFuturesModifyStopOrderv2PrivatePostFuturesModifyOrderr  r  )r  r8   r  r  r6  r   r  r  r  r  r  r)  r  r(  r  s                  r  
edit_orderzcoinex.edit_order
  s   & >#DGG.W$WXXV$fTl
  $ 8 8 HGH#66vuEGG))&2`a6K#@A%T1'+'>'>v|'TGO$!%!6!6r!:GI"&"7"7";GJ
!??VT
F&>%)1&)/&@@WV\A]^  <<T[[RX=YZ@ &/GM"CCDKKPWY_D`a  ??GU[@\]: ~~h3f--r  c                    |t        | j                  dz         | j                          | j                  |      }| j	                  |dd      }|d   }d|d   i}d}| j                  d|      \  }}|rd	|d
<   n|d|d
<   nd|d
<   | j                  |dd      }	| j                  |g d      }d}
|	|	|d<   |rG|r#| j                  | j                  ||            }
n| j                  | j                  ||            }
n|r"| j                  | j                  ||            }
n| j                  | j                  ||            }
n|rZ| j                  |      |d<   |r"| j                  | j                  ||            }
n{| j                  | j                  ||            }
nY| j                  |      |d<   |r"| j!                  | j                  ||            }
n!| j#                  | j                  ||            }
d}|	*| j%                  |
dg       }| j'                  |d   di       }n| j'                  |
di       }| j)                  ||      S )af  
        cancels an open order

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

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.clientOrderId]: client order id, defaults to id if not passed
        :param boolean [params.trigger]: set to True for canceling a trigger order
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentr  r=  rF   r  r8   rM   r   r  r   r   r  r  )r  r=  r  r  r5  r  r   )r(   r8   r  r  r  r{  r  r  -v2PrivatePostFuturesCancelStopOrderByClientIdr  *v2PrivatePostSpotCancelStopOrderByClientId)v2PrivatePostFuturesCancelOrderByClientId&v2PrivatePostSpotCancelOrderByClientIdr  #v2PrivatePostFuturesCancelStopOrder v2PrivatePostSpotCancelStopOrderv2PrivatePostFuturesCancelOrderv2PrivatePostSpotCancelOrderr  r  r  )r  r8   r  r  r  r  rF   r  r(  r  r  r  rowss                r  cancel_orderzcoinex.cancel_orderm  st   ( >#DGG.Y$YZZV$))&&)Df~fTl
 
!??vV
F%.GM"%)1&)/&**6;P6#GH$#0GK #QQRVR]R]^egmRnoH6  $NNt{{[bdjOklH8 #MMdkkZaciNjkHD  $JJ4;;W^`fKghHF %)%:%:2%>	"#GGT[]cHdeH,  $DDT[[QXZ`EabH, '+&;&;B&?
##CCDKKPWY_D`aH8  $@@WV\A]^H8 $>>(FB7D>>$q'626D>>(FB7Df--r  c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}d}|d   r'd|d<   | j	                  | j                  ||            }nEd}| j                  d|      \  }}|d	|d<   nd
|d<   | j                  | j                  ||            }| j                  d|i      gS )a4  
        cancel all open orders in a market

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

        :param str symbol: unified market symbol of the market to cancel orders in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' for canceling spot margin orders
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz- cancelAllOrders() requires a symbol argumentr  r8   rF   r   r  rL   r   r   r  )	r(   r8   r  r  "v2PrivatePostFuturesCancelAllOrderr  r{  v2PrivatePostSpotCancelAllOrderr  )r  r  r  r  r  r  r(  s          r  cancel_all_orderszcoinex.cancel_all_orders  s     >#DGG.]$]^^V$fTl
 &>%.GM">>t{{7TZ?[\H
 J!%!C!CDUW]!^J%)1&)/&;;DKKQW<XYH
 OO 
 	
r  c                    |t        | j                  dz         | j                          | j                  |      }|d   | j	                  |      d}d}|d   r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |di       }| j                  ||      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 argumentr8   )r  r5  rF   r  )
r(   r8   r  r  r  v2PrivateGetFuturesOrderStatusr  v2PrivateGetSpotOrderStatusr  r  )r  r8   r  r  r  r  r  r  s           r  fetch_orderzcoinex.fetch_order  s     >#DGG.X$XYYV$Tl--b1
 &>::4;;wPV;WXH> 77GV8TUH> ~~h3f--r  c                    | j                          i }d}|| j                  |      }|d   |d<   |||d<   | j                  |dd      }| j                  |ddg      }d}	| j	                  d||      \  }	}d}
|dk(  xs |d	k(  }|d
k(  xs |dk(  }|	dk(  rd|d<   |rG|r#| j                  | j                  ||            }
n | j                  | j                  ||            }
n|r|r"| j                  | j                  ||            }
n| j                  | j                  ||            }
nd}| j                  d|      \  }}|d|d<   nd|d<   |rF|r"| j                  | j                  ||            }
nl| j                  | j                  ||            }
nJ|d
k(  rE|r"| j                  | j                  ||            }
n!| j                  | j                  ||            }
| j                  |
dg       }| j!                  ||||      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>`
        Nr8   r  r9  r  r=  fetchOrdersByStatusfinishedr  pendingr  rF   r   r  r   r   r  )r  r  r  r  r  $v2PrivateGetFuturesFinishedStopOrderr   v2PrivateGetFuturesFinishedOrder#v2PrivateGetFuturesPendingStopOrderv2PrivateGetFuturesPendingOrderr{  !v2PrivateGetSpotFinishedStopOrderv2PrivateGetSpotFinishedOrder v2PrivateGetSpotPendingStopOrderv2PrivateGetSpotPendingOrderr  parse_orders)r  r~  r  rB  r9  r  r  r  r=  r  r  isClosedisOpenr(  r  s                  r  fetch_orders_by_statuszcoinex.fetch_orders_by_status
  sL   $ 	[[(F &tGH$GG""669=6FI#67
!??@UW]_ef
Fj(Af.@I%<6V+;%.GM"#HHU\^dIefH8  $DDT[[QXZ`EabH> #GGT[]cHdeH:  $CCDKKPWY_D`aHH J!%!C!CDY[a!bJ%)1&)/&#EEdkkRY[aFbcH:  $AA$++gW]B^_HB 9$#DDT[[QXZ`EabH<  $@@WV\A]^HH ~~h3  vue<<r  c                 t    | j                  d||||      }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  r   r  r~  )r"  r  r  )r  r  rB  r9  r  
openOrdersr  s          r  fetch_open_orderszcoinex.fetch_open_orders:  sK    " 00FE5RXY
q#j/* 	-A&,JqM(#	-r  c                 ,    | j                  d||||      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  )r"  )r  r  rB  r9  r  s        r  fetch_closed_orderszcoinex.fetch_closed_ordersP  s    " **:vueVTTr  r  c                    | j                          | j                  |      }| j                  |dd      }|t        | j                  dz         | j                  |d      }|d   | j                  ||d         d}| j                  | j                  ||            }| j                  |di       }| j                  ||      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>`
        r  r  z4 createDepositAddress() requires a network parameterr8   r  )r  r  r  )r  r3  r  r(   r8   r  network_code_to_id(v2PrivatePostAssetsRenewalDepositAddressr  r  parse_deposit_address)r  r  r  r3  r  r  r  r  s           r  create_deposit_addresszcoinex.create_deposit_addressc  s     	==&$$VWi@?#DGG.d$dee69-D>,,Whv6FG
 @@WV\A]^ ~~h3))$99r  c                 f   | j                          | j                  |      }d|d   i}d}| j                  |      \  }}|t        | j                  dz         | j                  |      |d<   | j                  | j                  ||            }| j                  |di       }| j                  ||      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>`
        r  r8   Nz5 fetchDepositAddress() requires a "network" parameterr  r  )
r  r3  handle_network_code_and_paramsr(   r8   r)   v2PrivateGetAssetsDepositAddressr  r  r+  )r  r  r  r3  r  networkCoder  r  s           r  fetch_deposit_addresszcoinex.fetch_deposit_address  s     	==&8D>
 "AA&IV#DGG.e$eff22;?88Wf9UV ~~h3))$99r  r3  c           	          | j                  |d      }|j                  d      }d }d }t        |      }|dkD  r|d   dk7  r|d   }|d   }n|}|| j                  d |      d || j                  |d|      dS )Naddressr  r   r   cfxmemo)r  r3  r  r3  tag)r  splitr  r  )r  depositAddressr3  coinAddresspartsr3  r6  partsLengths           r  r+  zcoinex.parse_deposit_address  s     &&~yA!!#&%j?uQx50AhG(C!G"//h?##NFC@
 	
r  c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   |||d<   | j	                  d||      \  }}d}|d   r'd	|d
<   | j                  | j                  ||            }nEd}| j                  d|      \  }}|d|d
<   nd|d
<   | j                  | j                  ||            }| j                  |dg       }	| j                  |	|||      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  r8   r9  
start_timeend_timerF   r   r  r|   r   r   r  )r(   r8   r  r  handle_until_optionv2PrivateGetFuturesUserDealsr  r{  v2PrivateGetSpotUserDealsr  rF  )
r  r  rB  r9  r  r  r  r  r(  r  s
             r  fetch_my_tradeszcoinex.fetch_my_trades  s2    >#DGG.[$[\\V$fTl
 $GG$)GL!22:wO&>%.GM"88Wf9UVH, J!%!C!COU[!\J%)1&)/&55dkk'66RSH, ~~h3  vue<<r  c                    | j                          d}| j                  |ddd      \  }}| j                  |      }ddi}d}|[d}t        |t              r.t        |      }|dkD  rt        | j                  dz         |d	   }n|}| j                  |      }|d
   |d<   d}|dk(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |dg       }	g }
t        d	t        |	            D ]&  }|
j                  | j                  |	|   |             ( | j!                  |
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   r8   r  r  r  F)r  r  r  
isinstancelistr  r)   r8   r  rE  r  #v2PrivateGetFuturesFinishedPositionr  r  r  parse_positionfilter_by_array_positions)r  r  r  defaultMethodr  r  r  symbolsLengthr  positionr  r  s               r  fetch_positionszcoinex.fetch_positions  sr    	 $ = =fFVX`  cG  !Hv%%g.9
 F'4( #G 1$$TWW/u%uvv  [[(F &tGH@@>>t{{7TZ?[\H??GU[@\]HX >>(FB7q#h-( 	DAMM$--hqk6BC	D--fhOOr  c                     | j                          | j                  |      }d|d   d}| j                  | j                  ||            }| j	                  |dg       }| j                  |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>`
        r   r8   r  r  r  r   )r  r  rE  r  r  rI  )r  r  r  r  r  r  r  s          r  fetch_positionzcoinex.fetch_positionj  sy     	V$$Tl
 ::4;;wPV;WXX ~~h3""47F33r  rM  c                    | j                  |d      }| j                  ||d d      }| j                  |d      }| j                  i d|d| j                  |d      d|d   d| j	                  |d	      d
| j                  |d      d| j	                  |d      d| j	                  |d      d| j	                  |d      d| j	                  |d      dd d| j	                  |d      d| j	                  |d      dd dd d| j                  |d      dd d|| j                  |      | j                  |d      | j	                  |d      | j	                  |d      | j	                  |d       d d | j	                  |d!      | j	                  |d"      | j                  | j                  |d#            | j                  | j                  |d$            d%      S )&Nr  rF   r0  r  r8   r  r  notionalsettle_valuer(  margin_modeliquidationPrice	liq_price
entryPricer  unrealizedPnlunrealized_pnlrealizedPnlrealized_pnlr  	contracts
close_avblr  r
  	lastPricer6  r0  r  r)  maintenance_margin_valuemaintenance_margin_ratemargin_avblr2  position_margin_rater  r  )r  lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager2  marginRatior,  r-  )r  r;  r#  safe_positionr  r=  	omit_zero)r  rM  r  r  r  s        r  rI  zcoinex.parse_position  sX   F ##Hh7!!(FD&A%%h=	!! #
H#
$##Hm<#
 fX&#
 ((>B	#

 $**8]C#
  0 0; G#
 $**85FG#
 T--h8HI#
 4++HnE#
 $#
 ))(LA#
 D,,V^D#
 #
 #
 D$$Xv6#
  d!#
" ##
$ Y/#'#4#4X|#L!%!1!1(<V!W+/+;+;HF_+`**8]C!'+((:>++H6LM!^^D,<,<XGX,YZ#~~d.>.>xI\.]^9#
  	r  r(  c                 d   |t        | j                  dz         |j                         }|dk7  r|dk7  rt        | j                  dz         | j	                          | j                  |      }|d   dk7  rt        | j                  dz         | j                  |d      }| j                  |d	   d   d
d      }|t        | j                  dz         |dk  s||kD  r*t        | j                  dz   t        |      z   dz   |z         |d   d||d}| j                  | j                  ||            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
        z+ setMarginMode() requires a symbol argumentisolatedcrossz@ setMarginMode() marginMode argument should be isolated or crossr  rF   z- setMarginMode() supports swap contracts onlyr2  r   r   d   z. setMarginMode() requires a leverage parameterr   z2 setMarginMode() leverage should be between 1 and  for r8   r   r  r  rU  r2  )r(   r8   lowerr)   r  r  r*   r#  str*v2PrivatePostFuturesAdjustPositionLeverager  )r  r(  r  r  r  r2  maxLeverager  s           r  set_margin_modezcoinex.set_margin_mode  sT    >#DGG.[$[\\%%'
#
g(=TWW'iijjV$&>V#DGG&UUVV$$VZ8''x(8(DeSQ#DGG.^$^__qLh4TWW'[[^abm^nnqxx  |B  B  C  CTl$% 	
 >>t{{7TZ?[\\r  r2  c                 "   |t        | j                  dz         | j                          | j                  |      }|d   st	        | j                  dz         d}| j                  d|d      \  }}| j                  |d   d   d	d
      }| j                  |d   d   dd      }||k  s||kD  r9t        | j                  dz   t        |      z   dz   t        |      z   dz   |z         |d   d||d}| j                  | j                  ||            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 argumentrF   z+ setLeverage() supports swap contracts onlyr   ro  r   r2  r   r   r   rp  z* setLeverage() leverage should be between z and rq  r8   r   rr  )r(   r8   r  r  r*   r{  r#  r)   rt  ru  r  )	r  r2  r  r  r  r(  minLeveragerv  r  s	            r  set_leveragezcoinex.set_leverage  sR    >#DGG.Y$YZZV$f~DGG&SSTT
!??vW^_
F''x(8(DeQO''x(8(DeSQ{";(>TWW'SSVYZeVffippsv  xC  tD  D  GN  N  QW  W  X  XTl$% 	
 >>t{{7TZ?[\\r  c                    | j                          i }|%| j                  |      }dj                  |      |d<   | j                  | j	                  ||            }| j                  |dg       }| j                  ||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
        ,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_tiersE  s     	0I # 3GH77GV8TU4 ~~h3((wAAr  c                    g }| j                  |dg       }d}t        dt        |            D ]  }||   }| j                  |d      }| j	                  ||d d      }| j                  |d      }	|j                  | j                  |d      | j                  ||d d      |d   r|d   n|d	   ||	| j                  |d
      | j                  |d      |d       |	} |S )Nlevelr   r  rF   r   r   r   r  r  ra  r2  )tierr  r3  minNotionalmaxNotionalmaintenanceMarginRaterv  r  )
r  r  r  r  r;  r  r  sumr  r#  )
r  r  r  tiersbracketsr  r  r  r  r  s
             r  parse_market_leverage_tiersz"coinex.parse_market_leverage_tiersq  s    >>$4q#h-( 	&AA;D''h7H%%hfEF**4:KLLA**8VT6J.4X.>F6NF7O**)-)9)9$@Y)Z#00zB	 	 &K	&  r  c                    | j                          | j                  |      }| j                  ||      }|}|dk(  rt        j                  |      }|d   d|d}| j                  | j                  ||            }	| j                  |	d      }
| j                  |	d      }|dk(  rdnd}| j                  | j                  |
|      || j                  |      |d      S )	Nreducer8   r   )r  r  r   r  messageadd)r  r   r~  )r  r  r  r3   
string_neg(v2PrivatePostFuturesAdjustPositionMarginr  r  r  parse_margin_modificationr  )r  r  r   addOrReducer  r  	rawAmountrequestAmountr  r  r  r~  r  s                r  modify_margin_helperzcoinex.modify_margin_helper  s    V$,,VV<	!("#..y9MTl$#

 @@WV\A]^N ~~h/'')<'83x%{{499$G''/J
  	r  r  c                 6   | j                  |d      }| j                  |dd      }| j                  |d      }|| j                  ||d d      d d| j                  t	        j
                  |            | j                  |d      |d   d || j                  |      d	
S )
Nr  r)  r0  margin_changerF   rn  rb  r  )
r  r  r  r(  r   totalr  r~  r  r  )r  safe_integer_2r  r  r3   
string_absr  r=  )r  r  r  r  r  r  s         r  r  z coinex.parse_margin_modification  s    l ##D(3''lLI	!!$8&&xvF$''(:(:6(BC%%dM:7O"Y/
 	
r  c                 *    | j                  ||d|      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=add-margin-structure>`
        r  r  r  r  r   r  s       r  
add_marginzcoinex.add_margin	  s     ((GGr  c                 *    | j                  ||d|      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=reduce-margin-structure>`
        r  r  r  s       r  reduce_marginzcoinex.reduce_margin  s     ((6JJr  c                 x   |t        | j                  dz         | j                          | j                  |      }|d   dd}| j	                  d||      \  }}|||d<   |||d<   | j                  | j                  ||            }| j                  |dg       }g }	t        d	t        |            D ]  }
||
   }| j                  |d
      }| j                  |d      }| j                  |      }|	j                  ||||| j                  |      | j                  |d      | j                  |d      d        |	S )aW  
        fetch the history of funding fee payments paid and received on self account

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

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

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

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        rF   z0 fetchFundingRate() supports swap contracts onlyr  r8   r  r   )	r  r  r*   r8   v2PublicGetFuturesFundingRater  r  r  parse_funding_rate)r  r  r  r  r  r  r  firsts           r  fetch_funding_ratezcoinex.fetch_funding_rated  s     	V$f~DGG&XXYYfTl
 55dkk'66RS& ~~h3tQ+&&uf55r  c                 &    | j                  ||      S )a|  
        fetch the current funding rate interval

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

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

 D
 #D
 
 
 4++H6KL
  7
 t||,CD
 t//:MN
 #$:
 "4<<0F#G
 "4
  '!
" &t#
$ 334HI%
 	
r  c                 8    dddddd}| j                  |||      S )Nr   r   8h16h24h)360000014400000288000005760000086400000r  )r  r'  	intervalss      r  r  zcoinex.parse_funding_interval  s/    
	 	8X>>r  c                    | j                          | j                  |      }i }d}|e| j                  |d      }| j                  |      }|d   st	        | j
                  dz         | j                  |      }dj                  |      |d<   | j                  | j                  ||            }| j                  |dg       }| j                  ||      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   rF   z1 fetchFundingRates() supports swap contracts onlyr|  r  r  )r  r  r  r  r*   r8   r}  r~  r  r  r  parse_funding_rates)	r  r  r  r  r  r  r  r  r  s	            r  fetch_funding_rateszcoinex.fetch_funding_rates  s     	%%g.__Wa0F[[(F&>*] ]^^0I # 3GH55dkk'66RS& ~~h3''g66r  r3  c                    | j                  ||      \  }}| j                  |       | j                          | j                  |      }|d   || j	                  ||      d}|||d<   d}| j                  |      \  }}|| j                  |      |d<   | j                  | j                  ||            }	| j                  |	di       }
| j                  |
|      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:
        :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>`
        r8   )r  
to_addressr   Nr5  r  r  )handle_withdraw_tag_and_paramscheck_addressr  r3  currency_to_precisionr.  r)  v2PrivatePostAssetsWithdrawr  r  parse_transaction)r  r  r   r3  r6  r  r3  r  r0  r  transactions              r  r   zcoinex.withdraw  s     99#vFV7#==&D>!00v>

 ?!GFO"AA&IV"#66{CGG33DKK4PQ6 nnXvr:%%k8<<r  c                 B    ddddddddddd
}| j                  |||      S )Nr  failedr  ok)
auditpassaudit_required
processing
confirmingnot_passr  finishr  failr  r  s      r  parse_transaction_statuszcoinex.parse_transaction_status2  s>    '##  
 &&99r  c           
         |t        | j                  dz         | j                          d}| j                  |dd      \  }}|r| j	                  d|||d|d      S | j                  |      }d|d	   i}|||d
<   |||d<   | j                  d||      \  }}| j                  | j                  ||            }| j                  |dg       }	g }
t        dt        |	            D ]u  }|	|   }| j                  |d      }| j                  ||dd      }| j                  |d      }|
j                  ||| j!                  |d      || j#                  |      d       w | j%                  |
d      }| j'                  ||d   ||      S )a  
        fetches historical funding rate prices

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

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

 Y/
 t..y9
 w
 
 4
 3
 T
 t
 D
 f
 
  d33D4D4D[RZ4[\!
" t#
$  )
 	
r  fromAccount	toAccountc                    | j                          | j                  |      }| j                  ||      }| j                  | j                  di       }| j                  |||      }	| j                  |||      }
|d   ||	|
d}|dk(  s|dk(  rR| j                  |d      }|t        | j                  dz         | j                  |d      }| j                  |      |d<   |dk7  r|dk7  rt        | j                  d	z         | j                  | j                  ||            }| j                  | j                  ||      | j                  |      ||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>`
        r   r8   )r  r   from_account_typeto_account_typerE   r  zE transfer() the symbol parameter must be defined for a margin accountr  rD   zs transfer() can only be between spot and swap, or spot and margin, either the fromAccount or toAccount must be spot)r   r
  r  )r  r3  r  r  r   r  r(   r8   r  	market_idr)   v2PrivatePostAssetsTransferr  parse_transferr  )r  r  r   r
  r  r  r3  amountToPrecisionr   fromIdtoIdr  r  r  s                 r  r   zcoinex.transfer  so    	==& 66tVD6FK!!.+{K	9ED>'!'#	
 8#h)>%%fh7F~'2y(yzzYYvx0F $v 6GH6!	V(;TWW  (]  ]  ^  ^33DKK4PQ {{4..xB''(9:&"E
  	r  c                 8    dddddd}| j                  |||      S )Nr  )r&  SUCCESSOKr  FINISHEDr  r  s      r  parse_transfer_statuszcoinex.parse_transfer_status  s/    
 &&99r  r   c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  | j                  di       }d || j	                  |      | j                  ||      | j                  |d      | j                  |||      | j                  |||      | j                  | j                  |dd            d	S )
Nr0  r  r  r  r!  r   r  r~  )r8   r  r  r3  r   r
  r  r~  )	r#  r  r  r   r=  r  r  r  r  )r  r   r3  r  r  r  r  r!  s           r  r  zcoinex.parse_transfer  s    %%h=	%%h6
!!(,?@*;<t||^RH"Y///
HE&&x:++L&&I)),dC001C1CHfV^1_`	
 		
r  c                    | j                          |t        | j                  dz         | j                  |      }d|d   i}d}| j	                  d|      \  }}|d|d<   nd|d<   |||d	<   |||d
<   | j                  d||      \  }}| j                  | j                  ||            }| j                  |dg       }	| j                  |	|||      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  r8   r   r   transfer_typer   r=  r9  r>  r  )
r  r(   r8   r3  r{  r?  !v2PrivateGetAssetsTransferHistoryr  r  parse_transfers)
r  r  rB  r9  r  r3  r  r(  r  r  s
             r  fetch_transferszcoinex.fetch_transfers0  s     	<#DGG.Z$Z[[==&8D>
 
!??@PRXY
F!'/GO$'0GO$$)GL!$GG22:wO99$++gv:VW* ~~h3##D(E5AAr  c                     | j                          i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )a3  
        fetch all withdrawals made from an account

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

        :param str [code]: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawal structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr8   r  r9  r  )r  r3  v2PrivateGetAssetsWithdrawr  r  parse_transactions	r  r  rB  r9  r  r  r3  r  r  s	            r  fetch_withdrawalszcoinex.fetch_withdrawalsg  s     	}}T*H%d^GEN$GG224;;w3OPB ~~h3&&tXueDDr  c                     | j                          i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||      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>`
        Nr8   r  r9  r  )r  r3   v2PrivateGetAssetsDepositHistoryr  r  r"  r#  s	            r  fetch_depositszcoinex.fetch_deposits  s     	}}T*H%d^GEN$GG88Wf9UV< ~~h3&&tXueDDr  r  c           
          | j                  |d      }| j                  ||d d      }| j                  |d      }| j                  |d      }d }d }||d   k(  r|}n
||d   k(  r|}|d   |d   ||d	   |d
d d |d	S )Nr  rD   r  daily_interest_rater  r  r  r  r  i \&)	r  r  baseRater  	quoteRaterT  r  r  r  )r  r;  r  )r  r  r  r  r3  rater*  r+  s           r  parse_isolated_borrow_ratez!coinex.parse_isolated_borrow_rate  s     ##D(3!!(FD&A##D%0&;<	vh''H	**IX&6N G_"

 
	
r  c                    | j                          | j                  |d      }|t        | j                  dz         | j	                  |d      }| j                  |      }| j                  |      }|d   |d   d}| j                  | j                  ||            }| j                  |di       }| j                  ||      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>`
        r  z4 fetchIsolatedBorrowRate() requires a code parameterr8   r  r  r  )r  r  r(   r8   r  r3  r  %v2PrivateGetAssetsMarginInterestLimitr  r  r-  	r  r  r  r  r3  r  r  r  r  s	            r  fetch_isolated_borrow_ratez!coinex.fetch_isolated_borrow_rate  s     	/<#DGG.d$dee66*==&V$TlD>
 ==dkk'SY>Z[ ~~h3..tV<<r  c                 "   | j                          i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  |dg       }	| j                  |	|      }
| j                  |
|||      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>`
        Nr8   r  r9  r  )r  r  %v2PrivateGetAssetsMarginBorrowHistoryr  r  parse_borrow_interestsfilter_by_currency_since_limit)r  r  r  rB  r9  r  r  r  r  r	  r^  s              r  fetch_borrow_interestzcoinex.fetch_borrow_interest  s     	[[(F &tGH$GG==dkk'SY>Z[2 x4..tV<228T5%PPr  c                 L   | j                  |d      }| j                  ||d d      }| j                  |d      }||d   | j                  | j                  |d            | j	                  |d      | j	                  |d      | j	                  |d      d	|| j                  |      d
	S )Nr  rD   
expired_atr  r  to_repaied_amountr)  borrow_amountrn  )	r  r  r3  r^  r  amountBorrowedr(  r  r  )r  r;  r#  r  r  r=  )r  r  r  r  r  s        r  parse_borrow_interestzcoinex.parse_borrow_interestO  s     ##D(3!!(FD&A%%dL9	X&//0@0@u0MN((/BC ,,T3HI"..t_E$"Y/

 
	
r  c                    | j                          | j                  |      }| j                  |      }| j                  |ddd      }| j	                  |d      }|d   |d   | j                  ||      |d}| j                  | j                  ||            }	| j                  |	di       }
| j                  |
|      }| j                  |||d      S )am  
        create a loan to borrow margin

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

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

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

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

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

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        r  r8   r  )r  r3  &v2PublicGetAssetsDepositWithdrawConfigr  r  parse_deposit_withdraw_fee)r  r  r  r3  r  r  r  s          r  fetch_deposit_withdraw_feez!coinex.fetch_deposit_withdraw_fee  st     	==&8D>
 >>t{{7TZ?[\D ~~h3..tX>>r  c                    |d d dd d di d}| j                  |dg       }| j                  |di       }t        dt        |            D ]  }||   }| j	                  |d      }|s| j                  |d      |d   d	<   d
|d   d<   | j                  |d      }	|	sR| j                  |	| j                  |d            }
| j                  |d      d
dd d dd|d   |
<    |S )N)r  r  )r  r   r  r"  r  r  r   r  r  r   r  Fr  r  r  )r   r  r"  )r  r  r  r  r  r  r  r  )r  r  r3  r  r  r  r  r  isWithdrawEnabledr  r0  s              r  rL  z!coinex.parse_deposit_withdraw_fee  s+   > "
 " 
 Xr2sGR0q#f+& 	A1IE $u6H I ,0,<,<UDT,Uz"5)38z"<0 ,,UG<	"&"9"9)TEUEUV[]bEc"dK $(#3#3E;K#L*/%
 $(*.$	7F:&{3	& r  c                    | j                          | j                  |d      }|t        | j                  dz         | j	                  |d      }| j                  |      }| j                  |      }|d   |d   d}| j                  | j                  ||            }| j                  |di       }| j                  ||      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>`
        r  z* fetchLeverage() requires a code parameterr8   r/  r  )r  r  r(   r8   r  r3  r  r0  r  r  parse_leverager1  s	            r  fetch_leveragezcoinex.fetch_leverageP  s     	/<#DGG.Z$Z[[66*==&V$TlD>
 ==dkk'SY>Z[ ~~h3""400r  c                 ~    | j                  |d      }| j                  |d      }|| j                  ||d d      d||dS )Nr  r2  rD   rn  )r  r  r(  longLeverageshortLeverage)r  r#  r  )r  r2  r  r  leverageValues        r  rQ  zcoinex.parse_leveragex  sR     ##Hh7))(J?&&xvF$)*
 	
r  c                 N   | j                          | j                  |      }d|d   d}|||d<   |||d<   | j                  d||      \  }}| j                  | j	                  ||            }| j                  |dg       }| j                  |      }	| j                  |	|||      S )ac  
        fetches historical positions

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

        :param str symbol: unified contract symbol
        :param int [since]: the earliest time in ms to fetch positions for
        :param int [limit]: the maximum amount of records to fetch, default is 10
        :param dict [params]: extra parameters specific to the exchange api endpoint
        :param int [params.until]: the latest time in ms to fetch positions for
        :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
        r   r8   rP  r9  r=  r>  r  )r  r  r?  rH  r  r  parse_positionsr  )
r  r  rB  r9  r  r  r  r  records	positionss
             r  fetch_position_historyzcoinex.fetch_position_history  s     	V$$Tl
 $GG$)GL!22:wO;;DKKQW<XYX ..626((1	00FE5QQr  c                 `   | j                          | j                  |      }| j                  |dd      }|d   d|d}| j                  |dd      }|||d<   | j	                  |d      }| j                  | j                  ||            }| j                  |di       }	| j                  |	|      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>`
        r  r  r8   r   )r  r  r  r  r  r  )	r  r  r  r  r  r  r  r  r  )
r  r  r6  r  r  r  r  r  r  r  s
             r  close_positionzcoinex.close_position  s     	V$9Tl$

 **6;P$#0GK 6?399$++gv:VW: ~~h3f--r  c                     | j                  | j                  d      }| j                  |dd      }d}t        t        |   |||      \  }}||dk(  s|du rd}||gS )aP  
 @ignore
        marginMode specified by params["marginMode"], self.options["marginMode"], self.options["defaultMarginMode"], params["margin"] = True or self.options["defaultType"] = 'margin'
        :param dict params: extra parameters specific to the exchange api endpoint
        :returns Array: the marginMode in lowercase
        r  rE   FNTrn  )r  r   r  r  r5   r{  )r  
methodNamer  defaultValuer  r|  r(  r  s          r  r{  z$coinex.handle_margin_mode_and_params  ss     &&t||]C>>&(E:
"64Nz[acop
Fx'X-='
F##r  c                 "    | j                         S N)milliseconds)r  s    r  noncezcoinex.nonce   s      ""r  GETc                 z   | j                  ||      }|d   }|d   }| j                  d   |   dz   |z   dz   |z   }	| j                  || j                  |            }
t	        | j                               }|dk(  r|j                  d      }| j                  |dd      }t        |      }| j                  ||dz
  d      }|j                  d      }t        |      }| j                  ||dz
  d      }|dk(  rV|d	k(  s|d
k(  rL| j                  |d      }|8d}| j                  | j                  d|      }|dz   | j                         z   |
d<   |dk(  r| j                          | j                  | j                  |d|
      }
| j                  |
      }
| j!                  |
      }| j#                  | j%                  |dz   | j&                  z         d      }|j)                         | j                  d}|dk(  s|dk(  r
|	d|z   z  }	nd|d<   |}n|dk(  s|dk(  r|
r|	d| j+                  |
      z   z  }	n|dk(  r| j                          | j                  | j                  |d|
      }
| j                  |
      }
| j!                  |
      }| j#                  | j%                  |dz   | j&                  z         d      }|j-                         dd}|dk(  s
|dk(  s|dk(  r	|	d|z   z  }	n| j/                  |
      }n|d k(  r| j                          | j                  |
      }
| j!                  |
      }|dz   |z   dz   |z   }|dk(  r| j/                  |
      }||z  }n
|r|d|z   z  }||| j&                  z   z  }| j#                  | j%                  |      d      }dd| j                  ||d!}|dk7  r
|r|	d|z   z  }	|	|||d"S )#Nr   r   r   r  POSTr  _r9  r9  r  r  r   r  r   )	access_idr  z&secret_key=sha256)AuthorizationAccessIdre  PUT?z!application/x-www-form-urlencodedContent-Typer   r   r   )ri  toncemd5zapplication/json)rk  ro  DELETEr<   )ro  AcceptzX-COINEX-KEYzX-COINEX-SIGNzX-COINEX-TIMESTAMP)urlrD  bodyheaders)implode_paramsr   r  extract_paramsrt  rd  r7  r  r  r  r   r  check_required_credentialsr  apiKeykeysort	rawencodehashencodesecretrs  	urlencodeupperjson)r  pathr   rD  r  rv  ru  r;   
requestUrlrt  r  rd  r:  	firstPartnumPartslastPart	lastWordsnumWordslastWordr  r  r  
urlencoded	signaturepreparedStrings                            r  signzcoinex.sign#  s   ""40a&V
iiz*S07:S@4G		&$"5"5d";<DJJL!VJJsOE((26I5zH''x!|R@H s+I9~H''	8a<DHW$8w+>(hBV !% 0 0 E ( -I#t||ZSH)1C$++-)GE+&++++-KK![["! E LL'E.J		$++j>.IDKK.W"XZbcI!*!2 KKG %Vu_sZ''*M'!8#z5F'FsT^^E222$//1!%"%  U+!^^E2
 IIdkk*~2MPTP[P[2[&\^cd	%.__%6$6 eO8);53++C99U+DD//1U+!^^E2
!'#!7#!=!DV#99U+D"d*N"cJ&66N%$++"55 IIdkk.&A8L	$60$(KK%.*/ V#!sZ//fdwOOr  httpCodereasonrt  rD  rv  ru  c
                 x   |y | j                  |d      }
| j                  |d      }| j                  |d      }|
dk7  s|dk7  rw|dk7  rr|j                         dk7  r_|s]| j                  dz   |z   }| j	                  | j
                  d	   ||       | j                  | j
                  d
   |
|       t        |      y )Nr  r  r  r&  Success	Succeededr   r  r  )r  r  rs  r8   throw_broadly_matched_exceptionrH  throw_exactly_matched_exceptionr$   )r  r  r  rt  rD  rv  ru  r  requestHeadersrequestBodyr  r  r  feedbacks                 r  handle_errorszcoinex.handle_errors  s    &1x0""8Y7CKg2K9OV]VcVcVeimVmw{ww}w.H001I7T\]001I4QYZ))r  c                    | j                          |t        | j                  dz         | j                  |dd      }| j	                  |d      }|t        | j                  dz         | j                  |      }|d   d|d}| j                  d	||      \  }}|||d
<   |||d<   | j                  | j                  ||            }	| j                  |	dg       }
| j                  |
ddd      }| j                  ||||      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 parameterr8   r   )r  r  r  r>  r=  r9  r  r  rF   )r  r(   r8   r  r  r  r?  (v2PrivateGetFuturesPositionMarginHistoryr  r  parse_margin_modificationsr  )r  r  r  rB  r9  r  r  r  r  r  r  modificationss               r  fetch_margin_adjustment_historyz&coinex.fetch_margin_adjustment_history  s"    	>#DGG.j$jkk((}M
6<0#DGG.o$oppV$Tl$%

 22:wO$)GL!$GG@@WV\A]^4 ~~h377dHfU00uUUr  rb  )}__name__
__module____qualname__r   r  r   r  r#   r   r  r  r  dictr   r  rt  r  r   r   r   r   r$  r-  r   rA  rG  r   rJ  r    rL  rI  rG  rR  rY  rm  rr  ru  rx  r   r}  r   r  r   r  floatr  r   r   r   r  r  r   r  r  r  r
  r  r  r"  r%  r'  r
   r,  r1  r	   r+  rB  r   rN  rQ  rI  rw  rz  r   r  r   r  r  r   r  r  r  r  r   r  r  r  r  r   r  r!   r   r  r  r  r"   r   r  r  r  r$  r'  r   r-  r2  r   r7  r=  rD  rG  rC  rM  rL  r   rR  rQ  r[  r]  r{  rd  r  r  r  r  __classcell__)r  s   @r  r5   r5      sS
   E
# E
N ') |Z || $& ;$v, ;&SDL Sj\|>4 > >6 >@ 02 F13 F1f F1P 04B G1W G17 G1R !# 4s 4, :<B O?s O?3 O?bE Ev E EN 6:UW +I3 +Is +I# +I\`af\g +IZ 57 @6 @6;N @6D )+ C{ CJ

T 

6 

EX 


 
4 
, 26DW[df 0H# 0Hc 0HQT 0Hkoptku 0Hd +- 3)j )+ )8 )+ )> .0 )8 $& 3( 36	: 	:D Dv D DL RT N N5 N& os{} P,3 P,i P,y P,Z_ P,hk P,d gksu l.3 l.i l.y l.RW l.`c l.\ @B yD$6 yd5k yv 04B n n` `drv  @B E.S E.# E.Y E.i E.Y\ E.lo E.N 37r Y.s Y.C Y.v /32 )
 )
V 26b U.c U.3 U.n <@daenp n=S n= n=[^ n=`	 /3TXac  3 c hlmrhs , 154VZce U# US UPS Ujnotju U& 8: !:3 !:n !:F 79 !:# !:^ !:F
h 
R` 
2 -1tRV_a Q=c Q= Q=C Q=f 26b SPw SPT(^ SPj 24 =4S =4~Ct CV CJ >B" !]# !]s !]Z 9=R ]S ]# ]T 7;2 *BG *B- *BX $|J\ , MO :3 :xD
d D
F D
N` D
L =? H He HCU H @B KC K KFX K 37TX\eg ?C ?s ?RU ?B 68 &6 &6K &6P :< 
7S 
7 
7(
6 (
[ (
T? 6:" )77 )7 )7V DHPR 9=S 9=% 9=# 9=Wb 9=v:s : 8<$]ajl ?Y ?YC ?YWZ ?YBa
T a
X a
Q\ a
F [] .S .% .c .c .an .`:
t 
x 
= 
" +/TPT]_ 5BC 5Bs 5B# 5Bdhivdw 5Bn -1tRV_a 6Ec 6E 6EC 6Efjkvfw 6Ep *.Dt\^ 3E3 3Ec 3E 3Ecghsct 3Ej
t 
V 
Oa 
B >@ &= &=DV &=P 15DW[jnwy 0Q# 0Qc 0QQT 0Qdg 0Q  C  DR  S 0Qd
$ 
 
. 
< TV .S . .U .` LN "C "s "H
 
4 <> 2?s 2?h? ?B 24 &1S &1 &1P
t 
V 
x 
* @DRV_a FRS FR FRC FRfjksft FRP =A 9.S 9.	 9.PU 9.v @BPT $ #  b$T [Pzc 3 S # X\ dg  =Adaetx  BD =Vc =V =V[^ =Vnq =V  IM  N`  Ia =Vr  r5   N)9ccxt.base.exchanger   ccxt.abstract.coinexr   ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   typingr#   ccxt.base.errorsr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   ccxt.base.decimal_to_precisionr2   ccxt.base.preciser3   r5    r  r  <module>r     s    ( , u  u  u  u  u  u  u  u  * 0 - - . ' & . ) * ) . 1 + 4 %nZVX{ nZVr  