
    ei\                         d dl Zd dlmZmZmZmZ d dlZd dlm	Z	m
Z
mZ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 d dlmZ d d	lmZ  G d
 dej         j!                  Z!dS )    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)AnyBalancesBoolIntOrder	OrderBookPositionStrStringsTickerTickersFundingRateTrade)Client)List)ExchangeError)AuthenticationError)NotSupported)Precisec                       e Zd Zdef fdZd Zd Zi fdedededefdZd	i fded
e	de
fdZi fdedefdZdefdZdefdZd ZdefdZd Zd Zi fdedefdZi fdedefdZdEdZdefdZd	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	i fdedefdZd	i fdedefdZdefdZ dEdZ!d d	d	i fded!ed"e	d
e	de"e#         f
d#Z$d i fded!edefd$Z%defd%Z&d	d	i fded"e	d
e	de"e'         fd&Z(i fdedefd'Z)defd(Z*dEd)Z+dFd+Z,i fd,Z-i fd-Z.i fd.Z/d	d	d	i fde0d"e	d
e	de"e1         fd/Z2d	d	d	i fde0d"e	d
e	de"e'         fd0Z3dEd1Z4defd2Z5defd3Z6defd4Z7d	d	d	i fded"e	d
e	de"e8         fd5Z9dEdedefd6Z:d7 Z;d8 Z<i fde=fd9Z>d: Z?i fdede@fd;ZAdefd<ZBdedeCfd=ZDdefd>ZEdefd?ZFdefd@ZGdefdAZHdefdBZIdefdCZJdefdDZK xZLS )Gwooreturnc                 P   |                      t          t          |                                           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dddddddiddddidddddddi dddd| j        dd dd!d"t
          iiid#          S )$NwsTwatchBalancewatchFundingRatewatchFundingRatesFwatchMyTrades
watchOHLCVwatchOrderBookwatchOrderswatchTickerwatchTickerswatchBidsAskswatchTradeswatchTradesForSymbolswatchPositionsunWatchTickerunWatchTickersunWatchOrderBook)unWatchOHLCVunWatchTradeszwss://wss.woox.io/ws/streamz&wss://wss.woox.io/v2/ws/private/stream)publicprivatez#wss://wss.staging.woox.io/ws/streamz.wss://wss.staging.woox.io/v2/ws/private/stream)apitest)apiKeysecretuid  )fetchPositionsSnapshotawaitPositionsSnapshot)tradesLimitordersLimit	requestIdr+   i(#  )ping	keepAliveexactzAuth is needed.)hasurlsrequiredCredentialsoptions	streaming
exceptions)deep_extendsuperr   describer>   r   )self	__class__s    J/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/pro/woo.pyrI   zwoo.describe   s   c4 0 0 9 9 ; ;d #D $U	
   d !$ t t    t ( !$    !$!" #D#$ !%!%'  . "?#K  "G#S   $ $  $#.2.2# #	  	! 
 )+>m=>
 =>
 = = =	    c                     |                      | j        di           }|                     ||d          }|                     |d          }|| j        d         |<   |S )Nr=   r      )
safe_valuerD   safe_integersum)rJ   urlrD   previousValuenewValues        rL   
request_idzwoo.request_idT   sY    //$,R@@))'3::88M1--)1[!#&rM   c                    K   | j         r
d| j         z   nd}| j        d         d         d         |z   }|                     |          }d|i}|                     ||          }|                     |||||           d {V S )N/ r3   r   r1   id)r7   rB   rV   extendwatch)rJ   messageHashmessageurlUidrS   r=   	subscriberequests           rL   watch_publiczwoo.watch_public[   s      $(H5tx2it$X.7OOC((	)
	 ++i11ZZ[';	RRRRRRRRRrM   subHashsymboltopicc                   K   | j         r
d| j         z   nd}| j        d         d         d         |z   }|                     |          }d|z   }|d|d}	t          |          d	|g||g|gd
}
|                     |d          }|||
d<   |                     |d          }|                     |||                     |	|          ||
           d {V S )NrX   rY   r3   r   r1   unsubscribe::unsubscribe)rZ   eventre   T)rZ   rh   symbolsre   subMessageHashesunsubMessageHashessymbolsAndTimeframes)r7   rB   rV   str	safe_listomitr\   r[   )rJ   rc   rd   re   paramsr_   rS   r=   	unsubHashr^   subscriptionrm   s               rL   unwatch_publiczwoo.unwatch_publice   s
     $(H5tx2it$X.7OOC((	#g-	"
 
 i..x!(	#,+
 
  $~~f6LMM+3GL/0YYv'=>>FZZYGV0L0LiYefffffffffrM   Nlimitc                 2  K   |                                   d{V  d}|                     |ddd          \  }}|                     |          }|d         dz   |z   }| j        r
d| j        z   nd}| j        d	         d
         d         |z   }|                     |          }	d||	d}
