
    E#iQ                         S SK rS SKJr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KJr  S SKJr   " S S	\R*                  R,                  5      rg)
    N)
ArrayCacheArrayCacheByTimestamp)AnyBoolInt	OrderBookStringsTickerTickersTrade)Client)List)ExchangeError)
BadRequestc                     ^  \ rS rSrS\4U 4S jjr0 4S\S\4S jjrSSS0 4S	\S
\S\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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0 4S	\S\S\4S jjrS\4S jrS\4S jrS\4S jrS\4S jrS\4S jrS\S\4S jrS\4S jrS\4S jrS\4U 4S jjr S\4U 4S jjr!Sr"U =r#$ ) p2b   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.ESSS00SSSSSSS.SS0SS0U R	                  5       S.S U R
                  0S!.5      $ )"NwsTcancelAllOrdersWsFcancelOrdersWscancelOrderWscreateOrderWseditOrderWsfetchBalanceWsfetchOpenOrdersWsfetchOrderWsfetchTradesWswatchBalancewatchMyTrades
watchOHLCVwatchOrderBookwatchOrderswatchTickerwatchTickers)watchTradeswatchTradesForSymbolsapizwss://apiws.p2pb2b.com/  i  i  i  iQ )15m30m1h1dnamestate)
OHLCVLimittradesLimit
timeframesr%   r&   
tickerSubsping)hasurlsoptions	streaming)deep_extendsuperr   describecreate_safe_dictionaryr5   )self	__class__s    F/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/p2b.pyr<   p2b.describe   sk   c4 9 ;d#U !%  	
   u !% $U       d !$ u" t#$ %&  $)-). 3 ##	 G  G! #99;$ 		[0>
 0 0	    r/   messageHashc                    #    U R                   S   S   nUUU R                  5       S.nU R                  Xd5      nU R                  XRXr5      I Sh  vN $  N7f)aS  
@ignore
       Connects to a websocket channel
       :param str name: name of the channel
       :param str messageHash: string to look up in handler
       :param str[]|float[] request: endpoint parameters
       :param dict [params]: extra parameters specific to the p2b api
       :returns dict: data from the websocket stream
       r)   r   methodparamsidN)r7   millisecondsextendwatch)r>   r/   rC   requestrG   url	subscribequerys           r@   rN   p2b.subscribeD   sZ      iit$##%
	
 I.ZZ%EEEEs   AAAAr+   Nsymbol	timeframesincelimitc                   #    U R                  5       I Sh  vN   U R                  U R                  S0 5      nU R                  Xb5      nUc  [	        U R
                  S-   U-   5      eU R                  U5      nUS   U/n	SUS   -   n
U R                  SXU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  
watches historical candlestick data containing the open, high, low, and close price, and the volume of a market. Can only subscribe to one timeframe at a time for each symbol

https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#kline-candlestick

:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: 15m, 30m, 1h or 1d
: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
Nr3   z' watchOHLCV cannot take a timeframe of rH   zkline::rQ   zkline.subscriber   T)load_markets
safe_valuer8   safe_integerr   rH   marketrN   
newUpdatesgetLimitfilter_by_since_limit)r>   rQ   rR   rS   rT   rG   r3   channelrY   rL   rC   ohlcvs               r@   watch_ohlcvp2b.watch_ohlcvW   s      !!!__T\\<D
##J:?TWW'PPS\\]]V$4L
  &"22nn%6fUU??NN61E))%q$GG 	" Vs"   CCBCC;C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SU5      u  pBU R                  U5      nUS   nSU R                  S   US	   '   U R                  S   n[        UR                  5       5      nUS
-   US   -   nU R                  US-   XU5      I Sh  vN $  N N7f)aP  
watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#last-price
https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#market-status

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param dict [params.method]: 'state'(default) or 'price'
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr%   r/   r0   rF   rQ   Tr4   rH   ::
.subscribe)	rV   	safe_dictr8   safe_stringhandle_option_and_paramsrY   listkeysrN   )	r>   rQ   rG   watchTickerOptionsr/   rY   r4   rL   rC   s	            r@   watch_tickerp2b.watch_tickert   s      !!!!^^DLL-H 2FGD44VXvtTV$!37\"6$<0\\,/
z()TkF8$44^^D<$7vVVV 	" Ws"   C CC C CC C symbolsc                   #    U R                  5       I Sh  vN   U R                  USS5      nU R                  U R                  S5      nU R	                  USS5      nU R                  USSU5      u  pB/ n/ n[        S[        U5      5       HD  nU R                  X   5      nUR                  US-   US	   -   5        UR                  US
   5        MF     U R                  S   S   n	US-   UU R                  5       S.n
U R                  XU R                  X5      U5      I Sh  vN   U R                  U R                  S	U5      $  GN. N$7f)ab  

https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#last-price
https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#market-status

watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
:param str[] [symbols]: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param dict [params.method]: 'state'(default) or 'price'
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
NFr%   r/   r0   rF   r   rb   rQ   rH   r)   r   rc   rE   )rV   market_symbolsrd   r8   re   rf   rangelenrY   appendr7   rI   watch_multiplerJ   filter_by_arraytickers)r>   rl   rG   ri   r/   messageHashesargsirY   rM   rL   s              r@   watch_tickersp2b.watch_tickers   sE     !!!%%gtU;!^^DLL-H 2FGD44VXvtTq#g,'A[[,F  vh/?!?@KKt% ( iit$\)##%

 !!#dkk'6RTabbb##DLL(GDD% 	"" 	cs"   E	EDE	"E#"E	E	c                 F   #    U R                  U/X#U5      I Sh  vN $  N7f)a  
get the list of most recent trades for a particular symbol

https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#deals

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
N)watch_trades_for_symbols)r>   rQ   rS   rT   rG   s        r@   watch_tradesp2b.watch_trades   s$      22F8U6RRRRs   !!c                 T  #    U R                  5       I Sh  vN   U R                  USSSS5      n/ nUb2  [        S[        U5      5       H  nUR	                  SX   -   5        M     U R                  U5      nU R                  S   S   nSUU R                  5       S	.n	U R                  X5      n
U R                  XX5      I Sh  vN nU R                  (       a5  U R                  US5      nU R                  US
5      nUR                  X5      nU R                  XUSS5      $  GN Na7f)a  
get the list of most recent trades for a list of symbols

https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#deals

