
    E#i                         S SK rS SKJrJrJrJr  S SKrS SK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  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr   " S
 S\R>                  R@                  5      r g)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)AnyBoolIntOrder	OrderBookPositionStrStringsTickerTickersTrade)Client)List)ExchangeError)AuthenticationError)ArgumentsRequired)NetworkErrorc                     ^  \ rS rSrS\4U 4S jj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S\4S jrS1S jrS0 4S\S\S\4S jjrS0 4S	\\   S\S\4S jjr0 4S jrS\4S jrS rS 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SSS0 4S\S\S\S\S\\   4
S jjrSS0 4S\\\      S\S\4S jjrS\4S jrS1S\4S jjr SSS0 4S\!S\S\S\\	   4S jjr"SSS0 4S	\S\S\S\\#   4S jjr$SSS0 4S\!S\S\S\\%   4S  jjr&S\4S! jr'S\4S" jr(S1S\S	\4S# jjr)S$ r*S% r+0 4S& jr,S\S\-4S' jr.S\4S( jr/S\4S) jr0S* r1S\4S+ jr2S\4S, jr3S\4S- jr4S\4S. jr5S\4S/ jr6S0r7U =r8$ )2apex   returnc                    > U R                  [        [        U ]  5       SSSSSSSSSSSS.SSSSS.0SS	S
S.0SSSSS.0 U R                  SS.S.5      $ )NTF)wswatchTickerwatchTickerswatchOrderBookwatchOrderswatchTradeswatchTradesForSymbolswatchPositionswatchMyTradeswatchBalance
watchOHLCVz;https://omni.apex.exchange/assets/logo_content-CY9uyFbz.svgr   z2wss://quote.omni.apex.exchange/realtime_public?v=2z3wss://quote.omni.apex.exchange/realtime_private?v=2)publicprivatez5wss://qa-quote.omni.apex.exchange/realtime_public?v=2z6wss://qa-quote.omni.apex.exchange/realtime_private?v=2zhttps://apex.exchange/z"https://api-docs.pro.apex.exchangez`https://apex-pro.gitbook.io/apex-pro/apex-omni-live-now/trading-perpetual-contracts/trading-feesz https://omni.apex.exchange/trade)logoapitestwwwdocfeesreferraliPF  )ping	keepAlive)hasurlsoptions	streaming)deep_extendsuperr   describer1   )self	__class__s    G/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/apex.pyr9   apex.describe   s    dD : <# $"&##)."&!% %" V"V#X "Y#[ 0;z>#& 		"E&?
 & &	    Nsymbolsincelimitc                 F   #    U R                  U/X#U5      I Sh  vN $  N7f)a  
watches information on multiple trades made in a market

https://api-docs.pro.apex.exchange/#websocket-v3-for-omni-websocket-endpoint

:param str symbol: unified market symbol of the market trades were made in
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum number of trade structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
N)watch_trades_for_symbols)r:   r?   r@   rA   paramss        r<   watch_tradesapex.watch_trades?   s$      22F8U6RRRRs   !!symbolsc                   #    U R                  5       I Sh  vN   U R                  U5      n[        U5      nUS:X  a  [        U R                  S-   5      e[        U R                  5       5      nU R                  S   S   S   S-   U-   n/ n/ n	[        S[        U5      5       HG  n
X   nU R                  U5      nSUS	   -   nUR                  U5        S
U-   nU	R                  U5        MI     U R                  XyX5      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      $  GNL Nb7f)a  
get the list of most recent trades for a list of symbols

https://api-docs.pro.apex.exchange/#websocket-v3-for-omni-websocket-endpoint

