
    ":hv                         d dl Zd dlmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ  G d d	ej0                  j2                        Zy)
    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)
AnyBalancesIntOrder	OrderBookStrStringsTickerTickersTrade)Client)List)ExchangeError)NotSupportedc            
           e Zd Zdef fdZi fdefdZdefdZd$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$dZddi fde
dededee   fdZdefdZdddi fdedededee   fdZdddi fde
dededee   fdZdefdZd$defdZdi fde
dedefdZd Zd Z defdZ!dddi fdedededee"   fdZ#defdZ$d$dZ%defdZ&defdZ'defd Z(defd!Z)defd"Z*i fd#Z+ xZ,S )%wazirxreturnc                     | j                  t        t        |          ddddddddddd
dddiii i i ddd	d
iiid      S )NTF)
wswatchBalancewatchTickerwatchTickerswatchTradeswatchTradesForSymbolswatchMyTradeswatchOrderswatchOrderBook
watchOHLCVapir   zwss://stream.wazirx.com/streamprivatepostcreate_auth_token   )hasurlsoptions	streaming
exceptionsr"   )deep_extendsuperr   describe)self	__class__s    I/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/pro/wazirx.pyr.   zwazirx.describe   s    fd < > $# $#).!%#"&" :
 +Q1A
  	    c                 
  K   | j                          d{    | j                  |       d{   }d}| j                  d   d   }ddg|d}| j                  ||      }| j	                  ||||       d{   S 7 f7 O7 w)aO  
        watch balance and get the amount of funds available for trading or funds locked in orders

        https://docs.wazirx.com/#account-update

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nbalancer"   r   	subscribeoutboundAccountPositioneventstreamsauth_key)load_marketsauthenticater(   r,   watch)r/   paramstokenmessageHashurlr5   requests          r1   watch_balancezwazirx.watch_balance3   s      !!!''//iit$ 12
	
 ""9f5ZZ[';GGG 	"/ Hs2   BA=BA?AB8B9B?BBclientc                    | j                  |di       }| j                  |dg       }| j                  |d      }|| j                  d<   || j                  d<   | j                  |      | j                  d<   t	        dt        |            D ]w  }||   }| j                  |d      }| j                  |      }	| j                  |d	      }
| j                  |d
      }| j                         }|
|d<   ||d<   || j                  |	<   y | j                  | j                        | _        d}|j                  | j                  |       y )NdataBEinfo	timestampdatetimer   ablfreeusedr4   )
safe_valuesafe_integerr4   iso8601rangelensafe_stringsafe_currency_codeaccountsafe_balanceresolve)r/   rD   messagerF   balancesrJ   ir4   
currencyIdcode	availablelockedrX   r@   s                 r1   handle_balancezwazirx.handle_balanceH   s0   " w3??4b1%%dC0	'V$-[!#'<<	#:Z q#h-( 		)AqkG))'37J**:6D((#6I%%gs3FllnG'GFO$GFO!(DLL		) ((6t||[1r2   Nc                    | j                  |d      }| j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      du }d }||| j	                  |      d d}| j                  | j                  |d      ||| j                  |      |d	   | j                  |d
g      d | j                  |d      |rdnd| j                  |d      | j                  |d      d |d|      S )NrH   sfUmT)costcurrencyratetsymboloSmakertakerpq)idrI   rJ   rK   rl   ordertypesidetakerOrMakerpriceamountrh   fee)rR   rV   safe_marketrQ   rW   
safe_traderS   safe_string_n)	r/   trademarketrJ   marketIdfeeCostfeeCurrencyIdisMakerrz   s	            r1   parse_ws_tradezwazirx.parse_ws_tradem   s2   > %%eS1	##E3/!!(F3""5#.((4//%-5 33MBC
 ""5#."Y/X&''u5$$UC0'.GG%%eS1&&uc2 
  	r2   rl   c                   K   | j                          d{    | j                  |      }| j                  d   d   }d|d   z   }d}d}d|gd	}| j                  ||      }	| j	                  |||	|       d{   S 7 g7 w)
