
    ":ha                         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 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y)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)AnyBalancesIntOrder	OrderBookPositionStrStringsTickerTickersTrade)Client)List)ExchangeError)AuthenticationError)Precisec            
           e Zd Zdef fdZd Zd Zdi fde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d7dZ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	efdZd7d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i fdedededee!   fdZ"d	efdZ#d7dZ$d8d Z%i fd!Z&i fd"Z'i 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,d7d&Z-d	efd'Z.d	efd(Z/d	efd)Z0dddi fdedededee1   fd*Z2d7d	edefd+Z3d, Z4d- Z5i fde6fd.Z7d/ Z8d	efd0Z9d	efd1Z:d	efd2Z;d	efd3Z<d	efd4Z=d	efd5Z>d	efd6Z? xZ@S )9wooreturnc                     | j                  t        t        |          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 )NTF)wswatchBalancewatchMyTrades
watchOHLCVwatchOrderBookwatchOrderswatchTickerwatchTickerswatchBidsAskswatchTradeswatchTradesForSymbolswatchPositionsr   z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   describer4   r   )self	__class__s    F/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/pro/woo.pyr?   zwoo.describe   s    c4 9 ; $!%""&## $!%#)."&  "?#K "G#S $  $#.2.2#	 		!
 )+>_6>
 6 6	    c                     | j                  | j                  di       }| j                  ||d      }| j                  |d      }|| j                  d   |<   |S )Nr3   r      )
safe_valuer:   safe_integersum)r@   urlr:   previousValuenewValues        rB   
request_idzwoo.request_idL   sT    //$,,R@))'3:88M1-)1[!#&rC   c                    K   | j                   rd| j                   z   nd}| j                  d   d   d   |z   }| j                  |      }d|i}| j                  ||      }| j	                  |||||       d {   S 7 w)N/ r)   r   r'   id)r-   r8   rL   extendwatch)r@   messageHashmessageurlUidrI   r3   	subscriberequests           rB   watch_publiczwoo.watch_publicS   s     $(HHtxx2iit$X.7OOC(	)
	 ++i1ZZ[';	RRRRs   A5A>7A<8A>Nsymbollimitc                   K   | j                          d{    d}| j                  |ddd      \  }}| j                  |      }|d   dz   |z   }| j                  rd| j                  z   nd}| j                  d	   d
   d   |z   }| j                  |      }	d||	d}
t        |	      ||||d}|dk(  r| j                  |d<   | j                  ||| j                  |
|      ||       d{   }|j                         S 7 7 w)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	orderbookrP   @rN   rO   r)   r   r'   rV   )eventtopicrP   )rP   namerY   rZ   paramsorderbookupdate)load_marketshandle_option_and_paramsmarketr-   r8   rL   strhandle_order_book_subscriptionrR   rQ   rZ   )r@   rY   rZ   rb   r\   rf   r`   rU   rI   r3   rW   subscriptionr]   s                rB   watch_order_bookzwoo.watch_order_book]   s"     !!!66v?OQY[fgV$ts"V+$(HHtxx2iit$X.7OOC(	 
 i.
 &&%)%H%HL"**S%Wf1MuVbcc	  / 	", ds"   DC>CD)D *D Dclientc                    | j                  |d      }| j                  |d      }| j                  |      }|d   }| j                  |d      }| j                  |j                  d      d      }|dk(  r|| j                  vry | j                  |   }	| j                  |	d      }
|
|	j                  j                  |       y 	 | j                  |d      }||
kD  r&| j                  |||	       |j                  |	|       y y || j                  vr^| j                  | j                  d	d
      }|j                  |   }| j                  |d|      }| j                  i |      | j                  |<   | j                  |   }	| j                  |d      }
