
    E#i                         S SK rS SKJrJrJrJ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  S SKJr  S SKJr  S SKJr   " S S\R4                  R6                  5      rg)	    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)AnyBalancesIntMarketOrder	OrderBookPositionStrStringsTickerTickersTrade)Client)List)NotSupportedc                     ^  \ rS rSrS\4U 4S jjrS\4S jrS rS r	SS0 4S	\
S
\
S\
S\S\\
   4
S jjrSS0 0 4S\
S	\
S
\
S\
S\
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0 4S\S\4S j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S0 4S\
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0 4S\
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#0 4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' r*S( r+S%\(S)\,4S* jr-S%\(S)\,4S+ jr.S%\(S)\,4S, jr/S%\(S)\,4S- jr0S%\(S)\,4S. jr1S=S/\,S\4S0 jjr2S=S1\,S\4S2 jjr3S%\(S)\,4S3 jr4S%\(S)\,4S4 jr5S%\(S)\,4S5 jr6S%\(4S6 jr7S%\(4S7 jr8S8 r9S%\(S9\,4S: jr:S%\(S)\,4S; jr;S<r<U =r=$ )>xt   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.00SSSSS0SS0SSSS.S.SU R                  S.S S .5      $ )!NwsT
watchOHLCVunWatchOHLCVwatchOrderBookunWatchOrderBookwatchTickerunWatchTickerwatchTickersunWatchTickerswatchTradesunWatchTradeswatchTradesForSymbolsFwatchBalancewatchOrderswatchMyTradeswatchPositionsapizwss://stream.xt.comzwss://fstream.xt.com/ws)spotcontract  methodtickertickersswap)typefetchPositionsSnapshotawaitPositionsSnapshot)tradesLimitordersLimit
OHLCVLimitr    r"   r*   i N  )	keepAliveping)hasurlsoptions	streamingtoken)deep_extendsuperr   describer:   )self	__class__s    E/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/xt.pyrB   xt.describe   sR   b$ 8 :dd  !$	
 #D t    !$ t   (  t    !$!&  5$=  $#"h  i! #.2.2#" #		 _0=
 0 0	    
isContractc                   #    U R                  5         U(       a  SOSnU R                  S   S   U   nU(       d  US-   nU R                  U5      nU R                  UR                  S5      nUc  U(       a8  U R                  5       I Sh  vN nU R                  US5      UR                  S'   OIU R                  5       I Sh  vN nU R                  US5      nU R                  US	5      UR                  S'   UR                  S   $  N| NF7f)
a  
@ignore
       required for private endpoints
       :param str isContract: True for contract trades

       https://doc.xt.com/#websocket_privategetToken
       https://doc.xt.com/#futures_user_websocket_v2base

       :returns str: listen key / access token
       r-   r,   r+   r   z/privater?   NresultaccessToken)check_required_credentialsr<   clientsafe_stringsubscriptions)privateLinearGetFutureUserV1UserListenKeyprivateSpotPostWsToken	safe_dict)rC   rH   	tradeTypeurlrM   r?   responserJ   s           rE   get_listen_keyxt.get_listen_keyC   s      	'')",J&	iit$Y/
"CS!  !5!5w?=!%!O!O!QQ 150@0@80T$$W-!%!<!<!>> (;040@0@0W$$W-##G,,3 R ?s%   BD
	D
7D
DAD
D
c                    U R                  US5      nU R                  US5      nU R                  USS5      nX5S-
  :  a  g[        S[	        U5      5       H#  nX&   nU R                  USS5      nX:  d  M!  Us  $    [	        U5      $ )Nnoncer   iu   )safe_integer
safe_valuesafe_integer_2rangelen)	rC   	orderbookcacherY   
firstDeltafirstDeltaNoncerZ   delta
deltaNonces	            rE   get_cache_indexxt.get_cache_indexr   s    !!)W5__UA.
--j#sCQ&&q#e*%AHE,,UC=J"	 &
 5zrG   c                    U R                  USS5      US'   U R                  US/ 5      nU R                  US/ 5      nUS   nUS   n[        S[        U5      5       H<  nXG   nU R	                  US5      n	U R	                  US	5      n
