
    i4u                         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 d dlmZ d dlmZ d dlmZ d dlmZ  G d d	ej        j                  ZdS )
    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)	BalancesIntOrder	OrderBookStrStringsTickerTickersTrade)Client)List)ExchangeError)NotSupportedc            
           e Zd Z 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 )%wazirxc                     |                      t          t          |                                           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 )NT)	wswatchBalancewatchTickerwatchTickerswatchTrades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    U/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/pro/wazirx.pyr+   zwazirx.describe   s    fd 3 3 < < > > $# $#!%#"&"
 
 :
 +Q/A
 A
   	    returnc                   K   |                                   d{V  |                     |           d{V }d}| j        d         d         }ddg|d}|                     ||          }|                     ||||           d{V S )aS  
        watch balance and get the amount of funds available for trading or funds locked in orders
        :see: 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urlr3   requests          r.   watch_balancezwazirx.watch_balance2   s       !!!!!!!!!''////////it$ 12
 
	
 ""9f55ZZ[';GGGGGGGGGr/   clientc                    |                      |di           }|                      |dg           }|                     |d          }|| j        d<   || j        d<   |                     |          | j        d<   t	          dt          |                    D ]}||         }|                     |d          }|                     |          }	|                     |d	          }
|                     |d
          }|                                 }|
|d<   ||d<   || j        |	<   | 	                    | j                  | _        d}|
                    | j        |           d S )NdataBEinfo	timestampdatetimer   ablfreeusedr2   )
safe_valuesafe_integerr2   iso8601rangelensafe_stringsafe_currency_codeaccountsafe_balanceresolve)r,   rB   messagerD   balancesrH   ir2   
currencyIdcode	availablelockedrV   r>   s                 r.   handle_balancezwazirx.handle_balanceE   sS   " w33??4b11%%dC00	'V$-[!#'<<	#:#:Z q#h--(( 		) 		)AqkG))'377J**:66D((#66I%%gs33FllnnG'GFO$GFO!(DL((66t|[11111r/   Nc                    |                      |d          }|                     |d          }|                     ||          }|                     |d          }|                     |d          }|                     |d          du }d }|||                     |          d d}|                     |                     |d          |||                     |          |d	         |                     |d
g          d |                     |d          |rdnd|                     |d          |                     |d          d |d|          S )NrF   sfUmT)costcurrencyratetsymboloSmakertakerpq)idrG   rH   rI   rj   ordertypesidetakerOrMakerpriceamountrf   fee)rP   rT   safe_marketrO   rU   
safe_traderQ   safe_string_n)	r,   trademarketrH   marketIdfeeCostfeeCurrencyIdisMakerrx   s	            r.   parse_ws_tradezwazirx.parse_ws_tradej   sm   > %%eS11	##E3//!!(F33""5#..((44//%--5 33MBB C
 ""5#.."Y//X&''u55$$UC00'.;GGG%%eS11&&uc22 
  
   	r/   rj   c                   K   |                                   d{V  |                     |          }| j        d         d         }d|d         z   }d}d}d|gd	}|                     ||          }	|                     |||	|           d{V S )
a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: 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:rj   tickers!ticker@arrr3   r6   r7   )r9   r}   r%   r)   r;   )
r,   rj   r<   r}   r?   r>   subscribeHashstreamr3   r@   s
             r.   watch_tickerzwazirx.watch_ticker   s       !!!!!!!!!V$$it$&"22!# x
 
	 ""9f55ZZ['=IIIIIIIIIr/   symbolsc                 6  K   |                                   d{V  |                     |          }| j        d         d         }d}d}d|gd}|                     ||          }|                     ||||           d{V }|                     |d|d	          S )
a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
        :see: 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   r3   r   rj   F)r9   market_symbolsr%   r)   r;   filter_by_array)	r,   r   r<   r?   r>   r   r3   r@   r   s	            r.   watch_tickerszwazirx.watch_tickers   s       !!!!!!!!!%%g..it$# x
 
	 ""9f55