| j                  |||
dd      }|	j!                  |       |j                  |	|       y # t        $ r6}| j                  |= |j                  |= |j                  ||       Y d }~y d }~ww xY w)NdatarY   r`   r^   rE   rc   	timestamptswatchOrderBookLimitr.   rZ   bidsasks)	safe_dictsafe_stringsafe_marketsplit
orderbooksrG   cacheappendhandle_order_book_messageresolve	Exceptionsubscriptionsrejectr:   
order_bookparse_order_bookreset)r@   rk   rT   rm   marketIdrf   rY   r`   r\   r]   rn   ro   edefaultLimitri   rZ   snapshots                    rB   handle_order_bookzwoo.handle_order_book   s   . ~~gv.##D(3!!(+!  '2!!%++c"2A6&&doo-/I)))[AI &&w/,**7D9BI~66vw	Ry%8 & doo-#00?TVZ[%33E:)),N*.//"e*D'/I))'48I,,T69ffUHOOH%NN9e, ! ,/,,U3MM!U++,s   <G 	H,H  Hc                 8   | j                  | j                  dd      }| j                  |d|      }| j                  |d      }|| j                  v r| j                  |= | j	                  i |      | j                  |<   | j                  | j                  |||       y )Nrp   r.   rZ   rY   )rG   r:   rt   rw   r   spawnfetch_order_book_snapshot)r@   rk   rT   ri   r   rZ   rY   s          rB   rh   z"woo.handle_order_book_subscription   s    ((7LdS!!,F!!,9T__$'"&//"e"<

41167LQrC   c                   K   | j                  |d      }| j                  |d      }	 | j                  | j                  dd      }| j                  |d|      }| j                  |d      }| j	                  |||       d {   }	| j                  | j
                  |      y | j
                  |   }
|
j                  |	       |
j                  }t        dt        |            D ]5  }||   }| j                  |d      }||
d	   k  r#| j                  |||
       7 |
| j
                  |<   |j                  |
|       y 7 # t        $ r)}|j                  |= |j                  ||       Y d }~y d }~ww xY ww)
NrY   r`   rp   r.   rZ   rb   r   ro   rn   )rt   rG   r:   rF   fetch_rest_order_book_saferw   r   rx   rangelenrz   r{   r|   r}   r~   )r@   rk   rT   ri   rY   rS   r   rZ   rb   r   r]   messagesimessageItemro   r   s                   rB   r   zwoo.fetch_order_book_snapshot   sl    !!,9&&w8	*,,T\\;PRVWL%%lG\JE__\8<F!<<VUFSSHt7?/IOOH% H1c(m, S&qk&&{D9	+..226;	RS '0DOOF#NN9k2 T   	*$$[1MM![))	*sN   %E4AD?  D= D? !E4"BD? <E4=D? ?	E1E,'E4,E11E4c                    | j                  |d      }| j                  |d   | j                  |dg              | j                  |d   | j                  |dg              | j                  |d      }||d<   | j	                  |      |d<   |S )Nrm   rr   rq   ro   rn   datetime)rs   handle_deltasrF   rG   iso8601)r@   rk   rT   r]   rm   rn   s         rB   rz   zwoo.handle_order_book_message   s    ~~gv.9V,doodFB.OP9V,doodFB.OP%%gt4	!*	+ $Y 7	*rC   c                 t    | j                  |dd      }| j                  |dd      }|j                  ||       y )Npricer   quantityrE   )safe_float_2store)r@   booksidedeltar   amounts        rB   handle_deltazwoo.handle_delta   s8    !!%!4""5*a8uf%rC   c                 b    t        dt        |            D ]  }| j                  |||           y )Nr   )r   r   r   )r@   r   deltasr   s       rB   r   zwoo.handle_deltas   s0    q#f+& 	3Ahq	2	3rC   c                    K   | j                          d{    d}| j                  |      }|d   }|d   dz   |z   }d|d}| j                  ||      }| j                  ||       d{   S 7 X7 w)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tickerrY   rP   r^   rV   r_   r`   )rd   rf   rQ   rX   )r@   rY   rb   ra   rf   r`   rW   rT   s           rB   watch_tickerzwoo.watch_ticker   s      !!!V$!ts"T) 
 ++gv.&&ug666 	" 7s"   A3A/AA3*A1+A31A3c                 x   | j                  i d| j                  d |      dd dd d| j                  |d      d| j                  |d      dd dd dd d	d d
