
    i                    d   d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ 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m)Z) d dlm*Z* d dlm+Z+ d dl,m-Z- d dl.m/Z/  G d dee          Z0dS )    )Exchange)ImplicitAPIN)Balances
CurrenciesCurrencyIntLeverage	LeveragesMarginModificationMarketNumOrderOrderRequest	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeeInterfaceTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)RateLimitExceeded)ExchangeNotAvailable)RequestTimeout)	TICK_SIZE)Precisec                       e Zd Z fdZi fdefdZi fdee         fdZd Z	d Z
dmd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Zdi fd
edefdZdmd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dmdedefdZdmd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  Z&dmd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'e-f
d(Z.di fd
ed$e+d%e,d&e)d'e-f
d)Z/i fd*ee0         dee'         fd+Z1di fd
e2fd,Z3ddi fd-ed
ed$e+d%e,d&e-d'e-fd.Z4di fd-ed
e2fd/Z5di fd
e2fd0Z6di fd-ed
e2fd1Z7dddi fd
e2dedefd2Z8dddi fd
e2dededee'         fd3Z9dddi fd
e2dededee'         fd4Z:i fd5efd6Z;i fd5efd7Z<dmd8e=fd9Z>dmd8e=fd:Z?dmd8e=fd;Z@dddi fd
e2dedefd<ZAdi fdefd=ZBi fd
efd>ZCdmdefd?ZDdi fd@ed
e2fdAZEdi fdBed
e2fdCZFdi fdefdDZGdmdefdEZHi fd
efdFZIdmdedeJfdGZKi fd
edeJfdHZLi fd
edeJfdIZMdddi fd
e2dedefdJZNi fd
efdKZOdmdefdLZPdi fdefdMZQdi fd5ed&e)fdNZRdO ZSdddi fd
e2dedefdPZTdmd8e=deUfdQZVi fd5ed&e)dRedSedeWf
dTZXdU ZYdmd8e=fdVZZdddi fd5e2dedefdWZ[dddi fd5e2dededeeU         fdXZ\dddi fd5e2dededeeU         fdYZ]dmdefdZZ^i fd
efd[Z_i fd\Z`ddddi fd5e2d
e2dedefd]Zadmdefd^Zbi fd
ed5ed&e)fd_Zci fd
ed5efd`Zddmd8e=fdaZedi fdbefdcZfdnddZgdi fdee         dehfdeZidmdejfdfZki df fdg	Zldh Zmg dii ddfdjZndk Zoddddi fd
e2d$e2de-de-deeJ         f
dlZp xZqS )ocoinexc                    |                      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d3d4d5dd6dd7dd8dd9dd:dd;dd<dd=d4d>dd?dd@ddAd4dBddCdi dDddEddFddGddHddIddJddKddLddMddNddOddPddQddRddSddTddddddddddddU
dVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdgdhdhdidjdkdldmdndodpdqdqdqdqdqdqdqdqdqdqdqdqdqdqdrii dsdtdudtdvdtdwdtdxdtdydtdzdtd{dtd|dtd}dtd~dtddtddqddqddtddtddtdtddddtdtddqdqdqdtdtdtdi dydtddtddtddtddtddtddddddddddddddddtddqddtddtddtidtdtdtdtdtddtdtddtddtdtdtdtd	ddpdqdqdqdqdqdqdqdqdqdqd
idqdtddtdtddddtdtdtdtdtdtdtdi ddqddqddddddddddddddddtddtddddtddddddddddddddddidpi ddqddqddqddqddqddqddqddqddqddqddqddqddqddqddqddqddqdqdqdqdii ddqddtddqddtddtddqddtddtddtddqddtddtddtddtddqddtddti ddtddqddtddddddddtddddtddtddtddddqddddtddddtdqdqdtdqdqdtdqdqdi ddtddtddtddtddtddtddtddtddtddtddtddtddtddtddqddqddi ddddtddqddddddqddddddddd dqddqddddddqddqddddqdddddqdqddddddddd	d
dddd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iddddddd d!id"t          d#t
          t          t          t          t          t          t          t          t          t          t          t          d$t
          t          d%d&          S ('  Nidr,   nameCoinExversionv1	countriesCN	rateLimitg      @proT	certifiedhasCORSspotmarginswapfutureFoption	addMarginborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelOrdercancelOrderscreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreateReduceOnlyOrdercreateStopLossOrdercreateTakeProfitOrdercreateTriggerOrder	editOrderfetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressByNetworkfetchDepositAddressesfetchDepositsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLeveragesfetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenOrders
fetchOrderfetchOrderBookfetchPositionfetchPositions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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/deposit-withdraw-configz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-order)zfutures/user-dealszfutures/order-dealszfutures/pending-positionzfutures/finished-positionzfutures/position-margin-historyz futures/position-funding-historyzfutures/position-adl-historyzfutures/position-settle-historyz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   )r2   v2r   gMbP?)makertakerr   g        g-C6?)BCHBTCLTCETHZECDASH)tradingfundinglimitsamountminmaxoptionsx-167673045linearfillResponseFromRequest0BSCTRC20ERC20)BEP20TRXr   )brokerId!createMarketBuyOrderRequiresPricedefaultTypedefaultSubTyperX   accountsByIdnetworkscommonCurrenciesACMActiniumprecisionMode
exceptions)232425343536213107600601602606)zip not allow visitzservice too busy)exactbroad)deep_extendsuperr,   describer)   r   r   r'   r(   r&   r"   r$   r#   )self	__class__s    _/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/async_support/coinex.pyr   zcoinex.describe   sG   fd 3 3 < < > > MA
(MA
HMA
 tMA
 $	MA
 MA
 4MA
  !MA
"  OOO $O 	O
 %O %O TO $UO 'O "4O tO O 'O /O ,UO  0!O" t#O O$ %O& ('O( &t)O* (+O, %d-O. T/O0 1O2 &t3O4 +E5O6 )%7O8 $T9O: ';O< (=O> "4?O@ &tAOB /COD (EO O OF  GOH *:IOJ +DKOL &tMON #DOOP *4QOR $TSOT "5UOV *4WOX +DYOZ  [O\ !$]O^ %d_O` /aOb +JcOd eOf !%gO O Oh  iOj dkOl "4mOn doOp !$qOr  sOt !$uOv %ewOx )%yOz t{O| }O~ TO@ tAOB "4COD #DEOF  GOH !$IO OJ $)$( $$)'+#!%#(  ]O O O#MA
B  CMA
` ~67'I(J	  075N aMA
z  *+4534459:-.+,+,-.12,-,-,--.   & 12 8"  6r  1"	 
 3B  4R  +B  B2  8  *2  -b  :2  -a  ,Q  22   6r! " *2# $ /1-.,-23023523457834<>46CE=     @!3R!7! *2! *2	!
 .r! 0! (! *6! +F! +F! /! 0! 0! 3B! 3A!  3B!!" 1"#!$ 3B%! !* DF4624CE35    6835-3247=:<?ACE:<
# 
#yG  G R $%$%+,34-.12,-,-67,-   (  23+--..03523,-1213020246137979   "!4a!4a! .r! /	!
 3B! 4R! +B! 0! +B! /! 1"! 0! 4R! 0! 1"!  5b!!" 1"#!$ 57579;>@13-! ! !%*) *)ST Tn   +Q "A  #A  *1	 
 *1  )!  )!  )!  )!  -a  -a  ,Q  ,Q  ,Q  ,Q   3A! " ;A# $ 78;<56)     2+ *A+ 5r+  0+  /	+ 
 <R+  8+  5b+  22+  5b+  4Q+  7+  3B+  1"+  ;B+  ;A+   5b!+ " 5b#+  + $ .r%+ & =a'+ ( 6r)+ * 0++ , 6q-+ . 1!/+ 0 221+ 2 6q3+ 4 75+ 6 .r7+ 8 /9+ : 3A;+ < 9!=+ > 4Q?+ @ 5bA+ B 9!C+ D :2E+  + F 34348:9:?@@B<=?@U+  +  + X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! 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! 0!F :<89469;:<?AABFG68>@@B>@@B_0! 0! 0![^  ^ 3x xmO O{MA
Z "" 
 "$$$% &! !	 [MA
z   {MA
F )59%"*-t( C! #""  GMA
h z!iMA
n YoMA
p  +---.(,,('''   +;(< ! qMA
 M M M	    returnc                 	  K   |                      |           d {V }|                     |dg           }t          |                                          }i }t	          dt          |                    D ]}||         }||         }|                     |d          }	|                     |d          }
|                     |	          }|                     |                     |d                    }| 	                    |          }|                     |d          }|                     |d          }|                     |d          }| 	                    |          }|                     |d	          }| 	                    |          }|                     |d
          }| 	                    |          }|                     ||           |	d |d d |o|||||d d d|d d|d ddd||<   |                     ||         d          }|||nt          j        ||          }|                     ||         d          }|r|n|}|                     ||         d          }|r|n|}|                     ||         d         d         d          }|||nt          j        ||          }|                     ||         d         d         d          }|||nt          j        ||          }|                     ||         d          }|||nt          j        ||          }|                     ||         di           }||
|
d d d d|                     |d	          d d|                     |d
          d dd|o|||||d
}|||
<   |||         d<   |o|||         d<   |||         d<   |||         d<   |                     ||         dg           }|                    |           |||         d<   | 	                    |          ||         d<   | 	                    |          ||         d<   | 	                    |          ||         d         d         d<   | 	                    |          ||         d         d         d<   |S )Ndatar   assetchainwithdrawal_precisioncan_depositcan_withdrawwithdraw_tx_feedeposit_least_amountwithdraw_least_amountr   )r   depositr   )r.   	numericIdcodeinfor/   activer  r   fee	precisionr   r  r  r   r   r   r  r   )
r  r.   networkr/   r   r  r  r   r  r  r  r  )v1PublicGetCommonAssetConfig
safe_valuelistkeysrangelensafe_stringsafe_currency_codeparse_precisionparse_numberr*   
string_minsafe_numberappend)r   paramsresponser  coinsresulticoincurrency
currencyId	networkIdr  precisionStringr  
canDepositcanWithdraw	feeStringr  minNetworkDepositStringminNetworkDepositminNetworkWithdrawStringminNetworkWithdrawminFeeStringdepositAvailablewithdrawAvailableminDepositStringminWithdrawStringminPrecisionStringr   r  r  s                                  r  fetch_currencieszcoinex.fetch_currencies  s     ::6BBBBBBBB( x44TYY[[!!q#e**%% `	] `	]A8DDzH))(G<<J((7;;I**:66D"2243C3CHNd3e3effO))/::I=AAJ//(NCCK((3DEEI##I..C&*&6&6xAW&X&X# $ 1 12I J J'+'7'7BY'Z'Z$!%!2!23K!L!Lvt,,4$!%   (8[) +!* $(#'# #
 $5#'$ $
 $6#'% %    t4  ++F4L%@@L$-9-AyyHZ[dfrHsHs#vd|YGG.8Ozz?O $tj I I0; SBS#//tX0Fy0QSXYY&2?O?W#:#:^e^p  rI  K[  _\  _\  $ 0 0h1G
1SUZ [ ['3ARAZ$<$<ahas  uM  O`  ba  ba!!%!1!1&,!L!L*9K9S__ZaZlm|  Q  [R  [R"vd|ZDDH $  $# 
  $//:PQQ#   
  $//:QRR#! !  %4%'&/ G2 #*HY'/F4L$%5%K:KF4L"&6F4L#'8F4L$??6$<<<DKK!!!#'F4L "&"3"3L"A"AF4L(,(9(9:L(M(MF4L%7;7H7HIY7Z7ZF4L"9-e48<8I8IJ[8\8\F4L":.u55r  c                    K   |                      |          |                     |          g}t          j        |  d{V }|d         }|d         }|                     ||          S )al  
        retrieves data on all markets for coinex
        :see: https://docs.coinex.com/api/v2/spot/market/http/list-market
        :see: https://docs.coinex.com/api/v2/futures/market/http/list-market
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nr   r   )fetch_spot_marketsfetch_contract_marketsasynciogatherarray_concat)r   r$  promisesUnresolvedpromisesspotMarketsswapMarketss         r  fetch_marketszcoinex.fetch_marketsi  s{       ##F++''//
 !);<<<<<<<qkqk  k:::r  c                   K   |                      |           d {V }|                     |dg           }g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }	|                     |          }