3WkJJJJJJJJ##GXwFFFr/   c                 >   |                      |dg           }t          dt          |                    D ]L}||         }|                     |          }|d         }|| j        |<   d|z   }|                    ||           M|                    | j        d           d S )NrD   r   rj   r   r   )rO   rR   rS   parse_ws_tickerr   rX   )	r,   rB   rY   rD   r[   tickerparsedTickerrj   r>   s	            r.   handle_tickerzwazirx.handle_ticker   s    . w33q#d))$$ 	6 	6A!WF//77L!(+F#/DL #f,KNN<5555t|Y/////r/   c                 ^   |                      |d          }|                     |d          }|                     i d|                     ||          d|d|                     |          d|                      |d          d|                      |d	          d
|                     |d          dd d|                     |d          dd dd d|                      |d          dd d|                      |d	          dd dd dd dd d |                      |d          |d|          S )Nrb   rF   rj   rH   rI   highhlowrL   bidrK   	bidVolumeaskrJ   	askVolumevwapopenrk   closelastpreviousClosechange
percentageaveragerp   )
baseVolumequoteVolumerG   )rT   rP   safe_tickersafe_symbolrQ   safe_number)r,   r   r}   r~   rH   s        r.   r   zwazirx.parse_ws_ticker   s   " ##FC00%%fc22	 !
d&&x88!
!
 Y//!
 D$$VS11	!

 4##FC00!
 4##FC00!
 !
 4##FC00!
 !
 D!
 D$$VS11!
 T!
 D$$VS11!
 T!
 d!
  $!!
" t#!
$ ++FC88)!
 !
 !
* +  	r/   sincelimitc                   K   |                                   d{V  |                     |          }|d         }|d         dz   }| j        d         d         }d|gd}|                     ||          }	|                     |||	|           d{V }
| j        r|
                    ||          }|                     |
||d	d
          S )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>`
        Nrj   rq   @tradesr   r   r3   r   rH   T)r9   r}   r%   extendr;   
newUpdatesgetLimitfilter_by_since_limit)r,   rj   r   r   r<   r}   r>   r?   rY   r@   tradess              r.   watch_tradeszwazirx.watch_trades  s       !!!!!!!!!V$$!TlY.it$ #}
 
 ++gv..zz#{G[IIIIIIII? 	3OOFE22E))&%TRRRr/   c                    |                      |di           }|                      |dg           }|                     |d          }|                    d          }|                     |d          }|                     |          }|                     ||          }	|                      | j        |	          }
|
5|                     | j        dd          }t          |          }
|
| j        |	<   t          dt          |                    D ]3}|                     ||         |          }|
                    |           4|                    |
|           d S )NrD   r   r   @r   tradesLimit  )rO   rT   splitry   r   r   rP   r&   r   rR   rS   r   appendrX   )r,   rB   rY   rD   	rawTradesr>   r   r~   r}   rj   r   r   r[   parsedTrades                 r.   handle_tradeszwazirx.handle_trades3  sF   & w33OOD(B77	&&w99!!#&&##E1--!!(++!!(F33f55>%%dlM4HHE&&F"(DKq#i..)) 	' 	'A--ilFCCKMM+&&&&v{+++++r/   c                   K   |                                   d{V  |                     |           d{V }||                     |          }|d         }| j        d         d         }d}ddg|d}	|                     |	|          }
|                     |||
|           d{V }| j        r|                    ||          }|                     ||||d	          S )
a  
        watch trades by user
        :see: 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>`
        Nrj   r   r   myTradesr3   ownTrader5   T)	r9   r:   r}   r%   r)   r;   r   r   filter_by_symbol_since_limit)r,   rj   r   r   r<   r=   r}   r?   r>   rY   r@   r   s               r.   watch_my_tradeszwazirx.watch_my_tradesW  s      !!!!!!!!!''////////[[((FH%Fit$  "|
 

 ""7F33zz#{G[IIIIIIII? 	3OOFE22E00tTTTr/   1mc                   K   |                                   d{V  |                     |          }|d         }| j        d         d         }d|z   dz   |z   }|d         dz   |z   }	d	|	gd
}
|                     |
|          }|                     ||||           d{V }| j        r|                    ||          }|                     |||dd          S )aQ  
        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
        Nrj   r   r   ohlcv::rq   z@kline_r3   r   r   T)r9   r}   r%   r)   r;   r   r   r   )r,   rj   	timeframer   r   r<   r}   r?   r>   r   rY   r@   ohlcvs                r.   watch_ohlcvzwazirx.watch_ohlcvs  s      !!!!!!!!!V$$!it$'#-	9	)I5 x
 
 ""7F33jjk7KHHHHHHHH? 	2NN6511E))%q$GGGr/   c                 ~   |                      |di           }|                     |d          }|                     |          }|                     ||          }|                     |d          }|                      | j        |i           | j        |<   |                      | j        |         |          }|;|                     | j        dd          }	t          |	          }|| j        |         |<   |                     ||          }