d d| j                  |d      d| j                  |d      dd dd dd dd dd | j                  |d      | j                  |d      |d|      S )NrY   rn   r   highlowbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechange
percentageaveragevolumer   )
baseVolumequoteVolumeinfo)safe_tickersafe_symbolrt   )r@   r   rf   s      rB   parse_ws_tickerzwoo.parse_ws_ticker  sT     !
d&&tV4!
!
 !
 D$$VV4	!

 4##FE2!
 4!
 !
 4!
 !
 D!
 D$$VV4!
 T%%fg6!
 D!
 T!
 d!
  $!!
" t#!
$ **68<++FH=)!
* + 	rC   c                 >   | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |d      }||d<   | j	                  ||      }|d   |d<   || j
                  |d   <   |j                  ||       |S )Nrm   r`   rY   ro   date)rF   rt   ru   rG   r   tickersr{   )	r@   rk   rT   rm   r`   r   rf   rn   r   s	            rB   handle_tickerzwoo.handle_ticker*  s    " w/1##D(3!!(+%%gt4	 V%%dF3!(+x)/VH%&vu%rC   symbolsc                    K   | j                          d{    | j                  |      }d}|}d|d}| j                  ||      }| j                  ||       d{   }| j	                  |d|      S 7 ]7 w)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   rV   r   rY   )rd   market_symbolsrQ   rX   filter_by_arrayr@   r   rb   ra   r`   rW   rT   r   s           rB   watch_tickerszwoo.watch_tickersG  s      !!!%%g. 
 ++gv.))%99##GXw?? 	" :s"   A8A4AA8A6A86A8c                    | j                  |d      }| j                  |d      }| j                  |d      }g }t        dt        |            D ]r  }| j	                  ||   d      }| j                  |      }	| j                  | j                  ||   d|i      |	      }
|
| j                  |	d   <   |j                  |
       t |j                  ||       y )Nr`   rm   ro   r   rY   r   )rF   rG   r   r   rt   ru   r   rQ   r   ry   r{   )r@   rk   rT   r`   rm   rn   resultr   r   rf   r   s              rB   handle_tickerszwoo.handle_tickers]  s    < 1w/%%gt4	q#d)$ 	"A''Q:H%%h/F))$++d1g	?R*SU[\F-3DLL)*MM&!	" 	vu%rC   c                 (  K   | j                          d{    | j                  |dd      }d}|}d|d}| j                  ||      }| j                  ||       d{   }| j                  r|S | j                  | j                  d|      S 7 w7 1w)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>`
        NFbbosrV   r   rY   )rd   r   rQ   rX   
newUpdatesr   bidsasksr   s           rB   watch_bids_askszwoo.watch_bids_asks  s      !!!%%gtU; 
 ++gv.))%99??N##DMM8WEE 	" :s"   BBABB0BBc                 P   | j                  |d      }| j                  |dg       }| j                  |d      }i }t        dt	        |            D ]C  }| j                  ||      }||d<   | j                  |      }	|	d   }
|	| j                  |
<   |	||
<   E |j                  ||       y )Nr`   rm   ro   r   rY   )	rt   	safe_listrG   r   r   rs   parse_ws_bid_askr   r{   )r@   rk   rT   r`   rm   rn   r   r   r   parsedTickerrY   s              rB   handle_bid_askzwoo.handle_bid_ask  s        '2~~gvr2%%gt4	q#d)$ 	*A^^D!,F$F4L008L!(+F$0DMM&!)F6N	* 	vu%rC   c                 f   | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  ||| j	                  |      | j                  |d      | j                  |d      | j                  |d      | j                  |d      |d|      S )NrY   ro   r   askSizer   bidSize)rY   rn   r   r   r   r   r   r   )rt   ru   rG   r   r   )r@   r   rf   r   rY   rn   s         rB   r   zwoo.parse_ws_bid_ask  s    ##FH5!!(F3!!&(3%%fd3	"Y/##FE2))&)<##FE2))&)<	!
 	 		rC   1msincec                   K   | j                          d{    |dk7  r;|dk7  r6|dk7  r1|dk7  r,|dk7  r'|dk7  r"|dk7  r|d	k7  rt        | j                  d
z         | j                  |      }| j	                  | j
                  ||      }d}|d   dz   |z   dz   |z   }	d|	d}