:param str[] symbols: 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>`
Nr   z> watchTradesForSymbols() requires a non-empty array of symbolsr+   r   r(   &timestamp=zrecentlyTrade.H.id2trade:r?   	timestampT)load_marketsmarket_symbolslenr   idstrmillisecondsr4   rangemarketappendwatch_topics
newUpdates
safe_valuesafe_stringgetLimitfilter_by_since_limit)r:   rG   r@   rA   rD   symbolsLength	timeStampurltopicsmessageHashesir?   rT   topicmessageHashtradesfirsttradeSymbols                     r<   rC   apex.watch_trades_for_symbolsM   s\     !!!%%g.GA#DGG.n$noo))+,	iit$X.>Jq#g,'AZF[[(F&6EMM% "V+K  - ( ((VLL??OOFA.E**5(;KOOK7E))&TRR+ 	"  Ms#   E'E"C+E'E%A E'%E'clientc                 4   U R                  US0 5      nU R                  US5      nUnUR                  S5      nU R                  US5      nU R                  US S 5      nUS   n	U R                  U R                  U	5      n
U
c6  U R                  U R                  SS5      n[        U5      n
XR                  U	'   [        U5      n[        SU5       H/  nX-
  S	-
  nU R                  X^   U5      nU
R                  U5        M1     S
U	-   nUR                  U
U5        g )Ndatarb   .   r?   tradesLimit  r      rK   )rX   rY   splitsafe_marketrd   safe_integerr5   r   rO   rS   parse_ws_traderU   resolve)r:   rh   messagerj   rb   rd   partsmarketIdrT   r?   storedrA   lengthjindexparsedrc   s                    r<   handle_tradesapex.handle_tradesp   s   * w3  '2C ##E1-!!(D$7!f5>%%dllM4HE&F"(KKVq&!AJNE((?FMM&! " $f,v{+r>   c                 ~   U R                  U/ SQ5      nU R                  USS/5      nU R                  XBS 5      nUS   nU R                  U/ SQ5      nU R                  USS/5      nU R                  USS/5      nU R                  U/ S	Q5      n	U R	                  UUUU R                  U5      US S US UU	S S S
.U5      $ )N)ra   rP   vsr?   )tT	createdAtSsidepprice)qr   size)rP   inforL   datetimer?   ordertyper   takerOrMakerr   amountcostfee)safe_string_nrq   safe_integer_nsafe_string_lower_n
safe_tradeiso8601)
r:   traderT   rP   rw   r?   rL   r   r   r   s
             r<   rs   apex.parse_ws_trade   s     '78%%ec8_=!!(D9!''/FG	''V}=""53.9##E+=>"Y/  
  	r>   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://api-docs.pro.apex.exchange/#websocket-v3-for-omni-websocket-endpoint

: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?   rA   rD   s       r<   watch_order_bookapex.watch_order_book   s"      66xOOOOs     c                 d  #    U R                  5       I Sh  vN   [        U5      nUS:X  a  [        U R                  S-   5      eU R	                  U5      n[        U R                  5       5      nU R                  S   S   S   S-   U-   n/ n/ n[        S[        U5      5       H[  n	X   n
U R                  U
5      nUc  SnS	[        U5      -   S
-   US   -   nUR                  U5        SU
-   nUR                  U5        M]     U R                  XhXs5      I Sh  vN nUR                  5       $  GN N7f)a  
watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://api-docs.pro.apex.exchange/#websocket-v3-for-omni-websocket-endpoint

:param str[] symbols: unified array of 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
Nr   zA watchOrderBookForSymbols() requires a non-empty array of symbolsr+   r   r(   rI      	orderBookz.H.rJ   
orderbook:)rM   rO   r   rP   rN   rQ   rR   r4   rS   rT   rU   rV   rA   )r:   rG   rA   rD   r\   r]   r^   r_   r`   ra   r?   rT   rb   rc   	orderbooks                  r<   r   !apex.watch_order_book_for_symbols   s1     !!!GA#DGG.q$qrr%%g.))+,	iit$X.>Jq#g,'AZF[[(F}#e*,u4ve}DEMM% &/K  - ( ++COO	  ' 	"$ Ps"   D0D+C?D0D.D0.D0c                 n   #    SUS.nU R                  XT5      nU R                  XXb5      I S h  vN $  N7f)N	subscribeopargs)extendwatch_multiple)r:   r^   r`   r_   rD   requestru   s          r<   rV   apex.watch_topics   s;     
 ++g.((WTTTTs   ,535c                    U R                  US5      nUS:H  nU R                  US0 5      nU R                  US5      nU R                  US S 5      nUS   nU R                  USS5      n	XR                  ;  a  U R                  5       U R                  U'   U R                  U   n
U(       a&  U R                  XXU	SS	5      nU
R                  U5        OhU 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'   SU-   nXR                  U'   UR                  X5        g )Nr   snapshotrj   r   r?   tsMbP?baasksbidsrL   r   r   )rY   	safe_dictrq   safe_integer_product
orderbooks
order_bookparse_order_bookreset	safe_listhandle_deltasr   rt   )r:   rh   ru   r   
isSnapshotrj   rw   rT   r?   rL   r   r   r   r   rc   s                  r<   handle_order_bookapex.handle_order_book   sT   D 0j(
~~gvr2##D#.!!(D$7!--gtUC	//)&*oo&7DOOF#OOF+	,,T9c3OHOOH%>>$R0D>>$R0Dy0$7y0$7%.k"$(LL$;Ij!'&0"+y.r>   c                 L    U R                  USS5      nUR                  U5        g )Nr   ro   )parse_bid_ask
storeArray)r:   booksidedeltabidAsks       r<   handle_deltaapex.handle_delta.  s$    ##E1a0F#r>   c                 d    [        S[        U5      5       H  nU R                  XU   5        M     g )Nr   )rS   rO   r   )r:   r   deltasra   s       r<   r   apex.handle_deltas2  s)    q#f+&Ahq	2 'r>   c                 ,  #    U R                  5       I Sh  vN   U R                  U5      nUS   n[        U R                  5       5      nU R                  S   S   S   S-   U-   nSU-   nSUS	   -   nU/nU R                  XV/X5      I Sh  vN $  Ny 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://api-docs.pro.apex.exchange/#websocket-v3-for-omni-websocket-endpoint

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr?   r+   r   r(   rI   ticker:instrumentInfo.H.rJ   )rM   rT   rQ   rR   r4   rV   )	r:   r?   rD   rT   r]   r^   rc   rb   r_   s	            r<   watch_tickerapex.watch_ticker6  s      !!!V$!))+,	iit$X.>J&((6%=8&&sM6JJJ 	" Ks"   BBA4BBBBc                 @  #    U R                  5       I Sh  vN   U R                  USS5      n/ n[        U R                  5       5      nU R                  S   S   S   S-   U-   n/ n[        S[        U5      5       HG  nX   nU R                  U5      n	SU	S	   -   n
UR                  U
5        S
U-   nUR                  U5        MI     U R                  XSXb5      I Sh  vN nU R                  (       a  0 nXUS   '   U$ U R                  U R                  SU5      $  G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://api-docs.pro.apex.exchange/#websocket-v3-for-omni-websocket-endpoint

:param str[] symbols: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
NFr+   r   r(   rI   r   r   rJ   r   r?   )rM   rN   rQ   rR   r4   rS   rO   rT   rU   rV   rW   filter_by_arraytickers)r:   rG   rD   r`   r]   r^   r_   ra   r?   rT   rb   rc   tickerresults                 r<   watch_tickersapex.watch_tickersJ  s!     !!!%%gtU;))+,	iit$X.>Jq#g,'AZF[[(F,ve}<EMM% #f,K  - ( ((VLL??F'-6(#$M##DLL(GDD% 	" Ms"   DDCDD>DDc                    U R                  USS5      nU R                  USS5      nU R                  US0 5      nS nS nUS:X  a  U R                  U5      nUS   nOUS:X  a  UR                  S5      n[	        U5      n	U R                  XS	-
  5      n
U R                  U
S S 5      nUS   nU R                  U R                  U0 5      nU R                  US
0 5      nU R                  X5      nU R                  U5      nU R                  USS5      nXS'   U R                  U5      US'   XpR                  U'   SU-   nUR                  U R                  U   U5        g )Nrb    r   rj   r   r?   r   rk   ro   r   r   r   rL   r   r   )rY   r   parse_tickerrp   rO   rq   r   r   r   r   rt   )r:   rh   ru   rb   
updateTyperj   r?   r|   
topicPartstopicLengthrw   rT   r   	rawTickermergedrL   rc   s                    r<   handle_tickerapex.handle_tickerh  s]   ,   '26%%gvr:
~~gvr2*$&&t,FH%F7"S)Jj/K''
!ODH%%hd;FH%F^^DLL&"=Fvvr:I[[1F&&v.F--gtUC	'{!\\)4z%V&(t||F+[9r>   1m	timeframec                 `   #    SUS'   U R                  X//X4U5      I Sh  vN nXa   U   $  N7f)a`  
watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://api-docs.pro.apex.exchange/#websocket-v3-for-omni-websocket-endpoint

:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: the length of time each candle represents
:param int [since]: timestamp in ms of the earliest candle to fetch
:param int [limit]: the maximum amount of candles to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int[][]: A list of candles ordered, open, high, low, close, volume
r'   callerMethodNameN)watch_ohlcv_for_symbols)r:   r?   r   r@   rA   rD   r   s          r<   watch_ohlcvapex.watch_ohlcv  sC      &2!"33f5H4I5Y_``~i(( as   .,.symbolsAndTimeframesc                   #    U R                  5       I Sh  vN   [        U R                  5       5      nU R                  S   S   S   S-   U-   n/ n/ n[	        S[        U5      5       H  n	X   n
U R                  U
S5      nU R                  U5      nUS   nU R                  U
SS	5      nU R                  U R                  X5      nUR                  S
U-   S-   U-   5        UR                  SU-   S-   U-   5        M     U R                  XhXt5      I Sh  vN u  nnnU R                  (       a  UR                  X5      nU R                  UX#SS5      nU R                  UUU5      $  GNO NT7f)a~  
watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://api-docs.pro.apex.exchange/#websocket-v3-for-omni-websocket-endpoint

:param str[][] symbolsAndTimeframes: array of arrays containing unified symbols and timeframes to fetch OHLCV data for, example [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]
:param int [since]: timestamp in ms of the earliest candle to fetch
:param int [limit]: the maximum amount of candles to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A list of candles ordered, open, high, low, close, volume
Nr+   r   r(   rI   r   rJ   ro   1zcandle.rk   ohlcv::::T)rM   rQ   rR   r4   rS   rO   rY   rT   
timeframesrU   rV   rW   rZ   r[   create_ohlcv_object)r:   r   r@   rA   rD   r]   r^   	rawHashesr`   ra   rj   symbolStringrT   unfiedTimeframetimeframeIdr?   r   rx   filtereds                      r<   r   apex.watch_ohlcv_for_symbols  sn     !!!))+,	iit$X.>J	q#234A'*D++D!4L[[.F!%=L"..tQ<O**4??O]KY4s:\IJ  \!9D!@?!RS 5 +/*;*;CPY*b$b!	6??OOF2E--feAtL''	8DD% 	" %cs#   E*E%C<E*E(AE*(E*c                 P   U R                  US0 5      nU R                  US5      nUR                  S5      n[        U5      nU R                  US5      nU R	                  U5      nU R                  XVS-
  5      n	UR
                  R                  S5      S:  n
U
(       a  SOSnU R                  U	S S U5      nUS   nU R                  U R                  U5      nUc  0 U R                  U'   U R                  X5      c8  U R                  U R                  S	S
5      n[        U5      U R                  U   U'   U R                  U   U   n[        S[        U5      5       H(  nU R                  UU   5      nUR                  U5        M*     SU-   S-   U-   nXU/nUR                  UU5        g )Nrj   rb   rk   ro   spotcontractr?   
OHLCVLimitrn   r   r   r   )rX   rY   rp   rO   find_timeframer^   findrq   ohlcvsrr   r5   r   rS   parse_ws_ohlcvrU   rt   )r:   rh   ru   rj   rb   r   r   r   r   rw   isSpot
marketTyperT   r?   ohlcvsByTimeframerA   rx   ra   r|   rc   resolveDatas                        r<   handle_ohlcvapex.handle_ohlcv  s   . w3  '2[[%
*o&&z15''4	##Ja@(2-%V:
!!(D$
C! OODKK@$"$DKK??,8@%%dllL$GE-B5-IDKK	*V$Y/q#d)$A((a1FMM&! %  &(4/);&1{K0r>   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S5      /$ )Nstartopenhighlowclosevolumeturnover)rr   safe_numbersafe_number_2)r:   ohlcvrT   s      r<   r   apex.parse_ws_ohlcv  sp    " eW-UF+UF+UE*UG,uh
;
 	
r>   c                   #    SnU R                  5       I Sh  vN   Ub  U R                  U5      nUSU-   -  n[        U R                  5       5      nU R                  S   S   S   S-   U-   nU R                  U5      I Sh  vN   U R                  Xu/S/U5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XX#S5      $  N NX N=7f)	a.  
watches information on multiple trades made by the user

https://api-docs.pro.apex.exchange/#private-websocket

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.unifiedMargin]: use unified margin account
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
myTradesN:r+   r   r)   rI   T
rM   r?   rQ   rR   r4   authenticaterV   rW   rZ   filter_by_symbol_since_limit)	r:   r?   r@   rA   rD   rc   r]   r^   rd   s	            r<   watch_my_tradesapex.watch_my_trades  s      !!!![[(F3<'K))+,	iit$Y/-?)K$$$((mj\6RR??OOF2E00tTT 	" 	%Rs4   CCA(CCCC:CCCc                   #    U R                  5       I Sh  vN   SnU R                  U5      (       d%  U R                  U5      nSSR                  U5      -   n[	        U R                  5       5      nU R                  S   S   S   S-   U-   nS	U-   nU R                  U5      nU R                  U5      I Sh  vN   U R                  X5        U R                  n	U	c,  UR                  S
5      I Sh  vN n
U R                  XX#S5      $ S	/nU R                  Xu/X5      I Sh  vN nU R                  (       a  U$ U R                  XX#S5      $  GN5 N N` N17f)a  

https://api-docs.pro.apex.exchange/#private-websocket

watch all open positions
:param str[] [symbols]: list of unified market symbols
:param int [since]: the earliest time in ms to fetch positions for
:param int [limit]: the maximum number of positions to retrieve
: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)   rI   	positionsfetchPositionsSnapshotT)rM   is_emptyrN   joinrQ   rR   r4   rh   r  set_positions_cacher  futurefilter_by_symbols_since_limitrV   rW   )r:   rG   r@   rA   rD   rc   r]   r^   rh   cacher   r_   newPositionss                r<   watch_positionsapex.watch_positions+  sL     !!!}}W%%))'2G'!22K))+,	iit$Y/-?)K!K/S!$$$  1=#]]+CDDH55hW[\\!..sM6RR??11%%PTUU' 	" 	% E SsF   EEBE6E78E/E00E E!+EEEEc                   #    U R                  5       I Sh  vN   SnUb  U R                  U5      nUSU-   -  n[        U R                  5       5      nU R                  S   S   S   S-   U-   nU R                  U5      I Sh  vN   S/nU R                  Xu/X5      I Sh  vN n	U R                  (       a  U	R                  X5      nU R                  XX#S5      $  N NY N=7f)	a  
watches information on multiple orders made by the user