a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://docs.wazirx.com/#all-market-tickers-stream

        :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"   r   ticker:rl   tickers!ticker@arrr5   r8   r9   )r;   r   r(   r,   r=   )
r/   rl   r>   r   rA   r@   subscribeHashstreamr5   rB   s
             r1   watch_tickerzwazirx.watch_ticker   s      !!!V$iit$&"22!# x
	 ""9f5ZZ['=III 	" Js"   BA>A"B9B :B Bsymbolsc                    K   | j                          d{    | j                  |      }| j                  d   d   }d}d}d|gd}| j                  ||      }| j	                  ||||       d{   }| j                  |d|d	      S 7 s7 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.wazirx.com/#all-market-tickers-stream

        :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>`
        Nr"   r   r   r   r5   r   rl   F)r;   market_symbolsr(   r,   r=   filter_by_array)	r/   r   r>   rA   r@   r   r5   rB   r   s	            r1   watch_tickerszwazirx.watch_tickers   s      !!!%%g.iit$# x
	 ""9f5

3WkJJ##GXwFF 	" Ks"   BB
AB1B2BBc                    | j                  |dg       }t        dt        |            D ]C  }||   }| j                  |      }|d   }|| j                  |<   d|z   }|j                  ||       E |j                  | j                  d       y )NrF   r   rl   r   r   )rQ   rT   rU   parse_ws_tickerr   rZ   )	r/   rD   r[   rF   r]   tickerparsedTickerrl   r@   s	            r1   handle_tickerzwazirx.handle_ticker   s    . w3q#d)$ 	6A!WF//7L!(+F#/DLL #f,KNN<5	6 	t||Y/r2   c                    | j                  |d      }| j                  |d      }| j                  i d| j                  ||      d|d| j	                  |      d| j                  |d      d| j                  |d	      d
| j                  |d      dd d| j                  |d      dd dd d| j                  |d      dd d| j                  |d	      dd dd dd dd d | j                  |d      |d|      S )Nrd   rH   rl   rJ   rK   highhlowrN   bidrM   	bidVolumeaskrL   	askVolumevwapopenrm   closelastpreviousClosechange
percentageaveragerr   )
baseVolumequoteVolumerI   )rV   rR   safe_tickersafe_symbolrS   safe_number)r/   r   r   r   rJ   s        r1   r   zwazirx.parse_ws_ticker   s   " ##FC0%%fc2	 !
d&&x8!
!
 Y/!
 D$$VS1	!

 4##FC0!
 4##FC0!
 !
 4##FC0!
 !
 D!
 D$$VS1!
 T!
 D$$VS1!
 T!
 d!
  $!!
" t#!
$ ++FC8)!
* + 	r2   sincelimitc                 p  K   | j                          d{    | j                  |      }|d   }|d   dz   }| j                  d   d   }d|gd}| j                  ||      }	| j	                  |||	|       d{   }
| j
                  r|
j                  ||      }| j                  |
||d	d
      S 7 7 9w)a  
        get the list of most recent trades for a particular symbol

        https://docs.wazirx.com/#trade-streams

        :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>`
        Nrl   rs   @tradesr"   r   r5   r   rJ   T)r;   r   r(   extendr=   
newUpdatesgetLimitfilter_by_since_limit)r/   rl   r   r   r>   r   r@   rA   r[   rB   tradess              r1   watch_tradeszwazirx.watch_trades"  s      !!!V$!TlY.iit$ #}
 ++gv.zz#{G[II??OOFE2E))&%TRR 	" Js"   B6B2A#B6:B4;8B64B6c                 N   | j                  |di       }| j                  |dg       }| j                  |d      }|j                  d      }| j                  |d      }| j                  |      }| j	                  ||      }	| j                  | j
                  |	      }