| j                  |
|      }| j                  |	|       d{   }| j                  r|j                  |d   |      }| j                  |||dd      S 7 7 <w)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klinerP   r^   _rV   r   rY   r   T)rd   r   rP   rf   rt   
timeframesrQ   rX   r   getLimitfilter_by_since_limit)r@   rY   	timeframer   rZ   rb   rf   intervalra   r`   rW   rT   ohlcvs                rB   watch_ohlcvzwoo.watch_ohlcv  sR     !!!I$5I<NU^bgUgnw{n  GP  TX  GX  _h  lp  _p  w@  DH  wH*s sttV$##DOOY	Jts"T)C/(: 
 ++gv.''w77??NN6(#3U;E))%q$GG 	" 8s"   DDB1DD	;DDc           	         | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }|d   }| j                  |d      }| j                  |      }	| j	                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d	      | j                  |d
      g}
| j                  | j                  |i       | j                  |<   | j                  | j                  |   |	      }|:| j	                  | j                  dd      }t        |      }|| j                  |   |	<   |j                  |
       |j                  ||       y )Nrm   r`   rY   type	startTimer   r   r   r   r   
OHLCVLimitr.   )rF   rt   ru   find_timeframerG   
safe_floatohlcvsr:   r   ry   r{   )r@   rk   rT   rm   r`   r   rf   rY   r   r   parsedstoredrZ   s                rB   handle_ohlcvzwoo.handle_ohlcv  s]   & w/1##D(3!!(+!##D&1''1	dK0OOD&)OOD&)OOD%(OOD'*OOD(+
 #oodkk62FFV!4i@>%%dllL$GE*51F-3DKK	*fvu%rC   c                 L  K   | j                          d{    | j                  |      }|d   }|d   dz   }d|d}| j                  ||      }| j                  ||       d{   }	| j                  r|	j                  |d   |      }| j                  |	|||d      S 7 7 <w)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>`
        NrY   rP   z@traderV   r   T)rd   rf   rQ   rX   r   r   filter_by_symbol_since_limit)
