
    E#i                     *   S SK rS SKJr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  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJ r   S SKJ!r!  S SKJ"r"  S SK#J$r$   " S S\RJ                  RL                  5      r&g)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)AnyBalancesBoolIntMarketOrder	OrderBookPositionStrStringsTickerTickersTrade)Client)List)ExchangeError)AuthenticationError)ArgumentsRequired)
BadRequest)NotSupported)RateLimitExceeded)ChecksumError)UnsubscribeError)Precisec                      ^  \ rS rSrS\4U 4S jjrS r0 4S jr0 4S jr0 4S jr	0 4S jr
0 4S	 jrS
\4S jr0 4S jr0 4S\S\S\S\4S jjrS\4S jrSFS\S\S
\S\4S jjr0 4S\S\4S jjr0 4S\S\4S jjrS0 4S\S\4S jjrS
\4S jrSFS jrSSS0 4S\S\S\S\S\\   4
S  jjr S0 4S\S\S\4S! jjr!S
\4S" jr"SFS\S\4S# jjr#S0 4S\S\S\$4S$ jjr%0 4S\S\4S% jjr&S0 4S\\   S\S\$4S& jjr'S
\4S' jr(S
\S\S(\4S) jr)S* r*S+ r+SS0 4S\S\S\S\\,   4S, jjr-SS0 4S\\   S\S\S\\,   4S- jjr.0 4S\S\4S. jjr/S
\4S/ jr0SFS\,4S0 jjr10 4S\24S1 jjr3S
\4S2 jr4SSS0 4S\S\S\S\\5   4S3 jjr6S
\4S4 jr7SFS5\8S\S\54S6 jjr9SSS0 4S\S\S\S\\:   4S7 jjr;S\4S8 jr<S
\4S9 jr=SFS: jr>S
\S\?4S; jr@S
\4S< jrAS
\4S= jrBS
\4S> jrCS
\4S? jrDS
\4S@ jrES
\4SA jrFS
\4SB jrGS
\4SC jrHS
\4SD jrISErJU =rK$ )G	coincatch   returnc                 <  > U R                  [        [        U ]  5       SSSSSSSSSSSSSS.SSSSS.00S	S
SSSSSSSSSS.	SS0S.SU R                  0S[
        [        [
        [        [        [        [        [        [        [        [
        [        S.0 S.0S.5      $ )NTF)wswatchTradeswatchTradesForSymbolswatchOrderBookwatchOrderBookForSymbols
watchOHLCVwatchOHLCVForSymbolswatchOrderswatchMyTradeswatchTickerwatchTickerswatchBalancewatchPositionsapir$   z'wss://ws.coincatch.com/public/v1/streamz(wss://ws.coincatch.com/private/v1/stream)publicprivate     1m5m15m30m1H4H12H1D1W)	r6   r7   r8   r9   1h4h12h1d1wchecksum)tradesLimit
OHLCVLimittimeframesForWsr'   ping)300013000230003300043000530006300073001130012300133001430015)exactbroad)hasurlsoptions	streaming
exceptions)deep_extendsuperr    describerH   r   r   r   )self	__class__s    L/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/coincatch.pyr^   coincatch.describe   s    i ? A#)-"&,0"(-#!&# $ $"&  "K#M  $!   
$ #& 		 !+!4!+!4!4!2!2!4!4!4!+!4  [@D
 @ @	    c                    U R                  US5      nU R                  US5      nU R                  U5      nUS   nUS   nSnUS:X  a  US:X  a  SnOS	nU R                  U5      U R                  U5      -   U-   nU R                  U5      $ )
NinstIdinstTypebaseIdquoteId_SPBLmcUSD_DMCBL_UMCBL)safe_stringparseSpotMarketIdsafe_currency_codesafeMarketCustom)	r_   entryre   rf   baseAndQuoterg   rh   suffixmarketIds	            ra   get_market_from_argcoincatch.get_market_from_arg\   s    !!%2##E:6--f5h'y)t%!!**62T5L5LW5UUX^^$$X..rc   c                 P  #    U R                  5         U R                  S   S   S   nU R                  U5      nSnUR                  U5      nU R	                  UR
                  U5      nUc  [        U R                  5       5      nUS-   S-   nU R                  U R                  U5      U R                  U R                  5      [        R                  S5      n	Sn
U
U R                  U R                  UU	S	./S
.nU R                  X5      nU R!                  X$X5        UI S h  vN $  N7f)Nr1   r$   r3   authenticatedGETz/user/verifybase64login)apiKey
passphrase	timestampsignopargs)check_required_credentialsrX   clientreusableFuture
safe_valuesubscriptionsstrsecondshmacencodesecrethashlibsha256r}   passwordextendwatch)r_   paramsurlr   messageHashfuturery   r   auth	signature	operationrequestmessages                ra   authenticatecoincatch.authenticatek   s    '')iit$Y/S!%&&{3(<(<kJ DLLN+Iu$~5D		$++d"3T[[5Mw~~_ghII #'++&*mm%. )	
G kk'2GJJs>||s   DD&D$ D&c                    #    U R                   S   S   S   nSU/S.nU R                  Xd5      nU R                  XQXr5      I S h  vN $  N7fNr1   r$   r2   	subscriber   rX   r   r   r_   r   subscribeHashr   r   r   r   r   s           ra   watch_publiccoincatch.watch_public   sS     iit$X.F
 ++g.ZZ'IIII   AAA	Ac                    #    U R                   S   S   S   nSU/S.nU R                  XS5      nU R                  XAXa5      I S h  vN $  N7f)Nr1   r$   r2   unsubscriber   r   )r_   r   r   r   r   r   r   s          ra   un_watch_publiccoincatch.un_watch_public   sS     iit$X.F
 ++g.ZZ'GGGGr   c                    #    U R                  5       I S h  vN   U R                  S   S   S   nSU/S.nU R                  Xd5      nU R                  XQXr5      I S h  vN $  NJ N7fNr1   r$   r3   r   r   )r   rX   r   r   r   s           ra   watch_privatecoincatch.watch_private   sm     !!!iit$Y/F
 ++g.ZZ'III 	" Js"   A%A!AA%A#A%#A%c                    #    U R                  5       I S h  vN   U R                  S   S   S   nSUS.nU R                  Xd5      nU R                  XQXr5      I S h  vN $  NI N7fr   )r   rX   r   watch_multiple)r_   messageHashessubscribeHashesr   r   r   r   r   s           ra   watch_private_multiple coincatch.watch_private_multiple   sm     !!!iit$Y/
 ++g.((WVVV 	" Ws"   A$A AA$A"A$"A$r   c                 b    SnU R                  UR                  U5      nUR                  S5        g )Nry   T)r   futuresresolve)r_   r   r   r   r   s        ra   handle_authenticatecoincatch.handle_authenticate   s)     &=trc   c                    #    U R                   S   S   S   nSUS.nU R                  Xd5      nU R                  XQXr5      I S h  vN $  N7fr   )rX   r   r   )r_   r   r   	argsArrayr   r   r   r   s           ra   watch_public_multiplecoincatch.watch_public_multiple   sS     iit$X.
 ++g.((WVVVVs   AA
AA
symbolchannelmessageHashTopicc                    #    U R                  5       I S h  vN   U R                  U5      nU R                  U5      u  pgSU-   S-   U-   nUUUS.n	U R                  XU5      I S h  vN $  NS N7f)Nzunsubscribe::rf   r   re   )load_marketsmarketget_public_inst_type_and_idr   )
r_   r   r   r   r   r   rf   re   r   r   s
             ra   un_watch_channelcoincatch.un_watch_channel   s     !!!V$;;FC$'77#=F 

 ))+VDDD 	" Es"   A.A*AA.%A,&A.,A.r   c                     US   US   -   nS nUS   (       a  SnX2/$ US   (       a  SnX2/$ [        U R                  S-   5      e)Nrg   rh   spotSPswapMCz$ supports only spot and swap markets)r   id)r_   r   re   rf   s       ra   r   %coincatch.get_public_inst_type_and_id   sb    !F9$55&>H
 !!	 F^H !! tww)OOPPrc   Nhash	timeframec                    US   nU R                  X25      nU R                  U R                  U/ 5      nSnUb  SU-   n[        S[	        U5      5       H-  n	Xy   nUS   n
X*-   U-   nU R                  X5      (       d  M+  Us  $    U$ )Nr    r   r   r   )find_message_hashes	safe_listmarkets_by_idrangelenin_array)r_   r   r   r   r   ru   r   marketsWithCurrentIdrt   ir   r   s               ra   %handle_dmcbl_market_by_message_hashes/coincatch.handle_dmcbl_market_by_message_hashes   s    $<00>  $~~d.@.@(BO 9_Fq#234A),FH%F-&0K}}[88 5 rc   c                    #    U R                  5       I Sh  vN   U R                  U5      nU R                  U5      u  pESnUS-   U-   nUUUS.nU R                  XwX5      I Sh  vN $  NR N7f)a<  
watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://coincatch.github.io/github.io/en/spot/#tickers-channel

: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.instType]: the type of the instrument to fetch the ticker for, 'SP' for spot markets, 'MC' for futures markets(default is 'SP')
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Ntickerr   r   )r   r   r   r   )	r_   r   r   r   rf   re   r   r   r   s	            ra   watch_tickercoincatch.watch_ticker   s      !!!V$;;FCmf, 

 &&{NNN 	" Os"   A-A)AA-$A+%A-+A-c                 z   #    U R                  5       I Sh  vN   U R                  USSU5      I Sh  vN $  N  N7f)a(  