https://api-docs.pro.apex.exchange/#private-websocket

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nordersr  r+   r   r)   rI   Tr  )
r:   r?   r@   rA   rD   rc   r]   r^   r_   r&  s
             r<   watch_ordersapex.watch_ordersL  s      !!![[(F3<'K))+,	iit$Y/-?)K$$$((mVLL??OOF2E00tTT 	" 	%Ls4   CCA*CCCC :CCCc                    U R                   c-  U R                  U R                  SS5      n[        U5      U l         U R                   n0 n[	        S[        U5      5       H4  nX&   nS nU R                  U5      nUS   n	SXY'   UR                  U5        M6     [        UR                  5       5      n
[	        S[        U
5      5       H  nSX   -   nUR                  XK5        M     SnUR                  XL5        g )Nrm   rn   r   r?   Tz	myTrades:r  )r  rr   r5   r   rS   rO   rs   rU   listkeysrt   )r:   rh   listsrA   rd   rG   ra   rawTrader|   r?   r+  currentMessageHashrc   s                r<   handle_my_tradesapex.handle_my_tradesf  s    $ == %%dllM4HE259DMq#e*%AxHF((2FH%F"GOMM&! & GLLN#q#d)$A!,tw!6NN66 % !v+r>   c                    U R                   c-  U R                  U R                  SS5      n[        U5      U l         U R                   n0 n[	        S[        U5      5       H2  nS nU R                  X&   5      nUS   nSXX'   UR                  U5        M4     [        UR                  5       5      n	[	        S[        U	5      5       H  nSX   -   n
UR                  XJ5        M     SnUR                  XK5        g )NordersLimitrn   r   r?   Tzorders:r&  )r&  rr   r5   r   rS   rO   parse_orderrU   r*  r+  rt   )r:   rh   r,  rA   r&  rG   ra   r|   r?   symbolsArrayr.  rc   s               r<   handle_orderapex.handle_order  s    < ;;%%dllM4HE07DKq#e*%AF%%eh/FH%F"GOMM&! & GLLN+q#l+,A!*\_!<NN66 - v+r>   c                     U R                   b  g SnX1R                  ;  a.  UR                  U5        U R                  U R                  X5        g g )Nr  )r  futuresr  spawnload_positions_snapshot)r:   rh   rG   rc   s       r<   r  apex.set_positions_cache  sC    >>%.~~-MM+&JJt33VI .r>   c                   #    U R                  S 5      /n[        R                  " U6 I S h  vN n[        5       U l        U R                  n[        S[        U5      5       H8  nXF   n[        S[        U5      5       H  nXx   n	UR                  U	5        M     M:     UR                  U   n
U
R                  U5        UR                  US5        g  N7f)Nr   r  )
fetch_positionsasynciogatherr   r  rS   rO   rU   r8  rt   )r:   rh   rc   fetchFunctionspromisesr!  ra   r  iipositionr  s              r<   r:  apex.load_positions_snapshot  s        &
 !8813q#h-(A IAs9~.$=X& / ) ,uuk* 9s   )CCB$Cc                    U R                   c  [        5       U l         U R                   n/ n[        S[        U5      5       H  nX%   nU R	                  U5      nU R                  US5      nUR                  U5        Ub  US:X  a3  SUS'   UR                  U5        SUS'   UR                  U5        S US'   Mw  UR                  U5        M     U R                  US5      n	[        S[        U	5      5       Hk  nX   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  MZ  UR                  X5        Mm     UR                  US5        g )Nr   r   r   longshortzpositions::r   ro   r  r?   Fr  )r  r   rS   rO   parse_positionrY   rU   find_message_hashesrp   r   r  rt   )r:   rh   r,  r!  r"  ra   rawPositionrC  r   r`   rc   rv   symbolsStringrG   r  s                  r<   handle_positionsapex.handle_positions  sa   . >>!57DNq#e*%A(K**;7H##Hf5D )|trz $* X&#* X&#'  X&# &$ 00Gq#m,-A'*K%%d+E!!HM#))#.G,,\8WeTI==++y6 . 	|[1r>   c           	      Z  #    U R                  5         [        U R                  5       5      nSnSnX5-   U-   nU R                  U R	                  U5      U R	                  U R                  U R                  5      5      [        R                  S5      nSnU R                  U5      n	U	R                  U5      n
