
    E#i                         S SK rS SKJrJrJr  S SKrS SKJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr   " S
 S\R@                  RB                  5      r!g)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)AnyBalancesBoolIntNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTrade)Client)List)ExchangeError)ArgumentsRequired)
BadRequest)Precisec                     ^  \ rS rSrS\4U 4S jjrS r0 4S\4S jjrS\	4S jr
SS0 4S	\S
\S\S\\   4S jjrS\	4S jrSAS jrS\	4S jr0 4S	\S\4S jjrS0 4S\S\4S jjr0 4S	\S\4S jjrS\	4S jrSAS jr0 4S\4S jjrSSS0 4S	\S
\S\S\\   4S jjrSSS0 4S	\S
\S\S\\   4S jjrS\	4S jr S\	4S jr!SAS jr"S\	4S jr#SAS jr$S r%S r&S\	4S  jr'S0 4S	\S\S\(4S! jjr)S\	4S" jr*S# r+S\	4S$ jr,S% r-S& r.S'SS0 4S	\S(\S
\S\S\\/   4
S) jjr0S\	4S* jr1S\	4S+ jr2S\	4S, jr3S\	4S- jr4S0 4S.\S	\4S/ jjr5SSS0 4S	\S
\S\4S0 jjr6S0 4S	\S1\7S2\8S3\9S4\:S\4S5 jjr;SS0 4S.\S	\S1\7S2\8S3\:S4\:S\4S6 jjr<S0 4S.\S	\4S7 jjr=S0 4S8\\   S	\4S9 jjr>S\	4S: jr?S\	4S; jr@S\	S\A4S< jrBS\	4S= jrCS\	4S> jrD0 4S? jrES@rFU =rG$ )Bcex   returnc           	         > U R                  [        [        U ]  5       0 SS_SS_SS_SS_SS_SS_S	S_S
S_SS_SS_SS _SS_SS_SS_SS_SS_SS_SSS.ESSS00S0 00 0 S.5      $ )NwsTwatchBalancewatchTickerwatchTickerswatchTradeswatchTradesForSymbolsFwatchMyTradeswatchOrderswatchOrderBook
watchOHLCVwatchPositioncreateOrderWseditOrderWscancelOrderWscancelOrdersWsfetchOrderWsfetchOpenOrdersWs)fetchTickerWsfetchBalanceWsapizwss://ws.cex.io/ws	orderbook)hasurlsoptions	streaming
exceptions)deep_extendsuperr   describe)self	__class__s    F/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/cex.pyr;   cex.describe   s-   c4 9 ;d t 	
 t (   t !$ d     t   !$  !" $T#$ "&"&', . RA">
 " "	    c                     U R                  U R                  U R                  SS5      S5      nXR                  S'   [        U5      $ )N	requestIdr      )sumsafe_integerr6   str)r<   rB   s     r>   
request_idcex.request_id9   s;    HHT..t||[!LaP	$-[!9~r@   c                   #    U R                  U5      I Sh  vN   U R                  5       nU R                  S   S   nS0 U R                  5       S.nU R                  XA5      nU R	                  X2XRU5      I Sh  vN $  Nf N7f)a(  
watch balance and get the amount of funds available for trading or funds locked in orders

https://cex.io/websocket-api#get-balance

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr2   r   get-balanceedataoid)authenticaterG   r5   r9   watch)r<   paramsmessageHashurl	subscriberequests         r>   watch_balancecex.watch_balance>   s      '''oo'iit$??$
	
 ""95ZZ'PPP 	( Qs"   BA>A!B9B :B Bclientc                    U R                  US0 5      nU R                  US0 5      nU R                  US0 5      nSU0n[        UR                  5       5      n[        S[	        U5      5       HT  nXx   n	U R                  5       n
U R                  XI5      U
S'   U R                  XY5      U
S'   U R                  U	5      nXU'   MV     U R                  U5      U l	        U R                  US5      nUR                  U R                  U5        g )	NrM   balanceobalanceinfor   freeusedrN   )
safe_valuelistkeysrangelenaccountsafe_stringsafe_currency_codesafe_balancerZ   resolve)r<   rX   messagerM   freeBalanceusedBalanceresultcurrencyIdsi
currencyIdrd   coderR   s                r>   handle_balancecex.handle_balanceR   s    * w3oodIr:oodJ;D
 ;++-.q#k*+A$JllnG"..{GGFO"..{GGFO**:6D"4L , ((0&&w6t||[1r@   Nsymbolsincelimitc                   #    U R                  5       I Sh  vN   U R                  U5      nUS   nU R                  S   S   nSnSU-   nXR                  S'   U R	                  U R
                  U5      n	U	bm  [        U	R                  R                  5       5      n
[        S[        U
5      5       H1  nX   nX:X  a  M  USS	 nUS
:X  d  M  [        U R                  S-   5      e   SSUS   -   S-   US   -   /S.nU R                  X5      nU R                  XgX5      I Sh  vN n[        S[        U5      5       H
  nXU   S'   M     U R                  XUSS5      $  GNE N>7f)a  
get the list of most recent trades for a particular symbol. Note: can only watch one symbol at a time.

https://cex.io/websocket-api#old-pair-room

: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 dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
Nrs   r2   r   tradeszold:currentWatchTradeSymbolr      oldz; watchTrades() only supports watching one symbol at a time.rT   pair-base-quoterL   rooms	timestampT)load_marketsmarketr5   r6   r_   clientsr`   subscriptionsra   rb   rc   r   idr9   rP   filter_by_since_limit)r<   rs   rt   ru   rQ   r   rS   rR   subscriptionHashrX   subscriptionKeysrn   subscriptionKeyri   rU   rw   s                   r>   watch_tradescex.watch_tradesy   sv     !!!V$!iit$!F?28./s3#F$8$8$=$=$?@1c"234"2"5"6"1!A"6"e+'2o(opp 5 v.4vgFG
 ""73zz#GNNq#f+&A"(1Ih '))&TRR5 	", Os)   E EB/E 
AE E <E E c                    U R                  US/ 5      nU R                  U R                  SS5      n[        U5      nU R	                  U R                  S5      nUc  g U R                  U5      n[        U5      n[        SU5       H1  n	US-
  U	-
  n
X:   nU R                  X5      nUR                  U5        M3     SnXPl
        UR                  U R                  U5        g )NrM   tradesLimit  rx   r   rC   rw   )	safe_listrE   r6   r   re   r   rc   rb   parse_ws_old_tradeappendrw   rh   )r<   rX   ri   rM   ru   storedrs   r   
dataLengthrn   indexrawTradeparsedrR   s                 r>   handle_trades_snapshotcex.handle_trades_snapshot   s     ~~gvr2!!$,,tDE"!!$,,0IJ>V$Y
q*%ANQ&E{H,,X>FMM&!	 &
 t{{K0r@   c                    [        U[        5      (       d  UR                  S5      nU R                  US5      nU R	                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  UUUU R                  U5      U R                  US5      S US S UUS S S.U5      $ )	N:r   rC      ry      rs   )r\   r   r   datetimers   typesideordertakerOrMakerpriceamountcostfee)
isinstancer`   splitre   rE   
safe_tradeiso8601)r<   trader   r   r   r   r   r   s           r>   r   cex.parse_ws_old_trade   s     %&&KK$Eq)%%eQ/	!!%+  *eQ'"Y/&&vx8  
  	r@   c                 "   U R                  US/ 5      nU R                  n[        U5      n[        SU5       H1  nUS-
  U-
  nX7   nU R	                  U5      n	UR                  U	5        M3     Sn
X@l        UR                  U R                  U
5        g )NrM   r   rC   rw   )r_   rw   rc   rb   r   r   rh   )r<   rX   ri   rM   r   r   rn   r   r   r   rR   s              r>   handle_tradecex.handle_trade   s     w3Y
q*%ANQ&E{H,,X6FMM&!	 &
 t{{K0r@   c                   #    U R                  5       I Sh  vN   U R                  U5      nUS   nU R                  S   S   nSU-   nU R                  USS5      nSS	/S
.nS	nUS:X  a9  U R	                  5       I Sh  vN   SUS   US   /U R                  5       S.nSU-   nU R                  Xr5      n	U R                  XEX5      I Sh  vN $  N NR N7f)a  

https://cex.io/websocket-api#ticker-subscription

watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.method]: public or private
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Nrs   r2   r   ticker:methodprivaterT   tickersr   tickerbaseIdquoteIdrK   )r   r   r5   re   rO   rG   r9   rP   )
r<   rs   rQ   r   rS   rR   r   ri   r   rU   s
             r>   watch_tickercex.watch_ticker   s     !!!V$!iit$&(!!&(I>
 %Y##%%%8$fY&7 (G  )61""73ZZ'LLL1 	" & Ms5   CCA%C<C=ACC	CCCsymbolsc                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  S   S   nSnSS/S.nU R                  XR5      nU R	                  X4Xd5      I Sh  vN nUS   nUb/  U R                  X5      (       d  U R                  X5      I Sh  vN $ U R                  (       a  0 n	XyU'   U	$ U R                  U R                  SU5      $  N Ns N>7f)a  

https://cex.io/websocket-api#ticker-subscription

watches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
: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>`
Nr2   r   r   rT   r   rs   )
r   market_symbolsr5   r9   rP   in_arraywatch_tickers
newUpdatesfilter_by_arrayr   )
r<   r   rQ   rS   rR   ri   rU   r   tickerSymbolrl   s
             r>   r   cex.watch_tickers  s      !!!%%g.iit$
 ""73zz#GIIh't}}\'K'K++G<<<??F#)< M##DLL(GDD' 	" J =s4   C$CAC$,C -6C$#C"$;C$ C$"C$c                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  S   S   nU R                  5       nU R	                  SUUS   US   /S.U5      nU R                  XEXe5      I Sh  vN $  No N7f)a  

https://docs.cex.io/#ws-api-ticker-deprecated

fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the cex api endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr2   r   r   r|   r~   rL   rN   rM   )r   r   r5   rG   extendrP   )r<   rs   rQ   r   rS   rR   rU   s          r>   fetch_ticker_wscex.fetch_ticker_ws5  s      !!!V$iit$oo'++F^VG_5
 	
 ZZ'GGG 	" Hs"   B
BA*B
BB
B
c                    U R                  US0 5      nU R                  U5      nUS   nUc  g X@R                  U'   SU-   nUR                  XF5        UR                  US5        U R	                  US5      nUb  UR                  XF5        g g )NrM   rs   r   r   rN   )r_   parse_ws_tickerr   rh   re   )r<   rX   ri   rM   r   rs   rR   s          r>   handle_tickercex.handle_tickerJ  s     w3%%d+!>%V&(v+vy)&&w6"NN6/ #r@   c           	      "   U R                  US/ 5      nU R                  US5      nUc  U R                  US5      nU R                  US5      nUc  U R                  US5      nU R                  U5      nU R                  U5      nUS-   U-   nU R                  US5      n	U	b  U	S-  n	U R	                  0 S	U_SU	_S
U R                  U	5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SS _SU R                  US5      _SS _SS _SU R                  US5      _SS _SU R                  USS5      _SS _SU R                  US5      _SU R                  US5      _SS _S U R                  US5      US.EU5      $ )Npairsymbol1r   symbol2rC   /r   r   rs   r   highlowbid	bidVolumeask	askVolumevwapopenopen24closelastr   previousClosechangepriceChange
percentagepriceChangePercentageaveragevolume)
baseVolumequoteVolumer\   )r_   re   rf   rE   safe_tickerr   safe_string_2)
r<   r   r   r   r   r   r|   r~   rs   r   s
             r>   r   cex.parse_ws_tickerd  s.   0 vvr2!!&)4>%%dA.F""695?&&tQ/G&&v.''0e#%%fk:	 !D(I !
f!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4##FE2!
 !
 4##FE2!
 !
 D!
 D$$VX6!
 T!
 D&&vw?!
 T!
 d&&v}=!
  $**63JK!!
" t#!
$ ++FH=)!
* + 	r@   c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  S   S   nU R                  5       nU R	                  SUS.U5      nU R                  X#XC5      I Sh  vN $  Nm NW N7f)a&  

https://docs.cex.io/#ws-api-get-balance

query for balance and get the amount of funds available for trading or funds locked in orders
:param dict [params]: extra parameters specific to the cex api endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr2   r   rJ   )rL   rN   )r   rO   r5   rG   r   rP   )r<   rQ   rS   rR   rU   s        r>   fetch_balance_wscex.fetch_balance_ws  s      !!!!!!iit$oo'++
  ZZ'GGG 	"! Hs2   B
BB
BAB
?B B
B
B
c                   #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      I Sh  vN   U R                  S   S   nU R                  U5      nUS   nSU-   nSSUS	   US
   /0US.nU R                  X5      n	U R                  XWXU	5      I Sh  vN n
U R                  (       a  U
R                  X5      nU R                  XX#S5      $  N N N=7f)a  
get the list of orders associated with the user. Note: In CEX.IO system, orders can be present in trade engine or in archive database. There can be time periods(~2 seconds or more), when order is done/canceled, but still not moved to archive database. That means, you cannot see it using calls: archived-orders/open-orders.

https://docs.cex.io/#ws-api-open-orders

: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 dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
Nz) watchOrders() requires a symbol argumentr2   r   rs   orders:open-ordersr   r   r   rK   T)r   r   r   rO   r5   r   r9   rP   r   getLimitfilter_by_symbol_since_limit)r<   rs   rt   ru   rQ   rS   r   rR   ri   rU   orderss              r>   watch_orderscex.watch_orders  s     >#DGG.Y$YZZ!!!'''iit$V$!&(8$9% 	
 ""73zz#G'RR??OOF2E00tTT) 	"'  Ss4   /C3C-C3
C/A(C33C14:C3/C31C3c                   #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      I Sh  vN   U R                  S   S   nU R                  U5      nSUS   -   nSUS   -   nSS	US
   US   /0US   S.n	U R                  X5      n
U R                  XWXU
5      I Sh  vN nU R                  XS   X#5      $  N N N7f)a  
get the list of trades associated with the user. Note: In CEX.IO system, orders can be present in trade engine or in archive database. There can be time periods(~2 seconds or more), when order is done/canceled, but still not moved to archive database. That means, you cannot see it using calls: archived-orders/open-orders.

https://docs.cex.io/#ws-api-open-orders

: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 dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
Nz+ watchMyTrades() requires a symbol argumentr2   r   	myTrades:rs   r   r   r   r   r   rK   )	r   r   r   rO   r5   r   r9   rP   r   )r<   rs   rt   ru   rQ   rS   r   rR   r   ri   rU   r   s               r>   watch_my_tradescex.watch_my_trades  s     >#DGG.[$[\\!!!'''iit$V$!F8$44$vh'778$9% (#	
 ""73zz#GwWW009I5XX% 	"'  Xs4   /CCC
CA1C<C=CCCc                     U R                  US5      nU R                  US5      nUc  g U R                  X5        U R                  X5        g )NrM   r   )r_   re   handle_order_updatehandle_my_trades)r<   rX   ri   rM   r   s        r>   handle_transactioncex.handle_transaction  sH    w/""43?  1f.r@   c                    U R                  US0 5      nU R                  nUc.  U R                  U R                  SS5      n[	        U5      nX@l        U R                  U5      nUR                  U5        SUS   -   nUR                  XG5        g )NrM   r   r   r   rs   )r_   myTradesrE   r6   r   parse_ws_trader   rh   )r<   rX   ri   rM   r   ru   r   rR   s           r>   r   cex.handle_my_trades  s    V w3>%%dllM4HE+E2F"M##D)e!E(O3v+r@   c                 R   U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      n	US-   U	-   n
U R                  US5      nUS:X  a  U	S-   U-   n
[        R                  " X5      nU R                  US	5      U R                  US
5      UU R	                  U5      UU
S US US US S.nU R                  US5      nUb	  UU	S S.US'   U R                  X5      $ )Nr   r   timers   r   r   r   sellr   r   )r   r   r\   r   r   rs   r   r   r   r   r   r   r   
fee_amountr   currencyrater   )re   rf   r   
string_div	parse8601r   )r<   r   r   r   r   r   r   r   r|   r~   rs   r   parsedTrader   s                 r>   r   cex.parse_ws_trade7  sS   0 v.  0##E62!!%2""5)4&&v.''0e#!!%26>S[4'F''6F""5$/%%eW51  
 ul3?!"K
 {33r@   c                 f   U R                  US0 5      nU R                  US5      S:H  nU R                  USS5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US	5      n	U	b$  U R                  U	S
5      nU R                  U	S5      nU R                  U5      n
U R                  U5      nU
S-   U-   nU R	                  U5      nU R                  X5      nU R                  c-  U R                  U R                  SS5      n[        U5      U l        U R                  nU R                  UR                  U0 5      nU R                  UU5      nUc  U R                  X=5      nUUS'   U R                  USS5      nU(       a  SUS'   U(       a  SUS'   U R                  US5      nUb	  UUS S.US'   U R                  US5      nUUS'   U R                  U5      US'   U R                  U5      nUR!                  U5        SU-   nUR#                  UU5        g )NrM   rL   txr   r   remainsrs   r   r   r   r   ordersLimitr   	remainingcancelFcanceledstatusclosedr   r  r  r   r   r   )r_   re   r   rf   safe_marketcurrency_from_precisionr   rE   r6   r   hashmapparse_ws_order_update	safe_boolsafe_numberr   
safe_orderr   rh   )r<   rX   ri   rM   isTransactionorderIdr  r   r   r   r|   r~   rs   r   ru   storedOrdersordersBySymbolr   r  r   r   rR   s                         r>   r   cex.handle_order_updates  s8   J w3((#6$>$$T49""43!!$1""43tV,%%dI6F&&tY7G&&v.''0e#!!&)..t=;;%%dllM4HE07DK{{)=)=vrJ8=..t<E$k>>$%8(E(O&E(OtU+?!E%L
 %%dF3	&k LL3j&E"&(|[1r@   c           	      b   U R                  US5      S LnU R                  US5      nS nUb  U R                  US   U5      nU R                  US5      nU(       d  U R                  US   U5        U R                  US5      nU R                  US5      nU R                  US5      n	U	b$  U R                  US5      nU R                  US5      nU R                  U5      n
U R                  U5      nS nU
b  Ub  U
S	-   U-   nU R	                  X5      nU R                  US
U R                  5       5      nUnU(       a  U R                  U5      nU R                  USS5      nSnU(       a  SnO	U(       a  Sn0 SU R                  USS5      _SS _SU_SU_SU R                  U5      _SS _SU_SU_SS _SS _SS _SU R                  US5      _SU R                  US5      _SS _SS _SS _S S _US UU R                  US!S"5      US S#.S S$.EnU(       a  U R                  X5      US%'   U R                  UU5      $ )&Ndr  r|   r   rs   r   r   r   r   r  r  Fr   r  r  r   r   clientOrderIdr\   r   r   lastTradeTimestampr  r   timeInForcepostOnlyr   r   	stopPricetriggerPricer   r   r   r  r  )r   filledr  r   rw   rw   )r_   re   r  rf   r  rE   millisecondsr  r  r   r   r  safe_number_2r   r  )r<   r   r   r  remainsPrecisionr  r   r   r   r   r|   r~   rs   r  r   r  r  parsedOrders                     r>   r  cex.parse_ws_order_update  s   J s34?++E9=	'44VF^EUVI!!%2((@!!%2""5)4uf-%%eY7F&&ui8G&&v.''0 1CZ%'F!!&1  0A0A0CD	t,I>>%59FF
$$$UD':
T
 E
 	

 Y/
 !$
 f
 f
 D
 4
 
 D$$UF3
 T%%eW5
 
 D
  t!
" D#
$ "**5%F!
 5
8 $($7$7$FK!{F33r@   c                     Uc  g [        U5      nU R                  UR                  U5      Ul        UR                  5         [	        U5      $ N)r   rD   decimalsreducerF   )r<   r   scaleprecises       r>   from_precisioncex.from_precisionG  s@    >&/88G$4$4e<7|r@   c                 d    U R                  U R                  U   SS5      nU R                  X#5      $ )N	precisionr   )rE   
currenciesr4  )r<   r  r   r2  s       r>   r  cex.currency_from_precisionO  s0    !!$//(";[!L""611r@   c                    U R                  US5      nU R                  US/ 5      nU R                  nU R                  c(  U R                  U R                  SS5      n[        U5      n[        S[        U5      5       H?  nXG   nU R                  U5      n	U R                  X5      n
SU
S'   UR                  U
5        MA     XPl        SU-   n[        U5      nUS:  a  UR                  X[5        g g )	NrN   rM   r  r   r   r   r  r   )re   r_   r   rE   r6   r   rb   rc   r  parse_orderr   rh   )r<   rX   ri   rs   	rawOrdersmyOrdersru   rn   rawOrderr   r   rR   ordersLengths                r>   handle_orders_snapshotcex.handle_orders_snapshotS  s      !!'51OOGVR8	;;;;%%dllM4HE-e4Hq#i.)A |H%%f-F$$X6E$E(OOOE" * &(8}!NN81 r@   c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  U5      nUS   nU R                  S   S   nSU-   nUc  SOUnSUS   US	   /S
US.U R	                  5       S.nU R                  X5      n	U R                  XVX5      I Sh  vN n
U
R                  5       $  N N N7f)a  
watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://cex.io/websocket-api#orderbook-subscribe

: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
Nrs   r2   r   
orderbook:r   order-book-subscriber   r   T)r   rT   depthrK   )r   rO   r   r5   rG   r9   rP   ru   )r<   rs   ru   rQ   r   rS   rR   rE  rT   rU   r3   s              r>   watch_order_bookcex.watch_order_booku  s      !!!!!!V$!iit$"V+m%' 8$9% " ??$
	 ""95**SwLL	  + 	"!& Ms2   CCCCA>C-C.CCCc                    U R                  US0 5      nU R                  US5      nU R                  U5      nSU-   nU R                  USS5      nU R	                  US5      nU R                  0 5      n	U R                  X5USS5      n
XS	'   U	R                  U
5        S
U0U R                  S   U'   XR                  U'   UR                  X5        g )NrM   r   rC  timestamp_msr   r   bidsasksnonceincrementalIdr3   )r_   re   pair_to_symbolsafe_integer_2rE   
order_bookparse_order_bookresetr6   
orderbooksrh   )r<   rX   ri   rM   r   rs   rR   r   rM  r3   snapshots              r>   handle_order_book_snapshotcex.handle_order_book_snapshot  s    . w3f-$$T*"V+''nkJ	))$5OOB'	((y&&Q)!]-
[!&) #,y.r@   c                     UR                  S5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nUS-   U-   nU$ )Nr   r   rC   r   )r   re   rf   )r<   r   partsr   r   r|   r~   rs   s           r>   rN  cex.pair_to_symbol  sf    