unsubscribe from the ticker channel

https://coincatch.github.io/github.io/en/mix/#tickers-channel

:param str symbol: unified symbol of the market to unwatch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns any: status of the unwatch request
Nr   r   r   r_   r   r   s      ra   un_watch_tickercoincatch.un_watch_ticker   s;      !!!**68XvNNN 	"N   ;7;9;;symbolsc                   #    U R                  5       I Sh  vN   Uc  U R                  n/ n/ n[        S[        U5      5       HV  nX   nU R	                  U5      nU R                  U5      u  pUSU	S.n
UR                  U
5        UR                  SU-   5        MX     U R                  XDX25      I Sh  vN nU R                  (       a  0 nXUS   '   U$ U R                  U R                  SU5      $  N N?7f)a  
watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list

https://coincatch.github.io/github.io/en/mix/#tickers-channel

:param str[] symbols: unified symbol of the market to watch the tickers for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   r   r   ticker:r   )r   r   r   r   r   r   appendr   
newUpdatesfilter_by_arraytickers)r_   r   r   topicsr   r   r   r   rf   re   r   r   results                ra   watch_tickerscoincatch.watch_tickers
  s      !!!?llGq#g,'AZF[[(F#??GH$# D
 MM$  V!34 ( 22=QW``??F(/78$%M##DLL(GDD+ 	"  as"   C4C0BC42C23>C42C4c                    U R                  US0 5      nU R                  U5      nUS   nSnUR                  S5      S:  a  U R                  XFU5      nU R	                  US/ 5      nU R                  U R                  US0 5      U5      nUS   n	XR                  U	'   Xi-   n
UR                  U R                  U	   U
5        g )Nargr   r   rl   r   datar   )	safe_dictrv   findr   r   parse_ws_tickerr   r   )r_   r   r   r   r   ru   r   r   r   r   r   s              ra   handle_tickercoincatch.handle_ticker+  s    2 nnWeR0))#.$<=="a'??fUF~~gvr2%%dnnT1b&A6J!%Vmt||F+[9rc   c           
         U R                  US5      nU R                  USS5      nU R                  0 SUS   _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U R                  US5      _SU R                  US5      _SU R                  US5      _SS _SU R	                  USS5      _SU_SU_SS _SS _S[
        R                  " U R                  US5      S5      _SS _U R                  US5      U R                  US5      U R                  US 5      U R                  US!5      US".EU5      $ )#Nlastts