|	                    |
           d|z   dz   |z   }|
                    ||           d S )NrD   rb   r[   
OHLCVLimitr   r   r   )rO   rT   ry   r   ohlcvsrP   r&   r   parse_ws_ohlcvr   rX   )r,   rB   rY   rD   r~   r}   rj   r   storedr   parsedr>   s               r.   handle_ohlcvzwazirx.handle_ohlcv  s4   $ w33##D#..!!(++!!(F33$$T3//	"oodk62FFFV!4i@@>%%dlL$GGE*511F-3DK	*$$T622f'#-	9v{+++++r/   c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nri   rk   cr   rL   v)rP   r   )r,   r   r}   s      r.   r   zwazirx.parse_ws_ohlcv  s      eS))UC((UC((UC((UC((UC((
 	
r/   c                 V  K   |                                   d{V  |                     |          }|d         }| j        d         d         }d|z   }|d         dz   }d|gd	}|                     ||          }	|                     |||	|           d{V }
|
                                S )
a'  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: 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
        Nrj   r   r   
orderbook:rq   @depthr3   r   )r9   r}   r%   r)   r;   r   )r,   rj   r   r<   r}   r?   r>   r   r3   r@   	orderbooks              r.   watch_order_bookzwazirx.watch_order_book  s       !!!!!!!!!V$$!it$"V+( x
 
	 ""9f55**S+wLLLLLLLL	   r/   c                 ^    |                      |dd          }|                    |           d S )Nr   r#   )parse_bid_ask
storeArray)r,   booksidedeltabidAsks       r.   handle_deltazwazirx.handle_delta  s3    ##E1a00F#####r/   c                 ~    t          dt          |                    D ]}|                     |||                    d S )Nr   )rR   rS   r   )r,   r   deltasr[   s       r.   handle_deltaszwazirx.handle_deltas  sH    q#f++&& 	3 	3Ahq	2222	3 	3r/   c                    |                      |di           }|                     |d          }|                     |d          }|                     |          }|d         }d|z   }|                      | j        |          }	|	9|                     |||dd          }
|                     |
          }|| j        |<   n|                      |dg           }|                      |dg           }|                     |	d         |           |                     |	d	         |           ||	d
<   ||	d<   |                     |          |	d<   |	| j        |<   |	                    | j        |         |           d S )NrD   rF   rb   rj   r   rK   rJ   asksbidsnoncerH   rI   )
rO   rP   rT   ry   
orderbooksparse_order_book
order_bookr   rQ   rX   )r,   rB   rY   rD   rH   r~   r}   rj   r>   currentOrderBooksnapshot	orderBookr   r   s                 r.   handle_order_bookzwazirx.handle_order_book  s}     w33%%dC00	##D#..!!(++!"V+??4?FCC#,,T69c3OOH11I&/DOF##??4b11D??4b11D/7>>>/7>>>(1W%,5[)+/<<	+B+BZ(&6DOF#tv.<<<<<r/   c                   K   |                                   d {V  ||                     |          }|d         }|                     |           d {V }d}ddg|d}| j        d         d         }	|                     ||          }
|                     |	||
||
           d {V }| j        r|                    ||          }|                     ||||d          S )	Nrj   ordersr3   orderUpdater5   r   r   T)	r9   r}   r:   r%   r)   r;   r   r   r   )r,   rj   r   r   r<   r}   r=   r>   rY   r?   r@   r   s               r.   watch_orderszwazirx.watch_orders  s     !!!!!!!!![[((FH%F''//////// %
 

 it$""7F33zz#{G['RRRRRRRR? 	3OOFE22E00tTTTr/   c                    |                      |di           }|                     |          }| j        0|                     | j        dd          }t          |          | _        | j        }|                    |           d}|                    | j        |           |d|d         z   z  }|                    | j        |           d S )NrD   ordersLimitr   r   r   rj   )rO   parse_ws_orderr   rP   r&   r   r   rX   )r,   rB   rY   rr   parsedOrderr   r   r>   s           r.   handle_orderzwazirx.handle_order  s    ( 44))%00;%%dlM4HHE077DKk"""t{K000s[222t{K00000r/   c           	         |                      |d          }|                     |d          }|                     |d          }|                     |          }|                     i d|d|                     |d          d|                     |d          d	|                     |          d
|dd d|d         d|                     |d          rdnddd dd d|                     |d          d|                     |d          dd dd d|                     |d          dd d|                     |d          d |                     |d          |                     |          d d d|          S ) NOrb   XrG   rq   r[   clientOrderIdr   rI   rH   lastTradeTimestamprj   rs   re   r   r}   timeInForcepostOnlyrt   rk   rv   ro   	stopPricetriggerPricerw   Vfilled	remainingrp   r   )rf   r   statusrx   r   )rP   rT   ry   
safe_orderrQ   rO   parse_order_status)r,   rr   r}   rH   r~   r  s         r.   r   zwazirx.parse_ws_order?  s   " %%eS11	##E3//!!%--!!(++  
E 
$""5#.. 
 T--eS99 
 Y//	 

  
 !$ 
 fX& 
 tuc::HGG 
 4 
  
 D$$UC00 
 T%%eS11 
  
 D 
 d&&uc22 
  d! 