3!!%+""5!,&&v.''0e#r@   c                 f   U R                  US0 5      nU R                  US5      nU R                  USS5      nU R                  U5      nU R                  U R                  U5      nSU-   nXGS   S-   :w  a-  UR
                  U	 UR                  U R                  S-   U5        g U R                  US	5      n	U R                  US
/ 5      n
U R                  US/ 5      nU R                  US
   U
5        U R                  US   U5        XS'   U R                  U	5      US'   XGS'   UR                  Xx5        g )NrM   r   r    rC  rL  rC   z# watchOrderBook() skipped a messager  rK  rJ  r   r   )r_   rE   re   rN  rS  r   rejectr   handle_deltasr   rh   )r<   rX   ri   rM   rM  r   rs   storedOrderBookrR   r   rK  rJ  s               r>   handle_order_book_updatecex.handle_order_book_update  s2    w3))$5fb1$$T*//$//6B"V+G4q88$$[1MM$''$II;W%%dF3	tVR0tVR0?62D9?62D9'0$&*ll9&=
##0 4r@   c                 L    U R                  USS5      nUR                  U5        g )Nr   rC   )parse_bid_ask
storeArray)r<   booksidedeltabidAsks       r>   handle_deltacex.handle_delta  s$    ##E1a0F#r@   c                 d    [        S[        U5      5       H  nU R                  XU   5        M     g )Nr   )rb   rc   rg  )r<   rd  deltasrn   s       r>   r]  cex.handle_deltas  s)    q#f+&Ahq	2 'r@   1m	timeframec                   #    U R                  5       I Sh  vN   U R                  U5      nUS   nSU-   nU R                  S   S   nSUSUS   -   S	-   US
   -   /S.n	U R                  XU R	                  X5      U5      I Sh  vN n