t          |	          ||d         ||d}|dk    r
| j        |d<   |                     ||| 	                    |
|          ||           d{V }|
                                S )a  

        https://docs.woox.io/#orderbookupdate
        https://docs.woox.io/#orderbook

        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
        :param str [params.method]: either(default) 'orderbook' or 'orderbookupdate', default is 'orderbook'
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/?id=order-book-structure>` indexed by market symbols
        Nr$   method	orderbookrZ   @rX   rY   r3   r   r1   r`   )ri   re   rZ   rd   )rZ   namerd   ru   rq   orderbookupdate)load_marketshandle_option_and_paramsmarketr7   rB   rV   rn   handle_order_book_subscriptionr\   r[   ru   )rJ   rd   ru   rq   rw   r~   re   r_   rS   r=   ra   rs   rx   s                rL   watch_order_bookzwoo.watch_order_book}   sY      !!!!!!!!!66v?OQY[fggV$$ts"V+$(H5tx2it$X.7OOC((	 
 
 i..X&
 
 &&&%)%HL"**S%Wf1M1MuVbcccccccc	   rM   c                   K   |                                   d{V  d}|                     |ddd          \  }}|                     |          }|d         dz   |z   }d}|                     ||d         ||           d{V S )a  
        unWatches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://docs.woox.io/#orderbookupdate
        https://docs.woox.io/#orderbook

        :param str symbol: unified symbol of the market
        :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
        Nr$   rw   rx   rZ   ry   rd   r|   r}   r~   rt   rJ   rd   rq   rw   r~   rc   re   s          rL   un_watch_order_bookzwoo.un_watch_order_book   s       !!!!!!!!!66v?OQY[fggV$$,$v-((&2BE6RRRRRRRRRrM   clientc                 n   |                      |d          }|                     |d          }|                     |          }|d         }|                     |d          }|                     |                    d          d          }|dk    r|| j        vrd S | j        |         }	|                     |	d          }
|
|	j                            |           d S 	 |                     |d          }||
k    r/|                     |||	           |	                    |	|           d S d S # t          $ r1}| j        |= |j        |= |                    ||           Y d }~d S d }~ww xY w|| j        vr^|                     | j        d	d
          }|j        |         }|                     |d|          }|                     i |          | j        |<   | j        |         }	|                     |d          }
|                     |||
dd          }|	                    |           |	                    |	|           d S )Ndatard   re   ry   rO   r{   	timestamptswatchOrderBookLimitr8   ru   bidsasks)	safe_dictsafe_stringsafe_marketsplit
orderbooksrQ   cacheappendhandle_order_book_messageresolve	ExceptionsubscriptionsrejectrD   
order_bookparse_order_bookreset)rJ   r   r^   r   marketIdr~   rd   re   rw   rx   r   r   edefaultLimitrs   ru   snapshots                    rL   handle_order_bookzwoo.handle_order_book   sh   . ~~gv..##D(33!!(++!  '22!!%++c"2"2A66&&&do--/I)))[AAI &&w/////,**7D99BI~~66vw	RRRy%88888 &~ ! , , ,/,U3MM!U+++++++++,
 do--#00?TVZ[[%3E:)),NN*.//"e*D*D'/I))'488I,,T69ffUUHOOH%%%NN9e,,,,,s   A	D) )
E$3&EE$c                 0   |                      | j        dd          }|                      |d|          }|                     |d          }|| j        v r| j        |= |                     i |          | j        |<   |                     | j        |||           d S )Nr   r8   ru   rd   )rQ   rD   r   r   r   spawnfetch_order_book_snapshot)rJ   r   r^   rs   r   ru   rd   s          rL   r   z"woo.handle_order_book_subscription   s    ((7LdSS!!,FF!!,99T_$$'"&//"e"<"<

4167LQQQQQrM   c                 ,  K   |                      |d          }|                      |d          }	 |                     | j        dd          }|                     |d|          }|                     |d          }|                     |||           d {V }	|                     | j        |          d S | j        |         }
|
                    |	           |
j        }t          dt          |                    D ]D}||         }|                     |d          }||
d	         k     r-| 
                    |||
           E|
| j        |<   |                    |
|           d S # t          $ r)}|j        |= |                    ||           Y d }~d S d }~ww xY w)
Nrd   re   r   r8   ru   rq   r   r   r   )r   rQ   rD   rP   fetch_rest_order_book_safer   r   r   rangelenr   r   r   r   r   )rJ   r   r^   rs   rd   r]   r   ru   rq   r   rx   messagesimessageItemr   r   s                   rL   r   zwoo.fetch_order_book_snapshot   s     !!,99&&w88	*,,T\;PRVWWL%%lG\JJE__\8<<F!<<VUFSSSSSSSSHt77?/IOOH%%% H1c(mm,, S S&qk&&{D99	+...226;	RRRR&/DOF#NN9k22222 	* 	* 	*$[1MM![)))))))))	*s   BE  3B+E   
F*FFc                 \   |                      |d          }|                     |d         |                     |dg                      |                     |d         |                     |dg                      |                     |d          }||d<   |                     |          |d<   |S )Nr   r   r   r   r   datetime)r   handle_deltasrP   rQ   iso8601)rJ   r   r^   rx   r   r   s         rL   r   zwoo.handle_order_book_message  s    ~~gv..9V,doodFB.O.OPPP9V,doodFB.O.OPPP%%gt44	!*	+ $Y 7 7	*rM   c                     |                      |dd          }|                      |dd          }|                    ||           d S )Npricer   quantityrO   )safe_float_2store)rJ   booksidedeltar   amounts        rL   handle_deltazwoo.handle_delta  sJ    !!%!44""5*a88uf%%%%%rM   c                 ~    t          dt          |                    D ]}|                     |||                    d S )Nr   )r   r   r   )rJ   r   deltasr   s       rL   r   zwoo.handle_deltas"  sH    q#f++&& 	3 	3Ahq	2222	3 	3rM   c                   K   |                                   d{V  d}|                     |          }|d         }|d         dz   |z   }d|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
        :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>`
        Ntickerrd   rZ   ry   r`   ri   re   r|   r~   r[   rb   )rJ   rd   rq   rz   r~   re   ra   r^   s           rL   watch_tickerzwoo.watch_ticker&  s       !!!!!!!!!V$$!ts"T) 
 
 ++gv..&&ug666666666rM   c                   K   |                                   d{V  d}|                     |ddd          \  }}|                     |          }|d         dz   |z   }d}|                     ||d         ||           d{V S )a  
        unWatches 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>`
        Nr&   rw   r   rZ   ry   rd   r   r   s          rL   un_watch_tickerzwoo.un_watch_ticker9  s       !!!!!!!!!66v}hX`aaV$$,$v-((&2BE6RRRRRRRRRrM   c                    |                      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 |                     |d          |                     |d          |d|          S )Nrd   r   r   highlowbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechange
percentageaveragevolumer   )
baseVolumequoteVolumeinfo)safe_tickersafe_symbolr   )rJ   r   r~   s      rL   parse_ws_tickerzwoo.parse_ws_tickerH  sx     !
d&&tV44!
!
 !
 D$$VV44	!

 4##FE22!
 4!
 !
 4!
 !
 D!
 D$$VV44!
 T%%fg66!
 D!
 T!
 d!
  $!!