|                     |	          }|
dz   |z   }|                    i d|d|d	|
d
|dd d|d|	dd dddddd dddddddd dddd d |                     |d          |                     |d          d d d d d |                     | 	                    |                     |d                              |                     | 	                    |                     |d                              dd d d|                     |d           d dd d dd d dd!d |d"           |S )#Nr  r   marketbase_ccy	quote_ccy/r.   symbolbasequotesettlebaseIdquoteIdsettleIdtyper:   Tr;   r<   Fr=   r>   r  contractr   taker_fee_ratemaker_fee_ratebase_ccy_precisionquote_ccy_precisionr   pricer   
min_amountleverager   rZ  costinverser   r   contractSizeexpiryexpiryDatetimestrike
optionTyper  r   createdr  )
v2PublicGetSpotMarket	safe_listr  r  r  r  r#  r"  r   r  )r   r$  r%  marketsr'  r(  rH  r.   rP  rQ  rM  rN  rL  s                r  r=  zcoinex.fetch_spot_marketsz  s     33F;;;;;;;;* ..6266q#g,,'' :	 :	AQZF!!&(33B%%fj99F&&v{;;G**622D++G44ECZ%'FMM 2b2&2 2 	2
 $2 &2 72 D2 2 2 $2 2 %2 %2 $2  E!2" $#2$  ))&2BCC))&2BCC $"&""//0D0DTEUEUV\^rEsEs0t0tuu!..t/C/CDDTDTU[]rDsDs/t/tuu   $#! !
  $//EE# 
  $# 
  $#  $  c2 2 2 2 2 2 2f r  c                 (  K   |                      |           d {V }|                     |dg           }g }t          dt          |                    D ]<}||         }| j        }|                     |dg           }|                     |d          }	|	dk    }
|	dk    }|                     |d          }|                     |d          }|                     |d	          }|                     |          }|                     |          }|	dk    rd
n|}|                     |          }|dz   |z   dz   |z   }t          |          }|                    i d|d|d|d|d|d|d|d|dddddddddddddd ddd|
||d         d          |d         d!         |                     d"          d d d d |                     | 	                    |                     |d#                              |                     | 	                    |                     |d$                              d%| 
                    |d          | 
                    ||d&z
            d'| 
                    |d(          d d'd d d'd d d'd)d |d*           >|S )+Nr  r   r]  contract_typer   r`  rH  rI  rJ  USDTrK  :r.   rL  rM  rN  rO  rP  rQ  rR  rS  r<   r:   Fr;   Tr=   r>   r  rT  r   r   r   1rW  rX  rY  r   r   r[  r\  r_  )v2PublicGetFuturesMarketrh  r  r  r   r  r  r#  r   r  r"  )r   r$  r%  ri  r'  r(  entryr   	leveragessubTyper   r`  r.   rP  rQ  rM  rN  rR  rO  rL  leveragesLengths                        r  r>  zcoinex.fetch_contract_markets  s     66v>>>>>>>>, ..6266q#g,,'' B	 B	AAJE9Duj"==I&&uo>>G)F)+G!!%22B%%eZ88F&&uk::G**622D++G44E")X"5"5vvFH,,X66FCZ%'#-6F!)nnOMM 2b2&2 2 	2
 &2 &2 72 H2 2 2 %2 2 %2 %2 $2  D!2" &#2$ #i1i1 $ 1 1# 6 6"&""//0D0DTEUEUV[]qErEr0s0stt!..t/C/CDDTDTUZ\qDrDr/s/stt   $//	1==#//	?Q;NOO! !
  $//|DD# 
  $# 
  $#  $  c2 2 2 2 2 2 2f r  NrH  c                    |                      |d          }|                     d |          }|                     |di           }|                     |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|          S )NdatetickerlastrL  	timestampdatetimehighlowbidbuy	bidVolume
buy_amountasksell	askVolumesell_amountvwapopenclosepreviousClosechange
percentageaveragevolvolume)
baseVolumequoteVolumer  )safe_integersafe_symbolr  r  safe_tickeriso8601safe_string_2)r   rv  rH  rx  rL  rw  s         r  parse_tickerzcoinex.parse_ticker-  s   R %%ff55	!!$//266// !
f!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4##FE22!
 ))&,??!
 4##FF33!
 ))&-@@!
 D!
 D$$VV44!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ ,,VUHEE)!
 !
 !
* +  	r  rL  c                   K   |                                   d{V  |                     |          }d|d         i}d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |d         |          S )aa  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot001_market007_single_market_ticker
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http008_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>`
        NrH  r.   r<   r  )load_marketsrH   v1PerpetualPublicGetMarketTickerextendv1PublicGetMarketTickerr  )r   rL  r$  rH  requestr%  s         r  fetch_tickerzcoinex.fetch_tickerq  s       !!!!!!!!!V$$fTl
 &> 	X!BB4;;wX^C_C_````````HH!99$++gv:V:VWWWWWWWWHn   &!16:::r  symbolsc                 N  K   |                                   d{V  |                     |          }d}|+|                     |d          }|                     |          }|                     d||          \  }}d}|dk    r|                     |           d{V }n|                                  d{V }|                     |d          }|                     |d          }	|                     |di           }
t          |
	                                          }i }t          dt          |                    D ]S}||         }|                     |dd|          }|d         }|                     |	|
|         d	|          }||d<   |||<   T|                     |d|          S )
a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot001_market008_all_market_ticker
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http009_market_ticker_all
        :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   rw   r<   r  ru  rv  rL  )ru  rv  )r  market_symbolsr  rH  handle_market_type_and_params#v1PerpetualPublicGetMarketTickerAllv1PublicGetMarketTickerAllr  r  r  r  r  safe_marketr  filter_by_array_tickers)r   r  r$  rH  rL  
marketTypequeryr%  r  rx  tickers	marketIdsr'  r(  marketIdmarketInnerrv  s                    r  fetch_tickerszcoinex.fetch_tickers  s      !!!!!!!!!%%g..__Wa00F[[((F >>~vW]^^
E!EEeLLLLLLLLHH!<<>>>>>>>>Hv x00%%dF33	//$"55((	q#i..)) 		$ 		$A |H**8T4LLK *F&&!!(+( (  F  &F8#F6NN++FHgFFFr  c                    K   |                      |           d{V }|                     |di           }|                     |d          S )aP  
        fetches the current integer timestamp in milliseconds from the exchange server
        :see: https://docs.coinex.com/api/v2/common/http/time
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        Nr  rx  )v2PublicGetTime	safe_dictr  )r   r$  r%  r  s       r  
fetch_timezcoinex.fetch_time  sZ       --f55555555 ~~h33  {333r  r   limitc                   K   |                                   d{V  |                     |          }|d}|d         |dd}d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |di           }|                     |di           }|                     |d	          }	|                     |||	          S )
a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://docs.coinex.com/api/v2/spot/market/http/list-market-depth
        :see: https://docs.coinex.com/api/v2/futures/market/http/list-market-depth
        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        Nr   r.   r   )rH  r  intervalr<   r  depth
updated_at)r  rH  v2PublicGetFuturesDepthr  v2PublicGetSpotDepthr  r  parse_order_book)
r   rL  r  r$  rH  r  r%  r  r  rx  s
             r  fetch_order_bookzcoinex.fetch_order_book0  s7      !!!!!!!!!V$$=ETl
 

 &> 	U!99$++gv:V:VWWWWWWWWHH6 "66t{{7F7S7STTTTTTTTH4 ~~h33tWb11%%e\::	$$UFI>>>r  c                    |                      |dd          }||                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d	          }	|	d
nd}
|                     ||d |
          }|d         }|                     |d          }d }|                     |dd          }|0|                     |d          }|                     |          }||d}|                     |d          }|dk    rd}n|dk    rd}d }|d         dk    r@|                     |d          }|dk    rd}n|dk    rd}||                     |d          }n|                     |d          }|                     |||                     |          |||d ||||||d|          S )Ncreate_timer   date_msr.   order_idrZ  r   rH  market_typer:   r<   rL  
deal_moneyr  deal_fee	fee_assetr^  r*  rolern  r   2r   rS  sider   r     r}  )r  rx  ry  rL  r.   orderrS  r  takerOrMakerrZ  r   r^  r  )safe_timestamp_2r  r  r  r  r  
safe_trader  )r   traderH  rx  tradeIdorderIdpriceStringamountStringr  r  r   rL  
costStringr  feeCostStringfeeCurrencyIdfeeCurrencyCoder  r  rawSides                       r  parse_tradezcoinex.parse_trade  s_   ~ ))%GG	))%;;I""5$//""5*55&&ug66''x88##E844%%e];;
!+!3ff&!!(FD+FF!%%e\::
**5%DD$ ,,UK@@M"55mDDO%+ C ''v663"LLS  "L&>V##''v66G!||A|''v66##E622D"Y//( " 
  
   	r  sincec                   K   |                                   d{V  |                     |          }d|d         i}|||d<   d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |d         |||          S )a  
        get the list of most recent trades for a particular symbol
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot001_market005_market_deals
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http011_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>`
        NrH  r.   r  r<   r  )r  rH  v1PerpetualPublicGetMarketDealsr  v1PublicGetMarketDealsparse_trades)r   rL  r  r  r$  rH  r  r%  s           r  fetch_tradeszcoinex.fetch_trades  s       !!!!!!!!!V$$fTl
 $GG&> 	W!AA$++gW]B^B^________HH!88Wf9U9UVVVVVVVVH&   &!165%HHHr  c                   K   |                                   d{V  |                     |          }d|d         i}d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     ||          S )a  
        fetch the trading fees for a market
        :see: https://docs.coinex.com/api/v2/spot/market/http/list-market
        :see: 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>`
        NrH  r.   r:   r  r   )r  rH  rg  r  ro  rh  r  parse_trading_fee)r   rL  r$  rH  r  r%  r  r'  s           r  fetch_trading_feezcoinex.fetch_trading_fee   s      !!!!!!!!!V$$fTl
 &> 	Y!77GV8T8TUUUUUUUUHH, "::4;;wPV;W;WXXXXXXXXH, ~~h33a,,%%ff555r  c                   K   |                                   d{V  d}|                     dd|          \  }}d}|dk    r|                     |           d{V }n|                     |           d{V }|                     |dg           }i }t          dt          |                    D ]Y}||         }|                     |d          }|                     |dd|          }	|	d         }
| 	                    ||	          ||
<   Z|S )a  
        fetch the trading fees for multiple markets
        :see: https://docs.coinex.com/api/v2/spot/market/http/list-market
        :see: 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{   r<   r  r   rH  rL  )
r  r  ro  rg  rh  r  r  r  r  r  )r   r$  rS  r%  r  r'  r(  rp  r  rH  rL  s              r  fetch_trading_feeszcoinex.fetch_trading_fees`  sH      !!!!!!!!!99:LdTZ[[f6>>!::6BBBBBBBBHH. "77????????H* ~~h33q#d))$$ 	C 	CAGE''x88H%%hdDAAFH%F!33E6BBF6NNr  c                     |                      |d          }|                     ||          }|||                     |d          |                     |d          dddS )NrH  rV  rU  T)r  rL  r   r   r  	tierBased)r  r  r"  )r   r  rH  r  rL  s        r  r  zcoinex.parse_trading_fee  sm    ??311!!(F33%%c+;<<%%c+;<<
 
 	
r  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r         r     )safe_timestampr"  )r   ohlcvrH  s      r  parse_ohlcvzcoinex.parse_ohlcv  s     q))UA&&UA&&UA&&UA&&UA&&
 	
r  r   c                   K   |                                   d{V  |                     |          }|d         |                     | j        ||          d}|||d<   d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }	|                     |	||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot001_market006_market_kline
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http012_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
        Nr.   )rH  rS  r  r<   r  )	r  rH  r  r   v1PerpetualPublicGetMarketKliner  v1PublicGetMarketKlinerh  parse_ohlcvs)
r   rL  	timeframer  r  r$  rH  r  r%  r  s
             r  fetch_ohlcvzcoinex.fetch_ohlcv  s'      !!!!!!!!!V$$Tl$$T_iKK
 
 $GG&> 	W!AA$++gW]B^B^________HH!88Wf9U9UVVVVVVVVH4 ~~h33  vy%GGGr  c                   K   |                                   d {V  |                     |d          }|                     |d          }d }||                     |          }|d         }n|t          | j        dz             |                     |ddg          }d|i}|                     |                     ||                     d {V }d|i}|                     |di           }|                     |di           }	|                     |di           }