r@   rY   r   rZ   rb   rf   r`   rW   rT   tradess
             rB   watch_tradeszwoo.watch_trades  s      !!!V$!tx' 
 ++gv.((88??OOF8$4e<E00tTT 	" 9s"   B$B AB$%B"&;B$"B$c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }|d   }| j	                  | j                  |d|i      |      }	| j                  | j                  |      }
|
(| j                  | j                  dd      }t        |      }
|
j                  |	       |
| j                  |<   |j                  |
|       y )Nr`   ro   rm   rY   rn   r1   r.   )rt   rG   rF   ru   parse_ws_traderQ   r   r:   r   ry   r{   )r@   rk   rT   r`   rn   rm   r   rf   rY   tradetradesArrayrZ   s               rB   handle_tradezwoo.handle_trade/  s       '2%%gt4	w/##D(3!!(+!##DKK{I6N$OQWXoodkk6:%%dllM4HE$U+K5!)F{E*rC   c                    | j                  |d      }| j                  ||      }|d   }| j                  |dd      }| j                  |dd      }t        j                  ||      }| j                  |d      }| j                  |d      }	| j                  |d      }
d }|
|
rd	nd
}| j                  |d      }d }| j                  |d      }|$|| j                  | j                  |d            d}| j                  | j                  |d      |	| j                  |	      |||||| j                  |d      ||||d|      S )NrY   executedPricer   executedQuantitysizesidern   markermakertakerr   feefeeCurrencycostcurrencytradeIdorderId)rP   rn   r   rY   r   r   r   r  ordertakerOrMakerr   r  r   )rt   ru   safe_string_2r   
string_mulsafe_string_lowerrG   	safe_boolsafe_numbersafe_currency_code
safe_trader   )r@   r   rf   r   rY   r   r   r  r   rn   r   r
  r   r  feeCosts                  rB   r   zwoo.parse_ws_tradeL  sq   P ##E84!!(F3!""5/7C##E+=vF!!%0%%eV4%%e[9	uh/&+7L%%eV4""5%0 33D4D4DUM4Z[C ""5)4"Y/%%eY7( 
  	rC   c                 R    | j                   s|rt        | j                  dz         yy)Nz: requires `uid` credential(woox calls it `application_id`)FT)r-   r   rP   )r@   errors     rB   check_required_uidzwoo.check_required_uid  s'    xx)$''4p*pqqrC   c                 V  K   | j                          | j                  d   d   d   dz   | j                  z   }| j                  |      }d}d}|j	                  |      }| j                  |j                  |      }|t        | j                               }d|z   }	| j                  | j                  |	      | j                  | j                        t        j                        }
|| j                  |
|dd	}| j                  ||      }| j!                  |||||       | d {   S 7 w)
Nr)   r   r(   rN   authenticatedauth|)apikeysignrn   )r_   rb   )check_required_credentialsr8   r-   rk   futurerF   r}   rg   noncehmacencoder,   hashlibsha256r+   rQ   rR   )r@   rb   rI   rk   rS   r_   r  r  ro   r  	signaturerW   rT   s                rB   authenticatezwoo.authenticate  s    '')iit$Y/#5@S!%{+(<(<kJ TZZ\"B8D		$++d"3T[[5Mw~~^I"kk%!#G kk'62GJJsK+wG||s   D D)"D'#D)c                   K   | j                  |       d {    | j                  d   d   d   dz   | j                  z   }| j                  |      }d|i}| j	                  ||      }| j                  |||||       d {   S 7 m7 wNr)   r   r(   rN   rP   )r$  r8   r-   rL   rQ   rR   )r@   rS   rT   rb   rI   r3   rV   rW   s           rB   watch_privatezwoo.watch_private  s     '''iit$Y/#5@OOC(	)
	 ++i1ZZ[';	RRR 	( S"   B	BA(B	 BB	B	c                   K   | j                  |       d {    | j                  d   d   d   dz   | j                  z   }| j                  |      }d|i}| j	                  ||      }| j                  |||||       d {   S 7 m7 wr&  )r$  r8   r-   rL   rQ   watch_multiple)r@   messageHashesrT   rb   rI   r3   rV   rW   s           rB   watch_private_multiplezwoo.watch_private_multiple  s     '''iit$Y/#5@OOC(	)
	 ++i1((mWmU^___ 	( `r(  c                   K   | j                          d{    | j                  |ddd      }|rdnd}| j                  |ddg      }|}|| j                  |      }|d   }|d|z   z  }d	|d
}	| j	                  |	|      }
| j                  ||
       d{   }| j                  r|j                  ||      }| j                  ||||d      S 7 7 9w)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executionreportrY   :rV   r   T	rd   safe_bool_2omitrf   rQ   r'  r   r   r   )r@   rY   r   rZ   rb   r/  r`   rS   rf   rW   rT   orderss               rB   watch_orderszwoo.watch_orders  s      !!!""669eD,3':K6FI#67[[(FH%F3<'K 
 ++gv.))+w????OOFE2E00tTT# 	" @"   CCB CC8CCc                   K   | j                          d{    | j                  |ddd      }|rdnd}| j                  |ddg      }d}|| j                  |      }|d   }|d	|z   z  }d
|d}	| j	                  |	|      }
| j                  ||
       d{   }| j                  r|j                  ||      }| j                  ||||d      S 7 7 9w)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>`
        Nr.  r/  Fr0  r1  myTradesrY   r2  rV   r   Tr3  )r@   rY   r   rZ   rb   r/  r`   rS   rf   rW   rT   r   s               rB   watch_my_tradeszwoo.watch_my_trades  s      !!!""669eD,3':K6FI#67 [[(FH%F3<'K 
 ++gv.))+w????OOFE2E00tTT# 	" @r8  c           	      t   | j                  |d      }| j                  |d      }| j                  |      }|d   }| j                  |d      }| j                  |d      | j                  |d      d}| j                  |d      }| j                  |d      }	| j                  |d      }
t	        j
                  |d	      r|
