
    E#iJ                         S SK rS SKJrJr  S SK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\R*                  R,                  5      rg)	    N)
ArrayCacheArrayCacheBySymbolById)AnyBalancesIntMarket	OrderBookStrTickerTrade)Client)List)ExchangeErrorc            
       J  ^  \ rS rSrS\4U 4S jjrS rS0 4S\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\\   4S jjrS	\4S jrSS\S\S\4S jjr0 4S\S\4S jjrS	\4S jrS r0 4S\4S jjrS	\4S jrS	\4S jrSrU =r $ )bitopro   returnc                    > U R                  [        [        U ]  5       SSSSSSSSSSS.
SSSS.0SSSS.S	S	S
S0 00S.S.5      $ )NTF)
wswatchBalancewatchMyTrades
watchOHLCVwatchOrderBookwatchOrderswatchTickerwatchTickerswatchTradeswatchTradesForSymbolsr   z&wss://stream.bitopro.com:443/ws/v1/pubz+wss://stream.bitopro.com:443/ws/v1/pub/auth)publicprivate)apiKeysecretlogin  optionsheaders)tradesLimitordersLimitr   )hasurlsrequiredCredentialsr%   )deep_extendsuperr   describe)self	__class__s    J/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/bitopro.pyr.   bitopro.describe   s    gt = ? $!%#"&$# %#). FL $  $#!2 	1"B
 " "	    c                    #    U R                   S   S   S-   U-   S-   U-   nU R                  XBS U5      I S h  vN $  N7f)Nr   r   /)r*   watch)r/   pathmessageHashmarketIdurls        r1   watch_publicbitopro.watch_public6   sD     iioh'#-4s:XEZZ$DDDDs   5><>Nsymbollimitc                   #    UbB  US:w  a<  US:w  a6  US:w  a0  US:w  a*  US:w  a$  US:w  a  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SU-   nSnUc  US   nOUS   S-   U R	                  U5      -   nU R                  SXV5      I Sh  vN nUR                  5       $  Nn N7f)a#  
watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://github.com/bitoex/bitopro-offical-api-docs/blob/master/ws/public/order_book_stream.md

: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   
      2   d   i  r$   zL watchOrderBook limit argument must be None, 5, 10, 20, 50, 100, 500 or 1000r=   zORDER_BOOK:id:zorder-books)r   rE   load_marketsmarketnumber_to_stringr;   r>   )r/   r=   r>   paramsrH   r8   endPart	orderbooks           r1   watch_order_bookbitopro.watch_order_book:   s      
"5B;Ub[W\`cWcjosvjv  ~C  GK  ~K#DGG.|$|}}!!!V$!(61=TlGTlS(4+@+@+GGG++M;PP	   	" Qs%   ACC
AC5C6CCclientc           	         U R                  US5      nU R                  US S5      nUS   nU R                  US5      nUS-   U-   nU R                  U R                  U5      nUc  U R	                  0 5      nU R                  US5      n	U R                  X%U	SSS	S
5      n
UR                  U
5        UR                  X5        g )Npair_r=   eventrF   	timestampbidsaskspriceamount)	safe_stringsafe_market
safe_value
orderbooks
order_booksafe_integerparse_order_bookresetresolve)r/   rO   messager9   rH   r=   rS   r8   rL   rT   snapshots              r1   handle_order_bookbitopro.handle_order_bookT   s    , ##GV4!!(D#6!  '2ckF*OODOOV<	+I%%g{;	(()VVU\^fg!y.r3   sincec                   #    U R                  5       I Sh  vN   U R                  U5      nUS   nSU-   nU R                  SXeS   5      I Sh  vN nU R                  (       a  UR	                  X5      nU R                  XrUSS5      $  Nr N<7f)a  
get the list of most recent trades for a particular symbol

https://github.com/bitoex/bitopro-offical-api-docs/blob/master/ws/public/trade_stream.md