|                     |d	i           }|                     |d
i           }| 	                                }|                     |d          }| 
                    |          }|                     |	d          |d<   |                     |
d          |d<   |                     |d          }|                     |d          }t          j        ||          |d<   |||<   | 	                                }|                     |d          }| 
                    |          }|                     |	d          |d<   |                     |
d          |d<   |                     |d          }|                     |d          }t          j        ||          |d<   |||<   |                     |          S )NrL  rH  r.   za fetchMarginBalance() fetching a margin account requires a market parameter or a symbol parameterr  r  can_transferbalanceloaninterestsell_asset_type	sell_typefreetotaldebtbuy_asset_typebuy_type)r  r  rH  r   r.   omitv1PrivateGetMarginAccountr  r  accountr  r*   
string_addsafe_balance)r   r$  rL  r  rH  r  r%  r'  r  r  r  r  r  sellAccountsellCurrencyIdsellCurrencyCodesellDebtsellInterest
buyAccountbuyCurrencyIdbuyCurrencyCodebuyDebtbuyInterests                          r  fetch_margin_balancezcoinex.fetch_margin_balance  s     !!!!!!!!!!!&(33##FH55[[((Fd|HH#DG  /R  %R  S  S  S6Hh#788h
 77GV8T8TUUUUUUUUH (#x44t^R88i44tVR00??4R88llnn))$0ABB22>BB"..t[AAF#//{CCG##D+66''+>>%0<HHF#. \\^^
((/?@@11-@@!--dJ??
6"..ujAA
7""444&&x<<$/EE
6",  (((r  c                 P  K   |                                   d {V  |                     |           d {V }d|i}|                     |di           }t          |                                          }t          dt          |                    D ]}||         }|                     |          }|                     ||i           }	|                                 }
| 	                    |	d          |
d<   | 	                    |	d          |
d<   |
||<   | 
                    |          S )Nr  r  r   	availabler  frozenused)r  v1PrivateGetBalanceInfor  r  r  r  r  r  r  r  r  r   r$  r%  r'  balancescurrencyIdsr(  r+  r  r  r  s              r  fetch_spot_balancezcoinex.fetch_spot_balanceI  s5     !!!!!!!!!55f========* (#??8VR888==??++q#k**++ 	# 	#A$QJ**:66Dooh
B??GllnnG"..wDDGFO"..wAAGFO"F4LL  (((r  c                   K   |                                   d {V  |                     |           d {V }d|i}|                     |di           }t          |                                          }t          dt          |                    D ]}||         }|                     |          }|                     ||i           }	|                                 }
| 	                    |	d          |
d<   | 	                    |	d          |
d<   | 	                    |	d          |
d	<   |
||<   | 
                    |          S )
Nr  r  r   r  r  r  r  balance_totalr  )r  v1PerpetualPrivateGetAssetQueryr  r  r  r  r  r  r  r  r  r  s              r  fetch_swap_balancezcoinex.fetch_swap_balancem  sO     !!!!!!!!!==fEEEEEEEE" (#??8VR888==??++q#k**++ 	# 	#A$QJ**:66Dooh
B??GllnnG"..wDDGFO"..wAAGFO#//IIGG"F4LL  (((r  c                 b  K   |                                   d {V  |                     |           d {V }d|i}|                     |di           }t          dt	          |                    D ]}||         }|                     |d          }|                     |          }|                                 }	|                     |d          |	d<   |                     |d          }
|                     |d          }t          j	        |
|          |	d	<   |	||<   | 
                    |          S )
Nr  r  r   r  r  r  r  lockr  )r  $v1PrivateGetAccountInvestmentBalancer  r  r  r  r  r  r*   r  r  )r   r$  r%  r'  r  r(  r  r+  r  r  r  lockeds               r  fetch_financial_balancezcoinex.fetch_financial_balance  sE     !!!!!!!!!BB6JJJJJJJJ* (#??8VR88q#h--(( 		# 		#AqkG))'7;;J**:66DllnnG"..wDDGFO%%gx88F%%gv66F%0@@GFO"F4LL  (((r  c                   K   d}|                      dd|          \  }}d}|                     d|          \  }}|dn|}|                     |d          }|dk    r|                     |           d{V S |dk    r|                     |           d{V S |dk    r|                     |           d{V S |                     |           d{V S )a;  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account001_account_info         # spot
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account004_investment_balance   # financial
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account006_margin_account       # margin
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http016_asset_query       # swap
        :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>`
        NrP   r;   r<   	financial)r  handle_margin_mode_and_paramsr  r	  r  r  r  )r   r$  r  
marginModes       r  fetch_balancezcoinex.fetch_balance  s%      
!??PTV\]]
F
!??PVWW
F","8XXz
68,,!!226:::::::::6!!00888888888;&&55f=========00888888888r  c                 B    ddddddd}|                      |||          S )Nrejectedr  closedcanceled)r"  r  not_deal	part_dealdonecancelr  r   statusstatusess      r  parse_order_statuszcoinex.parse_order_status  s:    " 
 
 &&999r  c                    |                      |d          }|                     |d          }|                      |d          }|                      | j        d          }d|v rdn|}|                     ||d |          }|                      |d          }|                     |          }	|	|d         }	|                     |d	          }
d }|
d
k    rd}n|
dk    rd}n|                      |d          }|                      |d          }d }|(|                     |d          }|d
k    rd}n|dk    rd}n|}|                      |d          }|dk    rd }|                     i d|                     |dd          d|d|                     |          d|d|                     |d          d| 	                    |          d|d         d|dd dd dd d	|d|                      |d          d|                      |d           d!|                      |d           d"| 
                    |d#          d$| 
                    |d%          |                      |d&          |                      |d'          |                      |d(          |                      |d)          |                      |d*          d |	|                      |d+          d,|d-|          S ).Nr+  r  rH  r   sourcer<   r  rN  r  r   r  r  r}  rS  
order_typer  	client_id r.   r  clientOrderIdry  rx  lastTradeTimestampupdate_timerL  timeInForcepostOnly
reduceOnlyrZ  	stopPrice
stop_pricetriggerPricetakeProfitPricetake_profit_pricestopLossPricestop_loss_pricer  	avg_pricer   deal_amountleftr  )r*  r^  )r^  r  r   filled	remainingtradesr  r  )r  r  r   r  r  r  
safe_orderr  r  r-  r"  )r   r  rH  	rawStatusrx  r  r   	orderTyper  feeCurrencyr  r  rawTyperS  typeIntegerr3  s                   r  parse_orderzcoinex.parse_order  s   V $$UH55	''}==	##E844&&t|]CC'500FF{	!!(FD)DD((<<--m<< /K##E622a<<DD\\DD##E622D""5,77?++E6::Ka!!D((<<B M  
$$$UD*== 
] 
 Y// 
 	 

 !$"5"5e]"K"K 
 d--i88 
 fX& 
 D 
 4 
  
 $ 
 D 
 T%%eW55 
 ))%>> 
 D,,ULAA 
  t//7JKK! 
" T--e5FGG# 
$ $$UL99''{;;&&uh77&&um<<))%88'((
;;  9 
  
  
: ;  	r  r^  c                    K   |                                   d{V  |                     |          }|d         st          | j        dz             d|d<   |                     |dd|d|           d{V S )a  
        create a market buy order by providing the symbol and cost
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade003_market_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>`
        Nr:   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr   rH  r}  )r  rH  r%   r.   create_order)r   rL  r^  r$  rH  s        r  !create_market_buy_order_with_costz(coinex.create_market_buy_order_with_cost!  s       !!!!!!!!!V$$f~ 	ftw)ddeee6;23&&vxdFSSSSSSSSSr  rS  r  r   rZ  c                 
   |                      |          }|d         }|                     |dd          }	|                     |dd          }
|                     |d          }|                     |d          }|                     |d          }|d	k    }|                     ||d
k    |          }|                     |dd          }|                     |d          }|                     |d          }|rD|d         s#t          | j        dz   |d         z   dz             |t          | j        dz             d	|d         i}|	<d}|                     | j
        d|          }|dz   |                                 z   |d<   n|	|d<   |r|s|rr|                     |dd          |d<   |t          | j        dz             ||d<   |r|                     ||          |d<   n|r|                     ||          |d<   n|dk    rdnd}|
|                     ||
          |d<   |                     |dd          |d<   |                     ||          |d<   ||d <   |d!k    r|                     ||          |d"<   |                     ||          |d<   d }|d	k    s|
#|rd|d<   n||d#k    rd}n|d$k    rd%}nd}||d&<   |d!k    rC|
A|r||d<   n||d <   |                     ||          |d"<   |                     ||          |d<   n|d	k    r)|
'|r||d<   n||d <   |                     ||          |d<   n||d<   |d	k    r|dk    rd'}|                     |d(d)d'          \  }}|                     |d*          }|                     |d*          }|r||t          | j        d+z             |                     |          }|                     |          }|                     t)          j        ||                    }||n|}|                     ||          |d<   n3|                     ||          |d<   n|                     ||          |d<   |d!k    s|d,k    r|                     ||          |d"<   |
|                     ||
          |d<   |d	k    s|
:||r6|s|d#k    r|d!k    r|
t          | j        d-z             |rd
|d<   n|||d<   |                     |d.          }d }|                     d(|          \  }}||t1          | j        d/z             ||d.<   |                     |g d0          }|                     ||          S )1Nr<   r1  r3  r9  r;  r>  r<  r>   rH  
MAKER_ONLYposition_id
positionIdr6  r8  z/ createOrder() does not support reduceOnly for rS  z> orders, reduceOnly orders are supported for swap markets onlyzP createOrder() requires a position_id/positionId parameter for reduceOnly ordersr.   r   r   -	stop_typer   zT createOrder() requires a position_id parameter for stop loss and take profit ordersr?  r=  r}  r  r:  r   r  r  rZ  IOCFOKr  effect_typeTrI   r   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ioczA createOrder() only supports the IOC option for stop-limit orders
account_idzA createOrder() requires an account_id parameter for margin orders)r8  rS  r6  r7  r9  r;  r>  r<  )rH  r  safe_value_2r  r  is_post_onlysafe_integer_2r#   r.   r   r   uuid16r  price_to_precisionamount_to_precisionhandle_option_and_paramsr"  r  number_to_stringparse_to_numericr*   
string_mulcost_to_precisionr  r    r  ) r   rL  rS  r  r   rZ  r$  rH  r<   r3  r9  r>  r<  r>   isMarketOrderr7  rS  timeInForceRawr8  r  	defaultIdr   requestSider6  r   r^  r  r  quoteAmountcostRequest	accountIdr  s                                    r  create_order_requestzcoinex.create_order_request1  s   V$$f~**6;PP%%fk>JJ	@@//&2CDD!!&(33($$]Fl4JFSS((MM
))&-@@__V\::
 	F&> t"47-^#^aghnao#o  ss  $s  t  t  t!'  3E  )E  F  F  FfTl
  %I''j)LLH#+c>DKKMM#AGK  #0GK  N	? +U +U'+'8'8a'P'P$%+DG  7M  -M  N  N  N)3&  d151H1HQ^1_1_G-..$ d373J3J6Sb3c3cG/0$(EMMaa(,0,C,CFI,V,VGL)+/+<+<V[RS+T+TGK((,(@(@(P(PGH%&1GFOw+/+B+B65+Q+Q((,(@(@(P(PGH%"H$$)*? 	=,-))'3)U22*+KK+u44*+KK*+K1<.7??y'8! 61;..*5'+'>'>vu'M'MGG$(,(@(@(P(PGH%%X%%)*;! U1;..*5,0,D,DVV,T,T)"GFO  tu}}481<@<Y<YZ`bo  rU  W[  =\  =\916''7766224 
ODL*47  6q  ,q  r  r  r'+'<'<V'D'D&*&;&;E&B&B&*&;&;G<N|]h<i<i&j&j/3/?ddk,0,B,B6;,W,W))(,(>(>vv(N(NGH%%$($<$<VV$L$L!TU]]#'#:#:65#I#I $(,(?(?	(R(R%  i&;".8.  z^u%<%<TW__[d[p*475x+xyyy ?,8)))50>GH-%%fl;;	
!??vVV
F!  +n!nooo$-GL!6  $\  $\  $\  ]  ]{{7F+++r  c                   K   |                                   d{V  |                     |          }|                     |d          }|                     |dd          }	|                     |d          }
|                     |d          }|	du}|
du}|du}|p|}|                     ||||||          }d}|d         r|r@|dk    r|                     |           d{V }nW|                     |           d{V }n:|dk    r|                     |           d{V }n| 	                    |           d{V }n|r>|dk    r| 
                    |           d{V }n|                     |           d{V }n|r<|r|                     |           d{V }n|r|                     |           d{V }n}|r>|dk    r|                     |           d{V }nY|                     |           d{V }n=|dk    r|                     |           d{V }n|                     |           d{V }|                     |d	i           }|                     ||          S )