|
}	| j                  |d
      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }|}||k\  r||z  }| j                  |d      }| j                  |      }d }| j                  |d      }| j                  i d|d|d|d|d|d| j                  |      d|d|dd dd d|d|	dd dd d|dd d|
|||||d      S )Nr  rY   rn   totalFeefeeAssetr  r   avgPrice0r   r   r   totalExecutedQuantitystatusclientOrderIdr   rP   r   lastTradeTimestamptimeInForcepostOnly	stopPricetriggerPricer   r  r   )filled	remainingrB  r  r   )rt   rf   rG   r  r   	string_eqr   r  parse_order_status
safe_orderr   )r@   r	  rf   r  r   rY   rn   r  priceStringr   r?  r   r   r   rI  totalExecQuantityrJ  	rawStatusrB  r   rC  s                        rB   parse_ws_orderzwoo.parse_ws_order  ss   4 ""5)4##E84X&!%%e[9	$$UJ7((
;
 &&ug6  0##E:6[#.H4HE
3%%eV4%%eV4!!%)@A OOE3JK	&&**I$$UH5	((3((@  
E 
f 
 ' 
 ]	 

  
 Y/ 
 !) 
 D 
 4 
  
 D 
 U 
  
 D 
 f 
  D! 
" x# 
$ "- 
  	rC   c                    | j                  |d      }| j                  |d      }t        |t              rht	        dt        |            D ]O  }||   }| j                  | j                  |d            }|| j                  ||       | j                  |||       Q y | j                  | j                  |d            }|| j                  ||       | j                  |||       y )Nr`   rm   r   r  )	rt   rF   
isinstancelistr   r   	omit_zerohandle_my_tradehandle_order)r@   rk   rT   r`   rm   r   r	  r  s           rB   handle_order_updatezwoo.handle_order_update[  s    <   '2w/dD!1c$i( 8Q..)9)9$	)JK&((7!!&%78 nnT%5%5dI%FGG"$$VT2fdE2rC   c                    | j                  |      }| j                  |d      }| j                  |d      }|9| j                  -| j                  | j                  dd      }t        |      | _        | j                  }| j                  |j                  |i       }	| j                  |	|      }
|
q| j                  |
d      }|||d<   | j                  |
d      }|||d<   | j                  |
d      |d<   | j                  |
d      |d<   | j                  |
d	      |d	<   |j                  |       |j                  | j                  |       |d
z   |z   }|j                  | j                  |       y y )NrY   rP   r2   r.   r  feesr   rn   r   r2  )
rQ  rt   r6  rG   r:   r   rF   hashmapry   r{   )r@   rk   rT   r`   r   rY   r  rZ   cachedOrdersr6  r	  r  rZ  messageHashSymbols                 rB   rW  zwoo.handle_order  sh   $$W-!!&(3""640{{"))$,,tL4U;;;L__\%9%962FFOOFG4E ooeU3?$'F5Muf5#%)F6N#'??5(#Cx &*&7&7{&K{#%)%5%5eZ%Hz"'NN4;;. %f 4NN4;;(9:) rC   c                    | j                   }|(| j                  | j                  dd      }t        |      }| j	                  |      }|j                  |       d|d   z   }|j                  ||       d}|j                  ||       y )Nr1   r.   z	myTrades:rY   r:  )r:  rG   r:   r   r   ry   r{   )r@   rk   rT   r:  rZ   r   rS   s          rB   rV  zwoo.handle_my_trade  s    > ==%%dllM4HE-e4H##G,!E(O3x- x-rC   c                   K   | j                          d{    g }| j                  |      }| j                  |      s4t        dt	        |            D ]  }||   }|j                  d|z           n|j                  d       | j                  d   d   d   dz   | j                  z   }| j                  |      }	| j                  |	|       | j                  d	d
d      }
| j                  d	dd      }|
r<|r:| j                  .|	j                  d
       d{   }| j                  ||||d      S ddd}| j                  |||       d{   }| j                  r|S | j                  | j                  |||d      S 7 g7 i7 6w)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::	positionsr)   r   r(   rN   r&   r/   Tr0   rV   positionr   )rd   r   is_emptyr   r   ry   r8   r-   rk   set_positions_cachehandle_optionra  r  filter_by_symbols_since_limitr,  r   )r@   r   r   rZ   rb   r+  r   rY   rI   rk   r/   r0   r   rW   newPositionss                  rB   watch_positionszwoo.watch_positions  s     !!!%%g.}}W%1c'l+ = $$]V%;<=   -iit$Y/#5@S!  1!%!3!34DF^`d!e!%!3!34DF^`d!e!&<AW#]]+CDDH55hPUW[\\ 
 "88QWXX??11$..'5RWY]^^1 	" E Ys4   FE=C?FF 4FF2F FFc                     | j                  ddd      }|r@d}||j                  vr/|j                  |       | j                  | j                  ||       y y t               | _        y )Nr&   r/   F)re  futuresr  r   load_positions_snapshotr   ra  )r@   rk   r   r   r/   rS   s         rB   rd  zwoo.set_positions_cache  sa    !%!3!34DF^`e!f!2K6>>1k*