: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>`
Nr=   zTRADE:tradesrE   rT   T)rG   rH   r;   
newUpdatesgetLimitfilter_by_since_limit)r/   r=   rf   r>   rJ   rH   r8   rh   s           r1   watch_tradesbitopro.watch_tradesw   s      !!!V$!#f,((;tMM??OOF2E))&TRR 	" Ns!   BB	7BB;BBc                    U R                  US5      nU R                  US S5      nUS   nU R                  US5      nUS-   U-   nU R                  US/ 5      nU R                  X5      n	U R                  U R                  U5      n
U
c(  U R                  U R                  SS5      n[        U5      n
[        S	[        U	5      5       H  nU
R                  X   5        M     XR                  U'   UR                  X5        g )
NrQ   rR   r=   rS   rF   datar'   r$   r   )rY   rZ   r[   parse_tradesrh   r^   r%   r   rangelenappendra   )r/   rO   rb   r9   rH   r=   rS   r8   rawDatarh   tradesCacher>   is                r1   handle_tradebitopro.handle_trade   s    ( ##GV4!!(D#6!  '2ckF*//'626""73oodkk6:%%dllM4HE$U+Kq#f+&Avy) ')F{0r3   c                   #    U R                  5         U R                  5       I Sh  vN   SnUb  U R                  U5      nUS-   US   -   nU R                  S   S   S-   S-   nU R	                  U5        U R                  XuS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  
watches information on multiple trades made by the user

https://github.com/bitoex/bitopro-offical-api-docs/blob/master/ws/private/matches_stream.md

: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
USER_TRADErF   r=   r   r    r5   zuser-tradesrT   T)	check_required_credentialsrG   rH   r*   authenticater6   ri   rj   rk   )	r/   r=   rf   r>   rJ   r8   rH   r:   rh   s	            r1   watch_my_tradesbitopro.watch_my_trades   s      	'')!!!"[[(F%+fX.>>Kiioi(3.>#zz#D+FF??OOF2E))&TRR 	" Gs"   $C
CA$C
C;C
C
c                 (   U R                  US0 5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nU R                  US-   U-   5      nU R                  US5      n	U R                  c-  U R                  U R                  SS5      n
[        U
5      U l        U R                  nU R                  U5      nUR                  U5        UR                  X5        UR                  XS-   U-   5        g )	Nro   basequoter5   rS   r'   r$   rF   )r[   rY   safe_currency_coder=   myTradesr^   r%   r   parse_ws_traders   ra   )r/   rO   rb   ro   baseIdquoteIdr   r   r=   r8   r>   rh   parseds                r1   handle_my_tradebitopro.handle_my_trade   s    0 w3!!$/""41&&v.''0TCZ%/0&&w8== %%dllM4HE259DM$$T*fv+vS069:r3   traderH   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 R                  U5      n	U R                  US-   U	-   5      n
U R	                  X5      nU R                  US5      nU R                  US5      nU R                  US	5      nUb  US
:X  a  SnOUS:X  a  SnU R                  US5      nS nU R                  US5      nU R                  U R                  US5      5      nUb  UUS S.nU R                  US5      nS nUb  U(       a  SnOSnU R                  UUUUU R                  U5      U
UUUUUS US.U5      $ )NmatchIDorderIDtransactionTimestampr   r   r5   rW   	orderTypesideasksellbidbuyvolumefeefeeCurrency)costcurrencyrateisMakermakertaker)rE   infoorderrT   datetimer=   takerOrMakertyper   rW   rX   r   r   )	rY   safe_timestampr   r=   rZ   safe_string_lowerr[   
safe_tradeiso8601)r/   r   rH   rE   orderIdrT   r   r   r   r   r=   rW   r   r   rX   r   	feeAmount	feeSymbolr   r   s                       r1   r   bitopro.parse_ws_trade   s   & eY/""5)4''/EF	!!%0""5'2&&v.''0TCZ%/0!!&1  0%%e[9v.u}!!%2$$UE2	++D,<,<UM,RS	 !%C
 //%3&&"Y/( 
  	r3   c                    #    U R                  5       I Sh  vN   U R                  U5      nUS   nSU-   nU R                  SXCS   5      I Sh  vN $  N< 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://github.com/bitoex/bitopro-offical-api-docs/blob/master/ws/public/ticker_stream.md

: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=   zTICKER:tickersrE   )rG   rH   r;   )r/   r=   rJ   rH   r8   s        r1   watch_tickerbitopro.watch_ticker6  s`      !!!V$!$v-&&y+d|LLL	 	" Ms!   AA7AAAAc                    U R                  US5      nU R                  UR                  5       S S5      nUS   nU R                  US5      nUS-   U-   nU R                  X$5      nU R                  US5      US'   U R	                  US5      n	XS'   U R                  U	5      US'   XR                  U'   UR                  X5        g )NrQ   rR   r=   rS   rF   rT   r   )rY   rZ   lowerparse_tickerr^   r   r   ra   )
r/   rO   rb   r9   rH   r=   rS   r8   resultrT   s
             r1   handle_tickerbitopro.handle_tickerF  s    & ##GV4!!(.."2D#>!  '2ckF*""73++FH=x%%g{;	'{!\\)4z%Vv+r3   c                 ^   U R                   b  XR                   ;   a  g U R                  5         U R                  5       nU R                  UU R                  S.5      nU R                  U5      nU R                  U R                  U5      U R                  U R                  5      [        R                  5      nSSS0 000nU R                  U5        U R                  S   S   S   nSU R                  UUS.nXR                  S   S   S'   U R                  U5        XpR                  S   S   S'   g )N)nonceidentityr   r%   r&   ccxt)zX-BITOPRO-APIzX-BITOPRO-APIKEYzX-BITOPRO-PAYLOADzX-BITOPRO-SIGNATURE)clientsr{   millisecondsjsonr#   string_to_base64hmacencoder"   hashlibsha384extend_exchange_optionsr%   r!   rO   )	r/   r:   r   rt   payload	signaturedefaultOptionsoriginalHeadersr&   s	            r1   r|   bitopro.authenticateg  s"   LL$3,,+>'')!!#))


  ''0IIdkk'2DKK4Lgnn]	r 
 	$$^4,,t,Y7	B# $!(#,	
 4;T9%i0C3BT9%i0r3   c                    #    U R                  5         U R                  5       I Sh  vN   SnU R                  S   S   S-   S-   nU R                  U5        U R	                  X2SU5      I Sh  vN $  NJ N7f)a`  