a	  
        create a trade order
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade001_limit_order
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade003_market_order
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade004_IOC_order
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade005_stop_limit_order
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade006_stop_market_order
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http017_put_limit
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http018_put_market
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http019_put_limit_stop
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http020_put_market_stop
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http031_market_close
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http030_limit_close
        :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 fullfilled, 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
        :param int [params.position_id]: *required for reduce only orders* the position id to reduce
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr8  r9  r;  r>  r<  r:   r  r  )r  rH  r  safe_number_2r"  rm  v1PrivatePostOrderStopLimitv1PrivatePostOrderStopMarketv1PrivatePostOrderLimitv1PrivatePostOrderMarket'v1PerpetualPrivatePostOrderPutStopLimit(v1PerpetualPrivatePostOrderPutStopMarket&v1PerpetualPrivatePostPositionStopLoss(v1PerpetualPrivatePostPositionTakeProfit%v1PerpetualPrivatePostOrderCloseLimit&v1PerpetualPrivatePostOrderCloseMarket#v1PerpetualPrivatePostOrderPutLimit$v1PerpetualPrivatePostOrderPutMarketr  rL  )r   rL  rS  r  r   rZ  r$  rH  r8  r;  stopLossTriggerPricetakeProfitTriggerPriceisTriggerOrderisStopLossTriggerOrderisTakeProfitTriggerOrderisStopLossOrTakeProfitTriggerr  r%  r  s                      r  rN  zcoinex.create_order  sY     : !!!!!!!!!V$$__V\::
))&+~NN#//HH!%!1!1&:K!L!L%T1!5T!A#9#E (>(ZBZ%++FD$vVV&>  	\ 	L7??%)%E%Eg%N%NNNNNNNHH%)%F%Fw%O%OOOOOOOHH7??%)%A%A'%J%JJJJJJJHH%)%B%B7%K%KKKKKKKHH \7??%)%Q%QRY%Z%ZZZZZZZHH%)%R%RSZ%[%[[[[[[[HH. \) \%)%P%PQX%Y%YYYYYYYHH- \%)%R%RSZ%[%[[[[[[[H 	\w)-)S)ST[)\)\#\#\#\#\#\#\)-)T)TU\)])]#]#]#]#]#]#]w)-)Q)QRY)Z)Z#Z#Z#Z#Z#Z#Z)-)R)RSZ)[)[#[#[#[#[#[#[\ ~~h33f---r  ordersc           	        K   |                                   d{V  g }d}t          dt          |                    D ]}||         }|                     |d          }||}n||k    rt	          | j        dz             |                     |d          }|                     |d          }	|                     |d          }
|                     |d          }|                     |d	i           }|d
k    rt          | j        dz   |z   dz             |                     |||	|
||          }|	                    |           | 
                    |          }|d         s#t          | j        dz   |d         z   dz             |d         |                     |          d}|                     |           d{V }|                     |dg           }g }t          dt          |                    D ]v}||         }d}|                     |d          }||dk    rd}nd}|                     |di           }||d<   |                     ||          }|	                    |           w|S )a  
        create a list of trade orders(all orders should be of the same symbol)
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade002_batch_limit_orders
        :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>`
        Nr   rL  z; createOrders() requires all orders to have the same symbolrS  r  r   rZ  r$  r  z! createOrders() does not support z' orders, only limit orders are acceptedr:   & orders, only spot orders are acceptedr.   )rH  batch_ordersr  r  r"  r  r+  )r  r  r  r  r    r.   r  r%   rm  r#  rH  jsonv1PrivatePostOrderLimitBatchr  rL  )r   r  r$  ordersRequestsrL  r(  rawOrderr  rS  r  r   rZ  orderParamsorderRequestrH  r  r%  r  resultsrp  r+  r  itemr  s                           r  create_orderszcoinex.create_orders?	  s      !!!!!!!!!q#f++&& 	0 	0AayH''(;;H~!X%%$TW/l%lmmm##Hf55D##Hf55D__Xx88FOOHg66E//(HbAAKw"47-P#PSW#W  [D  $D  E  E  E44XtT6SXZeffL!!,////V$$f~ 	Jtw)LLvV\~]  aI   I  J  J  JTl IIn55
 
 ::7CCCCCCCCL x44q#d))$$ 	" 	"AGEF$$UF33D199'FF#F??5&"55D#DN$$T622ENN5!!!!r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}d                    |          }d}|d         r5||d<   |                     |                     ||                     d{V }n4||d<   |                     |                     ||                     d{V }|                     |d	g           }g }	t          d
t          |                    D ]X}
||
         }|d         rd	nd}|                     ||i           }|                     ||          }|	                    |           Y|	S )a	  
        cancel multiple orders
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade016_batch_cancel_order
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http021-0_cancel_order_batch
        :param str[] ids: order ids
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz* cancelOrders() requires a symbol argumentrH  r.   ,r:   	batch_ids	order_idsr  r   r  )r   r.   r  rH  join v1PrivateDeleteOrderPendingBatchr  &v1PerpetualPrivatePostOrderCancelBatchr  r  r  rL  r#  )r   idsrL  r$  rH  r  	idsStringr%  r  r  r(  rp  dataRequestr  r  s                  r  cancel_orderszcoinex.cancel_orders	  s      >#DG.Z$Z[[[!!!!!!!!!V$$fTl
 HHSMM	&> 	g#,GK !BB4;;wX^C_C_````````HH#,GK !HHU\^dIeIeffffffffHx x44q#d))$$ 	" 	"AGE$*6N?&&K??5+r::D$$T622ENN5!!!!r  r.   c                 @  K   |t          | j        dz             |                                  d{V  |                     |          }|d         s#t	          | j        dz   |d         z   dz             |d         t          |          d}	||                     ||          |	d	<   ||                     ||          |	d
<   |                     | 	                    |	|                     d{V }
| 
                    |
di           }|                     ||          S )a  
        edit a trade order
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade022_modify_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 fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz' editOrder() requires a symbol argumentr:   z editOrder() does not support rS  r  r.   )rH  r.   r   rZ  r  )r   r.   r  rH  r%   intr`  r_  v1PrivatePostOrderModifyr  r  rL  )r   r.   rL  rS  r  r   rZ  r$  rH  r  r%  r  s               r  
edit_orderzcoinex.edit_order
  sZ      >#DG.W$WXXX!!!!!!!!!V$$f~ 	Gtw)IIFSYNZ  ^F   F  G  G  GTlb''
 
  $ 8 8 H HGH#66vuEEGG66t{{7F7S7STTTTTTTT@ ~~h33f---r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }|                     |d          }|d         }d|d         i}|                     |d          }d}	|                     d|          \  }	}|                     |d	d
          }
|	|t          | j        dz             ||d<   | 	                    |g d          }d}|
|
|d	<   |rd|r1| 
                    |                     ||                     d{V }nd|                     |                     ||                     d{V }n3|r1|                     |                     ||                     d{V }n |                     |                     ||                     d{V }n|rdnd}|||<   |rb|r0|                     |                     ||                     d{V }n|                     |                     ||                     d{V }na|r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |d          }|                     ||          S )aU  
        cancels an open order
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade018_cancle_stop_pending_order
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade015_cancel_order
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade024_cancel_order_by_client_id
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade025_cancel_stop_order_by_client_id
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http023_cancel_stop_order
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http021_cancel_order
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http042_cancel_order_by_client_id
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http043_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.stop]: if stop order = True, default = False
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentstopr<   rH  r.   rZ  rC   r1  r3  zA cancelOrder() requires an account_id parameter for margin orders)r  rZ  r3  r  r  )r   r.   r  rH  r  r  r  r  r    r  /v1PerpetualPrivatePostOrderCancelStopByClientIdr  )v1PrivateDeleteOrderStopPendingByClientId+v1PerpetualPrivatePostOrderCancelByClientId%v1PrivateDeleteOrderPendingByClientId%v1PerpetualPrivatePostOrderCancelStop!v1PrivateDeleteOrderStopPendingId!v1PerpetualPrivatePostOrderCancelv1PrivateDeleteOrderPendingr  rL  )r   r.   rL  r$  rH  r  r<   r  rl  r  r3  r  r%  	idRequestr  s                  r  cancel_orderzcoinex.cancel_orderU
  sk     $ >#DG.Y$YZZZ!!!!!!!!!V$$vv..f~fTl
 %%fl;;	
!??vVV
F**6;PP!  +n!nooo$-GL!		&"I"I"IJJ$#0GK  	m q%)%Y%YZ^ZeZefmotZuZu%v%vvvvvvvHH%)%S%STXT_T_`ginToTo%p%pppppppHH m%)%U%UVZVaVabikpVqVq%r%rrrrrrrHH%)%O%OPTP[P[\cejPkPk%l%lllllllHH&*4

I!#GI 	c i%)%O%OPTP[P[\cejPkPk%l%lllllllHH%)%K%KDKKX_afLgLg%h%hhhhhhhHH c%)%K%KDKKX_afLgLg%h%hhhhhhhHH%)%E%EdkkRY[`FaFa%b%bbbbbbbHV ~~h//f---r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }|d         }|                     |dd          }d|i}|d         }|                     |d          }|                     |ddg          }d}	|rb|r0|                     |                     ||                     d{V }	n| 	                    |                     ||                     d{V }	nf||d<   |r0| 
                    |                     ||                     d{V }	n/|                     |                     ||                     d{V }	|	S )	a  
        cancel all open orders in a market
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade018_cancle_stop_pending_order
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade015_cancel_order
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http024_cancel_stop_all
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http022_cancel_all
        :param str symbol: unified market symbol of the market to cancel orders in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz- cancelAllOrders() requires a symbol argumentr.   rZ  r   rH  r<   r  )r   r.   r  rH  r  r  r  (v1PerpetualPrivatePostOrderCancelStopAllr  $v1PerpetualPrivatePostOrderCancelAllv1PrivateDeleteOrderStopPendingr  )
r   rL  r$  rH  r  rl  r  r<   r  r%  s
             r  cancel_all_orderszcoinex.cancel_all_orders   s      >#DG.]$]^^^!!!!!!!!!V$$$<%%flA>>	h

 f~vv..6FL#9:: 
	` i!%!N!Nt{{[bdjOkOk!l!lllllll!%!J!J4;;W^`fKgKg!h!hhhhhhh$-GL! `!%!E!EdkkRY[aFbFb!c!ccccccc!%!A!A$++gW]B^B^!_!_______ r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }|d         }|                     |d          }|                     |d          }d|d         i}|rdnd}|||<   d}	|rb|r0|                     |                     ||                     d{V }	n_|                     |                     ||                     d{V }	n/| 	                    |                     ||                     d{V }	| 
                    |	d          }
|                     |
|          S )	ak  
        fetches information on an order made by the user
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http028_stop_status
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http026_order_status
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade007_order_status
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( fetchOrder() requires a symbol argumentr<   r  rH  r.   r  r  )r   r.   r  rH  r  r  $v1PerpetualPrivateGetOrderStopStatusr   v1PerpetualPrivateGetOrderStatusv1PrivateGetOrderStatusr  rL  )r   r.   rL  r$  rH  r<   r  r  r  r%  r  s              r  fetch_orderzcoinex.fetch_order0  s      >#DG.X$XYYY!!!!!!!!!V$$f~vv..66**fTl

 #'0JJD		 	X e!%!J!J4;;W^`fKgKg!h!hhhhhhh!%!F!Ft{{SZ\bGcGc!d!ddddddd!99$++gv:V:VWWWWWWWWHF ~~h//f---r  c                   K   |                                   d {V  |dn|}d|i}|                     |d          }|                     |d          }|                     |d          }d }	| |                     |          }	|	d         |d<   |                     d|	|          \  }
}|                     |d          }d }|                     d|          \  }}||t          | j        d	z             ||d<   |                     |d          }d }|
d
k    r|t          | j        dz             |||d<   nd|d<   d|d<   |r1| 
                    |                     ||                     d {V }nA|dk    r1|                     |                     ||                     d {V }n