477M 2 67DNrC   c                 l  K   | j                          d {   }t               | _        | j                  }t        dt	        |            D ]1  }||   }| j                  |dd      }|dkD  s!|j                  |       3 |j                  |   }|j                  |       |j                  |d       y 7 w)Nr   	contractsra  )	fetch_positionsr   ra  r   r   r  ry   rj  r{   )	r@   rk   rS   ra  rx   r   rb  rm  r  s	            rB   rk  zwoo.load_positions_snapshot  s     ..00	13q#i.) 	'A |H((;BI1}X&		' ,uuk* 1s   B4B2AB4,AB4c                    | j                  |di       }| j                  |di       }t        |j                               }| j                  t	               | _        | j                  }g }t        dt        |            D ]k  }||   }	| j                  |	      }
||	   }| j                  ||
      }|j                  |       |j                  |       d|
d   z   }|j                  ||       m |j                  |d       y )Nrm   ra  r   r`  rY   )rF   rT  keysra  r   r   r   ru   parse_positionry   r{   )r@   rk   rT   rm   rawPositionspostitionsIdsrx   rg  r   r   rf   rawPositionrb  rS   s                 rB   handle_positionszwoo.handle_positions  s    4 w3t["=\..01>>!57DNq#m,- 	2A$Q'H%%h/F&x0K**;?H)LL"'&*::KNN8[1	2 	|[1rC   c                    K   | j                          d{    d}|}d|d}| j                  ||      }| j                  ||       d{   S 7 97 w)aE  

        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balancerV   r   )rd   rQ   r'  )r@   rb   r`   rS   rW   rT   s         rB   watch_balancezwoo.watch_balance8  sd      !!! 
 ++gv.''W=== 	" >s!   AA4AAAAc                    | j                  |d      }| j                  |d      }t        |j                               }| j                  |d      }|| j                  d<   || j                  d<   | j                  |      | j                  d<   t        dt        |            D ]  }||   }||   }	| j                  |      }
|
| j                  v r| j                  |
   n| j                         }| j                  |	d      }| j                  |	d	      }||d
<   ||d<   t        j                  ||      |d<   || j                  |
<    | j                  | j                        | _        |j                  | j                  d       y )Nrm   balancesro   r   rn   r   r   holdingfrozentotalusedfreerw  )rF   rT  rp  rG   rw  r   r   r   r  accountrt   r   
string_subsafe_balancer{   )r@   rk   rT   rm   rz  rp  ro   r   keyvaluecoder  r}  r~  s                 rB   handle_balancezwoo.handle_balanceK  s[   : w/??44HMMO$w-#V$&[!#'<<#3Z q#d)$ 
	)Aq'CSME**3/D-1T\\-Adll4(G$$UI6E##E84D$GG"GFO%00=GFO!(DLL
	) ((6t||Y/rC   c                    d|vry| j                  |d      }|ry| j                  |d      }	 |A| j                  dz   | j                  |      z   }| j	                  | j
                  d   ||       y# t        $ r[}t        |t              r0d}|j                  ||       ||j                  v r|j                  |= n|j                  |       Y d }~yd }~ww xY w)NsuccessFerrorMsg r6   r  T)r  rt   rP   jsonthrow_exactly_matched_exceptionr<   r|   rS  r   r~   r}   )r@   rk   rT   r  errorMessagefeedbackr  rS   s           rB   handle_error_messagezwoo.handle_error_message}  s     W$..)4''<	'77S=499W+==44T__W5M|]ef 	%!45-e[1&"6"66,,[9e$	s   AA2 2	C;ACCc                    | j                  ||      ry | j                  | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  d}| j                  |d      }| j                  ||      }|
 |||       y | j                  |d      }|| j                  ||      }|
 |||       y |j!                  d      }t#        |      }|dk(  r| j                  |d      }	| j                  ||	      }|
 |||       y |	j!                  d      }