systemTimer   r   datetimehighhigh24hlowlow24hbidbestBid	bidVolumebidSzaskbestAsk	askVolumeaskSzvwapopenopen24hopenUtcclosepreviousClosechange
percentagechgUTC100average
baseVolumequoteVolume
indexPrice	markPrice)r  r  r  r  info)rn   safe_integer_2safe_tickeriso8601safe_string_2r   
string_mulsafe_number)r_   r   r   r   r   s        ra   r   coincatch.parse_ws_tickerQ  s   ^ /''lC	 !
fX&!
!
 Y/!
 D$$VY7	!

 4##FH5!
 4##FI6!
 ))&':!
 4##FI6!
 ))&':!
 D!
 D&&vy)D!
 T!
 D!
 T!
 d!
  ',,T-=-=fh-OQVW!!
" t#!
$ **6<@++FMB**6<@))&+>-!
. / 	rc   r6   sincelimitc                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  S   nSU R                  Xr5      -   nU R	                  U5      u  pU	UU
S.nSU-   S-   U-   nU R                  XX5      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  
watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://coincatch.github.io/github.io/en/spot/#candlesticks-channel

: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(not including)
:param int [limit]: the maximum amount of candles to fetch(not including)
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.instType]: the type of the instrument to fetch the OHLCV data for, 'SP' for spot markets, 'MC' for futures markets(default is 'SP')
:returns int[][]: A list of candles ordered, open, high, low, close, volume
NrG   candler   ohlcv:r   r   T)	r   r   rY   rn   r   r   r   getLimitfilter_by_since_limit)r_   r   r   r#  r$  r   r   
timeframesr   rf   re   r   r   ohlcvs                 ra   watch_ohlcvcoincatch.watch_ohlcv  s      !!!V$\\"34
T--jDD;;FC 

 '#-	9''$OO??NN61E))%q$GG 	" Ps"   CCA1CC	;CCc                    #    U R                  5       I Sh  vN   U R                  S   nU R                  XB5      nSU-   nU R                  XSU-   U5      I Sh  vN $  NG N7f)a  
       unsubscribe from the ohlcv channel

       https://www.bitget.com/api-doc/spot/websocket/public/Candlesticks-Channel

       :param str symbol: unified symbol of the market to unwatch the ohlcv for
@param timeframe
       :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
       NrG   r&  r'  )r   rY   rn   r   )r_   r   r   r   r*  intervalr   s          ra   un_watch_ohlcvcoincatch.un_watch_ohlcv  sk      !!!\\"34
