
    ":h                         d dl Zd dlmZmZmZmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZmZ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j8                  j:                        Zy)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)AnyBalancesIntOrder	OrderBookPositionStrStringsTickerTickersTrade)Client)List)AuthenticationError)NotSupported)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i fdedefdZd2d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d2d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d2dZd	efd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'd2d!Z(d	efd"Z)d	efd#Z*d	efd$Z+dddi fdedededee,   fd%Z-d2d	edefd&Z.d' Z/d( Z0d2d)Z1i fde2fd*Z3d+ Z4d	efd,Z5d	efd-Z6d	efd.Z7d	efd/Z8d	efd0Z9d	efd1Z: xZ;S )3woofipro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://ws-evm.orderly.org/ws/streamz5wss://ws-private-evm.orderly.org/v2/ws/private/stream)publicprivatez*wss://testnet-ws-evm.orderly.org/ws/streamz=wss://testnet-ws-private-evm.orderly.org/v2/ws/private/stream)apitest)apiKeysecret	accountId  )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    K/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/pro/woofipro.pyr?   zwoofipro.describe   s    h > @ $!%""&## $!%#)."&  "F#Z "N#b !$  $#.2.2#	 		"
 )+>_6C
 6 6	    c                     | j                  | j                  di       }| j                  ||d      }| j                  |d      }|| j                  d   |<   |S )Nr3   r      )	safe_dictr:   safe_integersum)r@   urlr:   previousValuenewValues        rB   
request_idzwoofipro.request_idK   sT    ..{B?))'3:88M1-)1[!#&rC   c                    K   d}| j                   | j                   }| j                  d   d   d   dz   |z   }| j                  |      }d|i}| j                  ||      }| j	                  |||||       d {   S 7 w)N(OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xYr)   r   r'   /id)r-   r8   rL   extendwatch)r@   messageHashmessagerP   rI   r3   	subscriberequests           rB   watch_publiczwoofipro.watch_publicR   s     7>>%Biit$X.4r9OOC(	)
	 ++i1ZZ[';	RRRRs   A5A>7A<8A>Nsymbollimitc                    K   | j                          d{    d}| j                  |      }|d   dz   |z   }d|d}| j                  ||      }| j                  ||       d{   }	|	j	                         S 7 c7 w)aO  

        https://orderly.network/docs/build-on-evm/evm-api/websocket-api/public/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
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        N	orderbookrP   @rU   eventtopic)load_marketsmarketrQ   rW   rY   )
r@   rX   rY   paramsnamera   r_   rV   rT   r[   s
             rB   watch_order_bookzwoofipro.watch_order_book_   s      !!!V$ts"T) 
 ++gv.++E7;;	   	" <s"   A>A:AA>%A<&A><A>clientc                    | j                  |di       }| j                  |d      }| j                  |      }|d   }| j                  |d      }|| j                  vr| j	                         | j                  |<   | j                  |   }| j                  |d      }	| j                  |||	dd      }
|j                  |
       |j                  ||       y )NdatarX   r_   tsbidsasks)	rF   safe_stringsafe_market