" t#!
$ **68<<++FH==)!
 !
 !
* +  	rM   c                 x   |                      |d          }|                      |d          }|                     |d          }|                     |          }|                     |d          }||d<   |                     ||          }|d         |d<   || j        |d         <   |                    ||           |S )Nr   re   rd   r   date)rP   r   r   rQ   r   tickersr   )	rJ   r   r^   r   re   r   r~   r   r   s	            rL   handle_tickerzwoo.handle_tickerl  s    " w//11##D(33!!(++%%gt44	 V%%dF33!(+x)/VH%&vu%%%rM   rj   c                   K   |                                   d{V  |                     |          }d}|}d|d}|                     ||          }|                     ||           d{V }|                     |d|          S )a  

        https://docs.woox.io/#24h-tickers

        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
        :returns dict: a `ticker structure <https://docs.ccxt.com/?id=ticker-structure>`
        Nr   r`   r   rd   )r|   market_symbolsr[   rb   filter_by_array)rJ   rj   rq   rz   re   ra   r^   r   s           rL   watch_tickerszwoo.watch_tickers  s       !!!!!!!!!%%g.. 
 
 ++gv..))%99999999##GXw???rM   c                    K   |                                   d{V  |t          | j        dz             d}d}|                     |d||           d{V S )a  

        https://docs.woox.io/#24h-tickers

        stops watching 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 stop fetching 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>`
        NzW unWatchTickers() does not support a symbols argument. Only unwatch all tickers at oncer   r   r|   r   rZ   rt   )rJ   rj   rq   re   rc   s        rL   un_watch_tickerszwoo.un_watch_tickers  s       !!!!!!!!!tw  *C   C  D  D  D(($vFFFFFFFFFrM   c                 
   |                      |d          }|                      |d          }|                     |d          }g }t          dt          |                    D ]}|                     ||         d          }|                     |          }	|                     |                     ||         d|i          |	          }
|
| j        |	d         <   |	                    |
           |
                    ||           d S )Nre   r   r   r   rd   r   )rP   rQ   r   r   r   r   r   r[   r   r   r   )rJ   r   r^   re   r   r   resultr   r   r~   r   s              rL   handle_tickerszwoo.handle_tickers  s    < 11w//%%gt44	q#d))$$ 	" 	"A''Q::H%%h//F))$++d1g	?R*S*SU[\\F-3DL)*MM&!!!!vu%%%%%rM   c                 $  K   |                                   d{V  |                     |          }d}|}d|d}|                     ||          }|                     ||           d{V }| j        r|S |                     | j        d|          S )a\  

        https://docs.woox.io/#bbos

        watches best bid & ask for symbols
        :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>`
        Nbbosr`   r   rd   )r|   r   r[   rb   
newUpdatesr   bidsasks)rJ   rj   rq   rz   re   ra   r^   r   s           rL   watch_bids_askszwoo.watch_bids_asks  s       !!!!!!!!!%%g.. 
 
 ++gv..**5'::::::::? 	O##DM8WEEErM   c                    K   |                                   d{V  |t          | j        dz             d}d}|                     |d||           d{V S )ao  

        https://docs.woox.io/#bbos

        unWatches best bid & ask for symbols
        :param str[] [symbols]: unified symbol of the market to fetch the ticker for(not used by woo)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/?id=ticker-structure>`
        NzY unWatchBidsAsks() does not support a symbols argument. Only unwatch all bidsAsks at oncer   r   r   )rJ   rj   rq   rc   re   s        rL   un_watch_bids_askszwoo.un_watch_bids_asks  s       !!!!!!!!!tw  *E   E  F  F  F(($vFFFFFFFFFrM   c                    |                      |d          }|                     |dg           }|                     |d          }i }t          dt	          |                    D ]I}|                     ||          }||d<   |                     |          }	|	d         }
|	| j        |
<   |	||
<   J|                    ||           d S )Nre   r   r   r   rd   )	r   ro   rQ   r   r   r   parse_ws_bid_askr   r   )rJ   r   r^   re   r   r   r   r   r   parsedTickerrd   s              rL   handle_bid_askzwoo.handle_bid_ask  s        '22~~gvr22%%gt44	q#d))$$ 	* 	*A^^D!,,F$F4L0088L!(+F$0DM&!)F6NNvu%%%%%rM   c                    |                      |d          }|                     ||          }|                      |d          }|                     |d          }|                     |||                     |          |                      |d          |                      |d          |                      |d          |                      |d          |d|          S )Nrd   r   r   askSizer   bidSize)rd   r   r   r   r   r   r   r   )r   r   rQ   r   r   )rJ   r   r~   r   rd   r   s         rL   r   zwoo.parse_ws_bid_ask   s    ##FH55!!(F33!!&(33%%fd33	"Y//##FE22))&)<<##FE22))&)<<	!
 	!
 	 	 		rM   1m	timeframesincec                 <  K   |                                   d{V  |dk    rA|dk    r;|dk    r5|dk    r/|dk    r)|dk    r#|dk    r|d	k    rt          | j        d
z             |                     |          }|                     | j        ||          }d}|d         dz   |z   dz   |z   }	d|	d}
|                     |
|          }|                     |	|           d{V }| j        r|	                    |d         |          }| 
                    |||dd          S )ax  
        watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://docs.woox.io/#k-line

        :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
        Nr   5m15m30m1h1d1w1MzG watchOHLCV timeframe argument must be 1m, 5m, 15m, 30m, 1h, 1d, 1w, 1MklinerZ   ry   _r`   r   rd   r   T)r|   r   rZ   r~   r   