##J:X%**6Hx<OQWXXX	 	" Ys"   A"AAA"A A" A"c                    U R                  US0 5      nU R                  U5      nUS   nSnU R                  US/ 5      nU R                  US5      nUSS  n	U R	                  U	5      n
UR                  S5      S:  a  U R                  XFX5      nUS	   nXR                  ;  a  0 U R                  U'   XR                  U   ;  a8  U R                  U R                  S
S5      n[        U5      U R                  U   U
'   U R                  U   U
   n[        S[        U5      5       H7  nU R                  X~/ 5      nU R                  X5      nUR                  U5        M9     Xk-   S-   U
-   nUR                  UU5        g )Nr   r   r'  r   r      rl   r   r   rF   r4   r   )r   rv   r   rn   find_timeframer   r   ohlcvssafe_integerrY   r   r   r   parse_ws_ohlcvr   r   )r_   r   r   r   r   ru   r   r   r   	klineTyper   r   r$  storedr   r&  parsedr   s                     ra   handle_ohlcvcoincatch.handle_ohlcv  sl   $ nnWeR0))#.$<~~gvr2""3	2ABK	''	2	=="a'??f`F!++%"$DKK[[00%%dllL$GE-B5-IDKK	*V$Y/q#d)$A^^DR0F((8FMM&! % mc)I5v{+rc   c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Nr                  )r6  r!  )r_   r+  r   s      ra   r7  coincatch.parse_ws_ohlcv  sn     eQ'UA&UA&UA&UA&UA&
 	
rc   c                 D   #    U R                  U/X#5      I Sh  vN $  N7f)a  
watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://coincatch.github.io/github.io/en/spot/#depth-channel

: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
N)watch_order_book_for_symbols)r_   r   r$  r   s       ra   watch_order_bookcoincatch.watch_order_book  s"      66xOOOOs     c                    #    U R                  5       I Sh  vN   SnU R                  US5      nUS:X  d  US:X  a   U R                  US5      nU[        U5      -  nU R	                  XX25      I Sh  vN $  N^ N7f)a  
unsubscribe from the orderbook channel

https://coincatch.github.io/github.io/en/spot/#depth-channel

:param str symbol: unified symbol of the market to fetch the order book for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.limit]: orderbook limit, default is None
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
Nbooksr$  rB     )r   r6  omitr   r   )r_   r   r   r   r$  s        ra   un_watch_order_bookcoincatch.un_watch_order_book  s|      !!!!!&'2QJERKYYvw/Fs5z!G**6GLLL 	" Ms"   A9A5AA90A71A97A9c                   #    U R                  5       I Sh  vN   U R                  U5      nSn/ n/ n[        S[        U5      5       HY  nX   nU R	                  U5      n	U R                  U	5      u  pU
UUS.nUR                  U5        UR                  US-   U-   5        M[     U R                  XfXS5      I Sh  vN nUR                  5       $  N N7f)a  
       watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

       https://coincatch.github.io/github.io/en/spot/#depth-channel

@param symbols
       :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
       NrI  r   r   r   )	r   market_symbolsr   r   r   r   r   r   r$  )r_   r   r$  r   r   r   r   r   r   r   rf   re   r   	orderbooks                 ra   rE  &coincatch.watch_order_book_for_symbols(  s      !!!%%g.q#g,'AZF[[(F#??GH$" D
 MM$  3!78 ( 44]SYbb	  # 	"  cs"   CCB"C9C:CCc                    U R                  US0 5      nU R                  U5      nUS   nSnUR                  S5      S:  a  U R                  XFU5      nUS   nU R	                  US5      nXg-   n	U R                  US/ 5      n
U R                  U
S5      nU R                  US	5      nUnU(       Ga  XpR                  ;  a#  U R                  0 5      nX~S'   XR                  U'   U R                  U   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'   U R                  U R                  SS5      nU R	                  US5      S:H  nU(       Gd  U(       Ga  US
   nUS   n[        U5      n[        U5      n/ n[        SS5       Hy  nUU:  a4  UR                  UU   S   S   5        UR                  UU   S   S   5        UU:  d  ME  UR                  UU   S   S   5        UR                  UU   S   S   5        M{     SR!                  U5      nU R#                  US5      nU R                  US5      nUU:w  a  U R%                  U R&                  XU	5        g OCU R)                  0 5      nU R+                  XU5      nUR-                  U5        UU R                  U'   UR/                  U R                  U   U	5        g )Nr   r   zbooks:rl   r   r   r   r   r   asksbidsr   r   rD   Tactionsnapshot   r?  r>  r   )r   rv   r   r   rn   r   r6  
orderbookscounted_order_bookhandle_deltasr  	safe_boolrY   r   r   r   joincrc32spawnhandle_check_sum_error
order_bookparse_order_bookresetr   )r_   r   r   r   r   ru   r   r   r   r   r   rawOrderBookr   incrementalBookobstoredOrderBookrS  rT  rD   
isSnapshot
storedAsks
storedBids
asksLength
bidsLengthpayloadArrayr   payloadcalculatedChecksumresponseChecksumrP  parsedOrderbooks                                  ra   handle_order_bookcoincatch.handle_order_bookF  s     nnWeR0))#.$<=="a'??fUF!""3	2m~~gvr2~~dA.%%lD9	!oo-,,R0%8*,'"oof5O>>,;D>>,;Dv6=v6=+4K(*.,,y*AOJ'~~dllJEH))'8<
JJ(,V4
,V4
 _
 _
!q"A:~$++JqM!,<Q,?@$++JqM!,<Q,?@:~$++JqM!,<Q,?@$++JqM!,<Q,?@ & ((<0%)ZZ%>"#'#4#4\:#N %)99JJt::FKX+I"33L)TOOOO,&/DOOF#tv.<rc   r   c                    #    U R                  U5      I S h  vN   [        U R                  S-   U R                  U5      -   5      nUR	                  XC5        g  N@7f)N )rL  r   r   orderbook_checksum_messagereject)r_   r   r   r   errors        ra   r_   coincatch.handle_check_sum_error  sL     &&v...dggmd.M.Mf.UUVe) 	/s   AAAAc                 n    U R                  USS5      nUR                  U5        UR                  U5        g )Nr   r>  )parse_bid_askr   
storeArray)r_   booksidedeltabidAsks       ra   handle_deltacoincatch.handle_delta  s0    ##E1a0eF#rc   c                 d    [        S[        U5      5       H  nU R                  XU   5        M     g )Nr   )r   r   r  )r_   r|  deltasr   s       ra   rZ  coincatch.handle_deltas  s)    q#f+&Ahq	2 'rc   c                 F   #    U R                  U/X#U5      I Sh  vN $  N7f)a  
get the list of most recent trades for a particular symbol

https://coincatch.github.io/github.io/en/spot/#trades-channel

: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>`
N)watch_trades_for_symbols)r_   r   r#  r$  r   s        ra   watch_tradescoincatch.watch_trades  s$      22F8U6RRRRs   !!c                   #    [        U5      nUS:X  a  [        U R                  S-   5      eU R                  5       I Sh  vN   U R	                  U5      n/ n/ n[        S[        U5      5       HV  nX   n	U R                  U	5      n
U R                  U
5      u  pUSUS.nUR                  U5        UR                  SU	-   5        MX     U R                  XwXd5      I Sh  vN nU R                  (       a6  U R                  US5      nU R                  US5      nUR                  UU5      nU R                  XUSS	5      $  N Na7f)
a  
       watches information on multiple trades made in a market

       https://coincatch.github.io/github.io/en/spot/#trades-channel