orderbooks
order_bookrG   parse_order_bookresetresolve)r@   re   rT   rg   marketIdra   rX   r_   r[   	timestampsnapshots              rB   handle_order_bookzwoofipro.handle_order_bookv   s    , ~~gvr2##D(3!!(+!  '2$//)&*oo&7DOOF#OOF+	%%gt4	((vy&&Q!y%(rC   c                    K   | j                          d{    d}| j                  |      }|d   }|d   dz   |z   }d|d}| j                  ||      }| j                  ||       d{   S 7 X7 w)a  

        https://orderly.network/docs/build-on-evm/evm-api/websocket-api/public/24-hour-ticker

        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tickerrX   rP   r\   rU   r]   )r`   ra   rQ   rW   )r@   rX   rb   rc   ra   r_   rV   rT   s           rB   watch_tickerzwoofipro.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 )NrX   rs   datetimehighlowbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechange
percentageaveragevolumeamount)
baseVolumequoteVolumeinfo)safe_tickersafe_symbolrk   )r@   rw   ra   s      rB   parse_ws_tickerzwoofipro.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i       }| j                  |d      }| j                  |d      }| j                  |      }| j                  |d      }||d<   | j	                  ||      }|d   |d<   || j
                  |d   <   |j                  ||       |S )Nrg   r_   rX   rh   date)rF   rk   rl   rG   r   tickersrq   )	r@   re   rT   rg   r_   rr   ra   rs   rw   s	            rB   handle_tickerzwoofipro.handle_ticker   s    " ~~gvr2  '2##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://orderly.network/docs/build-on-evm/evm-api/websocket-api/public/24-hour-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   rU   r]   rX   r`   market_symbolsrQ   rW   filter_by_arrayr@   r   rb   rc   r_   rV   rT   r   s           rB   watch_tickerszwoofipro.watch_tickers   s      !!!%%g. 
 ++gv.))%99##GXw?? 	" :"   A8A4AA8A6A86A8c                    | j                  |d      }| j                  |dg       }| j                  |d      }g }t        dt	        |            D ]r  }| j                  ||   d      }| j                  |      }	| j                  | j                  ||   d|i      |	      }
|
| j                  |	d   <   |j                  |
       t |j                  ||       y )Nr_   rg   rh   r   rX   r   )rk   	safe_listrG   rangelenrl   r   rQ   r   appendrq   )r@   re   rT   r_   rg   rs   resultirr   ra   rw   s              rB   handle_tickerszwoofipro.handle_tickers  s    (   '2~~gvr2%%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}| j                  ||      }| j                  ||       d{   }| j	                  |d|      S 7 ]7 w)a  

        https://orderly.network/docs/build-on-evm/evm-api/websocket-api/public/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bbosrU   r]   rX   r   r   s           rB   watch_bids_askszwoofipro.watch_bids_asks&  s      !!!%%g. 
 ++gv.))%99##GXw?? 	" :r   c                 `   | j                  |d      }| j                  |dg       }| j                  |d      }g }t        dt	        |            D ]K  }| j                  | j                  ||   d|i            }|| j                  |d   <   |j                  |       M |j                  ||       y )Nr_   rg   rh   r   rX   )
rk   r   rG   r   r   parse_ws_bid_askrQ   r   r   rq   )	r@   re   rT   r_   rg   rs   r   r   rw   s	            rB   handle_bid_askzwoofipro.handle_bid_ask<  s        '2~~gvr2%%gt4	q#d)$ 	"A**4;;tAwy@Q+RSF-3DLL)*MM&!	" 	vu%rC   c                 f   | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  ||| j	                  |      | j                  |d      | j                  |d      | j                  |d      | j                  |d      |d|      S )NrX   rh   r   askSizer}   bidSize)rX   rs   rz   r   r   r}   r~   r   )rk   rl   rG   r   iso8601)r@   rw   ra   rr   rX   rs   s         rB   r   zwoofipro.parse_ws_bid_askV  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)a  
        watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://orderly.network/docs/build-on-evm/evm-api/websocket-api/public/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\   _rU   r]   rX   r   T)r`   r   rP   ra   rk   
timeframesrQ   rW   
newUpdatesgetLimitfilter_by_since_limit)r@   rX   	timeframer   rY   rb   ra   intervalrc   r_   rV   rT   ohlcvs                rB   watch_ohlcvzwoofipro.watch_ohlcvf  sR     !!!I$5I<NU^bgUgnw{n  GP  TX  GX  _h  lp  _p  w@  DH  wHtww)rrss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i       }| 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                  |
       |j                  ||       y )Nrg   r_   rX   type	startTimer   r{   r|   r   r   
OHLCVLimitr.   )rF   rk   rl   find_timeframerG   safe_number
safe_valueohlcvsr:   r   r   rq   )r@   re   rT   rg   r_   rr   ra   rX   r   r   parsedstoredrY   
ohlcvCaches                 rB   handle_ohlcvzwoofipro.handle_ohlcv  s   & ~~gvr2  '2##D(3!!(+!##D&1''1	dK0T6*T6*T5)T7+T8,
 #oodkk62FFV!4i@>%%dllL$GE*51F-3DKK	*[[(3