watch balance and get the amount of funds available for trading or funds locked in orders

https://github.com/bitoex/bitopro-offical-api-docs/blob/master/ws/private/user_balance_stream.md

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
NACCOUNT_BALANCEr   r    r5   zaccount-balance)r{   rG   r*   r|   r6   )r/   rJ   r8   r:   s       r1   watch_balancebitopro.watch_balance  sv      	'')!!!'iioi(3.1BB#ZZ$DDD	 	" Es"   $A5A1AA5,A3-A53A5c                 t   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	                  5       5      nUUUS.n[        S[        U5      5       H  n	U R                  Xy5      n
U R                  XJ5      nU R                  US5      nU R                  U5      nU R                  5       nU R                  US5      US	'   U R                  US
5      US'   XU'   M     U R                  U5      U l
        UR                  U R                  U5        g )NrS   ro   rT   r   )r   rT   r   r   r   	availablefreerX   total)rY   r[   r^   listkeysrq   rr   r   accountsafe_balancebalancera   )r/   rO   rb   rS   ro   rT   r   
currenciesr   rv   r   r   
currencyIdcoder   s                  r1   handle_balancebitopro.handle_balance  s&   "   '2w/%%g{;	##GZ8$))+&
" 

 q#j/*A''
6Hood5G))':>J**:6DllnG"..wDGFO#//BGG"4L + ((0t||U+r3   c                     U R                   U R                  U R                  U R                  U R                  S.nU R                  US5      nU R                  X45      nUb	  U" X5        g g )N)TRADETICKER
ORDER_BOOKr   rz   rS   )rw   r   rd   r   r   rY   r[   )r/   rO   rb   methodsrS   methods         r1   handle_messagebitopro.handle_message  sk    &&((00#22..
   '206# r3   )r   r   )N)!__name__
__module____qualname____firstlineno__r   r.   r;   strr   r	   rM   r   rd   r   r   rl   rw   r
   r}   r   dictr   r   r   r   r   r|   r   r   r   r   __static_attributes____classcell__)r0   s   @r1   r   r      sS   ## #JE @DB !S ! !S\ !4!/ !/F <@d[] S SS S Sbfglbm S*"16 "1H 37TX\eg SC Ss SRU Slpqvlw S2&;f &;PCD C& CE CJ 68 M MF M ,F ,BC@ *, E E %,V %,N$V $ $r3   r   )ccxt.async_supportr    ccxt.async_support.base.ws.cacher   r   r   ccxt.base.typesr   r   r   r   r	   r
   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   async_supportr    r3   r1   <module>r      s<     O  U U U 4  *z$d  (( z$r3   