|dk    r/|                     |                     ||                     d {V }nd|d<   |dk    rb|r0|                     |                     ||                     d {V }n|                     |                     ||                     d {V }ng|dk    ra|r0|                     |                     ||                     d {V }n/|                     |                     ||                     d {V }|
d
k    rdnd}|                     |d          }|                     ||g           }|                     ||	||          S )Nd   r  r  r  r.   rH  fetchOrdersByStatusrZ  z\ fetchOpenOrders() and fetchClosedOrders() require an account_id parameter for margin ordersr<   zB fetchOrdersByStatus() requires a symbol argument for swap marketsr   offsetfinishedpendingr   pagerecordsr  )r  r  r  r  rH  r  r  r    r.   r   %v1PerpetualPrivateGetOrderStopPendingr  "v1PerpetualPrivateGetOrderFinished!v1PerpetualPrivateGetOrderPendingv1PrivateGetOrderStopFinishedv1PrivateGetOrderFinishedv1PrivateGetOrderStopPendingv1PrivateGetOrderPendingrh  parse_orders)r   r+  rL  r  r  r$  r  r  r  rH  r  r  rl  r  r%  tradeRequestr  r  s                     r  fetch_orders_by_statuszcoinex.fetch_orders_by_status  s     !!!!!!!!!EU
 vv..  0066**[[((F &tGH >>?TV\^dee
E%%fl;;	
!??@UW]^^
F!    ,J  "J  K  K  K$-GL!5,//~'2v(vwww"&"# !GH j!%!K!KDKKX_agLhLh!i!iiiiiiiZ''%)%L%LT[[Y`bhMiMi%j%jjjjjjjHHy((%)%K%KDKKX_agLhLh%i%iiiiiiiHGFO## b%)%G%GT[]cHdHd%e%eeeeeeeHH%)%C%CDKKPWY_D`D`%a%aaaaaaaHH9$$ a%)%F%Ft{{SZ\bGcGc%d%dddddddHH%)%B%B4;;wX^C_C_%`%```````Hn &06%9%9yyx00lB77  >>>r  c                 D   K   |                      d||||           d{V S )ad  
        fetch all unfilled currently open orders
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http027_query_pending_stop
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http025_query_pending
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade013_stop_pending_order
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade011_pending_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 orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  Nr  r   rL  r  r  r$  s        r  fetch_open_orderszcoinex.fetch_open_orders  s7       00FE5RXYYYYYYYYYr  c                 D   K   |                      d||||           d{V S )a'  
        fetches information on multiple closed orders made by the user
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http029_query_finished
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade010_stop_finished_order
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade012_finished_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
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  Nr  r  s        r  fetch_closed_orderszcoinex.fetch_closed_orders  s7       00VUESYZZZZZZZZZr  r  c                   K   |                                   d{V  |                     |          }d|d         i}d|v r1|                     |d          }|                     |d          }||d<   |                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        create a currency deposit address
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account019_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
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        N	coin_typer.   r  smart_contract_namer  )r  r*  r  r  )v1PrivatePutBalanceDepositAddressCoinTyper  r  parse_deposit_address)r   r  r$  r*  r  r  r%  r  s           r  create_deposit_addresszcoinex.create_deposit_address  s       !!!!!!!!!==&&$
 &&vy99GYYvy11F-4G)*GGT[]cHdHdeeeeeeee ~~h33))$999r  c                 Z  K   |                                   d{V  |                     |          }d|d         i}|                     |di           }|                     |d          }|                     |d          }t          |                                          }t          |          }|I|dk    rC|t          | j	        dz   |z   dz             ||vr t          | j	        dz   |z   d	z   |z             |||d
<   |                     |                     ||                     d{V }	|                     |	di           }
|                     |
|          }|                     | j        di           }|                     |dd          }|r|                     ||          |d<   |S )a  
        fetch the deposit address for a currency associated with self account
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account020_query_deposit_address
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nr  r.   r   r  r   z fetchDepositAddress() z requires a network parameterz network not supported for r  r  rX   r   T)r  r*  r  r  r  r  r  r  r   r.   r   )v1PrivateGetBalanceDepositAddressCoinTyper  r  r   	safe_boolsafe_network_code)r   r  r$  r*  r  r   r  networksKeysnumOfNetworksr%  r  depositAddressr   r   s                 r  fetch_deposit_addresszcoinex.fetch_deposit_address  s      !!!!!!!!!==&&$
 ??8Z<<""695569--HMMOO,,L))MA$5$5'2K(Kd(RUt(tuuux''#DG.G$G'$QTq$qtx$xyyy-4G)*GGT[]cHdHdeeeeeeee x4433D(CC//$,0ErJJ"&..:SUY"Z"Z" 	R(,(>(>w(Q(QN9%r  r*  c                     |                      |di           }t          |                                          }t          |          }||dk    r||d                  S ||d n|                                dS )Nr   r   r   )r.   r  )r  r  r  r  upper)r   r,  r*  r   networksCodesnetworksCodesLengths         r  safe_networkzcoinex.safe_network  s    ??8Z<<X]]__--!-00!4!9!9M!,-- ) 1tt	8I8I
 
 	
r  c                 >    |                      ||          }|d         S )Nr  )r  )r   r,  r*  r  s       r  r  zcoinex.safe_network_code  s"    ##Ix88y!!r  c                     |                      |d          }|                    d          }d }d }t          |          }|dk    r|d         dk    r|d         }|d         }n|}||                     d |          ||d dS )Ncoin_addressrm  r   r   cfx)r  r*  addresstagr  )r  splitr  r  )r   r  r*  coinAddresspartsr  r  partsLengths           r  r  zcoinex.parse_deposit_address  s     &&~~FF!!#&&%jj??uQx500AhG(CC!G"//h??
 
 	
r  c                 b  K   |                                   d{V  d}|d}|dd}| |                     |          }|d         |d<   d}|                     d||          \  }}|dk    r|t          | j        d	z             |d
k    }|                     |d          }	d}
|                     d|          \  }
}|
4|	t          | j        dz             |	|d<   |                     |d          }d}|r<|||d<   d|d<   | 	                    | 
                    ||                     d{V }n4d|d<   |                     | 
                    ||                     d{V }|rdnd}|                     |d          }|                     ||g           }|                     ||||          S )ay  
        fetch all trades made by the user
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http013_user_deals
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade014_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 trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nr  r   )r  r  r.   rH  rm   r:   z@ fetchMyTrades() requires a symbol argument for non-spot marketsr<   rZ  zC fetchMyTrades() requires an account_id parameter for margin trades
start_timer  r   r  r  r  )r  rH  r  r   r.   r  r  r    r  $v1PerpetualPrivateGetMarketUserDealsr  v1PrivateGetOrderUserDealsr  rh  r  )r   rL  r  r  r$  rH  r  rS  r<   rl  r  r%  r  r  rE  s                  r  fetch_my_tradeszcoinex.fetch_my_trades  s#      !!!!!!!!!=E
 
 [[((F &tGH99/6SYZZf6>>fn#DG.p$pqqq%%fl;;	
!??QWXX
F!  +p!pqqq$-GL!YYv|44F 	[ (-%GFO!FFt{{SZ\bGcGcddddddddHHGFO!<<T[[RX=Y=YZZZZZZZZHR %)4yyfx00lB77  >>>r  c                   K   |                                   d{V  d}|                     |ddd          \  }}|dk    }|                     |          }i }d}|od}t          |t                    r5t          |          }|dk    rt          | j        dz             |d         }n|}|                     |          }|d	         |d
<   n|rt          | j        dz             |rd|d<   | 
                    |dd          |d<   d}	|dk    r0|                     |                     ||                     d{V }	n/|                     |                     ||                     d{V }	|                     |	dg           }
g }t          dt          |
                    D ]1}|                    |                     |
|         |                     2|                     |d|d          S )a  
        fetch all open positions
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033_pending_position
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033-0_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 'perpetualPrivateGetPositionPending' or 'perpetualPrivateGetPositionFinished' default is 'perpetualPrivateGetPositionPending'
        :param int [params.side]: *history endpoint only* 0: All, 1: Sell, 2: Buy, default is 0
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nrs   method$v1PerpetualPrivateGetPositionPending%v1PerpetualPrivateGetPositionFinishedr   zD fetchPositions() symbols argument cannot contain more than 1 symbolr   r.   rH  zA fetchPositions() requires a symbol argument for closed positionsr  r  r  r  rL  F)r  ra  r  
isinstancer  r  r    r.   rH  r   r  r  r  r  r  r  r#  parse_positionfilter_by_array_positions)r   r  r$  defaultMethod	isHistoryr  rH  rL  symbolsLengthr%  positionr'  r(  s                r  fetch_positionszcoinex.fetch_positions  sJ      !!!!!!!!! $ = =fFVX`  cI  !J  !Jv"&MM	%%g..F'4(( ! #G 1$$$TW/u%uvvv  [[((F &tGH w'2u(uvvv 	C"GG"//BBGFOBBB!FFt{{SZ\bGcGcddddddddHH!GGT[]cHdHdeeeeeeeeHx ??8VR88q#h--(( 	D 	DAMM$--hqk6BBCCCC--fhOOOr  c                 <  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |dg           }|                     |d         |          S )a  
        fetch data on a single open contract trade position
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033_pending_position
        :param str symbol: unified market symbol of the market the position is held in, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        NrH  r.   r  r   )r  rH  r  r  rh  r  r   rL  r$  rH  r  r%  r  s          r  fetch_positionzcoinex.fetch_position  s       !!!!!!!!!V$$fTl
 BB4;;wX^C_C_````````x ~~h33""47F333r  c                    |                      |d          }|                     ||d d          }|d         }|                     |d          }|                     |d          }|dk    rdnd}|                      |d	          }|                      |d
          }	|                      |d          }
|                     |d          }|                     |d          }|dk    rdnd}|                     |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }t          j        ||          }t          j        d|          }|                     i d|d|d|d|                     |          d|d|d|                     |	          d|                     |
          dd d|d |                     |d           d!d d"d d|d#d d$|d%| 	                    |          d |                     |          |                     |          |                     |          |                     |          |                     |          |                     |          d | 
                    |                      |d&                    | 
                    |                      |d'                    d(
          S ))NrH  r<   rL  rR  rS  r   isolatedcross	liq_price
open_priceprofit_unrealr   r  shortlongr5  mainten_margin_amountmainten_marginmargin_amountr]  open_valrn  r  r.   notionalr  liquidationPrice
entryPriceunrealizedPnlr  	contractsra  	markPrice	lastPricehedgedrx  ry  r?  r=  )
lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager]  marginRatior>  r<  )r  r  r  r"  r  r*   
string_divsafe_positionr   r  	omit_zero)r   r  rH  r  rL  rS  marginModeIntegerr  r
  r  r  r  sideIntegerr  rx  r  r  r  r]  r	  r  r  s                         r  r  zcoinex.parse_positionG  s   l ##Hh77!!(FD&AA!&&x??
 --h??$5$:$:ZZ
++HkBB%%h==
((?CC$$Xx88	''&99&!++ww&''-@@	 ,,X7NOO&*&6&6xAQ&R&R#%%h@@
##Hj99##Hj99*8X>>")"4S("C"C!! #
H#
*#
 f#
 ))(33	#

 *#
  0#
 $++J77#
 T..}==#
 $#
 #
 D,,V^DD#
 #
 #
 D#
 d#
  !#
" Y//##
$ $(!%!2!23D!E!E+/+<+<=X+Y+Y++J77!..}=='+'8'89P'Q'Q))(33!^^D,<,<XGX,Y,YZZ#~~d.>.>xI\.].]^^7#
 #
 #
   	r  r  c                 v  K   |t          | j        dz             |                                }|dk    r|dk    rt          | j        dz             |                                  d{V  |                     |          }|d         dk    rt          | j        dz             d}|dk    rd	}n|dk    rd
}|                     |d          }|                     |d         d         dd          }|                     |d|          }|t          | j        dz             |t          | j        dz             |dk     s||k    r-t          | j        dz   t          |          z   dz   |z             |d         t          |          |d}	| 	                    | 
                    |	|                     d{V S )a  
        set margin mode to 'cross' or 'isolated'
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http014_adjust_leverage
        :param str marginMode: 'cross' or 'isolated'
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        Nz+ setMarginMode() requires a symbol argumentr  r  z@ setMarginMode() marginMode argument should be isolated or crossrS  r<   z- setMarginMode() supports swap contracts onlyr   r  r]  r   r   r  position_typez. setMarginMode() requires a leverage parameterzk setMarginMode() requires a position_type parameter that will transfer margin to the specified trading pairr  z2 setMarginMode() leverage should be between 3 and  for r.   rH  r]  r  )r   r.   lowerr    r  rH  r!   r  str*v1PerpetualPrivatePostMarketAdjustLeverager  )
r   r  rL  r$  rH  defaultPositionTyper]  maxLeveragepositionTyper  s
             r  set_margin_modezcoinex.set_margin_mode  s$      >#DG.[$[\\\%%''