&!z5)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)aC  
        watches information on multiple trades made in a market

        https://orderly.network/docs/build-on-evm/evm-api/websocket-api/public/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>`
        NrX   rP   z@traderU   r]   T)r`   ra   rQ   rW   r   r   filter_by_symbol_since_limit)
r@   rX   r   rY   rb   ra   r_   rV   rT   tradess
             rB   watch_tradeszwoofipro.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i       }| j                  |d      }| j                  |      }|d   }| j	                  | j                  |d|i      |      }	|| j                  vr7| j                  | j                  dd      }
t        |
      }|| j                  |<   | j                  |   }|j                  |	       || j                  |<   |j                  ||       y )Nr_   rh   rg   rX   rs   r1   r.   )rk   rG   rF   rl   parse_ws_traderQ   r   r:   r   r   rq   )r@   re   rT   r_   rs   rg   rr   ra   rX   traderY   r   r   s                rB   handle_tradezwoofipro.handle_trade  s       '2%%gt4	~~gvr2##D(3!!(+!##DKK{I6N$OQWX$++%%%dllM4HE&F"(DKKV$e$Fvu%rC   c                 ~   | j                  |d      }| j                  ||      }|d   }| j                  |dd      }| j                  |dd      }t        j                  ||      }| j                  |d      }| j                  |d      }	d }
| j                  |d      }||rdnd	}
d }| j                  |d
      }|$|| j                  | j                  |d            d}| j                  | j                  |d      |	| j                  |	      |||||| j                  |d      |
| j                  |d      ||d|      S )NrX   executedPricepriceexecutedQuantitysizesiders   makertakerfeefeeAssetcostcurrencytradeIdorderIdr   )rP   rs   rz   rX   r   r   r   r   ordertakerOrMakerr   r   r   )rk   rl   safe_string_2r   
string_mulsafe_string_lowerrG   	safe_boolsafe_currency_code
safe_trader   )r@   r   ra   rr   rX   r   r   r   r   rs   r   r   r   feeValues                 rB   r   zwoofipro.parse_ws_trade  sl   J ##E84!!(F3!""5/7C##E+=vF!!%0%%eV4%%e[9	ug.&+7L##E51  33D4D4DUJ4WXC ""5)4"Y/%%eY7(**5&9 
  	rC   c                    d}| j                  |d      }|r.| j                  |j                  d      }|j                  d       y t        | j	                  |            }|j                  ||       ||j                  v r|j                  d= y y )NauthenticatedsuccessT)r   futuresrq   r   jsonrejectsubscriptions)r@   re   rT   rS   r   futureerrors          rB   handle_authzwoofipro.handle_auth/  s~     &//'95__V^^_EFNN4 '		'(:;EMM%-f222((9 3rC   c                   K   | j                          | j                  d   d   d   dz   | j                  z   }| j                  |      }d}d}|j	                  |      }| j                  |j                  |      }|t        | j                               }|}	| j                  }
|
j                  d      dk\  r|
j                  d      }|d	   }
| j                  | j                  |	      | j                  |
      d
      }|| j                  ||dd}| j!                  ||      }| j#                  ||||       | d {   S 7 w)Nr)   r   r(   rO   r   authzed25519:r   rE   ed25519)orderly_keysignrs   )r^   rb   )check_required_credentialsr8   r-   re   r   r   r   strnoncer,   findspliteddsaencodebase58_to_binaryr+   rQ   rR   )r@   rb   rI   re   rS   r^   r   r   rh   r   r,   parts	signaturerV   rT   s                  rB   authenticatezwoofipro.authenticateD  s1    '')iit$Y/#5FS!%{+(<(<kJ TZZ\"BD[[F{{:&!+Z0q

4;;t#4d6K6KF6SU^_I#';;%!#G kk'62GJJsK+>||s   D:E<E=E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(   rO   rP   )r  r8   r-   rL   rQ   rR   )r@   rS   rT   rb   rI   r3   rU   rV   s           rB   watch_privatezwoofipro.watch_private`  s     '''iit$Y/#5F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   rU   rV   s           rB   watch_private_multiplezwoofipro.watch_private_multiplej  s     '''iit$Y/#5F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  
        watches information on multiple orders made by the user

        https://orderly.network/docs/build-on-evm/evm-api/websocket-api/private/execution-report
        https://orderly.network/docs/build-on-evm/evm-api/websocket-api/private/algo-execution-report

        :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algoexecutionreportexecutionreportrX   :rU   r]   T	r`   safe_bool_2omitra   rQ   r  r   r   r   r@   rX   r   rY   rb   r  r_   rS   ra   rV   rT   orderss               rB   watch_orderszwoofipro.watch_orderst  s      !!!""669eD*1%8I6FI#67[[(FH%F3<'K 
 ++gv.))+w????OOFE2E00tTT# 	" @s"   CCB CC8CCc                   K   | j                          d{    | j                  |ddd      }|rdnd}| j                  |d      }d}|| j                  |      }|d   }|d	|z   z  }d
|d}	| j	                  |	|      }
| j                  ||
       d{   }| j                  r|j                  ||      }| j                  ||||d      S 7 7 9w)a  
        watches information on multiple trades made by the user

        https://orderly.network/docs/build-on-evm/evm-api/websocket-api/private/execution-report
        https://orderly.network/docs/build-on-evm/evm-api/websocket-api/private/algo-execution-report

        :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>`
        Nr  r  Fr  r  myTradesrX   r  rU   r]   Tr  r  s               rB   watch_my_tradeszwoofipro.watch_my_trades  s      !!!""669eD*1%8I66* [[(FH%F3<'K 
 ++gv.))+w????OOFE2E00tTT# 	" @s"   CCA>CC8CCc           	         | 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      }|}t	        j                  ||      rt	        j                  ||      }| j                  |d      }| 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      S )Nr   rX   rs   totalFeer   r   r   avgPrice0quantityr   r   totalExecutedQuantitystatusclientOrderIdtriggerPricer   rP   rz   lastTradeTimestamptimeInForcepostOnly	stopPricer   r   r   )filled	remainingr&  r   r   )rk   ra   rG   r   r   	string_eqr   	string_ge
string_subparse_order_status
safe_orderr   )r@   r   ra   r   rr   rX   rs   r   priceStringr   r"  r   r   r   r-  totalExecQuantityr.  	rawStatusr&  r   r'  r(  s                         rB   parse_ws_orderzwoofipro.parse_ws_order  s   D ""5)4##E84X&!%%e[9	$$UJ7((
;
 &&ug6  0##E:6[#.H4HE!!%4%%eV4%%eV4!!%)@A ,,U4KL	V%67**96GHI$$UH5	((3((@''~>  