timeframesr[   rb   r   getLimitfilter_by_since_limit)rJ   rd   r   r   ru   rq   r~   intervalrz   re   ra   r^   ohlcvs                rL   watch_ohlcvzwoo.watch_ohlcv0  s      !!!!!!!!!I$5$5I<N<NU^bgUgUgnw{nn  GP  TX  GX  GX  _h  lp  _p  _p  w@  DH  wH  wH*s stttV$$##DOY	JJts"T)C/(: 
 
 ++gv..''w77777777? 	<NN6(#3U;;E))%q$GGGrM   c                 0  K   |                                   d{V  |                     |          }|                     | j        ||          }d}d}|d         dz   |z   dz   |z   }|d         |gg|d<   |                     ||d         ||           d{V S )	aY  
        unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://docs.woox.io/#k-line

        :param str symbol: unified symbol of the market
        :param str timeframe: the length of time each candle represents
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param dict [params.timezone]: if provided, kline intervals are interpreted in that timezone instead of UTC, example '+08:00'
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr  r   rZ   ry   r   rd   rm   )r|   r~   r   r   rt   )	rJ   rd   r   rq   r~   r  re   rz   rc   s	            rL   un_watch_ohlcvzwoo.un_watch_ohlcvN  s       !!!!!!!!!V$$##DOY	JJ,$t+c1H<+1(+;Y*G)H%&((&2BE6RRRRRRRRRrM   c           	      t   |                      |d          }|                      |d          }|                     |d          }|                     |          }|d         }|                     |d          }|                     |          }	|                     |d          |                     |d          |                     |d          |                     |d          |                     |d	          |                     |d
          g}
|                      | j        |i           | j        |<   |                      | j        |         |	          }|;|                     | j        dd          }t          |          }|| j        |         |	<   |	                    |
           |
                    ||           d S )Nr   re   rd   type	startTimer   r   r   r   r   
OHLCVLimitr8   )rP   r   r   find_timeframerQ   
safe_floatohlcvsrD   r   r   r   )rJ   r   r^   r   re   r   r~   rd   r  r   parsedstoredru   s                rL   handle_ohlcvzwoo.handle_ohlcvc  s   & w//11##D(33!!(++!##D&11''11	dK00OOD&))OOD&))OOD%((OOD'**OOD(++
 #oodk62FFFV!4i@@>%%dlL$GGE*511F-3DK	*fvu%%%%%rM   c                 p  K   |                                   d{V  |                     |          }|d         }|d         dz   }d|d}|                     ||          }|                     ||           d{V }	| j        r|	                    |d         |          }|                     |	|||d          S )a  
        watches information on multiple trades made in a market

        https://docs.woox.io/#trade

        :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>`
        Nrd   rZ   @trader`   r   T)r|   r~   r[   rb   r   r  filter_by_symbol_since_limit)
rJ   rd   r   ru   rq   r~   re   ra   r^   tradess
             rL   watch_tradeszwoo.watch_trades  s       !!!!!!!!!V$$!tx' 
 
 ++gv..((88888888? 	=OOF8$4e<<E00tTTTrM   c                    K   |                                   d{V  |                     |          }d}|d         dz   }|                     ||d         ||           d{V S )a  
        unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list

        https://docs.woox.io/#trade

        :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  rZ   r  rd   )r|   r~   rt   )rJ   rd   rq   r~   re   rc   s         rL   un_watch_tradeszwoo.un_watch_trades  s       !!!!!!!!!V$$,)((&2BE6RRRRRRRRRrM   c                 B   |                      |d          }|                     |d          }|                     |d          }|                      |d          }|                     |          }|d         }|                     |                     |d|i          |          }	|                     | j        |          }