##
g(=(=TW'iijjj!!!!!!!!!V$$&>V##DG&UUVVV"##"#7"""#$$VZ88''x(8(DeSQQ((BUVV#DG.^$^___#DG  /\  %\  ]  ]  ]qLLh44TW'[[^abm^n^nnqxx  |B  B  C  C  CTlH)
 

 DDT[[QXZ`EaEabbbbbbbbbr  r]  c                   K   |t          | j        dz             |                                  d{V  |                     |          }|d         st	          | j        dz             d}|                     d|d          \  }}d}|dk    rd}n|dk    rd	}|                     |d
         d         dd          }|                     |d
         d         dd          }||k     s||k    r@t          | j        dz   t          |          z   dz   t          |          z   dz   |z             |d         t          |          |d}	| 	                    | 
                    |	|                     d{V S )a  
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http014_adjust_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 argumentr<   z+ setLeverage() supports swap contracts onlyr   r  r  r   r  r   r]  r   r   r  z* setLeverage() leverage should be between z and r  r.   r   )r   r.   r  rH  r!   r  r  r    r"  r#  r  )
r   r]  rL  r$  rH  r  r&  minLeverager%  r  s
             r  set_leveragezcoinex.set_leverage  s      >#DG.Y$YZZZ!!!!!!!!!V$$f~ 	UDG&SSTTT
!??vW^__
F##LL7""L''x(8(DeQOO''x(8(DeSQQ{"";(>(>TW'SSVYZeVfVffippsv  xC  tD  tD  D  GN  N  QW  W  X  X  XTlH)
 

 DDT[[QXZ`EaEabbbbbbbbbr  c                    K   |                                   d{V  |                     |           d{V }|                     |di           }|                     ||d          S )a
  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http007_market_limit
        :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
        Nr  )r  %v1PerpetualPublicGetMarketLimitConfigr  parse_leverage_tiers)r   r  r$  r%  r  s        r  fetch_leverage_tierszcoinex.fetch_leverage_tiers  s       !!!!!!!!!CCFKKKKKKKK$ x44((w===r  c                 J   g }d}t          dt          |                    D ]}||         }|                     |d          }|                    |dz   |d         r|d         n|d         |||                     |d          |                     |d          |d           |}|S )Nr   r   r   rM  rN  r  )tierr*  minNotionalmaxNotionalmaintenanceMarginRater%  r  )r  r  r"  r#  r  )r   r  rH  tiersr1  jbracketr2  s           r  parse_market_leverage_tiersz"coinex.parse_market_leverage_tiers  s    q#d))$$ 	& 	&A1gG**7A66KLLA.4X.>SF6NNF7O**)-)9)9'1)E)E#00!<<     &KKr  c                   K   |                                   d {V  |                     |          }|d         |                     ||          |d}|                     |                     ||                     d {V }|                     |d          }|                     |d          }	|                     |                     ||          |                     |          |	d          S )Nr.   )rH  r   rS  r  message)r   r+  )	r  rH  r`  *v1PerpetualPrivatePostPositionAdjustMarginr  r  r  parse_margin_modificationr   )
r   rL  r   addOrReducer$  rH  r  r%  r  r+  s
             r  modify_margin_helperzcoinex.modify_margin_helper(  s     !!!!!!!!!V$$Tl..vv>>
 

 HHU\^dIeIefffffffft ~~h//!!(I66{{499$GG''//J
 J
   	r  c                 b   |                      |d          }|                      |d          }|                     |ddd          }||                     ||d d          |dk    rdnd	d
|                     |d          |                     |d          |d         d ||                     |          d
S )NrH  rS  r   r5    r<   rn  addreducer  margin_changeposition_amountrN  )
r  rL  rS  r  r   r  r  r+  rx  ry  )r  safe_integer_product_2r  r"  r  )r   r  rH  r  rS  rx  s         r  r;  z coinex.parse_margin_modificationq  s    T ##D(33f--//fmTRR	&&xvFF"ckkEE$&&t_==%%d,=>>7O"Y//
 
 	
r  c                 B   K   |                      ||d|           d{V S )a  
        add margin
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http032_adjust_position_margin
        :param str symbol: unified market symbol
        :param float amount: amount of margin to add
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
        r   Nr=  r   rL  r   r$  s       r  
add_marginzcoinex.add_margin  4       ..vvq&IIIIIIIIIr  c                 B   K   |                      ||d|           d{V S )a  
        remove margin from a position
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http032_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  NrF  rG  s       r  reduce_marginzcoinex.reduce_margin  rI  r  c                 
  K   |t          | j        dz             |dn|}|                                  d{V  |                     |          }|d         |d}|||d<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }	g }
t          d	t          |	                    D ]}|	|         }| 	                    |d
          }| 
                    |d          }|                     |          }|
                    |||||                     |          |                     |d          |                     |d          d           |
S )a`  
        fetch the history of funding payments paid and received on self account
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http034_funding_position
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
        Nz1 fetchFundingHistory() requires a symbol argumentr  r.   )rH  r  r  r  r  r   r   r  rR  r   )r  rL  r  rx  ry  r.   r   )r   r.   r  rH  $v1PerpetualPrivateGetPositionFundingr  r  r  r  r  r  r  r#  r  r"  )r   rL  r  r  r$  rH  r  r%  r  
resultListr'  r(  rp  rx  r+  r  s                   r  fetch_funding_historyzcoinex.fetch_funding_history  s      >#DG.a$abbbE!!!!!!!!!V$$Tl
 
 $)GL!BB4;;wX^C_C_````````8 x44__T9b99
q#j//** 	 	AqME++E6::I))%99J**:66DMM & LL33&&um<<**5)<<      r  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     |di           }|                     |d          }||d	<   |                     ||          S )
a  
        fetch the current funding rate
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http008_market_ticker
        :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>`
        Nr<   z0 fetchFundingRate() supports swap contracts onlyrH  r.   r  rv  ru  rx  )	r  rH  r!   r.   r  r  r  r  parse_funding_rate)	r   rL  r$  rH  r  r%  r  rv  rx  s	            r  fetch_funding_ratezcoinex.fetch_funding_rate(  s      !!!!!!!!!V$$f~ 	ZDG&XXYYYfTl
 >>t{{7TZ?[?[\\\\\\\\B x44x44%%dF33	'{&&vv666r  c                    |                      |d          }|                     |d          }|                      |d          dz  dz  }||z   dz  }t          t          |                    dz  }i d|d|                     d |          d|                     |d	          d
|                     |d          dd dd d|d|                     |          d|                     |d          d|d|                     |          d|                     |d          dd dd d|                     |d          dd dd S )Nrx  funding_time<   r?  i6 r  rL  r  
sign_price
indexPriceindex_priceinterestRateestimatedSettlePricery  fundingRatefunding_rate_nextfundingTimestampfundingDatetimenextFundingRatefunding_rate_predictnextFundingTimestampnextFundingDatetimepreviousFundingRatefunding_rate_lastpreviousFundingTimestamppreviousFundingDatetime)r  r  r  roundr  r"  r  )r   rT  rH  rx  fundingDeltafundingHourr]  s          r  rQ  zcoinex.parse_funding_rate^  s   6 %%h<<	99X{33((>BBRG$N </7:u[1122W<
H
d&&tV44
 ))(LAA
 $**8]CC	

 D
 #D
 
 Y//
 4++H6IJJ
  0
 t||,<==
 t//:PQQ
 #D
 "4
 "4#3#3H>Q#R#R
  '!
" &t#
 	
r  c                 P  K   |                                   d{V  |                     |          }d}|J|                     |d          }|                     |          }|d         st	          | j        dz             |                     |           d{V }|                     |di           }|                     |di           }|                     |d          }g }	t          |	                                          }
t          dt          |
                    D ]q}|
|         }|                    d          d	k    rN|                     |ddd          }||         }||d
<   |	                    |                     ||                     r|                     |	d|          S )a  
         *  @method
        fetch the current funding rates
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http009_market_ticker_all
        :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   r<   z1 fetchFundingRates() supports swap contracts onlyr  rv  ru  _rx  rL  )r  r  r  rH  r!   r.   r  r  r  r  r  r  findr  r#  rQ  filter_by_array)r   r  r$  rH  rL  r%  r  r  rx  r'  r  r(  r  r  rv  s                  r  fetch_funding_rateszcoinex.fetch_funding_rates  s      !!!!!!!!!%%g..__Wa00F[[((F&> _*] ]^^^AA&IIIIIIIID x44//$"55%%dF33	((	q#i..)) 	L 	LA |H}}S!!R''"..xtVLL *&/{#d55fkJJKKK##FHg>>>r  c                 r  K   |                      ||          \  }}|                     |           |                                  d{V  |                     |          }|                     |d          }|                     |d          }|r|dz   |z   }|d         |t          |                     |                    dd}||                     |          |d<   | 	                    | 
                    ||                     d{V }	|                     |	di           }