E 
f 
 ' 
 ]	 

  
 Y/ 
 !) 
 D 
 4 
  
 D 
 U 
  
 L 
 f 
  D! 
" t# 
$ "- 
  	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_   rg   r   r   )	rk   r   
isinstancelistr   r   	omit_zerohandle_my_tradehandle_order)r@   re   rT   r_   rg   r   r   r   s           rB   handle_order_updatezwoofipro.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 )NrX   rP   r2   r.   r   feesr   rs   rz   r  )r7  rk   r  rG   r:   r   rF   hashmapr   r   r   rq   )r@   re   rT   r_   r   rX   r   rY   cachedOrdersr  r   r   r@  messageHashSymbols                 rB   r=  zwoofipro.handle_orderZ  sh   $$W-!!&(3""640{{"))$,,tL4U;;;L^^L$8$8&"EFNN673E ooeU3?$'F5M~~eV4#%)F6N#'>>%#Bx &*&7&7{&K{#%)%5%5eZ%Hz"'NN4;;. %f 4NN4;;(9:) rC   c                 p   d}| j                  |d      }| j                  |      }|d   }| j                  ||      }| j                  }|/| j	                  | j
                  dd      }	t        |	      }|| _        |j                  |       |j                  ||       |dz   |z   }
|j                  ||
       y )Nr  rX   r1   r.   r  )	rk   rl   r   r  rG   r:   r   r   rq   )r@   re   rT   rS   rr   ra   rX   r   r   rY   symbolSpecificMessageHashs              rB   r<  zwoofipro.handle_my_tradet  s    : !##GX6!!(+!##GV4>%%dllM4HE+E2F"DMev{+$/#$5$>!v89rC   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://orderly.network/docs/build-on-evm/evm-api/websocket-api/private/position-push

        watch all open positions
        :param str[] [symbols]: list of unified market symbols
 @param since timestamp in ms of the earliest position to fetch
 @param limit the maximum number of positions to fetch
        :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(   rO   r&   r/   Tr0   rU   positionr]   )r`   r   is_emptyr   r   r   r8   r-   re   set_positions_cachehandle_optionrH  r   filter_by_symbols_since_limitr  r   )r@   r   r   rY   rb   r  r   rX   rI   re   r/   r0   rt   rV   newPositionss                  rB   watch_positionszwoofipro.watch_positions  s     !!!%%g.}}W%1c'l+ = $$]V%;<=   -iit$Y/#5F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)rL  r   r   spawnload_positions_snapshotr   rH  )r@   re   r   r   r/   rS   s         rB   rK  zwoofipro.set_positions_cache  sa    !%!3!34DF^`e!f!2K6>>1k*