U R
                  (       a  U
R                  X5      nU R                  XUSS5      $  N N<7f)a  

https://cex.io/websocket-api#minute-data

watches historical candlestick data containing the open, high, low, and close price, and the volume of a market. It will return the last 120 minutes with the selected timeframe and then 1m candle updates after that.
: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
Nrs   ohlcv:r2   r   z
init-ohlcvr{   r   r}   r   )rL   rn   r   r   T)r   r   r5   rP   r   r   r   r   )r<   rs   rm  rt   ru   rQ   r   rR   rS   rU   ohlcvs              r>   watch_ohlcvcex.watch_ohlcv  s      !!!V$!'iit$&**S06)3DD
 jj4;;w3OQ\]]??NN61E))%q$GG 	" ^s"   CB>A,CC ;C Cc                    U R                  US5      nUR                  S5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nUS-   U-   n	U R                  U	5      n
SU	-   nU R	                  US/ 5      nU R                  U R                  SS	5      n[        U5      nU R                  US5      n[        S[        U5      5       H'  nUR                  U R                  UU   U
5      5        M)     XR                  ;  a  0 U R                  U	'   XR                  U	   S
'   UR                  X5        g )Nr   r   r   rC   r   ro  rM   
OHLCVLimitr   unknown)re   r   rf   r  r_   rE   r6   r   sort_byrb   rc   r   parse_ohlcvohlcvsrh   )r<   rX   ri   r   rX  r   r   r|   r~   rs   r   rR   rM   ru   r   sortedrn   s                    r>   handle_init_ohlcvcex.handle_init_ohlcv  s:   $ 0