U R                  U	R                  U5      nUcL  SS/UUU R                  U R                  UUS.nS[        R                   " U5      /S.nU R#                  XX5        U
I S h  vN $  N7f)	Nz/ws/accountsGETbase64authenticatedloginws_zk_accounts_v3)r   r_   
httpMethodrequestPathapiKey
passphraserL   	signaturer   )check_required_credentialsrQ   rR   hmacencodestring_to_base64secrethashlibsha256rh   reusableFuturerX   subscriptionsrV  passwordjsondumpswatch)r:   r^   rD   rL   request_pathhttp_methodmessageStringrX  rc   rh   r  rQ  r   ru   s                 r<   r  apex.authenticate  s"    '')))+,	%"0<?IIdkk-8$++dF[F[\`\g\gFh:ikrkyky  |D  E	%S!&&{3(<(<kJ   ./)+++"mm&&	G G,-G JJs>||s   D"D+$D)%D+c                 <   U R                  U/ SQ5      n Ub  US:w  a}  U R                  S-   U R                  U5      -   nU R                  U R                  S   X45        U R                  USS5      nU R                  U R                  S   XT5        [        U5      eU R                  US5      nUbm  U(       df  U R                  US5      nU R                  US	0 5      nU R                  US
5      n	U	S:X  a  [        SU-   5      e[        U R                  S-   U-   5      eg! [         ar  n
[        U
[        5      (       a0  SnUR                  X5        XR                  ;   a  UR                  U	 O#U R                  US5      nUR                  X5         S n
A
gS n
A
ff = f)N)coderet_coderetCode0 exactretMsgret_msgbroadsuccessr   r   authzAuthentication failed: FrQ  reqIdT)r   rP   rc  throw_exactly_matched_exception
exceptionssafe_string_2throw_broadly_matched_exceptionr   rX   rY   r   	Exception
isinstancerejectra  )r:   rh   ru   rk  feedbackmsgrt  rr  r   r   errorrc   s               r<   handle_error_messageapex.handle_error_message,  s   X !!'+JK	DCK77S=499W+==44T__W5Mt^(((IF44T__W5Ms]#H--oogy9G"7**7I>//'9bA%%gt4<-.G'.QRR'#(?@@ 		%!455-e1"6"66,,[9"..w@e1		s   DD 
F)A(FFc                    U R                  X5      (       a  g U R                  USSS5      nU R                  U R                  U R                  U R                  U R                  U R
                  U R
                  U R                  U R                  U R                  U R                  U R                  S.nU R                  XC5      nUb	  U" X5        g [        UR                  5       5      n[        S[        U5      5       H,  nXg   nUR                  Xg   5      S:  d  M   XH   n	U	" X5          g    U R!                  US5      n
U
S:X  a  U R                  X5        g g )Nrb   r   r   )rS  r   depthcandlekliner   instrumentInfor   recentlyTradepongru  r1   r   r   	AUTH_RESP)r  ry  handle_accountr   r  r   r}   handle_ponghandle_authenticatehandle_pingrX   r*  r+  rS   rO   r   rY   )r:   rh   ru   rb   methods
exacMethodr+  ra   keymethodr   s              r<   handle_messageapex.handle_messageu  s@   $$V55""7GT2>!%!4!4//++''&&(("00''!//$$,,$$
 __W4
!v'GLLN#q#d)$A'Czz$'"a' v' % 0;$$V5 r>   c                 L    U R                  5       nX!l        [        U5      /SS.$ )Nr1   r   r   )rR   lastPongrQ   )r:   rh   r]   s      r<   r1   	apex.ping  s,    %%'	#^$
 	
r>   c                 "  #    U R                  5       n UR                  [        U5      /SS.5      I S h  vN   g  N! [         aE  n[	        U R
                  S-   U R                  U5      -   5      nUR                  U5         S nAg S nAff = f7f)Nr  r  z handlePing failed with error )rR   sendrQ   r{  r   rP   rc  r   )r:   rh   ru   r]   er  s         r<   r  	apex.pong  sx      %%'		 ++I'7vFGGG 	  +K!KdiiXYl!Z[ELL	 s7   B!= ;= B= 
B;BBBBc                 4    U R                  US5      Ul        U$ )Nr  )rr   r  r:   rh   ru   s      r<   r  apex.handle_pong  s     ++GV<r>   c                 <    U R                  U R                  X5        g N)r9  r  r  s      r<   r  apex.handle_ping  s    

499f.r>   c                    U R                  US0 5      nU R                  US/ 5      nUb  U R                  X5        U R                  US/ 5      nUb  U R                  X5        U R                  US/ 5      nUb  U R	                  X5        g g )Ncontentsfillsr  r&  )r   r   r/  rL  r5  )r:   rh   ru   r  r  r  r&  s          r<   r  apex.handle_account  s    >>':r:x"5!!&0NN8["=	 !!&4(B7f- r>   c                 x   U R                  US5      nU R                  US5      nSnU(       d  US:X  a/  U R                  UR                  U5      nUR                  S5        U$ [	        U R
                  S-   U R                  U5      -   5      nUR                  Xu5        XQR                  ;   a  UR                  U	 U$ )Nrt  rm  rQ  r   Tro  )	rX   rr   r8  rt   r   rP   rc  r}  ra  )r:   rh   ru   rt  rk  rc   r  r  s           r<   r  apex.handle_authenticate  s     //'95  )4%dai__V^^[AFNN4  	 (#		'8J(JKEMM%-222((5r>   c                     U$ r   r  s      r<   handle_subscription_statusapex.handle_subscription_status  s	     r>   )r  r&  r  r  )9__name__
__module____qualname____firstlineno__r   r9   rQ   r	   r   r   rE   rC   r   r}   rs   r   r   r   rV   r   r   r   r   r   r   r   r   r   r*  r   r   r  r   r   r  r   r#  r
   r'  r/  r5  r  r:  rL  r  r   r  r  r1   r  r  r  r  r  r  __static_attributes____classcell__)r;   s   @r<   r   r      s`   '# 'R <@d[] S SS S Sbfglbm S OSaenp !Sd3i !S !S[^ !Suyz  vA !SF',F ',R$L @DB PS P PS\ P SW_a !$s) !C !fo !@ EG U8/ 8/t$3 68 K KF K( 6:" E7 E E<-:F -:^ ?CQUdhqs ) ) )3 )^a )x|  ~B  yC )" aesw  AC E$tCy/ EZ] Emp E@.16 .1`
D 
2 37TX\eg UC Us URU Ulpqvlw U4 8<$]ajl VW VC VWZ Vquv~q VB 04$UYbd U UC Us Uimnsit U4$,v $,L.,6 .,`J& J7 J+$62p .0 <G6 Gt GR 6V  6D
6 
	 & /& /
.V 
.& ,  r>   r   )!ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r   r>  r^  rc  ccxt.base.typesr   r   r	   r
   r   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   r   async_supportr   r  r>   r<   <module>r     sW     A  A    l l l l 4  * 0 . )X4"" Xr>   