
    E#i;[                         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  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TickerTrade)Client)List)ExchangeErrorc                     ^  \ rS rSrS\4U 4S jjrS r0 4S\S\4S jjr	S\
4S jrS	S	0 4S\S
\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\
4S jrS	0 4S\S\S\4S jjrS\
4S jrS rS rS 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\
4S jrS r S\
4S jr!S\
S\"4S jr#S\
4S  jr$S!r%U =r&$ )"bittrade   returnc                    > U R                  [        [        U ]  5       SSSSSSSSS.SSSSSS.000S	S	SS
S0S.S.5      $ )NTF)wswatchOrderBookwatchTickerswatchTickerwatchTradeswatchTradesForSymbolswatchBalance
watchOHLCVapir   zwss://{hostname}/wszwss://{hostname}/ws/v2)publicprivate  gunzip)tradesLimit
OHLCVLimitr   r   )hasurlsoptions)deep_extendsuperr   describe)self	__class__s    K/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/bittrade.pyr'   bittrade.describe   s    h > @"& %##). %"	 &;'? 	  $"d	+C
  	    c                     U R                  U R                  U R                  SS5      S5      nXR                  S'   [        U5      $ )N	requestIdr      )sumsafe_integerr$   str)r(   r.   s     r*   
request_idbittrade.request_id0   s;    HHT..t||[!LaP	$-[!9~r,   symbolc                   #    U R                  5       I Sh  vN   U R                  U5      nUS   nSUS   -   S-   nU R                  U R                  SS5      nSU R                  0nU R                  U R                  S   S   U   S	   U5      nU R                  5       nUUS
.n	UUUUS.n
U R                  XtU R                  X5      XJ5      I Sh  vN $  N N7f)ah  
watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
: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>`
Nr5   market.idz.detailr   hostnamer   r   subr8   r8   messageHashr5   params)
load_marketsmarketsafe_stringr$   r9   implode_paramsr#   r3   watchextend)r(   r5   r>   r@   r=   r   r9   urlr.   requestsubscriptions              r*   watch_tickerbittrade.watch_ticker5   s      !!!V$!&,.:t||UE:$dmm4!!$))E"24"8"=h"GROO%	

 &	
 ZZ$++g2NP[jjj' 	"& ks"   CCB9CCCCclientc                 v   U R                  US0 5      nU R                  US5      nUR                  S5      nU R                  US5      nU R                  U5      nU R	                  X75      nU R                  US5      n	XS'   U R                  U	5      US'   US   n
XR                  U
'   UR                  X5        U$ )	Ntickch.r/   ts	timestampdatetimer5   )
safe_valuerA   splitsafe_marketparse_tickeriso8601tickersresolve)r(   rJ   messagerL   rM   partsmarketIdr@   tickerrP   r5   s              r*   handle_tickerbittrade.handle_tickerQ   s    $ w3gt,##E1-!!(+""40OOGT2	'{!\\)4z!%Vv"r,   Nsincelimitc                 "  #    U R                  5       I Sh  vN   U R                  U5      nUS   nSUS   -   S-   nU R                  U R                  SS5      nSU R                  0nU R                  U R                  S   S   U   S	   U5      n	U R                  5       n
UU
S
.nU
UUUS.nU R                  XU R                  X5      Xl5      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
: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>`
Nr5   r7   r8   z.trade.detailr   r9   r   r   r:   r<   rP   T)r?   r@   rA   r$   r9   rB   r#   r3   rC   rD   
newUpdatesgetLimitfilter_by_since_limit)r(   r5   r_   r`   r>   r@   r=   r   r9   rE   r.   rF   rG   tradess                 r*   watch_tradesbittrade.watch_tradesq   s     !!!V$!&,.@t||UE:$dmm4!!$))E"24"8"=h"GROO%	

 &	
 zz#DKK4PR]ll??OOF2E))&TRR- 	"& ms"   DDB9DD;DDc                 6   U R                  US0 5      nU R                  US0 5      nU R                  US5      nUR                  S5      nU R                  US5      nU R                  U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	'   [        S	[        U5      5       H(  nU R                  XL   U5      nU
R                  U5        M*     UR                  X5        U$ )
NrL   datarM   rN   r/   r5   r    r   r   )rR   rA   rS   rT   re   r1   r$   r   rangelenparse_tradeappendrX   )r(   rJ   rY   rL   ri   rM   rZ   r[   r@   r5   tradesCacher`   itrades                 r*   handle_tradesbittrade.handle_trades   s   * w3tVR0gt,##E1-!!(+!oodkk6:%%dllM4HE$U+K"-KKq#d)$A$$TWf5Eu% % 	{'r,   1m	timeframec                 d  #    U R                  5       I Sh  vN   U R                  U5      nUS   nU R                  U R                  X"5      nSUS   -   S-   U-   nU R                  U R                  SS5      n	SU R
                  0n
U R                  U R                  S   S   U	   S	   U
5      nU R                  5       nUUS
.nUUUUUS.nU R                  XU R                  X5      X5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XUSS5      $  GN N=7f)a  
watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
: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
Nr5   r7   r8   z.kline.r   r9   r   r   r:   )r8   r=   r5   rt   r>   r   T)r?   r@   rA   
timeframesr$   r9   rB   r#   r3   rC   rD   rb   rc   rd   )r(   r5   rt   r_   r`   r>   r@   intervalr=   r   r9   rE   r.   rF   rG   ohlcvs                   r*   watch_ohlcvbittrade.watch_ohlcv   s8     !!!V$!##DOOYJ&,.:XEt||UE:$dmm4!!$))E"24"8"=h"GROO%	

 &"
 jj4;;w3OQ\kk??NN61E))%q$GG/ 	"( ls"   D0D+CD00D.1;D0.D0c                 t   U R                  US5      nUR                  S5      nU R                  US5      nU R                  U5      nUS   nU R                  US5      nU R                  U5      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S5      nU R                  X5      nU