3!!%+""5!,&&v.''0e#!!&)'w3!!$,,dC&u-dA&q#f+&AMM$**6!9f=> '++%"$DKK)/FI&v+r@   c                     U$ r/   r<   rX   ri   s      r>   handle_ohlcv24cex.handle_ohlcv246  s	     r@   c           	         U R                  US0 5      nU R                  US5      nU R                  U5      nSU-   nU R                  US5      U R	                  US5      U R	                  US5      U R	                  US5      U R	                  US5      U R	                  US	5      /nU R                  U R
                  U5      nUR                  U5        UR                  X5        g )
NrM   r   ro  r  ohlcv)r_   re   rN  safe_timestampr  rx  r   rh   )	r<   rX   ri   rM   r   rs   rR   rp  r   s	            r>   handle_ohlcv1mcex.handle_ohlcv1m@  s      w3f-$$T*'f-T3'T3'T3'T3'T3'
 f5ev+r@   c           
      &   U R                  US/ 5      nU R                  US5      nU R                  U5      nSU-   nU R                  U   S   n[	        S[        U5      5       H  nU R                  X8   S5      U R                  X8   S5      U R                  X8   S5      U R                  X8   S5      U R                  X8   S	5      U R                  X8   S
5      /n	UR                  U	5        M     [        U5      n
U
S:  a  UR                  Xv5        g g )NrM   r   ro  ru  r   rC   r   ry   r      )
r_   re   rN  rx  rb   rc   r  r  r   rh   )r<   rX   ri   rM   r   rs   rR   r   rn   rp  r   s              r>   handle_ohlcvcex.handle_ohlcv`  s    w30$$T*'V$Y/q#d)$A##DGQ/  !,  !,  !,  !,  !,E MM%  % Y
>NN6/ r@   r   c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnUb  U R                  U5      nU R                  S[	        U5      0U5      nU R
                  S   S   nU R                  5       nSUUS.nU R                  XgX5      I Sh  vN n	U R                  X5      $  N N N7f)a>  
fetches information on an order made by the user

https://docs.cex.io/#ws-api-get-order

:param str id: the order id
:param str symbol: not used by cex fetchOrder
:param dict [params]: extra parameters specific to the cex api endpoint
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Norder_idr2   r   	get-orderr   )	r   rO   r   r   rF   r5   rG   rP   r;  )
r<   r   rs   rQ   r   rM   rS   rR   rU   responses
             r>   fetch_order_wscex.fetch_order_ws~  s      !!!!!![[(F{{B
 iit$oo'

 CgKK11! 	"! Ls2   B?B9B?B;A4B?#B=$B?;B?=B?c                   #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  5       I Sh  vN   U R	                  U5      nU R
                  S   S   nU R                  5       nU R                  SUS   US   /0U5      nSUUS	.n	U R                  XgX5      I Sh  vN n
U R                  XX#U5      $  N N N7f)
a  

https://docs.cex.io/#ws-api-open-orders

fetch all unfilled currently open orders
: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 cex api endpoint
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nz% fetchOpenOrdersWs requires a symbol.r2   r   r   r   r   r   r   )
r   r   r   rO   r   r5   rG   r   rP   parse_orders)r<   rs   rt   ru   rQ   r   rS   rR   rM   rU   r  s              r>   fetch_open_orders_wscex.fetch_open_orders_ws  s      >#DGG.U$UVV!!!!!!V$iit$oo'{{VH%vi'89
 

 CgKK  5HH 	"! Ls4   /CCC	C
A.C8C9CCCr   r   r   r   c                   #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  5       I Sh  vN   U R	                  U5      nU R
                  S   S   nU R                  5       n	U R                  US   US   /UUUS.U5      n
SU	U
S	.nU R                  XX5      I Sh  vN nU R                  X5      $  N N N7f)
a,  

https://docs.cex.io/#ws-api-order-placement

create a trade order
: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 currency you want to trade in units of base currency
:param float price: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the kraken api endpoint
:param boolean [params.maker_only]: Optional, maker only places an order only if offers best sell(<= max) or buy(>= max) price for self pair, if not order placement will be rejected with an error - "Order is not maker"
:returns dict: an `order structure <https://docs.ccxt.com/en/latest/manual.html#order-structure>`
Nz( createOrderWs requires a price argumentr2   r   r   r   )r   r   r   r   place-orderr   )
r   r   r   rO   r   r5   rG   r   rP   r;  )r<   rs   r   r   r   r   rQ   r   rS   rR   rM   rU   r>  s                r>   create_order_wscex.create_order_ws  s      =TWW'QQRR!!!!!!V$iit$oo'{{H%vi'89	

  

 CgKK11# 	"! Ls4   /CCC	C
A1C;C<CCCc                   #    Uc  [        U R                  S-   5      eUc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  5       I Sh  vN   U R	                  U5      nU R                  US   US   /UUUUS.U5      n	U R                  5       n
U R                  S   S   nS	U
U	S
.nU R                  XXU
5      I Sh  vN nU R                  X5      $  N N N7f)ar  
edit a trade order

https://docs.cex.io/#ws-api-cancel-replace

: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|None [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the cex api endpoint
:returns dict: an `order structure <https://docs.ccxt.com/en/latest/manual.html#order-structure>`
Nz' editOrder() requires a amount argumentz& editOrder() requires a price argumentr   r   )r   r   r   r   r  r2   r   cancel-replace-orderr   )
r   r   r   rO   r   r   rG   r5   rP   r;  )r<   r   rs   r   r   r   r   rQ   r   rM   rR   rS   rU   r  s                 r>   edit_order_wscex.edit_order_ws  s
     >#DGG.W$WXX=#DGG.V$VWW!!!!!!V${{H%vi'89
  oo'iit$'

 CgKXX11% 	"!  Ys7   A
C4C.C4$C0%A3C4C2C40C42C4c                 r  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnUb  U R                  U5      nU R                  SU0U5      nU R	                  5       nU R
                  S   S   nSUUS.nU R                  XvXU5      I Sh  vN n	U R                  X5      $  N N N7f)a%  

