
    ":h[8                         d dl Zd dlmZ d dlmZmZmZmZm	Z	m
Z
mZ d dlmZ d dlmZ  G d dej                   j"                        Zy)    N)
ArrayCache)AnyInt	OrderBookStringsTickerTickersTrade)Client)Listc            
            e Zd Zdef fdZddi fdedededee   fdZ	de
fd	Zdi fdededefd
Zde
fdZi fdedefdZdi fdedefdZde
fdZde
fdZde
fdZ xZS )paradexreturnc                 ~    | j                  t        t        |          dddddddddd	dddiddidd	d
ddi i d      S )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/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/pro/paradex.pyr(   zparadex.describe   s    gt = ?# $"&$#). %#
 ;> A 4@Q 5B
  	    Nsymbolsincelimitc                 z  K   | j                          d{    d}|| j                  |      }||d   z  }n|dz  }| j                  d   d   }ddd	|id
}| j                  ||| j	                  ||      |       d{   }	| j
                  r|	j                  ||      }| j                  |	||dd      S 7 7 9w)a1  
        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)   r-   r.   r/   r9   messageHashr<   urlrequesttradess
             r+   watch_tradeszparadex.watch_trades-   s      !!![[(F6$<'K5 Kiit$!;
 zz#{D4D4DWf4UWbcc??OOFE2E))&%TRR% 	" ds"   B;B7A(B;?B9 8B;9B;clientc                    | j                  |di       }| j                  |di       }| j                  |      }|d   }| j                  |d      }| j                  | j                  |      }|5t        | j                  | j                  dd            }|| j                  |<   |j                  |       |j                  ||       |S )Nr9   datar-   r5   tradesLimiti  )
	safe_dictparse_tradesafe_string
safe_valuerD   r   safe_integerr$   appendresolve)	r)   rF   messager9   rH   parsedTrader-   rA   storeds	            r+   handle_tradezparadex.handle_tradeM   s    & 26~~ffb1&&t,X&&&vy9f5> 1 1$,,t TUF"(DKKk"v{+r,   c                 &  K   | j                          d{    | j                  |      }d|d   z   dz   }| j                  d   d   }ddd	|id
}| j                  ||| j	                  ||      |       d{   }|j                         S 7 v7 w)ae  
        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.r1   z.snapshot@15@100msr   r   r3   r4   r5   r6   )r;   r<   r#   r=   r&   r/   )	r)   r-   r/   r9   r<   rA   rB   rC   	orderbooks	            r+   watch_order_bookzparadex.watch_order_bookm   s      !!!V$#fTl25IIiit$!;
 **S+t7G7GQW7XZeff	   	" gs"   BBA!B8B9BBc                 L   | j                  |di       }| j                  |di       }| j                  |d      }| j                  |      }| j                  |d      }|d   }|| j                  vr| j                         | j                  |<   g g d}	| j                  |d      }
t        dt        |
            D ]|  }| j                  |
|      }| j                  |d	      }| j                  |d
      }| j                  |d      }|dk(  r|	d   j                  ||g       g|	d   j                  ||g       ~ | j                  |   }| j                  |	||dd      }| j                  |d      |d<   |j                  |       | j                  |d      }|j                  ||       y )Nr9   rH   r<   last_updated_atr-   )bidsasksinsertsr   sidepricesizeBUYrZ   r[   seq_nononcer5   )rJ   rL   safe_marketrN   
orderbooks
order_book	safe_listrangelenrO   parse_order_booksafe_numberresetrP   )r)   rF   rQ   r9   rH   marketIdr<   r:   r-   orderbookDatar\   iinsertr]   r^   r_   rV   snapshotrA   s                      r+   handle_order_bookzparadex.handle_order_book   s   < 26~~ffb1##D(3!!(+%%d,=>	!$//)&*oo&7DOOF#
 ..y1q#g,' 	<A^^GQ/F##FF3D$$VW5E##FF3Du}f%,,eT];f%,,eT];	< OOF+	((	6SYZ ,,T8<!&&vy9y+.r,   c                   K   | j                          d{    | j                  |      }d}| j                  d   d   }ddd|id}|d	z   |z   }| j                  ||| j	                  ||      |       d{   S 7 e7 w)
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   r3   r4   r5   r6   .)r;   r-   r#   r=   r&   )r)   r-   r9   r5   rB   rC   rA   s          r+   watch_tickerzparadex.watch_ticker   s      !!!V$#iit$!7
 mf,ZZ[$2B2B7F2SU`aaa 	" bs"   B A<A B 7A>8B >B symbolsc                   K   | j                          d{    | j                  |      }d}| j                  d   d   }ddd|id}g }t        |t              r7t        d	t        |            D ]  }|d
z   ||   z   }|j                  |         n|j                  |       | j                  ||| j                  ||      |       d{   }	| j                  ri }
|	|
|	d   <   |
S | j                  | j                  d|      S 7 7 ;w)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>`
        Nrs   r   r   r3   r4   r5   r6   r   rt   r-   )r;   market_symbolsr#   
isinstancelistrg   rh   rO   watch_multipler&   r>   filter_by_arraytickers)r)   rv   r9   r5   rB   rC   messageHashesrn   rA   
newTickersresults              r+   watch_tickerszparadex.watch_tickers   s"     !!!%%g.#iit$!7
 gt$1c'l+ 2%mgaj8$$[12   )..sM4CSCST[]cCdfstt
??F+5F:h'(M##DLL(GDD/ 	"$ us"   DDB2D	D
:DDc                 `   | j                  |di       }| j                  |di       }| j                  |d      }| j                  |      }|d   }| j                  |d      }|dz   |z   }	| j                  ||      }
|
| j                  |<   |j                  |
|       |j                  |
|	       |S )Nr9   rH   r-   r5   rt   )rJ   rL   rc   parse_tickerr}   rP   )r)   rF   rQ   r9   rH   rl   r<   r-   r5   rA   tickers              r+   handle_tickerzparadex.handle_ticker   s    2 26~~ffb1##D(3!!(+!""695mf,""40%Vvw'v{+r,   c                 @   | j                  |d      }|y| j                  |d      }|u| j                  dz   | j                  |      z   }| j	                  | j
                  d   d|       | j                  |d      }| | j                  | j
                  d   ||       y	)
NerrorTcode exactz-32600rQ   broadF)rJ   rL   r1   jsonthrow_exactly_matched_exception
exceptionsrM   throw_broadly_matched_exception)r)   rF   rQ   r   	errorCodefeedbackmessageStrings          r+   handle_error_messagezparadex.handle_error_message"  s     w0=((7I$77S=499U+;;44T__W5MxYab $y A ,889QS`bjkr,   c                 B   | j                  ||      sy | j                  |d      }|x| j                  |d      }|j                  d      }| j                  |d      }| j                  | j
                  | j                  d}| j                  ||      }|
 |||       y y y )Nr9   r5   rt   r   )rD   re   rs   )r   rJ   rL   splitrT   rq   r   rM   )	r)   rF   rQ   rH   r5   partsnamemethodsr8   s	            r+   handle_messagezparadex.handle_message>  s    ((9& ~~gx0&&tY7GMM#&E##E1-D++"44#'#5#5G __Wd3F!vw' " r,   )__name__
__module____qualname__r   r(   strr   r   r
   rE   r   rT   r   rW   rq   r   ru   r   r	   r   r   r   r   __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 8"(V "(r,   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   ccxt.base.typesr   r   r   r   r   r	   r
   !ccxt.async_support.base.ws.clientr   typingr   async_supportr    r,   r+   <module>r      s6     7 P P P 4 S(d  (( S(r,   