UR                  X5        M>     [        S[        U5      5       H<  nX7   nU R	                  US5      n	U R	                  US	5      n
UR                  X5        M>     g )
NrZ   r[   rY   abbidsasksr   r\   )r`   	safe_listra   rb   safe_numberstore)rC   rc   rg   obAsksobBidsrn   ro   rZ   bidpricequantityasks               rE   handle_deltaxt.handle_delta   s    !00SA	'sB/sB/  q#f+&A)C$$S!,E''Q/HJJu'	 '
 q#f+&A)C$$S!,E''Q/HJJu'	 'rG   Nnameaccess
methodNamemarketsymbolsc                   #    US:H  nSnU R                  X4U5      u  pUS:g  n	U R                  U R                  5       5      U-   n
U	(       a  SOSU
S.nU(       aR  U	(       d#  U/US'   U R                  U	5      I Sh  vN US'   O.U R                  U	5      I Sh  vN nUS	-   U-   nU/US'   OU/US'   U	(       a  S
OSnUS-   U-   nUb  US-   SR	                  U5      -   nU R                  X5      nUnU	(       a  U(       a  SOSnSU
0nU R                  S   S   U   S-   U-   nU R                  UUUUU5      I Sh  vN $  N N N7f)a  
@ignore
       Connects to a websocket channel

       https://doc.xt.com/#websocket_privaterequestFormat
       https://doc.xt.com/#futures_market_websocket_v2base

       :param str name: name of the channel
       :param str access: public or private
       :param str methodName: the name of the CCXT class method
       :param dict [market]: CCXT market
       :param str[] [symbols]: unified market symbols
       :param dict params: extra parameters specific to the xt api
       :returns dict: data from the websocket stream
       privateNr,   	SUBSCRIBE	subscriber/   idparams	listenKey@r-   ::,userr~   r   r+   r   /handle_market_type_and_paramsnumber_to_stringmillisecondsrV   joinextendr<   watch)rC   r{   r|   r}   r~   r   r   privateAccessr3   rH   r   r   r   paramrS   messageHashrequesttailsubscriptionrT   s                       rE   r   xt.subscribe   st      )+99*fUfn
""4#4#4#67$>%/k[
	 '+f	(#/3/B/B:/N)N	+&"&"5"5j"AA	s
Y.',g	(##'&Ih",J&	TkI-%,sxx/@@K++i0*6D"
 iit$Y/#5<ZZ[';UUU' *OA" Vs7   A9E;E <EEB"E;E<EEEr   topicc
           
        #    US:H  n
SnU R                  XFU5      u  pUS:g  nU R                  U R                  5       5      U-   nU(       a  SOSUS.nU
(       aR  U(       d#  U/US'   U R                  U5      I Sh  vN US'   O.U R                  U5      I Sh  vN nUS	-   U-   nU/US'   OU/US'   U(       a  S
OSnUS-   U-   nUb  US-   SR	                  U5      -   nU R                  X5      nUnU(       a  U
(       a  SOSnU R                  S   S   U   S-   U-   nSUU/U/UUS.nU R                  UXR                  UU5      XR                  UU	5      5      I Sh  vN $  N N N7f)a  
@ignore
       Connects to a websocket channel

       https://doc.xt.com/#websocket_privaterequestFormat
       https://doc.xt.com/#futures_market_websocket_v2base

       :param str messageHash: the message hash of the subscription
       :param str name: name of the channel
       :param str access: public or private
       :param str methodName: the name of the CCXT class method
       :param str topic: topic of the subscription
       :param dict [market]: CCXT market
       :param str[] [symbols]: unified market symbols
       :param dict params: extra parameters specific to the xt api
       :param dict subscriptionParams: extra parameters specific to the subscription
       :returns dict: data from the websocket stream
       r   Nr,   UNSUBSCRIBEunsubscriber   r   r   r   r-   r   r   r   r~   r+   r   r   T)r   r   subMessageHashesmessageHashesr   r   r   )rC   r   r{   r|   r}   r   r~   r   r   subscriptionParamsr   r3   rH   r   r   r   r   rS   subMessageHashr   r   rT   r   s                          rE   un_subscribext.un_subscribe   s    & )+99*fUfn
""4#4#4#67$>'1m}
 )-H%151D1DZ1P+PK("&"5"5j"AA	s
Y.).H%%)FK!",J&	y0+d2SXXg5FFN++k2*6Diit$Y/#5<!/ 0)]
 ZZ[++gv2NP[]h]hiu  xJ  ^K  L  L  	L1 ,QA, Ls7   A9E+;E%<E+E'CE+ E)!E+'E+)E+symbolc                 :  #    U R                  5       I Sh  vN   U R                  U5      nU R                  U R                  S5      nU R	                  USS5      nU R	                  USU5      nUS-   US   -   nU R                  USSUSU5      I Sh  vN $  N 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://doc.xt.com/#websocket_publictickerRealTime
https://doc.xt.com/#futures_market_websocket_v2tickerRealTime
https://doc.xt.com/#futures_market_websocket_v2aggTickerRealTime

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict params: extra parameters specific to the xt api endpoint
:param str [params.method]: 'agg_ticker'(contract only) or 'ticker', default = 'ticker' - the endpoint that will be streamed
:returns dict: a `ticker structure <https://docs.ccxt.com/en/latest/manual.html#ticker-structure>`
Nr    r/   r0   r   r   public)load_marketsr~   rR   r=   rN   r   )rC   r   r   r~   r=   defaultMethodr/   r{   s           rE   watch_tickerxt.watch_ticker   s      !!!V$..}=(((HE!!&(MB|fTl*^^D(M64QWXXX 	" Ys"   BBA;BBBBc           
      D  #    U R                  5       I Sh  vN   U R                  U5      nU R                  U R                  S5      nU R	                  USS5      nU R	                  USU5      nUS-   US   -   nSU-   nU R                  XSSXSSU5      I Sh  vN $  N N7f)	a  
stops watching a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://doc.xt.com/#websocket_publictickerRealTime
https://doc.xt.com/#futures_market_websocket_v2tickerRealTime
https://doc.xt.com/#futures_market_websocket_v2aggTickerRealTime

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict params: extra parameters specific to the xt api endpoint
:param str [params.method]: 'agg_ticker'(contract only) or 'ticker', default = 'ticker' - the endpoint that will be streamed
:returns dict: a `ticker structure <https://docs.ccxt.com/en/latest/manual.html#ticker-structure>`
Nr!   r/   r0   r   r   unsubscribe::r   )r   r~   rR   r=   rN   r   )	rC   r   r   r~   r=   r   r/   r{   r   s	            rE   un_watch_tickerxt.un_watch_ticker  s      !!!V$..?(((HE!!&(MB|fTl*%,&&{(OUblprxyyy 	" zs"   B BB B BB B c                   #    U R                  5       I Sh  vN   U R                  U R                  S5      nU R                  USS5      nU R                  USU5      nU R	                  U5      nSnUb  U R                  US   5      nU R                  USSXaU5      I Sh  vN nU R                  (       a  U$ U R                  U R                  SU5      $  N N67f)az  
watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://doc.xt.com/#websocket_publicallTicker
https://doc.xt.com/#futures_market_websocket_v2allTicker
https://doc.xt.com/#futures_market_websocket_v2allAggTicker

:param str [symbols]: unified market symbols
:param dict params: extra parameters specific to the xt api endpoint
:param str [params.method]: 'agg_tickers'(contract only) or 'tickers', default = 'tickers' - the endpoint that will be streamed
:returns dict: a `ticker structure <https://docs.ccxt.com/en/latest/manual.html#ticker-structure>`
Nr"   r/   r1   r   r   r   )
r   rR   r=   rN   market_symbolsr~   r   
newUpdatesfilter_by_arrayr1   )rC   r   r   r=   r   r{   r~   r1   s           rE   watch_tickersxt.watch_tickers(  s      !!!..~>(((IF-@%%g.[[,FtX~vX^__??N##DLL(GDD 	" `s"   CCBCC 5CCc           
        #    U R                  5       I Sh  vN   U R                  U R                  S5      nU R                  USS5      nU R                  USU5      nUb  [	        U R
                  S-   5      eSU-   nU R                  XeSSSSX5      I Sh  vN nU R                  (       a  U$ U R                  U R                  S	U5      $  N N67f)
a  
stops watching a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://doc.xt.com/#websocket_publicallTicker
https://doc.xt.com/#futures_market_websocket_v2allTicker
https://doc.xt.com/#futures_market_websocket_v2allAggTicker

:param str [symbols]: unified market symbols
:param dict params: extra parameters specific to the xt api endpoint
:param str [params.method]: 'agg_tickers'(contract only) or 'tickers', default = 'tickers' - the endpoint that will be streamed
:returns dict: a `ticker structure <https://docs.ccxt.com/en/latest/manual.html#ticker-structure>`
Nr#   r/   r1   zc unWatchTickers() does not support symbols argument, unsubscribtion is for all tickers at once onlyr   r   r0   r   )
r   rR   r=   rN   r   r   r   r   r   r1   )rC   r   r   r=   r   r{   r   r1   s           rE   un_watch_tickersxt.un_watch_tickersB  s      !!!../?@(((IF-@tww  *O   O  P  P%,))+XGWYacgipyy??N##DLL(GDD 	" zs"   CCA?CC5CC1m	timeframesincelimitc                 (  #    U R                  5       I Sh  vN   U R                  U5      nSUS   -   S-   U-   nU R                  USSUSU5      I Sh  vN nU R                  (       a  UR	                  X5      nU R                  XUSS5      $  Nw N<7f)	aj  
watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://doc.xt.com/#websocket_publicsymbolKline
https://doc.xt.com/#futures_market_websocket_v2symbolKline

:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, or 1M
:param int [since]: not used by xt watchOHLCV
:param int [limit]: not used by xt watchOHLCV
:param dict params: extra parameters specific to the xt api endpoint
:returns int[][]: A list of candles ordered, open, high, low, close, volume
Nkline@r   r   r   r   r   Tr   r~   r   r   getLimitfilter_by_since_limit)	rC   r   r   r   r   r   r~   r{   ohlcvs	            rE   watch_ohlcvxt.watch_ohlcv[  s      !!!V$&,&,y8nnT8\64QWXX??NN61E))%q$GG 	" Ys!   BB<BB;BBc           
         #    U R                  5       I Sh  vN   U R                  U5      nSUS   -   S-   U-   nSU-   nUS   U//US'   U R                  XeSS	S
USU5      I Sh  vN $  NR N7f)a  
stops watching historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://doc.xt.com/#websocket_publicsymbolKline
https://doc.xt.com/#futures_market_websocket_v2symbolKline

:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, or 1M
:param dict params: extra parameters specific to the xt api endpoint
:returns int[][]: A list of candles ordered, open, high, low, close, volume
Nr   r   r   r   r   symbolsAndTimeframesr   r   kliner   r~   r   )rC   r   r   r   r~   r{   r   s          rE   un_watch_ohlcvxt.un_watch_ohlcvq  s      !!!V$&,&,y8%,+1(+;Y*G)H%&&&{(NT[]ceikqrrr 	"
 ss"   A-A)AA-$A+%A-+A-c                   #    U R                  5       I Sh  vN   U R                  U5      nSUS   -   nU R                  USSUSU5      I Sh  vN nU R                  (       a  UR	                  X5      nU R                  XrUS5      $  Np N;7f)a  
get the list of most recent trades for a particular symbol

https://doc.xt.com/#websocket_publicdealRecord
https://doc.xt.com/#futures_market_websocket_v2dealRecord

: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 xt api endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/en/latest/manual.html?#public-trades>`
Ntrade@r   r   r$   	timestampr   )rC   r   r   r   r   r~   r{   tradess           rE   watch_tradesxt.watch_trades  s      !!!V$&,&~~dHmVTSYZZ??OOF2E))&LL 	" [s!   BB6BB	:B	Bc           
         #    U R                  5       I Sh  vN   U R                  U5      nSUS   -   nSU-   nU R                  XTSSSUSU5      I Sh  vN $  NA N7f)a  
stops watching the list of most recent trades for a particular symbol

https://doc.xt.com/#websocket_publicdealRecord
https://doc.xt.com/#futures_market_websocket_v2dealRecord

:param str symbol: unified symbol of the market to fetch trades for
:param dict params: extra parameters specific to the xt api endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/en/latest/manual.html?#public-trades>`
Nr   r   r   r   r%   trader   )rC   r   r   r~   r{   r   s         rE   un_watch_tradesxt.un_watch_trades  sn      !!!V$&,&%,&&{(OU\^dfjlrsss	 	" ts!   AA<AAAAc                 :  #    U R                  5       I Sh  vN   U R                  U5      nU R                  US5      nU R                  US5      nSUS   -   nUb  SUS   -   S-   U-   nU R	                  USSUSU5      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://doc.xt.com/#websocket_publiclimitDepth
https://doc.xt.com/#websocket_publicincreDepth
https://doc.xt.com/#futures_market_websocket_v2limitDepth
https://doc.xt.com/#futures_market_websocket_v2increDepth

:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: not used by xt watchOrderBook
:param dict params: extra parameters specific to the xt api endpoint
:param int [params.levels]: 5, 10, 20, or 50
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/en/latest/manual.html#order-book-structure>` indexed by market symbols
Nlevelsdepth_update@r   depth@r   r   r   )r   r~   rN   omitr   r   )rC   r   r   r   r~   r   r{   rc   s           rE   watch_order_bookxt.watch_order_book  s      !!!V$!!&(368,-fTl*S069D..x9I6SWY_``	   	" as"   BBA+BBBBc           
      &  #    U R                  5       I Sh  vN   U R                  U5      nU R                  US5      nU R                  US5      nSUS   -   nUb  SUS   -   S-   U-   nSU-   nU R	                  XeSS	S
USU5      I Sh  vN $  Nv N7f)a  
stops watching information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://doc.xt.com/#websocket_publiclimitDepth
https://doc.xt.com/#websocket_publicincreDepth
https://doc.xt.com/#futures_market_websocket_v2limitDepth
https://doc.xt.com/#futures_market_websocket_v2increDepth

:param str symbol: unified symbol of the market to fetch the order book for
:param dict params: extra parameters specific to the xt api endpoint
:param int [params.levels]: 5, 10, 20, or 50
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/en/latest/manual.html#order-book-structure>` indexed by market symbols
Nr   r   r   r   r   r   r   r   depth)r   r~   rN   r   r   )rC   r   r   r~   r   r{   r   s          rE   un_watch_order_bookxt.un_watch_order_book  s      !!!V$!!&(368,-fTl*S069D%,&&{(DVX_agimouvvv 	" ws"   BBA1BB	BBc                   #    U R                  5       I Sh  vN   SnSnUb  U R                  U5      nU R                  USSUSU5      I Sh  vN nU R                  (       a  UR	                  X5      nU R                  XrUS5      $  No N;7f)a  
watches information on multiple orders made by the user

https://doc.xt.com/#websocket_privateorderChange
https://doc.xt.com/#futures_user_websocket_v2order

:param str [symbol]: unified market symbol
:param int [since]: not used by xt watchOrders
:param int [limit]: the maximum number of orders to return
:param dict params: extra parameters specific to the xt api endpoint
:returns dict[]: a list of `order structures <https://docs.ccxt.com/en/latest/manual.html#order-structure>`
Norderr   r(   r   r   )rC   r   r   r   r   r{   r~   orderss           rE   watch_ordersxt.watch_orders  s      !!![[(F~~dI}fdTZ[[??OOF2E))&LL 	"
 \!   B
B5B
B:B
B
c                   #    U R                  5       I Sh  vN   SnSnUb  U R                  U5      nU R                  USSUSU5      I Sh  vN nU R                  (       a  UR	                  X5      nU R                  XrUS5      $  No N;7f)a  
watches information on multiple trades made by the user

https://doc.xt.com/#websocket_privateorderDeal
https://doc.xt.com/#futures_user_websocket_v2trade

: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  orde structures to retrieve
:param dict params: extra parameters specific to the kucoin api endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Nr   r   r)   r   r   )rC   r   r   r   r   r{   r~   r   s           rE   watch_my_tradesxt.watch_my_trades  s      !!![[(F~~dIPTV\]]??OOF2E))&LL 	"
 ^r   c                    #    U R                  5       I Sh  vN   SnU R                  USSSSU5      I Sh  vN $  N$ N7f)aH  
watches information on multiple orders made by the user

https://doc.xt.com/#websocket_privatebalanceChange
https://doc.xt.com/#futures_user_websocket_v2balance

:param dict params: extra parameters specific to the xt api endpoint
:returns dict[]: a list of `balance structures <https://docs.ccxt.com/#/?id=balance-structure>`
Nbalancer   r'   )r   r   )rC   r   r{   s      rE   watch_balancext.watch_balance	  sC      !!!^^D)^T4QWXXX 	"Xs   ?;?=??c                 R  #    U R                  5       I Sh  vN   U R                  S   S   S   S-   S-   nU R                  U5      nU R                  U5        U R	                  SSS	5      nU R	                  SS
S	5      nU R
                  n	U(       aI  U(       aB  U R                  U	5      (       a,  UR                  S5      I Sh  vN n
U R                  XX#S	5      $ SnU R                  USSSSU5      I Sh  vN nU R                  (       a  U$ U R                  XX#S	5      $  GN
 N` N/7f)a  

https://doc.xt.com/#futures_user_websocket_v2position

watch all open positions
:param str[]|None symbols: list of unified market symbols
:param number [since]: since timestamp
:param number [limit]: 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+   r   r-   r   r   r*   r4   Tr5   positionr   )r   r<   rM   set_positions_cachehandle_option	positionsis_emptyfuturefilter_by_symbols_since_limitr   r   )rC   r   r   r   r   rT   rM   r4   r5   rd   snapshotr{   newPositionss                rE   watch_positionsxt.watch_positions  s#     !!!iit$Z036?S!  (!%!3!34DF^`d!e!%!3!34DF^`d!e!&<uAUAU#]]+CDDH55hW[\\!^^D)=MtUY[abb??11%%PTUU 	" E cs4   D'D B+D'D#2D'5D%6+D'#D'%D'rM   c                     U R                   c  [        5       U l         U R                  SS5      nU(       a@  SnX1R                  ;  a.  UR	                  U5        U R                  U R                  X5        g g g )Nr*   r4   )r   r   r   futuresr   spawnload_positions_snapshot)rC   rM   r4   r   s       rE   r   xt.set_positions_cache3  sg    >>!57DN!%!3!34DF^!_!2K>>1k*

477M 2 "rG   c                 t  #    U R                  S 5      I S h  vN n[        5       U l        U R                  n[        S[	        U5      5       H3  nX5   nU R                  USS5      nUS:  d  M"  UR                  U5        M5     UR                  U   nUR                  U5        UR                  US5        g  N7f)Nr   	contractsposition::contract)	fetch_positionsr   r   ra   rb   rq   appendr   resolve)	rC   rM   r   r   rd   rZ   r   r   r   s	            rE   r   xt.load_positions_snapshot=  s     ..t44	13q#i.)A |H((;BI1}X&	 * ,uu23 5s   B8B6AB8.A	B8c                    U R                   c  [        5       U l         U R                   nU R                  US0 5      nU R                  U5      nUR	                  U5        U R                  US5      n[        S[        U5      5       Hl  nXg   nUR                  S5      n	U	S   n
U
R                  S5      nU R                  U/SUS5      nU R                  U5      (       a  M[  UR                  X5        Mn     UR                  U/S5        g )	Ndatar   r   r   r\   r   r   F)r   r   rR   parse_positionr  find_message_hashesra   rb   splitr   r   r  )rC   rM   messagerd   r  r   r   rZ   r   partssymbolsStringr   r   s                rE   handle_positionxt.handle_positionK  s    > >>!57DN~~gvr2&&t,X009MNq#m,-A'*K%%d+E!!HM#))#.G,,hZ7ERI==++y6 . 	z#78rG   r
  c                 4   U R                  US5      nU R                  US5      nUbp  U R                  US5      nUS LnU R                  U5      nUS   nXpR                  U'   U R                  US5      n	U(       a  SOSn
U	S-   U
-   nUR	                  X{5        U$ )	Nr  scvr   eventr,   r-   r   )rR   rN   parse_tickerr1   r  )rC   rM   r
  r  marketIdr  isSpotr0   r   r  messageHashTailr   s               rE   handle_tickerxt.handle_ticker{  s    z ~~gv.##D#.!!$-Bt^F&&t,FH%F#)LL $$Wg6E(.fJO$,8KNN6/rG   c                    U R                  US/ 5      nU R                  US5      nU R                  USS5      nUb  SOSn/ n[        S[	        U5      5       H<  nX8   n	U R                  U	5      n
U
S   nXR                  U'   UR                  U
5        M>     U R                  US5      S	-   U-   nU R                  XS	-   5      n[        S[	        U5      5       H  nX   nUR                  S	5      nUS
   nUR                  S5      nU R                  USU5      n[        UR                  5       5      n[	        U5      nUS:  d  Mm  UR                  UU5        M     UR                  U R                  U5        U$ )Nr  r   r  aqr,   r-   r   r   r      r   )rp   rR   safe_string_2ra   rb   r  r1   r  rN   r  r	  r   listkeysr  )rC   rM   r
  r  firstTickerspotTestrS   
newTickersrZ   
tickerDatar0   r   messageHashStartr   r   r  r  r   r1   tickersSymbols
numTickerss                        rE   handle_tickersxt.handle_tickers  st   H ~~gvr2nnT1-%%k4>'3F*	
q#d)$AJ&&z2FH%F#)LL f% %  ++GW=DyP00D9PQq#m,-A'*K%%d+E!!HM#))#.G**:xIG!',,.1N^,JA~w4 . 	t||%56rG   c                 f   U R                  US0 5      nU R                  US5      nUGb  U R                  US5      nSU;   a  SOSnU R                  US S U5      nUS   nU R                  X75      n	U R                  U R                  U0 5      U R                  U'   U R                  U R                  U   U5      n
U
c9  U R                  U R                  SS	5      n[        U5      n
XR                  U   U'   U
R                  U	5        U R                  US
5      nUS-   U-   nUR                  X5        U$ )Nr  r  rZ   qr,   r-   r   r8   r.   r  r   )rR   rN   safe_marketparse_ohlcvohlcvsr_   r^   r=   r   r  r  )rC   rM   r
  r  r  r   rS   r~   r   parsedstoredr   r  r   s                 rE   handle_ohlcvxt.handle_ohlcv$  s+   L ~~gvr2##D#.((s3I#&$;ZI%%hdIFFH%F%%d3F"&..fb"IDKK__T[[%8)DF~))$,,dK.u517F#I.MM&!$$Wg6E$,2KNN6/rG   c                    U R                  US5      nU R                  US5      nUb  U R                  U5      nU R                  US5      nUb  SOSnU R	                  US S U5      nUS   n	U R                  US5      n
U R                  U R                  U	5      nUc6  U R                  U R                  SS	5      n[        U5      nXR                  U	'   UR                  U5        U
S
-   U-   nUR                  X5        U$ )Nr  r  rZ   r,   r-   r   r  r6   r.   r   )rR   safe_string_lowerparse_traderN   r*  r_   r   r^   r=   r   r  r  )rC   rM   r
  r  r  r   rZ   rS   r~   r   r  tradesArrayr6   r   s                 rE   handle_tradext.handle_trade^  s    > ~~gv.))$4$$T*E  s+A#$=zI%%hdIFFH%F$$Wg6E//$++v>K""//mTR(5&1F#u%$,2KNN;4rG   c                 V   U R                  US5      nU R                  US5      nUGb  U R                  US5      nUR                  S5      nU R                  US5      nSU;   a  SOSnU R                  US S U5      nUS	   n	U R	                  US
5      n
U R	                  US5      nUS-   U-   nXR
                  ;  aN  U R                  UR                  U0 5      nU R                  US5      nU R                  0 U5      U R
                  U	'   U R
                  U	   nU R                  US5      nUcg  [        UR                  5      nU R                  SSS5      nUU:X  a  U R                  U R                  XU	5        UR                  R                  U5        g U
b\  US   n[        S[        U
5      5       H>  nU
U   nU R!                  US5      nU R!                  US5      nUR#                  UU5        M@     Ub\  US   n[        S[        U5      5       H>  nUU   nU R!                  US5      nU R!                  US5      nUR#                  UU5        M@     U R                  US5      nU R%                  USS5      US'   UUS'   U R'                  U5      US'   XS	'   UR)                  X5        g g )Nr  r  r  r   r   fur-   r,   r   rl   rm   r   r   rY   r   snapshotDelay   ro   r\   rn   trZ   r[   r   datetime)rR   rN   r	  r*  rp   
orderbooksrO   r^   
order_bookrb   rd   r   r   load_order_bookr  ra   rq   rr   r`   iso8601r  )rC   rM   r
  r  r  r  
splitEventrS   r~   r   rs   rt   r   r   r   rc   rY   cacheLengthr9  ro   rZ   rx   rv   rw   rn   ru   r   s                              rE   handle_order_bookxt.handle_order_book  s   x ~~gv.##D#.$$Wg6ES)J$$Z3E'+t|
&I%%hdIFFH%F^^D#.F^^D#.F$,2Koo-#~~f.B.BKQST)),@*.//"e*D'/I%%i9E}!)//2 $ 2 23C_VX Y-/JJt33V&Q&&t,! (q#f+.A )C ,,S!4E#//Q7HJJuh/	 /
 ! (q#f+.A )C ,,S!4E#//Q7HJJuh/	 /
 ))$4I!%!4!4T3!DIg%.Ik"$(LL$;Ij!"(hNN92U  rG   r   c                    U R                  US5      nSU;   a  SOSnU R                  X2S U5      nU R                  US5      nU R                  US UU R                  U5      US   U R                  USS5      U R	                  U R                  USS	5      5      U R                  US
S5      S U R                  US5      U R                  US5      S S U R                  US5      S S.S.U5      $ )Nr  r   r-   r,   r;  rZ   orderIdststatesd	orderSiderv   origQtyf)currencycostrate)infor   r   r<  r   r   r3   sidetakerOrMakerrv   amountrN  fee)rN   r*  
safe_trader@  parse_order_statusr2  rq   )rC   r   r~   r  rS   r   s         rE   parse_ws_order_tradext.parse_ws_order_trade  s   B ##E3/#+u#4J6	!!(D)D$$UC0	"Y/X&%%eS)<++D,<,<UD',RS**5$D %%eW5&&ui8 ((4 
$ % 	rG   r   c                    U R                  USS5      nSU;   a  SOSnU R                  X2S U5      nU R                  USS5      nU R                  0 SU_SU R                  US	S
5      _SU R                  USS5      _SU_SU R	                  U5      _SS _SUS   _SUS   _SS _SS _SU R                  USS5      _SU R                  USS5      _SS _SS _SS _SU R                  USS5      _SU R                  USS 5      _U R                  US!5      S U R                  US"S#5      U R                  U R                  US$S%5      5      S U R                  US&5      S'.S S(.EU5      $ ))Nr  r   r-   r,   ct
createTimerP  r   rZ   rF  clientOrderIdcir   r<  lastTradeTimestampr3   timeInForcepostOnlyrQ  rI  rJ  rv   p	stopPricestopLoss
takeProfitrS  oqrK  filledeqexecutedQtylqapavgPricerG  rH  rL  )rM  rN  )	remainingrN  averagestatusrT  r   )
r  r*  r`   
safe_orderr@  safe_string_lower_2safe_number_2rN   rV  rq   )rC   r   r~   r  rS   r   s         rE   parse_ws_orderxt.parse_ws_order3  s   V %%eS(;#+u#4J6	!!(D)D''t\B	  
E 
$$$UC; 
 T//t_M 
 	 

 Y/ 
 !$ 
 fX& 
 F6N 
 4 
  
 D,,UD+F 
 T''sG< 
  
  
 $ 
  d((i@! 
" d((mD# 
$ ))%6))%zB--d.>.>udG.TU ((4 5 
6 7 	rG   c                 z   U R                   nUc-  U R                  U R                  S5      n[        U5      nX0l         U R	                  US0 5      nU R                  USS5      nUbU  SU;   a  SOSnU R                  US S U5      nU R                  XX5      n	UR                  U	5        UR                  USU-   5        U$ )Nr7   r  r  r   r-   r,   zorder::)
r   r^   r=   r   rR   r  r*  rr  r  r  )
rC   rM   r
  r   r   r   r  rS   r~   r-  s
             rE   handle_orderxt.handle_order  s    V >%%dllMBE+E2F Kw3%%eS(;'/5'8
vI%%hdIFF((7FMM&!NN69y#89rG   c                    U R                  US0 5      nU R                  USS5      nU R                  U5      nU R                  5       nU R	                  US5      US'   U R	                  US5      US'   U R                  USS	5      US
'   X`R
                  U'   U R                  U R
                  5      U l        SU;   a  SOSnUR                  U R
                  SU-   5        g )Nr  ccoinavailableBalancefreerL  usedrm   walletBalancetotalr-   r,   z	balance::)rR   r  safe_currency_codeaccountrN   r   safe_balancer  )rC   rM   r
  r  
currencyIdcoder  rS   s           rE   handle_balancext.handle_balance  s    F ~~gvr2''c6:
&&z2,,.**41CD**45--dCI$T((6#)T>J	t||[9%<=rG   c                 V   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S   5      nUR                  U5        US   (       a  SOSnUR                  USU-   5        g )Nr  r6   r.   r   r-   r,   ztrade::)	rR   myTradesr^   r=   r   r3  r~   r  r  )	rC   rM   r
  r  r.  r   parsedTrader~   rS   s	            rE   handle_my_tradesxt.handle_my_trades  s    F ~~gvr2>%%dllM4HE+E2F"M&&t,[23k""("4J&	vy945rG   c                 :   U R                  US5      nUS:X  a  UR                  5         g Ub  U R                  US5      nU R                  U R                  U R                  U R                  U R                  U R
                  U R
                  U R                  U R                  U R                  S.
nU R                  XT5      nUS:X  a7  U R                  US5      nSU;   d  SU;   a  U R                  nOU R                  nUb	  U" X5        g g U R                  X5        g )	Nr  pongr   )
r   r   depth_updater0   
agg_tickerr1   agg_tickersr   r   r   r   r  oirF  )rN   onPongr/  rC  r  r&  r  ru  r  r_   rR   r  r5  handle_subscription_status)rC   rM   r
  r  r   methodsr/   r  s           rE   handle_messagext.handle_message  s     '2F?MMO$$Wg6E**// $ 6 6,,"00..#22..** 00G __W4F~~gv6DLi4&7!22F!..F!v' " ++F<rG   c                 .    U R                  5       Ul        g)Nr:   )r   lastPong)rC   rM   s     rE   r:   xt.ping5  s    ++-rG   c                     U R                  US5      nUS:X  aQ  U R                  US5      nU R                  UR                  S5      nU R	                  XT0 5      nU R                  X5        U$ )Nr/   r   r   )r2  rN   index_byrO   r_   handle_un_subscription)rC   rM   r
  r/   r   subscriptionsByIdr   s          rE   r  xt.handle_subscription_status9  sk     '':]"!!'40B $f.B.BD I??+<"EL''=rG   r   c                     U R                  US/ 5      nU R                  US/ 5      n[        S[        U5      5       H  nX5   nXE   nU R                  XU5        M     U R	                  U5        g )Nr   r   r   )rp   ra   rb   clean_unsubscriptionclean_cache)rC   rM   r   r   r   j	unsubHashsubHashs           rE   r  xt.handle_un_subscriptionJ  sn    |_bI>>,8JBOq#m,-A%(I&)G%%fyA . 	&rG   c                     U R                  US5      nUS:X  d  US:X  a!  S UR                  S'   U R                  S5        g UR                  U5        g )Nmsginvalid_listen_keyztoken expirer?   T)rN   rO   rV   reject)rC   rM   r
  r  s       rE   handle_error_messagext.handle_error_messageS  sS     w.''SN-B,0F  )%grG   )r   r  r   r   )N)>__name__
__module____qualname____firstlineno__r   rB   boolrV   ri   ry   strr
   r   r   r   r   r   r   r   r   r   r   r	   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  dictr  r&  r/  r5  rC  rW  rr  ru  r  r  r  r:   r  r  r  __static_attributes____classcell__)rD   s   @rE   r   r      se   1# 1f--t --^(& Y]sw  AC /VC /V /V# /Vv /Vgklogp /Vb z~  UY  bd  y{ 7Lc 7L 7Lc 7LWZ 7Lcf 7Lpv 7L  IM  NQ  IR 7L  @C 7Lr 68 Y YF Y* 9; zC zv z, 6:" E7 E E4 9=R Eg EG E2 ?CQUdhqs H H H3 H^a Hx|  ~B  yC H, BFb s3 s3 sUYZ^U_ s& <@d[] M MS M Mbfglbm M* 9; tC ttE{ t" @DB !S ! !S\ !2 =? w w9 w0 04$UYbd M MC Ms Mimnsit M. 37TX\eg MC Ms MRU Mlpqvlw M. *, Y Y 8<$]ajl VW VC VWZ Vquv~q V8N& N4.9`IF IT IV\V \d \|86 8D 8t06 0D 0dh3 h3 h3T7$ 7 7rJD J& JX86 8D 8t->V ->d ->^-6v -6 -6^=V =<6 "'V '4 '6 D  rG   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   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   async_supportr    rG   rE   <module>r     sE     A  A x x x x 4  )R				 RrG   