https://docs.cex.io/#ws-api-order-cancel

cancels an open order
:param str id: order id
:param str symbol: not used by cex cancelOrder()
:param dict [params]: extra parameters specific to the cex api endpoint
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r2   r   cancel-orderr   )r   rO   r   r   rG   r5   rP   r;  )
r<   r   rs   rQ   r   rM   rR   rS   rU   r  s
             r>   cancel_order_wscex.cancel_order_ws  s      !!!!!![[(F{{
 oo'iit$

 CgKXX11! 	"! Ys2   B7B1B7B3A,B7B5B73B75B7idsc                   #    Ub  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  5       I Sh  vN   U R	                  5       nU R                  SU0U5      nU R                  S   S   nSUUS.nU R                  XdXtU5      I Sh  vN nU R                  US5      n	U R                  U	SSSU5      $  N N N/7f)a8  
cancel multiple orders

https://docs.cex.io/#ws-api-mass-cancel-place

:param str[] ids: order ids
:param str symbol: not used by cex cancelOrders()
:param dict [params]: extra parameters specific to the cex api endpoint
:returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nz1 cancelOrderWs does not allow filtering by symbolzcancel-ordersr2   r   mass-cancel-place-ordersr   )
r   r   r   rO   rG   r   r5   rP   r_   r  )
r<   r  rs   rQ   rR   rM   rS   rU   r  canceledOrderss
             r>   cancel_orders_wscex.cancel_orders_ws!  s      TWW'ZZ[[!!!!!!oo'{{S
 iit$+

 CgKXX ?C  tT6JJ1 	"! Ys4   /CCC	C
AC C!,CCCc                 n    U R                  US5      nU R                  US5      nUR                  X45        g )NrM   rN   )r_   re   rh   )r<   rX   ri   rM   rR   s        r>   resolve_datacex.resolve_dataH  s2    $ w/&&w6t)r@   c                     U$ r/  r}  r~  s      r>   handle_connectedcex.handle_connected^  s	     r@   c                     U R                  US0 5      nU R                  US5      nU R                  USS5      nU R                  S-   U-   S-   U-   nU R                  U R                  S   XF5        U R                  U R                  S   XF5        [        U5      e! [         aG  nU R                  US5      nU R                  US	   U5      nUb  UR                  XG5         S nAg
UeS nAff = f)NrM   errorrL   r[   exactbroadrN   futuresT)	r_   re   r   throw_exactly_matched_exceptionr8   throw_broadly_matched_exceptionr   	Exceptionr\  )	r<   rX   ri   rM   r  eventfeedbackrR   futures	            r>   handle_error_messagecex.handle_error_messagef  s    	??7FB7D$$T73E$$Wc26Eww}u,s2U:H001I5[001I5[)) 	**7E:K__VI%6DF!e1	s   BB 
C,%;C'%C''C,c                    U R                  US5      nUS:X  a  U R                  X5        g U R                  US5      n0 SU R                  _SU R                  _SU R                  _SU R                  _SU R
                  _S	U R                  _S
