
    E#ii8                         S SK rS SKJr  S SK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\R"                  R$                  5      rg)    N)
ArrayCache)AnyBoolInt	OrderBookStringsTickerTickersTrade)Client)Listc            
          ^  \ 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	\4S
 jrS0 4S\S\S\4S jjrS	\4S jr0 4S\S\4S jjrS0 4S\S\4S jjrS	\4S jrS	\S\4S jrS	\4S jrSrU =r$ )paradex   returnc                 ~   > U R                  [        [        U ]  5       SSSSSSSSSS.	SSS0SS0SS	S
SS.0 0 S.5      $ )NTF)	wswatchTickerwatchTickerswatchOrderBookwatchOrderswatchTradeswatchTradesForSymbolswatchBalance
watchOHLCVz https://x.com/tradeparadex/photor   z"wss://ws.api.prod.paradex.trade/v1z%wss://ws.api.testnet.paradex.trade/v1zhttps://www.paradex.trade/z'https://docs.api.testnet.paradex.trade/z7https://docs.paradex.trade/getting-started/trading-fees )logoapitestwwwdocfeesreferral)hasurlsoptions	streaming)deep_extendsuperr   describe)self	__class__s    J/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/paradex.pyr*   paradex.describe   s    gt = ?# $"&$#). %#
 ;> A 4@Q 5B
  	    Nsymbolsincelimitc                 |  #    U R                  5       I Sh  vN   SnUb  U R                  U5      nXVS   -  nOUS-  nU R                  S   S   nSSS	U0S
.nU R                  XuU R	                  X5      U5      I Sh  vN n	U R
                  (       a  U	R                  X5      nU R                  XUSS5      $  N N<7f)a  
get the list of most recent trades for a particular symbol

https://docs.api.testnet.paradex.trade/#sub-trades-market_symbol-operation

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
Nztrades.idALLr   r   2.0	subscribechanneljsonrpcmethodparams	timestampT)load_marketsmarketr%   watchr(   
newUpdatesgetLimitfilter_by_since_limit)
r+   r0   r1   r2   r<   messageHashr?   urlrequesttradess
             r-   watch_tradesparadex.watch_trades-   s      !!![[(F$<'K5 Kiit$!;
 zz#D4D4DW4UWbcc??OOF2E))&TRR% 	" ds"   B<B8A&B<=B:>;B<:B<clientc                    U R                  US0 5      nU R                  US0 5      nU R                  U5      nUS   nU R                  US5      nU R                  U R                  U5      nUc4  [        U R                  U R                  SS5      5      nXR                  U'   UR                  U5        UR                  X5        U$ )Nr<   datar0   r8   tradesLimiti  )
	safe_dictparse_tradesafe_string
safe_valuerG   r   safe_integerr&   appendresolve)	r+   rJ   messager<   rL   parsedTrader0   rD   storeds	            r-   handle_tradeparadex.handle_tradeM   s    & 26~~ffb1&&t,X&&&vy9f5> 1 1$,,t TUF"(KKk"v+r/   c                 "  #    U R                  5       I Sh  vN   U R                  U5      nSUS   -   S-   nU R                  S   S   nSSS	U0S
.nU R                  XeU R	                  Xs5      U5      I Sh  vN nUR                  5       $  Nt N7f)a-  
watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://docs.api.testnet.paradex.trade/#sub-order_book-market_symbol-snapshot-15-refresh_rate-operation

: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
Nzorder_book.r4   z.snapshot@15@100msr   r   r6   r7   r8   r9   )r>   r?   r%   r@   r(   r2   )	r+   r0   r2   r<   r?   rD   rE   rF   	orderbooks	            r-   watch_order_bookparadex.watch_order_bookm   s      !!!V$#fTl25IIiit$!;
 **St7G7G7XZeff	   	" gs"   BBAB6B7BBc                 N   U R                  US0 5      nU R                  US0 5      nU R                  US5      nU R                  U5      nU R                  US5      nUS   nXR                  ;  a  U R                  5       U R                  U'   / / S.n	U R                  US5      n