|
+|                     | j        dd          }t          |          }
|
	                    |	           |
| j        |<   |
                    |
|           d S )Nre   r   r   rd   r   r;   r8   )r   rQ   rP   r   parse_ws_trader[   r  rD   r   r   r   )rJ   r   r^   re   r   r   r   r~   rd   tradetradesArrayru   s               rL   handle_tradezwoo.handle_trade  s      '22%%gt44	w//##D(33!!(++!##DKK{I6N$O$OQWXXoodk6::%%dlM4HHE$U++K5!!!)F{E*****rM   c                    |                      |d          }|                     ||          }|d         }|                     |dd          }|                     |dd          }t          j        ||          }|                     |d          }|                     |d          }	|                     |d          }
d }|
|
rd	nd
}|                     |d          }d }|                     |d          }|,|| 	                    |                      |d                    d}| 
                    |                      |d          |	|                     |	          ||||||                      |d          ||||d|          S )Nrd   executedPricer   executedQuantitysizesider   markermakertakerr	  feefeeCurrencycostcurrencytradeIdorderId)rZ   r   r   rd   r"  r   r   r)  ordertakerOrMakerr	  r&  r   )r   r   safe_string_2r   
string_mulsafe_string_lowerrQ   	safe_boolsafe_numbersafe_currency_code
safe_trader   )rJ   r  r~   r   rd   r   r   r)  r"  r   r$  r.  r	  r&  feeCosts                  rL   r  zwoo.parse_ws_trade  s   P ##E844!!(F33!""5/7CC##E+=vFF!%00%%eV44%%e[99	uh//&+877L%%eV44""5%00 33D4D4DUM4Z4Z[[ C ""5)44"Y//%%eY77( 
  
   	rM   Tc                 J    | j         s|rt          | j        dz             dS dS )Nz: requires `uid` credential(woox calls it `application_id`)FT)r7   r   rZ   )rJ   errors     rL   check_required_uidzwoo.check_required_uid!  s4    x 	 )$'4p*pqqqutrM   c                 z  K   |                                   | j        d         d         d         dz   | j        z   }|                     |          }d}d}|                    |          }|                     |j        |          }|t          |                                           }d|z   }	| 	                    | 
                    |	          | 
                    | j                  t          j                  }
|| j        |
|dd	}|                     ||          }|                     |||||           | d {V S )
Nr3   r   r2   rX   authenticatedauth|)apikeysignr   )ri   rq   )check_required_credentialsrB   r7   r   reusableFuturerP   r   rn   noncehmacencoder6   hashlibsha256r5   r[   r\   )rJ   rq   rS   r   r]   ri   futurer;  r   r<  	signaturera   r^   s                rL   authenticatezwoo.authenticate)  s8     '')))it$Y/#5@S!!%&&{33(<kJJ TZZ\\""B8D		$++d"3"3T[[5M5Mw~^^I"k%!#  G kk'622GJJsK+wGGG||||||rM   c                    K   |                      |           d {V  | j        d         d         d         dz   | j        z   }|                     |          }d|i}|                     ||          }|                     |||||           d {V S Nr3   r   r2   rX   rZ   )rI  rB   r7   rV   r[   r\   )rJ   r]   r^   rq   rS   r=   r`   ra   s           rL   watch_privatezwoo.watch_privateA  s      '''''''''it$Y/#5@OOC((	)
	 ++i11ZZ[';	RRRRRRRRRrM   c                    K   |                      |           d {V  | j        d         d         d         dz   | j        z   }|                     |          }d|i}|                     ||          }|                     |||||           d {V S rK  )rI  rB   r7   rV   r[   watch_multiple)rJ   messageHashesr^   rq   rS   r=   r`   ra   s           rL   watch_private_multiplezwoo.watch_private_multipleK  s      '''''''''it$Y/#5@OOC((	)
	 ++i11((mWmU^_________rM   c                   K   |                                   d{V  |                     |ddd          }|rdnd}|                     |ddg          }|}|%|                     |          }|d         }|d|z   z  }d	|d
}	|                     |	|          }
|                     ||
           d{V }| j        r|                    ||          }|                     ||||d          S )a  

        https://docs.woox.io/#executionreport
        https://docs.woox.io/#algoexecutionreportv2

        watches information on multiple orders made by the user
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.trigger]: True if trigger order
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        NstoptriggerFalgoexecutionreportv2executionreportrd   :r`   r   T	r|   safe_bool_2rp   r~   r[   rL  r   r  r  )rJ   rd   r   ru   rq   rS  re   r]   r~   ra   r^   orderss               rL   watch_orderszwoo.watch_ordersU  s)      !!!!!!!!!""669eDD,3K'':K6FI#677[[((FH%F3<'K 
 
 ++gv..))+w????????? 	3OOFE22E00tTTTrM   c                   K   |                                   d{V  |                     |ddd          }|rdnd}|                     |ddg          }d}|%|                     |          }|d         }|d	|z   z  }d
|d}	|                     |	|          }
|                     ||
           d{V }| j        r|                    ||          }|                     ||||d          S )a  

        https://docs.woox.io/#executionreport
        https://docs.woox.io/#algoexecutionreportv2

        watches information on multiple trades made by the user
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.trigger]: True if trigger order
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        NrR  rS  FrT  rU  myTradesrd   rV  r`   r   TrW  )rJ   rd   r   ru   rq   rS  re   r]   r~   ra   r^   r  s               rL   watch_my_tradeszwoo.watch_my_tradesv  s)      !!!!!!!!!""669eDD,3K'':K6FI#677 [[((FH%F3<'K 
 
 ++gv..))+w????????? 	3OOFE22E00tTTTrM   c           
      (   |                      |dd          }|                     |d          }|                     |          }|d         }|                     |d          }|                     |d          |                     |d          d}|                     |d          }|                     |d          }	|                     |d	          }