U R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                   _SU R                  _U R                  U R                  U R                  U R                  S.EnU R#                  XT5      nUb	  U" X5        g g )Nokr  rL   auth	connectedtickr   zinit-ohlcv-dataohlcv24ohlcv1mrp  rJ   rD  	md_updater   r   zhistory-updatehistoryr  r  )r  r  r  r  )re   r  handle_authentication_messager  r   rz  r  r  r  rq   rU  r_  r  r   r   r   r   r_   )r<   rX   ri   r  r  handlershandlers          r>   handle_messagecex.handle_message  s   gt,=%%f6  #.
D66
..
 D&&
 d((	

 t55
 t**
 t**
 T&&
 4..
 #D$C$C
 66
 4,,
 T--
 d//
 t22
  $))!
" 4,,#
$ %)$5$5 --(,(9(9**+
. //(2F$ r@   c                 f    U R                  UR                  S5      nUb  UR                  S5        g g )NauthenticatedT)r_   r  rh   )r<   rX   ri   r  s       r>   r  !cex.handle_authentication_message  s/     ANN4  r@   c                 R  #    U R                   S   S   nU R                  U5      nSnUR                  S5      nU R                  UR                  U5      nUc  U R                  5         [        U R                  5       5      nXpR                  -   nU R                  U R                  U5      U R                  U R                  5      [        R                  5      n	SU R                  U	R                  5       US.S.n
U R                  X$U R!                  X5      U5        UI S h  vN $  N7f)Nr2   r   r  r  )key	signaturer   )rL   r  )r5   rX   reusableFuturer_   r   check_required_credentialsrF   secondsapiKeyhmacencodesecrethashlibsha256upperrP   r   )r<   rQ   rS   rX   rR   r  r  rL  r  r  rU   s              r>   rO   cex.authenticate  s     iit$S!%&&7(<(<kJ ++-'E;;&D		$++d"3T[[5Mw~~^I;;!*!2!&G JJsW)E{S||s   DD' D%!D')rZ   r   r   rw   r/  )H__name__
__module____qualname____firstlineno__r   r;   rG   r   rV   r   rq   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  r4  r  r@  r   rF  rU  rN  r_  rg  r]  r`   rq  rz  r  r  r  r  r  r   r   floatr
   r  r  r  r  r  r  r   r  r  r  rO   __static_attributes____classcell__)r=   s   @r>   r   r      s   ## #J
 *, Q Q(%2V %2N <@d[] &S &SS &S &Sbfglbm &SP1V 1:<16 1* 68 #M #MF #MJ 6:" E7 E E> 9; HC Hv H*0F 04:x -/ H8 H& 04$UYbd "U "UC "Us "Uimnsit "UH 37TX\eg  YC  Ys  YRU  Ylpqvlw  YD/ /4,v 4,l:4xo2& o2ba4F2 2V  2D @DB  !S  !  !S\  !D%/ %/N!5v !5F$3 ?CQUdhqs H H H3 H^a Hx|  ~B  yC H<$, $,LV ,V ,@06 0< ;?r 2s 2C 2: 8<$]ajl I IC IWZ I< pt|~ "2C "2y "2	 "2[` "2il "2  DI "2H im{  IK %2c %23 %2i %2y %2be %2ux %2  PU %2N <@ 2 2S 2: DHPR %K$s) %KS %KN*6 *,v 6 t 4%V %B!F ! )+  r@   r   )"ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r  ccxt.base.typesr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   ccxt.base.preciser   async_supportr   r}  r@   r>   <module>r     sW     f f  H  H  H  H 4  * . ' %r$


 
  rr@   