477M 2 67DNrC   c                   K   | j                          d {   }t               | _        | j                  }t        dt	        |            D ]B  }||   }| j                  |dd      }t        j                  |d      s2|j                  |       D |j                  |   }|j                  |       |j                  |d       y 7 w)Nr   	contractsr#  rH  )fetch_positionsr   rH  r   r   rk   r   	string_gtr   r   rq   )	r@   re   rS   rH  cacher   rI  rT  r   s	            rB   rR  z woofipro.load_positions_snapshot  s     ..00	13q#i.) 	'A |H((;DI  C0X&		' ,uuk* 1s   CCA%C=ACc                    | j                  |di       }| j                  |dg       }| j                  t               | _        | j                  }g }t	        dt        |            D ]x  }||   }| j                  |d      }	| j                  |	      }
| j                  ||
      }|j                  |       |j                  |       d|
d   z   }|j                  ||       z |j                  |d       y )Nrg   rH  r   rX   rG  )rF   r   rH  r   r   r   rk   rl   parse_ws_positionr   rq   )r@   re   rT   rg   rawPositionsrW  rN  r   rawPositionrr   ra   rI  rS   s                rB   handle_positionszwoofipro.handle_positions  s    B ~~gvr2~~dK<>>!57DNq#l+, 	2A&q/K''X>H%%h/F--k6BH)LL"'&*::KNN8[1	2 	|[1rC   c                 h   | j                  |d      }| j                  ||      }| j                  |d      }d }t        j                  |d      rd}nd}| j                  |d      }| j                  |d      }| j	                  |d      }| j                  |d	      }	| j                  |d
      }
t        j
                  |      }t        j                  ||      }| j                  i d|dd d| j                  |d      d|d| j                  |      dd dd dd dd dd d| j                  |	      d| j                  |      dd d| j                  |
      d| j                  |      d| j                  |      dd | j                  |d      | j                  |      d d dd |d d d d d      S )NrX   positionQtyr#  longshortcontractSize	markPricers   averageOpenPriceunsettledPnlr   rP   rz   lastUpdateTimestampinitialMargininitialMarginPercentagemaintenanceMarginmaintenanceMarginPercentage