|                     |
|          S )	a/  
        make a withdrawal
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account015_submit_withdraw
        :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>`
        Nr  rm  r.   onchain)r  r  actual_amounttransfer_methodr  r  )handle_withdraw_tag_and_paramscheck_addressr  r*  safe_string_upperr  floatrb  network_code_to_id v1PrivatePostBalanceCoinWithdrawr  r  parse_transaction)r   r  r   r  r  r$  r*  networkCoder  r%  transactions              r  r   zcoinex.withdraw  s\      99#vFFV7###!!!!!!!!!==&&,,VY??69-- 	*mc)G!$#"4#8#8#@#@AA(	
 
 "-1-D-D[-Q-QG)*>>t{{7TZ?[?[\\\\\\\\& nnXvr::%%k8<<<r  c           	      F    ddddddddd}|                      |||          S )Nr  failedr$  ok)auditpass
processing
confirmingnot_passr(  finishfailr)  r*  s      r  parse_transaction_statuszcoinex.parse_transaction_status  s@    ##  	
 	
 &&999r  c           
        K   |t          | j        dz             |                                  d{V  d}|                     |dd          \  }}|r!|                     d|||d|d           d{V S |d}|                     |          }|d	         |d
d}|||d<   |                     d||          \  }}|                     |                     ||                     d{V }| 	                    |d          }	| 	                    |	dg           }
g }t          d
t          |
                    D ]}|
|         }|                     |d          }|                     ||dd          }|                     |d          }|                    |||                     |d          ||                     |          d           |                     |d          }|                     ||d         ||          S )a  
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http038_funding_history
        fetches historical funding rate prices
        :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 [availble 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 argumentFra   paginate8hr?  r  r.   r   )rH  r  r  r  end_timer  r  rH  r<   r   funding_rate)r  rL  r[  rx  ry  rx  rL  )r   r.   r  ra  "fetch_paginated_call_deterministicrH  handle_until_option(v1PerpetualPublicGetMarketFundingHistoryr  r  r  r  r  r  r  r#  r"  r  sort_byfilter_by_symbol_since_limit)r   rL  r  r  r$  r  rH  r  r%  r  r'  ratesr(  rp  r  symbolInnerrx  sorteds                     r  fetch_funding_rate_historyz!coinex.fetch_funding_rate_history  s      >#DG.e$efff!!!!!!!!!88AZ\fgg& 	F@@AZ\bdikprvx~  AE  F  F  F  F  F  F  F  F  F=EV$$Tl
 
 $)GL!22:wOOFFt{{SZ\bGcGcdddddddd( x00y"55q#f++&& 	 	A1IE''x88H**8VT6JJK++E6::ILL%#//~FF& LL33      e[11009I5RWXXXr  c                    |                      |dd          }|                     |d          }|                     |d          }|t          |          dk     rd }|                     |d          }|t          |          dk     rd }|                     |d          }|                     ||          }|                     |d          }	d|v rd	nd
}
|                     |                     |d                    }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|dk    }d }d }|
d
k    rd}|}n|}|                     |          |d}i d|d|d|d|	d| 	                    |	          d| 
                    |          d|dd dd d|d|d|d|
d |                     |          d!|d|d"d |d |d#S )$Ncoin_withdraw_idcoin_deposit_idr  remarkr   tx_idr  r  
withdrawalr  r+  r  rr  tx_feers  localr   r  r  r.   txidrx  ry  r  r  	addressToaddressFromr  tagTotagFromrS  r   r*  updated)r  commentinternal)r  r  r  r  r  r  r  r"  r   r  network_id_to_code)r   r|  r*  r.   r  r  r  r+  r  rx  rS  r+  r,  r   feeCosttransferMethodr  r  r  r  s                       r  rz  zcoinex.parse_transactionW  s   l -?ARSS"";??{H55?3xx!||{G444yy1}}%%k;??
&&z8<<'']CC	 2k A A||	..t/?/?X/V/VWW$$[2GHH	!!+??"";99))+7HII!W,	9GII!K%%g..
 

K
"
 D
 	

 Y//
 t..y99
 w
 
 4
 3
 Y
 {
 D
 d''//
 
  f!
" t#
$  )
 
 
 	
r  fromAccount	toAccountc                 j  K   |                                   d{V  |                     |          }|                     ||          }||d         d}d}	|dk    r;|dk    r5d|d<   |                     |                     ||                     d{V }	n|dk    r;|dk    r5d|d<   |                     |                     ||                     d{V }	n|                     | j        d	i           }
|                     |
||          }|                     |
||          }t          |          |d
<   t          |          |d<   | 	                    |                     ||                     d{V }	|                     | 
                    |	|          |                     |          ||d          S )a  
        transfer currency internally between wallets on the same account
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account014_balance_contract_transfer
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account013_margin_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
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        Nr.   )r   r  r:   r<   intransfer_sideoutr   from_account
to_account)r   r  r  )r  r*  currency_to_precision$v1PrivatePostContractBalanceTransferr  r  r   r  r  v1PrivatePostMarginTransferparse_transferr   )r   r  r   r  r  r$  r*  amountToPrecisionr  r%  r   fromIdtoIds                r  r   zcoinex.transfer  s      !!!!!!!!!==&& 66tVDD'!$
 
 6!!	V(;(;'+GO$!FFt{{SZ\bGcGcddddddddHHV##)v*=*=',GO$!FFt{{SZ\bGcGcddddddddHH??4<LLL%%lKMMF##L)YGGD '*&kkGN#$'IIGL!!==dkk'SY>Z>Z[[[[[[[[H {{4..xBB''(9::&"E
 E
   	r  c                 :    ddd}|                      |||          S )Nr  )r   SUCCESSr)  r*  s      r  parse_transfer_statuszcoinex.parse_transfer_status  s.    
 
 &&999r  c                    |                      |d          }|                     |d          }d }d }|dk    rd}d}n |dk    rd}d}n|dk    rd}d}n
|d	k    rd}d}|                     |d
          }|                     ||          }||                     |d          ||                     |          ||                     |d          |||                     |                     |dd                    d	S )N
created_attransfer_typetransfer_outr<   r:   transfer_inINr;   OUTr  r.   r   r  r+  )	r  r.   rx  ry  r*  r   r  r  r+  )r  r  r  r  r  r"  r  r  )	r   r   r*  rx  transferTyper  r  r+  currencyCodes	            r  r  zcoinex.parse_transfer  s3   6 '',??	''/BB	>)) KII]** KIIT!! K IIU"""KI%%h88
..z8DD##Hd33"Y//$&&x::&"001C1CHfV^1_1_``

 

 
	
r  c                   K   |                                   d{V  d}ddi}|                     |d          }|||d<   | |                     |          }|d         |d<   |||d<   |||d<   nd|d<   |                     |d          }d}|                     d	|          \  }}d}	|0|                     |                     ||                     d{V }	n/|                     |                     ||                     d{V }	|                     |	d
i           }
| 	                    |
dg           }| 
                    ||||          S )a  
        fetch a history of internal transfers made on an account
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account025_margin_transfer_history
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account024_contract_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  transfers structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
        Nr  r   r.   r  r  r  r  r}   r  r  )r  r  r*  r  r  !v1PrivateGetMarginTransferHistoryr  #v1PrivateGetContractTransferHistoryr  rh  parse_transfers)r   r  r  r  r$  r*  r  r  r  r%  r  	transferss               r  fetch_transferszcoinex.fetch_transfers/  s      !!!!!!!!!A
   00"GFO}}T**H'~GG$)GL!$GG"GG66**
!??@PRXYY
F!!CCDKKPWY_D`D`aaaaaaaaHH!EEdkkRY[aFbFbccccccccHZ x44NN4B77	##IxFFFr  c                   K   i }d}|:|                                   d{V  |                     |          }|d         |d<   |||d<   |                     |                     ||                     d{V }|                     |d          }t          |t                    s|                     |dg           }|                     ||||          S )a6  
        fetch all withdrawals made from an account
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account026_withdraw_list
        :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 withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr.   r  Limitr  )r  r*  v1PrivateGetBalanceCoinWithdrawr  r  r  r  parse_transactions	r   r  r  r  r$  r  r*  r%  r  s	            r  fetch_withdrawalszcoinex.fetch_withdrawals  s       ##%%%%%%%%%}}T**H#+D>GK $GG==dkk'SY>Z>Z[[[[[[[[N x00$%% 	5??444D&&tXueDDDr  c                   K   i }d}|:|                                   d{V  |                     |          }|d         |d<   |||d<   |                     |                     ||                     d{V }|                     |d          }t          |t                    s|                     |dg           }|                     ||||          S )a*  
        fetch all deposits made to an account
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account009_deposit_list
        :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 deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr.   r  r  r  )r  r*  v1PrivateGetBalanceCoinDepositr  r  r  r  r  r  s	            r  fetch_depositszcoinex.fetch_deposits  s       ##%%%%%%%%%}}T**H#+D>GK $GG<<T[[RX=Y=YZZZZZZZZN x00$%% 	5??444D&&tXueDDDr  c           
      Z   |                      |d          }|                     ||d d          }|                     ||d                   }|                     ||d                   }|d         |d         |                     |d          |d         |                     |d          d	d d |d
	S )NrH  r:   rP  rQ  rL  rM  day_raterN  i \&)	rL  rM  baseRaterN  	quoteRateperiodrx  ry  r  )r  r  r  r"  )r   r  rH  r  baseInfo	quoteInfos         r  parse_isolated_borrow_ratez!coinex.parse_isolated_borrow_rate  s    " ##D(33!!(FD&AA??4)9::OOD&*;<<	X&6N((:>>G_)))Z@@

 

 
	
r  c                 0  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        fetch the rate of interest to borrow a currency for margin trading
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account007_margin_account_settings
        :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
        :returns dict: an `isolated borrow rate structure <https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure>`
        NrH  r.   r  )r  rH  v1PrivateGetMarginConfigr  r  r  r  s          r  fetch_isolated_borrow_ratez!coinex.fetch_isolated_borrow_rate%  s       !!!!!!!!!V$$fTl
 66t{{7F7S7STTTTTTTT* x44..tV<<<r  c                 B  K   |                                   d{V  |                     |           d{V }|                     |dg           }g }t          dt	          |                    D ]0}|                    |                     ||                              1|S )a  
        fetch the borrow interest rates of all currencies
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account007_margin_account_settings
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `isolated borrow rate structures <https://github.com/ccxt/ccxt/wiki/Manual#isolated-borrow-rate-structure>`
        Nr  r   )r  r  r  r  r  r#  r  )r   r$  r%  r  r  r(  s         r  fetch_isolated_borrow_ratesz"coinex.fetch_isolated_borrow_ratesJ  s       !!!!!!!!!66v>>>>>>>>. x44q#d))$$ 	C 	CALL88aAABBBBr  c                   K   |                                   d {V  i }d }| |                     |          }|d         |d<   |||d<   |                     |                     ||                     d {V }|                     |di           }	|                     |	dg           }
|                     |
|          }|                     ||||          S )Nr.   rH  r  r  )r  rH  v1PrivateGetMarginLoanHistoryr  r  parse_borrow_interestsfilter_by_currency_since_limit)r   r  rL  r  r  r$  r  rH  r%  r  rowsr  s               r  fetch_borrow_interestzcoinex.fetch_borrow_interesto  s      !!!!!!!!![[((F &tGH$GG;;DKKQW<X<XYYYYYYYY> x44tVR00..tV<<228T5%PPPr  c                 L   |                      |d          }|                     ||d d          }|                      |d          }|                     |d          }|                      |d          }|                      |d          }t          j        ||          }|dk    rd }d |dd |                     |                      |d	                    |                     |          |                     |d
          |                     |          ||                     |          |dS )Nr  r:   rL  expire_timeunflat_amountloan_amountr   r  r  r  )r  rL  r  
marginTyper*  r  rY  amountBorrowedrx  ry  r  )	r  r  r  r*   
string_subr  r   r"  r  )	r   r  rH  r  rL  rx  unflatAmount
loanAmountr  s	            r  parse_borrow_interestzcoinex.parse_borrow_interest  s.     ##D-88!!(FD&AA!!&(33''m<<	''o>>%%dM::
%lJ??3H$//0@0@{0S0STT))(33 ,,T:>>"//
;;"Y//
 
 	
r  c                   K   |                                   d{V  |                     |          }|                     |          }|d         |d         |                     ||          d}|                     |                     ||                     d{V }|                     |di           }	|                     |	|          }
|                     |
||d          S )a  
        create a loan to borrow margin
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account017_margin_loan
        :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
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        Nr.   rH  r  r   r  r   rL  )r  rH  r*  r  v1PrivatePostMarginLoanr  r  parse_margin_loan)r   rL  r  r   r$  rH  r*  r  r%  r  r|  s              r  borrow_isolated_marginzcoinex.borrow_isolated_margin  s      !!!!!!!!!V$$==&&Tl!$00v>>
 

 55dkk'66R6RSSSSSSSS x44,,T8<<{{;)
 )
   	r  c                   K   |                                   d{V  |                     |          }|                     |          }|d         |d         |                     ||          d}|                     |                     ||                     d{V }|                     ||          }	|                     |	||d          S )aY  
        repay borrowed margin and interest
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account018_margin_flat
        :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.loan_id]: extra parameter that is not required
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        Nr.   r  r  )r  rH  r*  r  v1PrivatePostMarginFlatr  r  )
r   rL  r  r   r$  rH  r*  r  r%  r|  s
             r  repay_isolated_marginzcoinex.repay_isolated_margin  s       !!!!!!!!!V$$==&&Tl!$00v>>
 

 55dkk'66R6RSSSSSSSS ,,Xx@@{{;)
 )
   	r  c                 f    |                      |d          |                     d |          d d d d |dS )Nloan_id)r.   r*  r   rL  rx  ry  r  )r  r  )r   r  r*  s      r  r  zcoinex.parse_margin_loan  sH    " ##D)44//h??
 
 	
r  codesc                 (  K   |                                   d{V  i }|.t          |          }|dk    r|                     |d          |d<   |                     |                     ||                     d{V }|                     ||          S )a  
        fetch deposit and withdraw fees
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot001_market010_asset_config
        :param str[]|None codes: list of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `fees structures <https://docs.ccxt.com/#/?id=fee-structure>`
        Nr   r   r  )r  r  r  r  r  parse_deposit_withdraw_fees)r   r  r$  r  codesLengthr%  s         r  fetch_deposit_withdraw_feesz"coinex.fetch_deposit_withdraw_fees!  s       !!!!!!!!!e**Ka'+ua'@'@$::4;;wPV;W;WXXXXXXXX6 //%@@@r  c                 d   i }|                      |          }|                     |d          }t          |                                          }t	          dt          |                    D ]E}||         }|                    d          }	|||                  }
|                     |
d          }|                     |          }|                     |d          }|| 	                    ||          r|                     ||          }|| 
                    i           ||<   |