" ))%55# 
$ ''s33--f55- 
  
  
. /  	r/   c                 >   |                      |di           }d}d }| j        3|                     | j        dd          }t	          |          }|| _        n| j        }|                     |          }|                    |           |                    ||           d S )NrD   r   r   r   )rO   r   rP   r&   r   r   r   rX   )r,   rB   rY   r|   r>   r   r   r   s           r.   handle_my_tradeszwazirx.handle_my_tradesm  s    . 44 = %%dlM4HHE-e44H$DMM}H))%00$$$x-----r/   c                     |S N r,   rB   rY   s      r.   handle_connectedzwazirx.handle_connected  s	     r/   c                     |S r  r	  r
  s      r.   handle_subscribedzwazirx.handle_subscribed  s	     r/   c                 \    t          | j        dz   |                     |          z             )N )r   rq   jsonr
  s      r.   handle_errorzwazirx.handle_error  s)      DGcMDIIg,>,>>???r/   c                    |                      |d          }|dk    r|                     ||           d S |                      |d          }| j        | j        | j        d}|                     ||          }| |||           d S |                      |dd          }| j        | j        | j        | j        | j	        | j
        | j        d}t          |                                          }	t          dt          |	                    D ];}
|                     |	|
         |          r||	|
                  } |||            d S <t#          | j        d	z   |                     |          z             )
Nr  errorr6   )r  	connected
subscribedr    )z
ticker@arrr   z@kliner   r4   r   r   r   z2 self message type is not supported yet. Message: )rT   r  r  r  rO   r   r   r   r   r`   r   r  listkeysrR   rS   in_arrayr   rq   r  )r,   rB   rY   r  r6   eventHandlerseventHandlerr   streamHandlersr7   r[   handlers               r.   handle_messagezwazirx.handle_message  s   !!'844Wfg...F  '22&.0
 

 }e<<#L)))F!!'8R88,,')'+':,-
 
 ~**,,--q#g,,'' 	 	A}}WQZ00 (4((( 47%YY\`\e\efm\n\nnooor/   c                   K   | j         d         d         }|                     |          }d}|                                 }|                     |j        |          }|                     |d          }|||k    rC|                                  d {V }||                     |d          dz  z   |d<   ||j        |<   |                     |d          S )Nr   r   authenticatedexpirestimeout_durationr   r8   )r%   rB   millisecondsrO   subscriptionsrP   privatePostCreateAuthTokenrT   )r,   r<   r?   rB   r>   nowsubscriptionr!  s           r.   r:   zwazirx.authenticate  s      it$S!!%!!v';[II##L)<<3==!%!@!@!B!BBBBBBBL&)D,=,=lL^,_,_bf,f&fL# 1=F -j999r/   r  ),__name__
__module____qualname__r+   r   rA   r   r`   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__)r-   s   @r.   r   r      s           B *, H H H H H H&#2V #2 #2 #2 #2J: : : :x 68 J J JF J J J J* 6:" G G7 G G G G G*0F 0 0 0 0B( ( ( (T <@d[] S S SS S Sbfglbm S S S S0",F ", ", ", ",H 37TX\eg U UC Us URU Ulpqvlw U U U U8 8<$]ajl H H HC HWZ Hquvzq{ H H H H4 ,6  ,  ,  ,  ,D
 
D 
 
 
 
0 @DB ! !S ! !S\ ! ! ! !.$ $ $3 3 3$= $= $= $= $=L 04$UYbd U U UC Us Uimnsit U U U U&16 1 1 1 1@, , , ,\".v ". ". ". ".H	v 	 	 	 	
 
 
 
 
@6 @ @ @ @$pV p p p pB )+ : : : : : : : :r/   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   ccxt.base.typesr   r   r   r	   r
   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   async_supportr   r	  r/   r.   <module>r5     s        f f f f f f f f f f a a a a a a a a a a a a a a a a a a a a a a 4 4 4 4 4 4       * * * * * * ) ) ) ) ) )]: ]: ]: ]: ]:T& ]: ]: ]: ]: ]:r/   