entryPricenotionalleverageunrealizedPnlrT  marginRatioestLiqPricecross)liquidationPricerb  	lastPrice
collateral
marginMode
marginTyper   r   hedgedstopLossPricetakeProfitPrice)rk   rl   r   rV  rG   
string_absr   safe_positionr   parse_numberr   )r@   rI  ra   contractr   r   ra  rb  rs   rj  unrealisedPnlrk  s               rB   rY  zwoofipro.parse_ws_position  sC   2 ##Hh7!!(F3-8T3'DD''?$$X{;	%%h<	%%h0BC
((>B!!$'%%dI6!! #
H#
$#
 d&&vx8#
 	#

 Y/#
 "4#
 T#
 &t#
  #
 *4#
 $++J7#
 ))(3#
 #
 T..}=#
 **40#
  D--l;!#
" 4##
$ !% 0 0= I**95!!#9#
  	rC   c                    K   | j                          d{    d}|}d|d}| j                  ||      }| j                  ||       d{   S 7 97 w)aw  
        watch balance and get the amount of funds available for trading or funds locked in orders

        https://orderly.network/docs/build-on-evm/evm-api/websocket-api/private/balance

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        NbalancerU   r]   )r`   rQ   r  )r@   rb   r_   rS   rV   rT   s         rB   watch_balancezwoofipro.watch_balanceW  sd      !!! 
 ++gv.''W=== 	" >s!   AA4AAAAc                    | j                  |di       }| j                  |di       }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 )Nrg   balancesrh   r   rs   rz   r   holdingfrozentotalusedfreer  )rF   r:  keysrG   r  r   r   r   r   accountrk   r   r1  safe_balancerq   )r@   re   rT   rg   r  r  rh   r   keyvaluecoder  r  r  s                 rB   handle_balancezwoofipro.handle_balancej  s_   8 ~~gvr2>>$
B7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)Nr   FerrorMsg r6   r   T)r   rk   rP   r   throw_exactly_matched_exceptionr<   	Exceptionr9  r   r   r   )r@   re   rT   r   errorMessagefeedbackr   rS   s           rB   handle_error_messagezwoofipro.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                 n   | j                  ||      ry | 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   pongrU   r[   rw   r   r   r   r   r  r  rI  r  r   r^   r_   r\      rE   r   r   )r  handle_pinghandle_ponghandle_subscriberu   r   r   r   r   r   r>  r\  r  r   rk   r   r  r   )r@   re   rT   methodsr^   methodr_   
splitTopicsplitLengthrc   	splitNamesplitNameLengths               rB   handle_messagezwoofipro.handle_message  s   $$VW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@   re   s     rB   r4   zwoofipro.ping        rC   c                 
    ddiS )Nr^   r  r  r@   re   rT   s      rB   r  zwoofipro.handle_ping  r  rC   c                 0    | j                         |_        |S N)millisecondslastPongr  s      rB   r  zwoofipro.handle_pong  s     ++-rC   c                     |S r  r  r  s      rB   r  zwoofipro.handle_subscribe  s	     rC   r  )<__name__
__module____qualname__r   r?   rL   rW   r   r	   r   rd   r   ru   r   rx   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  r7  r>  r=  r<  r   rO  rK  rR  r\  rY  r   r  r  r  r  r4   r  r  r  __classcell__)rA   s   @rB   r   r      s   7# 7rS @DB !S ! !S\ !.!) !)F 68 7 7F 7,"HF : 6:" @7 @ @,&V &@ 8<B @W @7 @,&V &4  8<$]ajl H HC HWZ Hquvzq{ H<**6 **X <@d[] U US U Ubfglbm U4&6 &:FP:& :* )+ 8 @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tl,3& ,3\;6 ;4*:f *:X 8<$]ajl $_W $_C $_WZ $_quv~q $_L8& 8 8+02dEN *, > >&/0b6 2+0V +0Z!6 !!& !& 	v 	rC   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   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     sK     A  A p p p p 4  0 ) %gt!!** grC   