||         d         |<   |                     |	d          }|                     |
d          }||d	nd d
}d d d
}|+|                     |          }||d||         d         |<   /|||         d<   |||         d<   Gt          |                                          }t	          dt          |                    D ]>}||         }|                     |          }|                     ||         |          ||<   ?|S )Nr  r   rT  r  r  r  r   r  F)r  r  )r   r  r   r   r  )market_codesr  r  r  r  r  r  r  safe_currencyin_arraydeposit_withdraw_feer  r*  $assign_default_deposit_withdraw_fees)r   r%  r  currencyIdKeydepositWithdrawFeesr  r  r(  rp  
splitEntryfeeInfor+  r*  r  depositWithdrawFeer,  withdrawFeewithdrawResultdepositResultr{  depositWithdrawCodess                        r  r  z"coinex.parse_deposit_withdraw_feesL  so    !!%((x00499;;''q#k**++ 	I 	IANES))J;q>*G))'7;;J))*55H##Hf55D4==u#=#=%)__5H$%O%O"%-040I0I"0M0M'-;B#D)&1%8 ,,Z;;	"oog7HII&,7,C%%$" "
  "&! ! ("&"9"9)"D"DK$2#0J J'-j9+FF
 =K'-j9;H'-i8#$7$<$<$>$>??q#23344 	w 	wA'*D}}T**H(,(Q(QRefjRkmu(v(v%%""r  c                   K   |                                   d{V  |                     |          }d}|+|                     |d          }|                     |          }d}|                     d||          \  }}|dk    rt          | j        dz             |                     |           d{V }|                     |dg           }| 	                    ||d|          S )a  
        fetch the set leverage for all contract and margin markets
        :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account007_margin_account_settings
        :param str[] [symbols]: a list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `leverage structures <https://docs.ccxt.com/#/?id=leverage-structure>`
        Nr   rg   r:   z3 fetchLeverages() supports spot margin markets onlyr  rH  )
r  r  r  rH  r  r%   r.   r  rh  parse_leverages)r   r  r$  rH  rL  r  r%  rq  s           r  fetch_leverageszcoinex.fetch_leveragesw  s	      !!!!!!!!!%%g..__Wa00F[[((F
!??@PRXZ`aa
Ftw)^^___66v>>>>>>>>. NN8VR88	##Iw*MMMr  c                     |                      |d          }|                     |d          }||                     ||d d          d ||dS )NrH  r]  r:   )r  rL  r  longLeverageshortLeverage)r  r  r  )r   r]  rH  r  leverageValues        r  parse_leveragezcoinex.parse_leverage  s^    ##Hh77))(J??&&xvFF)*
 
 	
r  c                     |                      | j        d          }|                     |dd          }d}t          t          |                               |||          \  }}||dk    s|du rd}||gS )aZ  
         * @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   r;   FNTr  )r  r   r  r   r,   r  )r   
methodNamer$  defaultValuer   isMarginr  r  s          r  r  z$coinex.handle_margin_mode_and_params  s     &&t|]CC>>&(E::
"6400NNz[acopp
Fx''X-=-='
F##r  c                 *    |                                  S N)milliseconds)r   s    r  noncezcoinex.nonce  s      """r  GETc                 l   |                      ||          }|d         }|d         }| j        d         |         dz   |z   dz   |z   }	|                     ||                     |                    }
t	          |                                           }|dk    r|                    d          }|                     |dd          }t          |          }|                     ||dz
  d          }|                    d          }t          |          }|                     ||dz
  d          }|dk    r_|d	k    s|d
k    rS|                     |d          }|;d}| 	                    | j
        d|          }|dz   |                                 z   |
d<   |dk    r|                                  |                     | j        |d|
          }
|                     |
          }
|                     |
          }|                     |                     |dz   | j        z             d          }|                                | j        d}|dk    s|dk    r
|	d|z   z  }	nd|d<   |}n|dk    s|dk    r|
r|	d|                     |
          z   z  }	n|dk    r|                                  |                     | j        |d|
          }
|                     |
          }
|                     |
          }|                     |                     |dz   | j        z             d          }|                                dd}|dk    s|dk    s|dk    r	|	d|z   z  }	n|                     |
          }n|d k    r|                                  |                     |
          }
|                     |
          }|dz   |z   dz   |z   dz   |z   |z   | j        z   }|                     |                     |          d          }| j        ||d!}|dk    s|dk    s|dk    r	|	d|z   z  }	n|                     |
          }|	|||d"S )#Nr   r   r   rK  POSTr2  rk  r  r  rH  r1  r   r   r   )	access_idrx  z&secret_key=sha256)AuthorizationAccessIdr  PUT?z!application/x-www-form-urlencodedContent-Typer   r   r2   )r"  toncemd5zapplication/json)r$  r(  DELETEr   )zX-COINEX-KEYzX-COINEX-SIGNzX-COINEX-TIMESTAMP)urlr  bodyheaders)implode_paramsr   r  extract_paramsr"  r  r  r  r  r  r   r^  check_required_credentialsr  apiKeykeysort	rawencodehashencodesecretr!  	urlencoder  r  )r   pathr   r  r$  r.  r-  r1   
requestUrlr,  r  r  r  	firstPartnumPartslastPart	lastWordsnumWordslastWordr3  rh  r   
urlencoded	signaturepreparedStrings                            r  signzcoinex.sign  s   ""400a&V
iz*S07:S@4G		&$"5"5d";";<<DJJLL!!VJJsOOE((266I5zzH''x!|R@@H s++I9~~H''	8a<DDHW$$8w+>+>(hBVBV !% 0 0 E E ( -I#t|ZSSH)1C$++--)GE+&+++++---KK!["! !  E LL''E..J		$++j>.IDK.W"X"XZbccI!*!2!2 K G %Vu__sZ''*M'!8##z5F'F'F 3sT^^E2222$//111!%"% %   U++!^^E22
 IIdkk*~2MPTP[2[&\&\^cdd	%.__%6%6$6  eOO8););53++CC99U++DDD//111U++!^^E22
!'#!7#!=!Ds!JZ!WZ_!_bfbm!m IIdkk.&A&A8LL	$(K%.*/ 
 eOO8););53++CC99U++DfdwOOOr  c
                    |d S |                      |d          }
|                     |d          }|                      |d          }|
dk    s|dk    rn|dk    rh|dk    rb|s`| j        dz   |z   }|                     | j        d	         ||           |                     | j        d
         |
|           t          |          d S )Nr  r  r9  r   Success	SucceededOk r   r   )r  r  r.   throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr   )r   httpCodereasonr,  r  r.  r-  r%  requestHeadersrequestBodyr  r  r9  feedbacks                 r  handle_errorszcoinex.handle_errors  s    4&11x00""8Y77CKKg22K9O9OV]aeVeVeosVew}w.H001I7T\]]]001I4QYZZZ)))tr  c                 "  K   |                                   d{V  |                     |d          }|                     |d          }|d}ddd|d}| |                     |          }|d         |d<   |||d	<   |||d
<   |                     |                     ||                     d{V }	|                     |	di           }
|                     |
dg           }|                     |ddd          }| 	                    ||||          S )ab  
        fetches the history of margin added or reduced from contract isolated positions
        :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http046_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=100, max=100
        :param dict params: extra parameters specific to the exchange api endpoint
        :param int [params.until]: timestamp in ms of the latest change to fetch
         *
         * EXCHANGE SPECIFIC PARAMETERS
        :param int [params.offset]: offset
        :returns dict[]: a list of `margin structures <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        Nuntilr  r2  r   )rH  rR  r  r  r.   rH  r  r  r  r  r<   )
r  r  r  rH  *v1PerpetualPrivateGetPositionMarginHistoryr  r  rh  parse_margin_modificationsr  )r   rL  rS  r  r  r$  rS  r  rH  r%  r  r  modificationss                r  fetch_margin_adjustment_historyz&coinex.fetch_margin_adjustment_history$  sR      !!!!!!!!!!!&'2267++=E	
 
 [[((F &tGH$)GL!"'GJHHU\^dIeIeffffffff8 ~~h33..y"5577xQWXX00uUUUr  r  )NN)r__name__
__module____qualname__r   r   r;  r   r   rF  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   rL  rw  rO  r   r   r   rm  rN  r   r  r   r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r'  r*  r.  r7  r=  r   r;  rH  rK  rO  rR  rQ  ro  r   r  r  r   rz  r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
   r  r	   r  r  r  rD  rQ  rW  __classcell__)r  s   @r  r,   r,      s       N N N N N` -/ y y: y y y yv *, ; ;V ; ; ; ;"S S Sj\ \ \|B B6 BV B B B BH 68 I; I; I;F I; I; I; I;V 6:" ^G ^G7 ^G ^G ^G ^G ^G@ ') 4 4 4 4( @B" M? M?S M? M? M? M? M?^s s s5 s s s sj <@d[] *I *I *IS *I *Ibfglbm *I *I *I *IX ;= >6 >6c >6AT >6 >6 >6 >6@ /1 A A[ A A A AF

 

V 

?R 

 

 

 


 
 
4 
 
 
 
, 8<$]ajl 3H 3H 3HC 3HWZ 3Hquvzq{ 3H 3H 3H 3Hj 13 M) M) M) M)^ /1 ") ") ") ")H /1 ) ) ) )B 46 #) #) #) #)J *, 9 9 9 9 9 94	: 	: 	:G G G5 G G G GR
 XZ T Tc T T T T T  os{} r, r,3 r,i r,y r,Z_ r,hk r, r, r, r,h mqy{ X. X. X.I X.Y X.X] X.fi X. X. X. X.t FH X X$|*< XDQVK X X X Xt 6:" | |s | | | || fjx|  FH <. <.3 <. <.9 <.I <._b <.ru <. <. <. <.| 9=R i. i.S i.# i. i. i. i.V 59 . .c . . . .` 8<B C. C.C C. C. C. C. C.J BFTXgktv N? N?3 N?c N?ad N? N? N? N?` 59tZ^gi Z Zc Z ZTW Znrsxny Z Z Z Z 7;\`ik [ [ [3 [VY [ptuzp{ [ [ [ [ >@ : : : : : :< =? + + + + + +Z	
 	
 	
 	
 	
 	
" "X " " " "
 
h 
 
 
 
2 37TX\eg {? {?C {?s {?RU {? {? {? {?z 8<B gP gPW gP gP gP gPR 8: J4 J43 J4 J4 J4 J4Xf fv f f f fP DHPR %c %c %cS %c %c %c %cN ?C2  c  c3  c  c  c  c  cD =A > >' > > > ><     $ SU G G G G G GRX
 X
f X
HZ X
 X
 X
 X
t <> 	J 	Js 	JBT 	J 	J 	J 	J ?A 	J 	J# 	JEW 	J 	J 	J 	J 9=4^bkm E E# ES EX[ E E E EN <> 47 47s 47 47 47 47l2
 2
6 2
 2
 2
 2
h <@ ?? ?? ?? ?? ?? ??B EIQS 0= 0=3 0= 0= 0= 0= 0=d: : : >BPTcgpr CY CYs CY# CY]` CY CY CY CYJj
 j
x j
; j
 j
 j
 j
X ac * *3 * *C *TW *gt * * * *X: : :7
 7
 7
 7
 7
 7
r 154VZce WG WG# WGS WGPS WG WG WG WGr 37TX\eg <E <EC <Es <ERU <Elpq|l} <E <E <E <E| 04$UYbd <E <E <EC <Es <Eimnyiz <E <E <E <E|
 
v 
 
 
 
B DF #= #=s #= #= #= #=J 8: # # # #J 7;$]apt} +Q +Q +QC +QWZ +Qjm +Q +Q +Q +QZ%
 %
& %
 %
 %
 %
N Z\ ! !3 !c !5 ! ! ! !F RT  # S    B
 
 
 
 
 
4 BFb )A )Aw )A )A )A )AV)# )# )# )#V :>b *N *NT#Y *NY *N *N *N *NX	
 	
x 	
 	
 	
 	
 @BPT $ $ $ $ $ $ # # #  b$T TP TP TP TPl   CGTXgkz~  HJ @V @VC @Vc @Vad @Vtw @V  OS  Tf  Og @V @V @V @V @V @V @V @Vr  r,   )1 ccxt.async_support.base.exchanger   ccxt.abstract.coinexr   r?  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   ccxt.base.decimal_to_precisionr)   ccxt.base.preciser*   r,    r  r  <module>rd     s   6 5 5 5 5 5 , , , , , ,  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) . . . . . . 1 1 1 1 1 1 + + + + + + 4 4 4 4 4 4 % % % % % %HUV HUV HUV HUV HUVX{ HUV HUV HUV HUV HUVr  