[        S[        U
5      5       H|  nU R                  X5      nU R                  US	5      nU R                  US
5      nU R                  US5      nUS:X  a  U	S   R                  X/5        Mg  U	S   R                  X/5        M~     U R                  U   nU R                  XUSS5      nU R                  US5      US'   UR                  U5        U R                  US5      nUR                  UU5        g )Nr<   rL   r?   last_updated_atr0   )bidsasksinsertsr   sidepricesizeBUYr`   ra   seq_nononcer8   )rN   rP   safe_marketrR   
orderbooks
order_book	safe_listrangelenrS   parse_order_booksafe_numberresetrT   )r+   rJ   rU   r<   rL   marketIdr?   r=   r0   orderbookDatarb   iinsertrc   rd   re   r[   snapshotrD   s                      r-   handle_order_bookparadex.handle_order_book   s   < 26~~ffb1##D(3!!(+%%d,=>	!//)&*oo&7DOOF#
 ..y1q#g,'A^^G/F##FF3D$$VW5E##FF3Du}f%,,e];f%,,e]; ( OOF+	((	6SYZ ,,T8<!&&vy9y+.r/   c                    #    U R                  5       I Sh  vN   U R                  U5      nSnU R                  S   S   nSSSU0S.nUS	-   U-   nU R                  XFU R	                  XR5      U5      I Sh  vN $  Nc 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://docs.api.testnet.paradex.trade/#sub-markets_summary-operation

: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>`
Nmarkets_summaryr   r   r6   r7   r8   r9   .)r>   r0   r%   r@   r(   )r+   r0   r<   r8   rE   rF   rD   s          r-   watch_tickerparadex.watch_ticker   s      !!!V$#iit$!7
 mf,ZZ$2B2B72SU`aaa 	" bs"   A>A:AA>5A<6A><A>symbolsc                 "  #    U R                  5       I Sh  vN   U R                  U5      nSnU R                  S   S   nSSSU0S.n/ n[        U[        5      (       a8  [        S	[        U5      5       H  nUS
-   X   -   nUR                  U5        M      OUR                  U5        U R                  XFU R                  XR5      U5      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://docs.api.testnet.paradex.trade/#sub-markets_summary-operation

: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>`
Nrz   r   r   r6   r7   r8   r9   r   r{   r0   )r>   market_symbolsr%   
isinstancelistrm   rn   rS   watch_multipler(   rA   filter_by_arraytickers)r+   r~   r<   r8   rE   rF   messageHashesrt   rD   
newTickersresults              r-   watch_tickersparadex.watch_tickers   s     !!!%%g.#iit$!7
 gt$$1c'l+%mgj8$$[1 ,   )..s4CSCST[Cdfstt
??F+5:h'(M##DLL(GDD/ 	"$ us"   DDB6DD>DDc                 X   U R                  US0 5      nU R                  US0 5      nU R                  US5      nU R                  U5      nUS   nU R                  US5      nUS-   U-   n	U R                  XF5      n
XR                  U'   UR                  X5        UR                  X5        U$ )Nr<   rL   r0   r8   r{   )rN   rP   ri   parse_tickerr   rT   )r+   rJ   rU   r<   rL   rr   r?   r0   r8   rD   tickers              r-   handle_tickerparadex.handle_ticker   s    2 26~~ffb1##D(3!!(+!""695mf,""40%Vv'v+r/   c                 D   U R                  US5      nUc  gU R                  US5      nUbu  U R                  S-   U R                  U5      -   nU R	                  U R
                  S   SU5        U R                  US5      nUb  U R                  U R
                  S   Xe5        g	)
NerrorTcode exactz-32600rU   broadF)rN   rP   r4   jsonthrow_exactly_matched_exception
exceptionsrQ   throw_broadly_matched_exception)r+   rJ   rU   r   	errorCodefeedbackmessageStrings          r-   handle_error_messageparadex.handle_error_message"  s     w0=((7I$77S=499U+;;44T__W5MxYab $y A ,889QS`kr/   c                 J   U R                  X5      (       d  g U R                  US5      nUbw  U R                  US5      nUR                  S5      nU R                  US5      nU R                  U R
                  U R                  S.nU R                  Xv5      nUb	  U" X5        g g g )Nr<   r8   r{   r   )rG   rk   rz   )r   rN   rP   splitrX   rw   r   rQ   )	r+   rJ   rU   rL   r8   partsnamemethodsr;   s	            r-   handle_messageparadex.handle_message>  s    ((99& ~~gx0&&tY7GMM#&E##E1-D++"44#'#5#5G __W3F!v' " r/    )__name__
__module____qualname____firstlineno__r   r*   strr   r   r   rH   r   rX   r   r\   rw   r	   r|   r   r
   r   r   r   r   r   __static_attributes____classcell__)r,   s   @r-   r   r      s    # < <@d[] S SS S Sbfglbm S@6 @ @DB !S ! !S\ !29/ 9/v 68 b bF b0 6:" !E7 !E !EF$F $L6 t 8"(V "( "(r/   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   ccxt.base.typesr   r   r   r   r   r	   r
   r   !ccxt.async_support.base.ws.clientr   typingr   async_supportr   r   r/   r-   <module>r      s6     7 V V V 4 S(d  (( S(r/   