t          j        |d
          r|
|
}	|                     |d          }|                     |d          }|                     |d          }|                      |dd          }|                      |dd          }|                     |          }d }|                     |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          S )Nr,  algoOrderIdrd   r   totalFeefeeAssetr(  r   avgPrice0r   r"  r	  totalExecutedQuantityexecutedstatus
algoStatusclientOrderIdtriggerPricer   rZ   r   lastTradeTimestamptimeInForcepostOnly	stopPrice
reduceOnlyr   r)  )r   filled	remainingrf  r&  r  )r/  r   r~   rQ   r3  r   	string_eqr1  parse_order_status
safe_orderr   r2  )rJ   r-  r~   r,  r   rd   r   r&  priceStringr   rb  r   r"  r	  ro  	rawStatusrf  r  rh  ri  s                       rL   parse_ws_orderzwoo.parse_ws_order  s   H $$UI}EE##E844X&&!%%e[99	$$UJ77((
;;
 
 &&ug66  00##E:66[#.. 	H4HE!!%44%%eV44%%eV44##E+BJOO&&uhEE	((33((@@''~>>  
E 
f 
 ' 
 ]	 

  
 Y// 
 !) 
 D 
 4 
  
 D 
 U 
  
 L 
 $..== 
  f! 
" D# 
$  / 
  
  
   	rM   c                 <   |                      |d          }|                     |d          }t          |t                    rt	          dt          |                    D ]b}||         }|                     |                      |d                    }||                     ||           |                     |||           cd S |                     |                      |d                    }||                     ||           |                     |||           d S )Nre   r   r   r+  )	r   rP   