: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>`
NFTr   deals::r)   r   zdeals.subscriberE   rQ   	timestamp)rV   rn   ro   rp   rq   
market_idsr7   rI   rJ   rr   rZ   rW   re   r[   r\   )r>   rl   rS   rT   rG   ru   rw   	marketIdsrM   rN   rO   tradesfirsttradeSymbols                 r@   r{   p2b.watch_trades_for_symbols   s     !!!%%gtUD$G1c'l+$$Y%;< ,OOG,	iit$'##%
	
 I.**3uTT??OOFA.E**5(;KOOK7E))&TRR' 	" Us#   D(D#B-D(D&AD(&D(c                   #    U R                  5       I Sh  vN   U R                  U5      nSnSUS   -   nU R                  USS5      nUc  SnUS   UU/nU R                  XVX5      I Sh  vN n	U	R	                  5       $  Ni N7f)	a  
watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#depth-of-market

:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: 1-100, default=100
:param dict [params]: extra parameters specific to the exchange API endpoint
:param float [params.interval]: 0, 0.00000001, 0.0000001, 0.000001, 0.00001, 0.0001, 0.001, 0.01, 0.1, interval of precision for order, default=0.001
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
Nzdepth.subscribeorderbook::rQ   intervalz0.001d   rH   )rV   rY   re   rN   rT   )
r>   rQ   rT   rG   rY   r/   rC   r   rL   	orderbooks
             r@   watch_order_bookp2b.watch_order_book   s      !!!V$ #fX&66##FJ@=E4L

 ..GLL	   	" Ms"   BB AB+B,BBclientc                    U R                  US5      nU R                  US5      nU R                  US5      nUR                  S5      nU R                  US5      nU R                  US5      nU R                  U5      nU R	                  U R
                  S0 5      n	U R                  Xi5      n
U R                  US5      nUS-   U-   nU R                  X85      nU R                  U R                  U0 5      U R                  U'   U R                  U R                  U   U
5      nUb^  Uc9  U R                  U R
                  S	S
5      n[        U5      nXR                  U   U
'   UR                  U5        UR                  X5        U$ )NrG   r   rF   .   r3   rQ   rb   r1   r*   )	safe_listre   splitsafe_marketrd   r8   find_timeframeparse_ohlcvrW   ohlcvsrX   r   rq   resolve)r>   r   messagedatarF   splitMethodr]   marketIdrY   r3   rR   rQ   rC   parsedstoredrT   s                   r@   handle_ohlcvp2b.handle_ohlcv   sa   & ~~gx0~~dA&!!'84ll3'"";2##D!,!!(+^^DLL,C
''<	!!&(3nv-!!$/"oodkk62FFV!4i@~))$,,dK.u517F#I.MM&!NN6/rB   c                    U R                  US/ 5      nU R                  US5      nU R                  US5      nU R                  U5      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'   [        S[        U5      5       H)  n
XJ   nU R                  X5      nUR                  U5        M+     SU-   nUR                  X5        U$ )NrG      r   rQ   r2   r*   r   )r   re   r   rW   r   rX   r8   r   ro   rp   parse_traderq   r   )r>   r   r   r   r   r   rY   rQ   tradesArrayr2   rw   itemtraderC   s                 r@   handle_tradep2b.handle_trade   s    ( ~~gx4a(##D!,!!(+!!&(3oodkk6:++DLL-NK$[1K"-KKq#f+&A9D$$T2Eu% '  &({0rB   c                    U R                  US/ 5      nU R                  US5      nU R                  U5      nU R                  US5      nUR                  S5      nU R                  US5      nU R	                  US5      n	S n
US:X  a+  U R                  US5      nU R                  UUUS   S.5      n
OU R                  X5      n
U
S   nXR                  U'   US	-   U-   nUR                  X5        U$ )
NrG   r   rF   r   r   price.updaterQ   )lastcloserQ   rb   )	r   re   r   r   rd   safe_tickerparse_tickerrt   r   )r>   r   r   r   r   rY   rF   r   messageHashStart
tickerDataticker	lastPricerQ   rC   s                 r@   handle_tickerp2b.handle_tickerF  s   B ~~gx4##D!,!!(+!!'84ll3'++K;^^D!,
^#((q1I%%!" *' F &&z:F!%V&-6v+rB   c                    U R                  US/ 5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  U5      nUS   n	SUS   -   n
U R	                  UR
                  U
0 5      nU R                  US5      nU R	                  U R                  U	5      nUc.  U R                  0 U5      U R                  U	'   U R                  U	   nUbh  [        S	[        U5      5       HO  nU R	                  Xn5      nU R                  US	5      nU R                  US5      nUS   nUR                  UU5        MQ     Ubh  [        S	[        U5      5       HO  nU R	                  X^5      nU R                  US	5      nU R                  US5      nUS   nUR                  UU5        MQ     XS'   UR                  X5        g )
NrG   r   asksbids   rQ   r   rT   r   )r   rd   re   r   rW   subscriptionsrX   
orderbooks
order_bookro   rp   safe_numberstorer   )r>   r   r   rG   r   r   r   r   rY   rQ   rC   subscriptionrT   r   rw   bidpriceamountbookSideaskbooksides                        r@   handle_order_bookp2b.handle_order_book~  s   & 26~~fa(~~dF+~~dF+##FA.!!(+!#fX&66v';';["M!!,8OODOOV<	&*oob%&@DOOF#/I1c$i(ood.((a0))#q1$V,uf- ) 1c$i(ood.((a0))#q1$V,uf- ) %(y.rB   c                 X   U R                  X5      (       a  g U R                  US5      nUS:X  a  U R                  X5        g U R                  US5      nU R                  U R                  U R
                  U R                  U R                  S.nU R                  XT5      nUb	  U" X5        g g )NresultpongrF   )zdepth.updater   zkline.updatezstate.updatezdeals.update)handle_error_messagere   handle_pongr   r   r   r   rW   )r>   r   r   r   rF   methodsendpoints          r@   handle_messagep2b.handle_message  s    $$V55!!'84VV-!!'84 22 .. -- .. --
 ??73V%  rB   c                     U R                  US5      nUb*  [        U R                  S-   U R                  U5      -   5      eg)Nerrorz error: F)re   r   rH   json)r>   r   r   r   s       r@   r   p2b.handle_error_message  s?      '2* 4tyy7G GHHrB   c                 *    S/ U R                  5       S.$ )zl
       https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#ping
@param client
       zserver.pingrE   )rI   )r>   r   s     r@   r5   p2b.ping  s      $##%
 	
rB   c                 4    U R                  US5      Ul        U$ )NrH   )rX   lastPong)r>   r   r   s      r@   r   p2b.handle_pong  s     ++GT:rB   c                 f   > U R                  5       U R                  S'   [        [        U ]  X5        g Nr4   )r=   r8   r;   r   on_errorr>   r   r   r?   s      r@   r   p2b.on_error  )    %)%@%@%B\"c4!&0rB   c                 f   > U R                  5       U R                  S'   [        [        U ]  X5        g r   )r=   r8   r;   r   on_closer   s      r@   r   p2b.on_close  r   rB    )$__name__
__module____qualname____firstlineno__r   r<   strrN   r   r   rg   r_   r
   rj   r	   r   rx   r   r|   r{   r   r   r   r   r   r   r   r   r   r   r5   r   r   r   __static_attributes____classcell__)r?   s   @r@   r   r      s   1# 1f LN FC Fc F& ?DRVeirt H H HC H_b Hy}  C  zD H: 68 W WF W0 6:" E7 E E@ <@d[] S SS S Sbfglbm S OSaenp Sd3i S S[^ Suyz  vA SB @DB !S ! !S\ !6(6 (T$6 $L6F 6p0/ 0/d&V &&6 t 	
6 	
	& 	1v 11v 1 1rB   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   ccxt.base.typesr   r   r   r   r	   r
   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   async_supportr   r   rB   r@   <module>r      s<     N V V V 4  * 'V1$


 
  V1rB   