R                  U5        UR                  X5        g )	NrM   rN   r/   r5      r!   r   rL   )rA   rS   rT   find_timeframerR   ohlcvsr1   r$   r   parse_ohlcvrm   rX   )r(   rJ   rY   rM   rZ   r[   r@   r5   rw   rt   storedr`   rL   parseds                 r*   handle_ohlcvbittrade.handle_ohlcv   s   " gt,##E1-!!(+!##E1-''1	"oodkk62FFV!4i@>%%dllL$GE*51F-3KK	*w/!!$/fv"r,   c                 V  #    Ub  US:w  a  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nUS   nUc  SOUnSUS   -   S-   [	        U5      -   nU R                  U R                  SS5      nS	U R                  0nU R                  U R                  S   S
   U   S   U5      nU R                  5       n	UU	S.n
U	UUUUU R                  S.nU R                  XU R                  X5      X[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
: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   z( watchOrderBook accepts limit = 150 onlyr5   r7   r8   z.mbp.r   r9   r   r   r:   r8   r=   r5   r`   r>   method)r   r8   r?   r@   r2   rA   r$   r9   rB   r#   r3   handle_order_book_subscriptionrC   rD   r`   )r(   r5   r`   r>   r@   r=   r   r9   rE   r.   rF   rG   	orderbooks                r*   watch_order_bookbittrade.watch_order_book   s<     ESL*T TUU!!!V$!E&,.83u:Et||UE:$dmm4!!$))E"24"8"=h"GROO%	

 &99
 **St{{77SU`oo	  / 	", ps"   5D)D%CD)D'D)'D)c                    U R                  US5      nU R                  US5      nU R                  U   nU R                  US5      nU R                  Xt5      nU R	                  US5      US'   UR                  U5        UR                  n	[        S[        U	5      5       H  n
U R                  XU
   U5        M     X`R                  U'   UR                  Xe5        g )Nr5   r=   ri   seqNumnoncer   )rA   
orderbooksrR   parse_order_bookr1   resetcacherj   rk   handle_order_book_messagerX   )r(   rJ   rY   rG   r5   r=   r   ri   snapshotmessagesro   s              r*   handle_order_book_snapshot#bittrade.handle_order_book_snapshot"  s    * !!,9&&|]COOF+	w/((6 --dH=!??q#h-(A**6A;	J )"+y.r,   c                 V  #    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 R                  SS5      nSU R                  0n	U R                  U R                  S   S   U   S   U	5      n
U R                  5       nUUS	.nUUUUUU R                  S
.nU R                  XXU5      I S h  vN nUR                  5       $  N! [         a(  nUR                  U	 UR                  X5         S nAg S nAff = f7f)Nr=   r5   r`   r>   r   r9   r   r   )reqr8   r   )rA   r1   rR   r$   r9   rB   r#   r3   r   rC   r`   	Exceptionsubscriptionsreject)r(   rJ   rY   rG   r=   r5   r`   r>   r   r9   rE   r.   rF   snapshotSubscriptionr   es                   r*   watch_order_book_snapshot"bittrade.watch_order_book_snapshotE  s5    &&|]C	*%%lH=F%%lG<E__\8<F""4<<>C($--8H%%dii&6t&<S&A(&KXVC)I"G  *  99*  #jjMabbI??$$ c 	*$$[1MM!))	*sA   D)CC4 C2C4 1D)2C4 4
D&>D!D)!D&&D)c                 n    U R                  US5      nU R                  US5      nUR                  X45        g )Nr   r/   )
safe_floatstore)r(   booksidedeltapriceamounts        r*   handle_deltabittrade.handle_deltad  s.    q)*u%r,   c                 d    [        S[        U5      5       H  nU R                  XU   5        M     g )Nr   )rj   rk   r   )r(   r   deltasro   s       r*   handle_deltasbittrade.handle_deltasi  s)    q#f+&Ahq	2 'r,   c                    U R                  US0 5      nU R                  US5      nU R                  US5      nXcS   ::  a  XSS   :  a~  U R                  US/ 5      nU R                  US/ 5      nU R                  US   U5        U R                  US   U5        XSS'   U R                  US5      n	XS'   U R                  U	5      US	'   U$ )
NrL   r   
prevSeqNumr   asksbidsrO   rP   rQ   )rR   r1   r   rV   )
r(   rJ   rY   r   rL   r   r   r   r   rP   s
             r*   r   "bittrade.handle_order_book_messagem  s    * w3""42&&t\:
G,,6g<N3N??44D??44Dy0$7y0$7!'g))'48I%.k"$(LL$;Ij!r,   c                 \   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5      nU R                  U   nUS   c  UR
                  R                  U5        g U R                  XU5        UR                  X5        g )NrM   rN   r/   r   )	rA   rR   rS   safe_symbolr   r   rm   r   rX   )	r(   rJ   rY   r=   rM   rZ   r[   r5   r   s	            r*   handle_order_bookbittrade.handle_order_book  s    . &&w5__Wd+##E1-!!(+OOF+	W%OO""7+**6IFNN92r,   c                     U R                  US5      nU R                  US5      nX@R                  ;   a  U R                  U	 U R                  0 U5      U R                  U'   U R	                  U R
                  XU5        g )Nr5   r`   )rA   r1   r   
order_bookspawnr   )r(   rJ   rY   rG   r5   r`   s         r*   r   'bittrade.handle_order_book_subscription  sk    !!,9!!,8__$'"&//"e"<

4116LQr,   c                     U R                  US5      nU R                  UR                  S5      nU R                  XC5      nUb:  U R                  US5      nUb	  U" XU5      $ X1R                  ;   a  UR                  U	 U$ )Nr8   r   )rA   index_byr   rR   )r(   rJ   rY   r8   subscriptionsByIdrG   r   s          r*   handle_subscription_status#bittrade.handle_subscription_status  s     gt, MM&*>*>E'8=#__\8<F!f|<<)))((,r,   c                     U$ N r(   rJ   rY   s      r*   handle_system_statusbittrade.handle_system_status  s	     r,   c                 8   U R                  US5      nUR                  S5      nU R                  US5      nUS:X  a_  U R                  US5      nU R                  U R                  U R
                  U R                  S.nU R                  Xv5      nUb	  U" X5        g g g )NrM   rN   r   r@      )mbpdetailrp   kline)rR   rS   rA   r   r]   rq   r   )	r(   rJ   rY   rM   rZ   type
methodNamemethodsr   s	            r*   handle_subjectbittrade.handle_subject  s    * __Wd+q)8))%3J--,,++**	G __W9F!v' " r,   c                 f   #    UR                  SU R                  US5      05      I S h  vN   g  N7f)Npongping)sendr1   r   s      r*   r   bittrade.pong  s+      kk64#4#4Wf#EFGGGs   '1/1c                 <    U R                  U R                  X5        g r   )r   r   r   s      r*   handle_pingbittrade.handle_ping	  s    

499f.r,   c                    U R                  US5      nUS:X  a  U R                  US5      nU R                  UR                  S5      nU R                  XT5      nUbB  U R                  US5      n U R	                  U R
                  S   XpR                  U5      5        ggU$ ! [         aZ  nU R                  US5      n	UR                  X5        UR                  X5        XAR                  ;   a  UR                  U	  S nAgS nAff = f)Nstatuserrorr8   zerr-codeexactr=   F)	rA   r   r   rR   throw_exactly_matched_exception
exceptionsjsonr   r   )
r(   rJ   rY   r   r8   r   rG   	errorCoder   r=   s
             r*   handle_error_messagebittrade.handle_error_message  s     !!'84W!!'40B $f.B.BD I??+<AL' ,,WjA	5889QS\^g^gho^pq  ! 5"&"2"2<"OKMM!1MM!(111"0045s   ..B   
D*AC??Dc                    U R                  X5      (       ap  U R                  US5      b  U R                  X5        g U R                  US5      b  U R                  X5        g U R                  US5      b  U R	                  X5        g g g )Nr8   rM   r   )r   rA   r   r   r   r   s      r*   handle_messagebittrade.handle_message(  s    $$V55 .://@!!'40<##F4!!'62>  1 ?# 6r,   r   )'__name__
__module____qualname____firstlineno__r   r'   r3   r2   r	   rH   r   r]   r   r   r
   rf   rq   listry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __static_attributes____classcell__)r)   s   @r*   r   r      s   # @
 68 k kF k8F @ <@d[] S SS S Sbfglbm SB%F %N ?CQUdhqs !H !H !H3 !H^a !Hx|  ~B  yC !HF!#6 !#F @DB !!S !! !!S\ !!F!/ !/F>&
3! !F!3 !3FRV R *6 #(V #(JH/& /6 t 82V 2 2r,   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   ccxt.base.typesr   r   r   r   r	   r
   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   async_supportr   r   r,   r*   <module>r      s6     N D D 4  *m2t!!** m2r,   