t#        |      }|dk(  r/| j                  || j                  |
d            }|
 |||       y y y y y )	N)r4   pongrV   r]   rc   r   r   r   r  r1  r0  r   rw  rb  r   r_   r`   r^      rE   r   r   )r  handle_pinghandle_ponghandle_subscriber   r   r   r   handle_authrX  r   r  ru  r   rt   rF   rv   r   )r@   rk   rT   methodsr_   r\   r`   
splitTopicsplitLengthra   	splitNamesplitNameLengths               rB   handle_messagezwoo.handle_message  s   $$VW5$$$$..//#55((**&&$$#77%)%=%=&&**--''
"   '2%067#  '2__We4F!vw'S)Jj/Ka''
A6$7%67+ JJsO	"%j/"a'!__Wd6F6FyRS6TUF)vw/ * (   rC   c                 
    ddiS )Nr_   r4    )r@   rk   s     rB   r4   zwoo.ping        rC   c                 
    ddiS )Nr_   r  r  r@   rk   rT   s      rB   r  zwoo.handle_ping  r  rC   c                 0    | j                         |_        |S N)millisecondslastPongr  s      rB   r  zwoo.handle_pong  s     ++-rC   c                     | j                  |d      }| j                  |j                  d      }| j                  ||i       }| j                  |d      }|
 ||||       |S )NrP   r\   )rt   index_byr}   rF   )r@   rk   rT   rP   subscriptionsByIdri   r\   s          rB   r  zwoo.handle_subscribe  sg     gt, MM&*>*>E'8"bAx867L1rC   c                    d}| j                  |d      }|r.| j                  |j                  d      }|j                  d       y t        | j	                  |            }|j                  ||       ||j                  v r|j                  d= y y )Nr  r  T)rF   rj  r{   r   r  r~   r}   )r@   rk   rT   rS   r  r  r  s          rB   r  zwoo.handle_auth  s~     &//'95__V^^_EFNN4 '		'(:;EMM%-f222((9 3rC   r  )T)A__name__
__module____qualname__r   r?   rL   rX   rg   r	   r   rj   r   r   rh   r   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rT  r   r   r   r   r   r   r  r$  r'  r,  r   r
   r7  r;  rQ  rX  rW  rV  r   rh  rd  rk  ru  r   rx  r  r  r  r4   r  r  r  r  __classcell__)rA   s   @rB   r   r      s   7# 7rS @DB $!S $! $!S\ $!L8- 8-tRV R*6 &
3 68 7 7F 7&"HF : 6:" @7 @ @,(&V (&T 8<B FW F7 F0&V &:  8<$]ajl H HC HWZ Hquvzq{ H<)&6 )&V <@d[] U US U Ubfglbm U4+6 +:JX )+ 0 @B S KM ` 04$UYbd U UC Us Uimnsit UB 37TX\eg UC Us URU Ulpqvlw UBKZ-3& -3^;6 ;4(.f (.T 8<$]ajl $_W $_C $_WZ $_quv~q $_L8& 8 8+*2X *, > >&00d6 2,0V ,0\!6 !!& !& v ":& :rC   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r   r!  ccxt.base.typesr   r   r	   r
   r   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   ccxt.base.preciser   async_supportr   r  rC   rB   <module>r     sN     A  A  p p p p 4  * 0 %d:$


 
  d:rC   