@param symbols
       :param int [since]: the earliest time in ms to fetch orders for
       :param int [limit]: the maximum number of trade structures to retrieve
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
       r   z> watchTradesForSymbols() requires a non-empty array of symbolsNtrader   trade:r   r   T)r   r   r   r   rO  r   r   r   r   r   r   r   rn   r(  r)  )r_   r   r#  r$  r   symbolsLengthr   r   r   r   r   rf   re   r   tradesfirsttradeSymbols                    ra   r  "coincatch.watch_trades_for_symbols  s:     GA#DGG.n$noo!!!%%g.q#g,'AZF[[(F#??GH$" D
 MM$  F!23 ( 11-PV__??NN61-E**5(;KOOK7E))&TRR) 	" `s$   =ED= BED?A E?Ec                 z   #    U R                  5       I Sh  vN   U R                  USSU5      I Sh  vN $  N  N7f)a(  
unsubscribe from the trades channel

https://coincatch.github.io/github.io/en/spot/#trades-channel

:param str symbol: unified symbol of the market to unwatch the trades for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns any: status of the unwatch request
Nr  r   r   s      ra   un_watch_tradescoincatch.un_watch_trades  s;      !!!**67GVLLL 	"Lr   c                 p   U R                  US0 5      nU R                  U5      nUS   nSnUR                  S5      S:  a  U R                  XFU5      nUS   nXpR                  ;  a5  U R                  U R                  SS5      n[        U5      U R                  U'   U R                  U   n	U R                  US	/ 5      n
U
ba  U R                  U
S5      n
[        S[        U
5      5       H6  nU R                  X5      nU R                  X5      nU	R                  U5        M8     Xg-   nUR                  X5        g )
Nr   r   r  rl   r   r   rE   r4   r   )r   rv   r   r   r  r6  rY   r   r   sort_byr   r   parse_ws_trader   r   )r_   r   r   r   r   ru   r   r   r$  r9  r   r   r  r:  r   s                  ra   handle_tradescoincatch.handle_trades  s     nnWeR0))#.$<=="a'??fUF!++%%%dllM4HE",U"3DKKV$~~gvr2<<a(D1c$i(t/,,U;f% ) mv+rc   c                     U R                  US5      nU R                  S UU R                  U5      US   U R                  US5      U R	                  US5      U R	                  US5      S S S S S US.U5      $ )Nr   r   r@  r>  r?  )r   r   r   r   sidepriceamountcosttakerOrMakertypeorderfeer  )r6  
safe_trader  safe_string_lowerrn   )r_   r  r   r   s       ra   r  coincatch.parse_ws_trade  s     %%eQ/	"Y/X&**5!4%%eQ/&&ua0  
  	rc   c                    #    SnU R                  SSU5      u  p!SnUS:X  a  SnSnU R                  USSU5      u  p1UUSS	.nS
UR                  5       -   nU R                  XfXQ5      I Sh  vN $  N7f)a  
watch balance and get the amount of funds available for trading or funds locked in orders

https://coincatch.github.io/github.io/en/spot/#account-channel
https://coincatch.github.io/github.io/en/mix/#account-channel

:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.type]: 'spot' or 'swap'(default is 'spot')
:param str [params.instType]: *swap only* 'umcbl' or 'dmcbl'(default is 'umcbl')
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr/   spblr   umcblaccountrf   defaultr   balance:)handle_market_type_and_paramshandle_option_and_paramslowerr   )r_   r   r  rf   r   r   r   s          ra   watch_balancecoincatch.watch_balance  s      99.$PVW6>H88Q[]ef 

 !8>>#33''$OOOOs   A(A1*A/+A1c                    U R                  US/ 5      n[        S[        U5      5       H  nX4   nU R                  USS5      nU R	                  U5      nXpR
                  ;   a  U R
                  U   OU R                  5       nSU;   a  SOSn	U R                  XY5      US'   U R                  US5      US	'   U R                  US
5      US'   XR
                  U'   M     U R                  U R
                  5      U l        U R                  US5      n
U R                  U
S5      nSU-   nUR                  U R
                  U5        g )Nr   r   coinName