isinstancelistr   r   	omit_zerohandle_my_tradehandle_order)rJ   r   r^   re   r   r   r-  r+  s           rL   handle_order_updatezwoo.handle_order_update  s%   <   '22w//dD!! 	31c$ii(( 8 8Q..)9)9$	)J)JKK&((777!!&%77778 8 nnT%5%5dI%F%FGGG"$$VT222fdE22222rM   c                 &   |                      |          }|                     |d          }|                     |d          }|L| j        0|                     | j        dd          }t          |          | _        | j        }|                     |j        |i           }	|                     |	|          }
|
|                     |
d          }|||d<   |                     |
d          }|||d<   |                     |
d          |d<   |                     |
d          |d<   |                     |
d	          |d	<   |                    |           |	                    | j        |           |d
z   |z   }|	                    | j        |           d S d S )Nrd   rZ   r<   r8   r&  feesr  r   r   rV  )
rv  r   rY  rQ   rD   r   rP   hashmapr   r   )rJ   r   r^   re   r  rd   r,  ru   cachedOrdersrY  r-  r&  r  messageHashSymbols                 rL   r|  zwoo.handle_order;  s   $$W--!!&(33""6400{"))$,tLL4U;;;L__\%962FFFOOFG44E ooeU33?$'F5Muf55#%)F6N#'??5(#C#Cx &*&7&7{&K&K{#%)%5%5eZ%H%Hz"'''NN4;... %f 4NN4;(9:::::) rM   c                 4   | j         }|+|                     | j        dd          }t          |          }|                     |          }|                    |           d|d         z   }|                    ||           d}|                    ||           d S )Nr;   r8   z	myTrades:rd   r\  )r\  rQ   rD   r   r  r   r   )rJ   r   r^   r\  ru   r  r]   s          rL   r{  zwoo.handle_my_tradeU  s    > =%%dlM4HHE-e44H##G,,!E(O3x--- x-----rM   c                 H  K   |                                   d{V  g }|                     |          }|                     |          sAt          dt	          |                    D ]"}||         }|                    d|z              #n|                    d           | j        d         d         d         dz   | j        z   }|                     |          }	| 	                    |	|           | 
                    d	d
d          }
| 
                    d	dd          }|
r=|r;| j        4|	                    d
           d{V }|                     ||||d          S ddd}|                     |||           d{V }| j        r|S |                     | j        |||d          S )a  

        https://docs.woox.io/#position-push

        watch all open positions
        :param str[]|None symbols: list of unified market symbols
 @param since
 @param limit
        :param dict params: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/en/latest/manual.html#position-structure>`
        Nr   positions::	positionsr3   r   r2   rX   r+   r9   Tr:   r`   positionr   )r|   r   is_emptyr   r   r   rB   r7   r   set_positions_cachehandle_optionr  rG  filter_by_symbols_since_limitrP  r   )rJ   rj   r   ru   rq   rO  r   rd   rS   r   r9   r:   r   ra   newPositionss                  rL   watch_positionszwoo.watch_positions  s      !!!!!!!!!%%g..}}W%% 	.1c'll++ = = $$]V%;<<<<=   ---it$Y/#5@S!!  111!%!3!34DF^`d!e!e!%!3!34DF^`d!e!e! 	]&< 	]AW#]]+CDDDDDDDDH55hPUW[\\\ 
 
 "88QWXXXXXXXX? 	 11$.'5RWY]^^^rM   c                     |                      ddd          }|r@d}||j        vr3|                    |           |                     | j        ||           d S d S t                      | _        d S )Nr+   r9   F)r  futuresrG  r   load_positions_snapshotr   r  )rJ   r   r	  rj   r9   r]   s         rL   r  zwoo.set_positions_cache  s    !%!3!34DF^`e!f!f! 	82K6>11k***

47MMMMM 21 677DNNNrM   c                   K   |                                   d {V }t                      | _        | j        }t          dt	          |                    D ]<}||         }|                     |dd          }|dk    r|                    |           =||j        v r:|j        |         }|                    |           |                    |d           d S d S )Nr   	contractsr  )	fetch_positionsr   r  r   r   r3  r   r  r   )	rJ   r   r]   r  r   r   r  r  rG  s	            rL   r  zwoo.load_positions_snapshot  s      ..00000000	133q#i..)) 	' 	'A |H((;BBI1}}X&&&&.((^K0FNN5!!!NN5+..... )(rM   c                 b   |                      |di           }|                      |di           }t          |                                          }| j        t	                      | _        | j        }g }t          dt          |                    D ]}||         }	|                     |	          }
||	         }|                     ||
          }|	                    |           |	                    |           d|
d         z   }|
                    ||           |
                    |d           d S )Nr   r  r   r  rd   )rP   ry  keysr  r   r   r   r   parse_positionr   r   )rJ   r   r^   r   rawPositionspostitionsIdsr   r  r   r   r~   rawPositionr  r]   s                 rL   handle_positionszwoo.handle_positions  s+   4 w33t["==\..0011>!577DNq#m,,-- 	2 	2A$Q'H%%h//F&x0K**;??H)))LL"""'&*::KNN8[1111|[11111rM   c                    K   |                                   d{V  d}|}d|d}|                     ||          }|                     ||           d{V S )aC  

        https://docs.woox.io/#balance

        watch balance and get the amount of funds available for trading or funds locked in orders
        :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   )r|   r[   rL  )rJ   rq   re   r]   ra   r^   s         rL   watch_balancezwoo.watch_balance  s       !!!!!!!!! 
 
 ++gv..''W=========rM   c                 0   |                      |d          }|                      |d          }t          |                                          }|                     |d          }|| j        d<   || j        d<   |                     |          | j        d<   t          dt          |                    D ]}||         }||         }	|                     |          }
|
| j        v r| j        |
         n| 	                                }| 
                    |	d          }| 
                    |	d	          }||d
<   ||d<   t          j        ||          |d<   || j        |
<   |                     | j                  | _        |                    | j        d           d S )Nr   balancesr   r   r   r   r   holdingfrozentotalusedfreer  )rP   ry  r  rQ   r  r   r   r   r4  accountr   r   
string_subsafe_balancer   )rJ   r   r^   r   r  r  r   r   keyvaluecoder  r  r  s                 rL   handle_balancezwoo.handle_balance  s   : w//??444HMMOO$$w--#V$&[!#'<<#3#3Z q#d))$$ 
	) 
	)Aq'CSME**3//D-1T\-A-Adl4((G$$UI66E##E844D$GG"GFO%0==GFO!(DL((66t|Y/////rM   c                    K   |                                   d{V  |                     |          }|d         }|d         dz   }d|d}|                     ||          }|                     ||           d{V S )aJ  
        watch the current funding rate

        https://docs.woox.io/#estfundingrate

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/?id=funding-rate-structure>`
        Nrd   rZ   z@estfundingrater`   r   r   )rJ   rd   rq   r~   re   ra   r^   s          rL   watch_funding_ratezwoo.watch_funding_rate/  s       !!!!!!!!!V$$!t00 
 
 ++gv..&&ug666666666rM   c                     |                      |di           }|                     |          }|d         }|| j        |<   |                     |d          }|                    ||           d S )Nr   rd   re   )r   parse_funding_ratefundingRatesr   r   )rJ   r   r^   r   fundingRaterd   r]   s          rL   handle_funding_ratezwoo.handle_funding_rateD  sr     ~~gvr22--d33X&$/&!&&w88{K00000rM   c                    d|vrdS |                      |d          }|rdS |                     |d          }	 |B| j        dz   |                     |          z   }|                     | j        d         ||           dS # t          $ r_}t          |t                    r*d}|	                    ||           ||j
        v r|j
        |= n|	                    |           Y d }~dS d }~ww xY w)NsuccessFerrorMsg r@   r;  T)r2  r   rZ   jsonthrow_exactly_matched_exceptionrF   r   rx  r   r   r   )rJ   r   r^   r  errorMessagefeedbackr8  r]   s           rL   handle_error_messagezwoo.handle_error_messageW  s    W$$5..)44 	5''<<	'7S=499W+=+==44T_W5M|]efff5 	 	 	%!455 %-e[111&"666,[9e$$$44444	s   AA> >
C'AC""C'c                    |                      |d          }d|z   }|                     |j        |i           }|                     |dg           }|                     |dg           }t	          dt          |                    D ])}||         }	||         }
|                     ||	|
           *|                     |           d S )Nr   rg   rk   rl   r   )r   r   r   ro   r   r   clean_unsubscriptionclean_cache)rJ   r   r^   subscribeHashunsubscribeHashrs   rk   rl   r   rc   rr   s              rL   handle_un_subscriptionzwoo.handle_un_subscriptionp  s     ((&99)M9~~f&:ORPP>>,8JBOO!^^L:NPRSSq#.//00 	B 	BA&q)G*1-I%%fgyAAAA&&&&&rM   c                    |                      ||          rd S i d| j        d| j        d| j        d| j        d| j        d| j        d| j        d| j        d	| j        d
| j	        d| j
        d| j
        d| j        d| j        d| j        d| j        d| j        }|                     |d          }|                     ||          }| |||           d S |                     |d          }||                     ||          }| |||           d S |                    d          }t'          |          }|dk    r|                     |d          }	|                     ||	          }| |||           d S |	                    d          }
t'          |          }|dk    r>|                     ||                     |
d                    }| |||           d S d S d S d S d S )Nr>   pongr`   rh   rx   r{   r   r   r   r<  rU  rT  r  r  r  r   estfundingrateri   re   ry      rO   r   r   )r  handle_pinghandle_ponghandle_subscriber  r   r   r   r  handle_authr}  r  r  r  r   r  r   rP   r   r   )rJ   r   r^   methodsri   rw   re   
splitTopicsplitLengthrz   	splitNamesplitNameLengths               rL   handle_messagezwoo.handle_message  s   $$VW55 	F
D$
D$
 .
 46	

 /
 t5
 d(
 t*
 T&
 D$
 t7
 $T%=
 T&
 t*
 -
  D'!
" d6#
&   '22%00F67###F  '22__We44F!vw'''S))Jj//Ka''
A66$77%F67+++F JJsOO	"%j//"a''!__Wd6F6FyRS6T6TUUF)vw/////%    ('))rM   c                 
    ddiS )Nri   r>    )rJ   r   s     rL   r>   zwoo.ping        rM   c                 
    ddiS )Nri   r  r  rJ   r   r^   s      rL   r  zwoo.handle_ping  r  rM   c                 8    |                                  |_        |S N)millisecondslastPongr  s      rL   r  zwoo.handle_pong  s     ++--rM   c                     |                      |d          }|                     |j        d          }|                     ||i           }|                     |d          }| ||||           |S )NrZ   rw   )r   index_byr   rP   )rJ   r   r^   rZ   subscriptionsByIdrs   rw   s          rL   r  zwoo.handle_subscribe  sx     gt,, MM&*>EE'8"bAAx88F67L111rM   c                 4   d}|                      |d          }|r2|                      |j        d          }|                    d           d S t          |                     |                    }|                    ||           ||j        v r