|
7| j                  | j                  dd      }t        |      }
|
| j
                  |	<   t        dt        |            D ](  }| j                  ||   |      }|
j                  |       * |j                  |
|       y )NrF   r   r   @r   tradesLimit  )rQ   rV   splitr{   r   r   rR   r)   r   rT   rU   r   appendrZ   )r/   rD   r[   rF   	rawTradesr@   r   r   r   rl   r   r   r]   parsedTrades                 r1   handle_tradeszwazirx.handle_trades=  s   & w3OOD(B7	&&w9!!#&##E1-!!(+!!(F3f5>%%dllM4HE&F"(DKKq#i.) 	'A--ilFCKMM+&	' 	v{+r2   c                   K   | j                          d{    | j                  |       d{   }|| j                  |      }|d   }| j                  d   d   }d}ddg|d}	| j	                  |	|      }
| j                  |||
|       d{   }| j                  r|j                  ||      }| j                  ||||d	      S 7 7 7 ;w)
a  
        watch trades by user

        https://docs.wazirx.com/#trade-update

        :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>`
        Nrl   r"   r   myTradesr5   ownTrader7   T)	r;   r<   r   r(   r,   r=   r   r   filter_by_symbol_since_limit)r/   rl   r   r   r>   r?   r   rA   r@   r[   rB   r   s               r1   watch_my_tradeszwazirx.watch_my_tradesa  s      !!!''//[[(FH%Fiit$  "|

 ""7F3zz#{G[II??OOFE2E00tTT! 	"/ Js2   CCCC
A CC8C
CC1mc                   K   | j                          d{    | j                  |      }|d   }| j                  d   d   }d|z   dz   |z   }|d   dz   |z   }	d	|	gd
}
| j                  |
|      }| j	                  ||||       d{   }| j
                  r|j                  ||      }| j                  |||dd      S 7 7 9w)a  
        watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://docs.wazirx.com/#kline-candlestick-stream

        :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
        Nrl   r"   r   ohlcv::rs   z@kline_r5   r   r   T)r;   r   r(   r,   r=   r   r   r   )r/   rl   	timeframer   r   r>   r   rA   r@   r   r[   rB   ohlcvs                r1   watch_ohlcvzwazirx.watch_ohlcv  s      !!!V$!iit$'#-	9	)I5 x
 ""7F3jjk7KHH??NN651E))%q$GG 	" Is"   CC A1CC	8CCc                 B   | j                  |di       }| j                  |d      }| j                  |      }| j                  ||      }| j                  |d      }| j                  | j                  |i       | j                  |<   | j                  | j                  |   |      }|:| j                  | j                  dd      }	t        |	      }|| j                  |   |<   | j                  ||      }
|j                  |
       d|z   dz   |z   }|j                  ||       y )NrF   rd   r]   
OHLCVLimitr   r   r   )rQ   rV   r{   r   ohlcvsrR   r)   r   parse_ws_ohlcvr   rZ   )r/   rD   r[   rF   r   r   rl   r   storedr   parsedr@   s               r1   handle_ohlcvzwazirx.handle_ohlcv  s   $ w3##D#.!!(+!!(F3$$T3/	"oodkk62FFV!4i@>%%dllL$GE*51F-3DKK	*$$T62f'#-	9v{+r2   c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nrk   rm   cr   rN   v)rR   r   )r/   r   r   s      r1   r   zwazirx.parse_ws_ohlcv  sn      eS)UC(UC(UC(UC(UC(
 	
r2   c                 4  K   | j                          d{    | j                  |      }|d   }| j                  d   d   }d|z   }|d   dz   }d|gd	}| j                  ||      }	| j	                  |||	|       d{   }
|
j                         S 7 }7 w)
a#  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://docs.wazirx.com/#depth-stream

        :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
        Nrl   r"   r   
orderbook:rs   @depthr5   r   )r;   r   r(   r,   r=   r   )r/   rl   r   r>   r   rA   r@   r   r5   rB   	orderbooks              r1   watch_order_bookzwazirx.watch_order_book  s      !!!V$!iit$"V+( x
	 ""9f5**S+wLL	   	" Ms"   BBA(B?B BBc                 L    | j                  |dd      }|j                  |       y )Nr   r&   )parse_bid_ask
storeArray)r/   booksidedeltabidAsks       r1   handle_deltazwazirx.handle_delta  s$    ##E1a0F#r2   c                 b    t        dt        |            D ]  }| j                  |||           y )Nr   )rT   rU   r   )r/   r   deltasr]   s       r1   handle_deltaszwazirx.handle_deltas  s0    q#f+& 	3Ahq	2	3r2   c                    | j                  |di       }| j                  |d      }| j                  |d      }| j                  |      }|d   }d|z   }|| j                  vr4| j                  |||dd      }	| j                  |	      | j                  |<   n| j                  |   }
| j                  |dg       }| j                  |dg       }| j                  |
d   |       | j                  |
d	   |       ||
d
<   ||
d<   | j                  |      |
d<   |
| j                  |<   |j                  | j                  |   |       y )NrF   rH   rd   rl   r   rM   rL   asksbidsnoncerJ   rK   )rQ   rR   rV   r{   
orderbooksparse_order_book
order_book	safe_listr   rS   rZ   )r/   rD   r[   rF   rJ   r   r   rl   r@   snapshotr   r   r   s                r1   handle_order_bookzwazirx.handle_order_book  sA     w3%%dC0	##D#.!!(+!"V+$//),,T69c3OH&*ooh&?DOOF#/I>>$R0D>>$R0Dy0$7y0$7!*Ig%.Ik"$(LL$;Ij!&/DOOF#tv.<r2   c                   K   | j                          d {    || j                  |      }|d   }| j                  |       d {   }d}ddg|d}| j                  d   d   }	| j	                  ||      }
| j                  |	||
||
       d {   }| j                  r|j                  ||      }| j                  ||||d      S 7 7 7 ;w)	Nrl   ordersr5   orderUpdater7   r"   r   T)	r;   r   r<   r(   r,   r=   r   r   r   )r/   rl   r   r   r>   r   r?   r@   r[   rA   rB   r   s               r1   watch_orderszwazirx.watch_orders  s     !!![[(FH%F''// %

 iit$""7F3zz#{G['RR??OOFE2E00tTT! 	" 0 Ss4   CC	0CCA	CC8CCCc                    | j                  |di       }| j                  |      }| j                  -| j                  | j                  dd      }t        |      | _        | j                  }|j                  |       d}|j                  | j                  |       |d|d   z   z  }|j                  | j                  |       y )NrF   ordersLimitr   r   r   rl   )rQ   parse_ws_orderr   rR   r)   r   r   rZ   )r/   rD   r[   rt   parsedOrderr   r   r@   s           r1   handle_orderzwazirx.handle_order0  s    ( 4))%0;;%%dllM4HE07DKk"t{{K0s[222t{{K0r2   c           	      t   | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  i d|d| j                  |d      d| j                  |d      d	| j	                  |      d
|dd d|d   d| j                  |d      rdnddd dd d| j                  |d      d| j                  |d      dd dd d| j                  |d      dd d| j                  |d      d | j                  |d      | j                  |      d d d|      S ) NOrd   XrI   rs   r]   clientOrderIdr   rK   rJ   lastTradeTimestamprl   ru   rg   r   r   timeInForcepostOnlyrv   rm   rx   rq   	stopPricetriggerPricery   Vfilled	remainingrr   r   )rh   r   statusrz   r   )rR   rV   r{   
safe_orderrS   rQ   parse_order_status)r/   rt   r   rJ   r   r  s         r1   r   zwazirx.parse_ws_orderP  s   " %%eS1	##E3/!!%-!!(+  
E 
$""5#. 
 T--eS9 
 Y/	 

  
 !$ 
 fX& 
 tuc:G 
 4 
  
 D$$UC0 
 T%%eS1 
  
 D 
 d&&uc2 
  d! 
" ))%5# 
$ ''s3--f5- 
. / 	r2   c                 *   | j                  |di       }d}d }| j                  0| j                  | j                  dd      }t	        |      }|| _        n| j                  }| j                  |      }|j                  |       |j                  ||       y )NrF   r   r   r   )rQ   r   rR   r)   r   r   r   rZ   )r/   rD   r[   r~   r@   r   r   r   s           r1   handle_my_tradeszwazirx.handle_my_trades~  s    . 4 == %%dllM4HE-e4H$DM}}H))%0$x-r2   c                     |S N r/   rD   r[   s      r1   handle_connectedzwazirx.handle_connected  s	     r2   c                     |S r	  r
  r  s      r1   handle_subscribedzwazirx.handle_subscribed  s	     r2   c                 V    t        | j                  dz   | j                  |      z         )N )r   rs   jsonr  s      r1   handle_errorzwazirx.handle_error  s%      DGGcMDIIg,>>??r2   c                    | j                  |d      }|dk(  r| j                  ||       y | j                  |d      }| j                  | j                  | j                  d}| j	                  ||      }|
 |||       y | j                  |dd      }| j
                  | j                  | j                  | j                  | j                  | j                  | j                  d}t        |j                               }	t        dt        |	            D ].  }
|j!                  |	|
         d	kD  }|s||	|
      } |||        y  t#        | j$                  d
z   | j'                  |      z         )Nr  errorr8   )r  	connected
subscribedr    )z
ticker@arrr   z@kliner   r6   r   r   r   z2 self message type is not supported yet. Message: )rV   r  r  r  rQ   r   r   r   r   rb   r   r  listkeysrT   rU   findr   rs   r  )r/   rD   r[   r  r8   eventHandlerseventHandlerr   streamHandlersr9   r]   streamContainshandlers                r1   handle_messagezwazirx.handle_message  so   !!'84Wfg.  '2&&..00

 }e<#)!!'8R8,,,,''))'+':':,,-- 
 ~**,-q#g,' 	A#[[4r9N(4(	 477%YY\`\e\efm\nnoor2   c                   K   | j                   d   d   }| j                  |      }d}| j                         }| j                  |j                  |      }| j                  |d      }|||kD  rB| j                          d {   }|| j                  |d      dz  z   |d<   ||j                  |<   | j                  |d      S 7 @w)Nr"   r   authenticatedexpirestimeout_durationr   r:   )r(   rD   millisecondsrQ   subscriptionsrR   privatePostCreateAuthTokenrV   )r/   r>   rA   rD   r@   nowsubscriptionr$  s           r1   r<   zwazirx.authenticate  s     iit$S!%!v';';[I##L)<3=!%!@!@!BBL&)D,=,=lL^,_bf,f&fL# 1=F  -j99 Cs   A>C CACr	  )-__name__
__module____qualname__r   r.   r   rC   r   rb   r   strr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r
   r   r   r   r   r	   r   r   r   r  r  r  r  r!  r<   __classcell__)r0   s   @r1   r   r      s)    #  D *, H H*#2V #2J:x 68 J JF J. 6:" G7 G G.0F 0B(T <@d[] S SS S Sbfglbm S6",F ",H 37TX\eg UC Us URU Ulpqvlw U< 8<$]ajl H HC HWZ Hquvzq{ H: ,6  ,D
D 
0 @DB !S ! !S\ !2$3$= $=L 04$UYbd U UC Us Uimnsit U&16 1@,\".v ".H	v 	
 
@6 @$ pV  pD )+ :r2   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   ccxt.base.typesr   r   r   r	   r
   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   async_supportr   r
  r2   r1   <module>r8     s?     f f f f f 4  * )o:T&& o:r2   