marginCoinmaxTransferOut	availablefreeequitytotalfrozenusedr   rf   r  )r   r   r   r  rp   balancer  rn   safe_balancer   r  r   )r_   r   r   r   r   
rawBalance
currencyIdcoder  	freeQueryr   rf   r   s                ra   handle_balancecoincatch.handle_balance,  s)   J ~~gvr2q#d)$AJ++J
LQJ**:6D-1\\-Adll4(G-=-K(R]I"..zEGFO#//
HEGG"..z8DGFO!(LL % ((6nnWe,))#z: 8+t||[1rc   c                   #    SnU R                  5       I Sh  vN   SnSnUb  U R                  U5      nUS   nUS   nSnU R                  XVU5      u  pSn	Un
US:X  a(  Uc$  [        U R                  S-   U-   S-   U-   S	-   5      eO4S
n
Sn	Uc  U R                  XESU	5      u  pOUR                  S5      S:  a  Sn	SnU R                  US5      nU(       a  SnU R                  US5      nU	UU
S.nSnUb  USU-   -  nU R                  XX5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XX#S5      $  GN4 N<7f)aH  
watches information on multiple orders made by the user

https://coincatch.github.io/github.io/en/spot/#order-channel
https://coincatch.github.io/github.io/en/mix/#order-channel
https://coincatch.github.io/github.io/en/mix/#plan-order-channel

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.type]: 'spot' or 'swap'
:param str [params.instType]: *swap only* 'umcbl' or 'dmcbl'(default is 'umcbl')
:param bool [params.trigger]: *swap only* whether to watch trigger orders(default is False)
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
r+   Nr   r   r  r   rt  z"() requires a symbol argument for z	 markets.r  r  rf   rl   r   dmcblorderstrigger
ordersAlgor   r   T)r   r   r  r   r   r  r   r[  rK  r   r   r(  filter_by_symbol_since_limit)r_   r   r#  r$  r   
methodNamer   ru   
marketTyperf   re   r   	isTriggerr   r   r  s                   ra   watch_orderscoincatch.watch_ordersb  s    " #
!!![[(FH%Fd|H
!??
TZ[
~'#
(BEi(ilv(v  zE  )E  F  F  FH~#'#@#@U_ai#j &==*a/&HNN695	"GYYvy1F 

 3<'K))+DQQ??OOF2E00tTTM 	"F Rs"   EEC9EE:EEc                 r   U R                  US0 5      nU R                  US5      nU R                  US5      nS nUS:X  a  SnOSnU R                  US/ 5      nU R                  c-  U R	                  U R
                  SS	5      n[        U5      U l        S
n	U R                  n
S n[        S[        U5      5       Hl  nX|   nU R                  USU5      nU R                  US S U5      nU R                  X5      nU
R                  U5        US   nSU-   nUR                  U
U5        Mn     UR                  X5        g )Nr   rf   re   r  r   r   r   ordersLimitr4   r  r   r   zorders:)r   rn   r   r  r6  rY   r   r   r   safe_marketparse_ws_orderr   r   )r_   r   r   r   rf   	argInstIdr  r   r$  r   r9  r   r   r  ru   r   r:  r   s                     ra   handle_ordercoincatch.handle_order  s7   B nnWeR0##C4$$S(3	
vJJ~~gvr2;;%%dllM4HE07DKq#d)$AGE''xCH%%hdJGF((7FMM&!H%F#f,KNN6;/ % 	v$rc   r  c                 n   U R                  US5      nU R                  US5      nU R                  X2U5      nU R                  US5      nUS   nU R                  US5      nU R                  US/ 5      nU R	                  US5      n	[
        R                  " U R                  U	S5      S	5      n
U R                  U	S
5      nU R                  U R                  US5      5      nU R                  U R                  US5      5      nUc  UnU R                  US5      nU R                  0 SU R                  US5      _SU R                  US5      _SU_SU R                  U5      _SS _SU R                  US5      _SU R                  U5      _SU_SU_SU R                  U R                  US5      5      _SU R                  US5      _SU_SU R                  US5      _SU R                  US5      _SU R                  US 5      _S!S _S"S _S S U R                  US#5      S UU
S$.U R                  US%5      S US&.EU5      $ )'Nre   tgtCcycTimer   statusorderFeer   r  z-1feeCcypxavgPxordTyper   ordIdclientOrderIdclOrdIdr   r   lastTradeTimestamplastUpdateTimestampuTimer  timeInForceforcer  r  r  r  szfilled	accFillSz	remainingtriggerPricenotional)currencyr  r  )takeProfitPricestopLossPricer  r  r  
reduceOnlypostOnlyr  )rn   rq   r6  r   r   r   r   	omit_zeror  
safe_orderr  parse_order_statusparseOrderTimeInForcer[  )r_   r  r   ru   settleIdr   r   	rawStatusr  r  feeCostfeeCurrencyr  priceAvgr  s                  ra   r  coincatch.parse_ws_order  s   ` ##E84##E84&&xB%%eW5	!$$UH5	>>%R8nnXq)$$T%5%5c5%A4H&&sH5t//t<=>>$"2"25'"BC=E%%eY7  
$""5'2 
T--eY? 
  
 Y/	 

 !$ 
 "4#4#4UG#D 
 d--i8 
 f 
 D 
 455d6L6LUT[6\] 
 D**5&9 
 U 
 t''w7 
 d&&ud3 
 d&&uk: 
  ! 
" D# 
$  $!$$UJ7' ..69 
: ; 	rc   c                   #    U R                  5       I Sh  vN   U R                  US5      n/ nSn/ nUb  [        S[        U5      5       Hg  nX   n	U R	                  U	5      n
U R                  U
5      nU R                  X5      (       d  UR                  U5        UR                  US-   U	-   5        Mi     OSS/nUR                  U5        / n/ n[        S[        U5      5       H5  nXx   nUUSS	.nUR                  US-   U-   5        UR                  U5        M7     U R                  X]X5      I Sh  vN nU R                  (       a  U$ U R                  XX#S
5      $  GNH N-7f)a  
       watch all open positions

       https://coincatch.github.io/github.io/en/mix/#positions-channel

       :param str[]|None symbols: list of unified market symbols
@param since
@param limit
       :param dict params: extra parameters specific to the exchange API endpoint
       :returns dict[]: a list of `position structure <https://docs.ccxt.com/en/latest/manual.html#position-structure>`
       Nr   	positionsr   ::r  r  r  r   T)r   rO  r   r   r   get_private_inst_typer   r   r   r   filter_by_symbols_since_limit)r_   r   r#  r$  r   r   r   	instTypesr   r   r   rf   r   r   r   newPositionss                   ra   watch_positionscoincatch.watch_positionsU  si     !!!%%gv6	1c'l+ V,55f=}}X99$$X.$$TD[6%9: , !'*I  &q#i.)A |H$#C
 ""4$;#9:KK * "88Y]ff??11,W[\\= 	"6 gs"   E#EDE#3E!4+E#!E#c                 :    US   nUR                  S5      S:  a  gg)Nr   rl   r   r  r  )r   )r_   r   ru   s      ra   r  coincatch.get_private_inst_type  s"    $<=="a'rc   c                    U R                   c  [        5       U l         U R                   nU R                  US/ 5      n[        U5      nUS:X  a  g / n/ n[	        S[        U5      5       HN  nXH   n	U R                  U	5      n
UR                  U
S   5        UR                  U
5        UR                  U
5        MP     SnU R                  X5      n[	        S[        U5      5       H  nX   nUR                  S5      nUS   nU R                  X5      (       d  M5  / n[	        S[        U5      5       H$  nUU   n
U
S   U:X  d  M  UR                  U
5        M&     UR                  UU5        M     UR                  Xk5        g )Nr   r   r   r  r  r>  )r  r   r   r   r   parse_ws_positionr   r   splitr   r   )r_   r   r   cacherawPositions
dataLengthr  r   r   rawPositionpositionr   r   r   partsr   positionsForSymboljs                     ra   handle_positionscoincatch.handle_positions  sf   F >>!57DNw;&
?q#l+,A&/K--k:HNN8H-.)LL" - 00>q#m,-A'*K%%d+E1XF}}V--%'"q#l"34A+AH)V3*11(; 5 1;? . 	|*rc   c                    U R                  US5      nU R                  US5      nU R                  X2U5      nU R                  US5      nU R                  US5      nU R                  USSS.5      nS nU R                  US5      n	U	S	:X  a  S
nOU	S:X  a  SnU R                  US5      n
[        R
                  " U
S5      nU R                  US5      nU R                  0 SUS   _SS _SU_SU R                  U5      _SU R                  US5      _SS _SU R                  US5      _SU_SU R                  US5      _SU R                  US5      _SU R                  US5      _SS _SU R                  US 5      _S!U R                  US!5      _S"U R                  US#5      _SU_S$U_S U R                  US%5      US U R                  US&5      U R                  US'5      S S S UUS(.E5      $ ))Nr   r  r  
marginModecrossisolated)crossedr  holdModedouble_holdTsingle_holdFuplRater  marginr   r   r   	contractsr  contractSizer  holdSider  leverageunrealizedPnluplrealizedPnlachievedProfits
collateral
entryPriceaverageOpenPricer  liquidationPriceliqPxhedgedkeepMarginRate
marginRater  )maintenanceMarginmaintenanceMarginPercentageinitialMargininitialMarginPercentagemarginRatior  	lastPricer  r  r  r  )
rn   rq   r6  get_supported_mappingr   r   r!  safe_positionr  r  )r_   r  r   ru   r  r   marginModeIdr  isHedgedr  percentageDecimalr  r  s                ra   r  coincatch.parse_ws_position  s   8 ##Hh7##Hl;&&xB%%h8	'',?//"?
 
 ##Hj9}$H&H ,,XyA''(95A
!!(H5!! #
fX&#
$#
 #
 Y/	#

 ))(G<#
 D#
 D**8Z@#
 #
 ))(J?#
 T--h>#
 4++H6GH#
 $#
 $**85GH#
 ))(K@#
  0 07 C#
  *!#
" h##
$ "&+/+;+;HFV+W#'+++HlC#'#4#4Xw#G!#$9#
  	rc   c                 :   U R                  US5      n US:X  a  U R                  US5      nU R                  S-   U R                  U5      -   nU R                  U R                  S   S   XE5        U R                  USS5      nU R                  U R                  S   S	   Xe5        [        U5      eg
! [         a`  n[        U[        5      (       a0  SnUR                  Xx5        XR                  ;   a  UR                  U	 OUR                  U5         S nAgS nAff = f)Neventrw  r  rt  r$   rU   msgr   rV   Fry   T)rn   r   jsonthrow_exactly_matched_exceptionr[   throw_broadly_matched_exceptionr   	Exception
isinstancer   rv  r   )	r_   r   r   r8  r  feedbackr9  er   s	            ra   handle_error_messagecoincatch.handle_error_message  s	      '2	''877S=499W+==44T__T5J75SUYd&&wr:44T__T5J75SUXc#H-- 	!011-a-"6"66,,[9a 	s   BB0 0
D:ADDc                 @   U R                  X5      (       a  g U R                  US5      nUS:X  a  U R                  X5        g US:X  a  U R                  X5        g U R                  US5      nUS:X  a  U R                  X5        g US:X  a  U R	                  X5        g US:X  a  U R                  X5        g U R                  US0 5      nU R                  US5      nUS	:X  a  U R                  X5        UR                  S
5      S:  a  U R                  X5        UR                  S5      S:  a  U R                  X5        US:X  a  U R                  X5        US:X  a  U R                  X5        US:X  d  US:X  a  U R                  X5        US:X  a  U R                  X5        g g )Nr   pongr8  r|   r   r   r   r   r   r&  r   rI  r  r  r  r  r  )rA  rn   handle_pongr   handle_subscription_statushandle_un_subscription_statusr   r   r   r;  rq  r  r  r  r  )r_   r   r   contentr8  r   r   s          ra   handle_messagecoincatch.handle_message-  s   $$V55""7I6fV-fV-  '2G$$V5K++F<M!..v?~~gub1""43hv/<<!Q&f.<< A%""63gv/i0xW%<f.k!!!&2 "rc   c                     g)NrH    )r_   r   s     ra   rH   coincatch.pingS  s    rc   c                 0    U R                  5       Ul        U$ N)millisecondslastPongr_   r   r   s      ra   rE  coincatch.handle_pongV  s    ++-rc   c                     U$ rO  rL  rR  s      ra   rF  $coincatch.handle_subscription_statusZ  s    rc   c                    U R                  US5      nUc  U R                  US0 5      /n[        S[        U5      5       H  nX4   nU R	                  US5      nUS:X  a  U R                  X5        M2  US:X  a  U R                  X5        MK  US:X  a  U R                  X5        Md  UR                  S5      (       d  M|  U R                  X5        M     U$ )	Nr   r   r   r   rI  r  r   r&  )
r   r   r   r   rn   !handle_order_book_un_subscriptionhandle_trades_un_subscriptionhandle_ticker_un_subscription
startswithhandle_ohlcv_un_subscription)r_   r   r   argsListr   r   r   s          ra   rG  'coincatch.handle_un_subscription_status]  s    >>'62wr:;Hq#h-(A+C&&sI6G'!66vGG#226CH$226C##H--11&B ) rc   c                    U R                  US0 5      nU R                  US5      nUS:X  a  SOSnU R                  US5      nU R                  US S U5      nUS   nSUS   -   n	S	U-   n
XR                  ;   a  U R                  U	 XR
                  ;   a  UR
                  U
	 XR
                  ;   a  UR
                  U		 [        U R                  S
-   U-   5      nUR                  X5        UR                  SU	5        g )Nr   rf   spr   r   re   r   zunsubscribe:orderbook:z
orderbook:z orderbook T)
r   r  rn   r  rX  r   r   r   rv  r   r_   r   r   r   rf   r  re   r   r   r   subMessageHashrw  s               ra   rW  +coincatch.handle_order_book_un_subscriptionn  s    nnWeR0))#z:"d*v!!#x0!!&$d;!.1AA%.__$'111$$^4...$$[1 =!86!ABe,t[)rc   c                    U R                  US0 5      nU R                  US5      nUS:X  a  SOSnU R                  US5      nU R                  US S U5      nUS   nSUS   -   n	S	U-   n
XR                  ;   a  U R                  U	 XR
                  ;   a  UR
                  U
	 XR
                  ;   a  UR
                  U		 [        U R                  S
-   U-   5      nUR                  X5        UR                  SU	5        g )Nr   rf   r_  r   r   re   r   zunsubscribe:trade:r  z trades T)
r   r  rn   r  r  r   r   r   rv  r   r`  s               ra   rX  'coincatch.handle_trades_un_subscription  s    nnWeR0))#z:"d*v!!#x0!!&$d;!*VH-==!F*[[ F#111$$^4...$$[1 :!5!>?e,t[)rc   c                    U R                  US0 5      nU R                  US5      nUS:X  a  SOSnU R                  US5      nU R                  US S U5      nUS   nSUS   -   n	S	U-   n
XR                  ;   a  U R                  U	 XR
                  ;   a  UR
                  U
	 XR
                  ;   a  UR
                  U		 [        U R                  S
-   U-   5      nUR                  X5        UR                  SU	5        g )Nr   rf   r_  r   r   re   r   zunsubscribe:ticker:r   z ticker T)
r   r  rn   r  r   r   r   r   rv  r   r`  s               ra   rY  'coincatch.handle_ticker_un_subscription  s    nnWeR0))#z:"d*v!!#x0!!&$d;!+fX.>>"V+\\!V$111$$^4...$$[1 :!5!>?e,t[)rc   c                    U R                  US0 5      nU R                  US5      nUS:X  a  SOSnU R                  US5      nU R                  US5      nUR                  SS	5      nU R                  U R                  S
5      n	U R                  X5      n
U R                  US S U5      nUS   nSU
-   S-   US   -   nSU-   S-   U
-   nXR                  ;   a"  XR                  U   ;   a  U R                  U   U
	 U R                  XU5        g )Nr   rf   r_  r   r   re   r   r&  r   rG   r   zunsubscribe:ohlcv:r   r'  )	r   r  rn   replacerY   r4  r  r5  clean_unsubscription)r_   r   r   r   rf   r  re   r   r/  r*  r   r   r   r   ra  s                  ra   r[  &coincatch.handle_ohlcv_un_subscription  s   nnWeR0))#z:"d*v!!#x0""3	2??8R0^^DLL2CD
''=	!!&$d;!*Y6<vh?OO!F*S09<[[ KK//KK'	2!!&+Frc   )r  r  r  rO  )L__name__
__module____qualname____firstlineno__r   r^   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r   listr,  r0  r;  r7  r   rF  rL  rE  rq  r_  r  rZ  r   r  r  r  r  r  r   r  r  r   r  r  dictr  r   r   r  r  r  r	   rA  rI  rH   rE  rF  rG  rW  rX  rY  r[  __static_attributes____classcell__)r`   s   @ra   r    r       s   A# AF/ )+ 6 KM J ?A H LN J Y[ W&  ]_ W _a 
ES 
E3 
ERU 
Eeh 
E	"& 	"F # W] jm $ 68 O OF O. 9; OC Os O 6:" E7 E EB$:F $:LHT ?CQUdhqs H H H3 H^a Hx|  ~B  yC H< BFb Y3 Y3 YUX Y"(,6 (,T
F 
d 
( @DB PS P PS\ P =? M M3 M& SW_a !$s) !C !fo !<C= C=J*6 *3 *UX *
$
3 <@d[] S SS S Sbfglbm S OSaenp #Sd3i #S #S[^ #Suyz  vA #SJ 9; MC Ms M,F ,<E 4 *, P P642V 42l 04$UYbd 8U 8UC 8Us 8Uimnsit 8UtY%6 Y%v\D \& \E \| 8<$]ajl *]W *]C *]WZ *]quv~q *]XF ?+v ?+BKZ6 t 0$3V $3L6 &  F "* *&*F *&*F *&G6 G Grc   r    )'ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r   r   ccxt.base.typesr   r   r	   r
   r   r   r   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   r   r   r   r   r   ccxt.base.preciser   async_supportr    rL  rc   ra   <module>r|     sb     A  A  ~ ~ ~ ~ 4  * 0 . ' ) . * - %`G"",, `Grc   