|j        d= d S d S )Nr;  r  T)rP   r  r   r   r  r   r   )rJ   r   r^   r]   r  rG  r8  s          rL   r  zwoo.handle_auth  s     &//'955 		:__V^_EEFNN4     '		'(:(:;;EMM%---f222(999 32rM   r  )T)M__name__
__module____qualname__r   rI   rV   rb   rn   rt   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   ry  r  r  r  r   r  r  r  r  r9  rI  rL  rP  r   r   rZ  r]  rv  r}  r|  r{  r   r  r  r  r  r   r  r  r   r  r  r	   r  r  r  r>   r  r  r  r  __classcell__)rK   s   @rL   r   r      s6       ># > > > > > >@  S S S RT g gC g gS gX[ g g g g0 @DB $! $!S $! $!S\ $! $! $! $!L =? S S S3 S S S S&8- 8- 8- 8- 8-tRV R R R R* * *6    & & &
3 3 3 68 7 7 7F 7 7 7 7& 9; S SC Ss S S S S" " " "HF    : 6:" @ @7 @ @ @ @ @, 9=R G Gg GG G G G G"(&V (& (& (& (&T 8<B F FW F7 F F F F0 ;?r G G Gc G G G G"&V & & & &:     ?CQUdhqs H H H H3 H^a Hx|  ~B  yC H H H H< BFb S S3 S3 SUX S S S S*)&6 )& )& )& )&V <@d[] U U US U Ubfglbm U U U U4 9; S SC Ss S S S S +6 + + + +:J J J JX    )+    0 @B S S S S KM ` ` ` ` 04$UYbd U U UC Us Uimnsit U U U UB 37TX\eg U UC Us URU Ulpqvlw U U U UBs s s sj-3& -3 -3 -3 -3^;6 ; ; ; ;4(.f (. (. (. (.T 8<$]ajl $_ $_W $_C $_WZ $_quv~q $_ $_ $_ $_L8 8& 8 8 8 8 8/ / /*2 *2 *2X *, > > > > > >&00 00 00d <> 7 7s 7+ 7 7 7 7*1& 1 1 1 1&6 t    2'V ' ' ' '*.0V .0 .0 .0 .0`!6 ! ! ! !!& ! ! ! !&    v    ":& : : : : : : : :rM   r   )"ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r   rE  ccxt.base.typesr   r   r	   r
   r   r   r   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   ccxt.base.preciser   async_supportr   r  rM   rL   <module>r     s       A  A  A  A  A  A  A  A  A  A  A  A  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 4 4 4 4 4 4       * * * * * * 0 0 0 0 0 0 ) ) ) ) ) ) % % % % % %T: T: T: T: T:$

  T: T: T: T: T:rM   