
    ":hC                         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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@                  jB                        Z!y)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)AnyBalancesIntMarketNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTickersTrade)Client)List)AuthenticationError)ArgumentsRequired)
BadRequestc                       e Zd Zdef fdZi fdZddi fdedededee	   fdZ
ddi fd	ee   dededee	   fd
ZdefdZd5de	fdZdddi fdedededee   fdZddi fdeee      dedefdZdefdZd5dedefdZdi fdededefdZdi fd	ee   dedefdZdefdZi fdedefdZdi fd	edefdZdefdZdi fd	edefdZdefdZ d5dZ!i fde"fdZ#d Z$dddi fd	edededee%   fd Z&defd!Z'd5defd"Z(dddi fde)dededee*   fd#Z+defd$Z,di fded%e-d&e.d'e/d(e0de*fd)Z1ddi fd*eded%e-d&e.d'e0d(e0de*fd+Z2defd,Z3di fd*ede)de*fd-Z4di fd.ee   de)fd/Z5i fd0Z6defd1Z7defd2Z8defd3Z9defd4Z: xZ;S )6oxfunreturnc                     | j                  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iddddddddd d!d"d#d$d%id&| j                  d'd(d)      S )*NwsTwatchTradeswatchTradesForSymbolswatchOrderBookwatchOrderBookForSymbols
watchOHLCVwatchOHLCVForSymbolswatchOrderswatchMyTradesFwatchTickerwatchTickerswatchBidsAskswatchBalancecreateOrderWseditOrderWscancelOrderWscancelOrdersWsapizwss://api.ox.fun/v2/websocketz wss://stgapi.ox.fun/v2/websocket)r   test60s180s300s900s1800s3600s7200s14400s21600s43200s86400s)1m3m5m15m30m1h2h4h6h12h1dchanneldepth)
timeframesr"   iP  )ping	keepAlive)hasurlsoptions	streaming)deep_extendsuperr   describerK   )self	__class__s    H/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/pro/oxfun.pyrS   zoxfun.describe   sU   eT ; =dt ( !$	
 +D d ' t   t       t   !" !$#( 9>    !"!!""#" w#& 		"Y0@
 0 0	    c                    K   | j                   d   d   }d|d}| j                  ||| j                  ||      |       d {   S 7 w)Nr0   r   	subscribeopargs)rN   watch_multipleextend)rT   messageHashes	argsArrayparamsurlrequests         rV   subscribe_multiplezoxfun.subscribe_multipleF   sR     iit$
 ((mT[[RX=Y[hiiiis   ?AAANsymbolsincelimitc                 H   K   | j                  |g|||       d{   S 7 w)a  
        watches information on multiple trades made in a market

        https://docs.ox.fun/?json#trade

        :param str symbol: unified market symbol of the market trades were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of trade structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int|str [params.tag]: If given it will be echoed in the reply and the max size of tag is 32
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        N)watch_trades_for_symbols)rT   re   rf   rg   ra   s        rV   watch_tradeszoxfun.watch_tradesN   s'      22F8UE6RRRRs   " "symbolsc                   K   | j                          d{    | j                  |dd      }g }g }t        dt        |            D ]D  }||   }d|z   }	|j	                  |	       | j                  |      }
d|
z   }|j	                  |       F | j                  |||       d{   }| j                  r7| j                  |di       }| j                  |d      }|j                  ||      }| j                  |||dd      S 7 7 ^w)	aC  
        get the list of most recent trades for a particular symbol

        https://docs.ox.fun/?json#trade

        :param str[] symbols:
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int|str [params.tag]: If given it will be echoed in the reply and the max size of tag is 32
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        NFr   trades:ztrade:re   	timestampT)load_marketsmarket_symbolsrangelenappend	market_idrd   
newUpdates	safe_dictsafe_stringgetLimitfilter_by_since_limit)rT   rk   rf   rg   ra   r\   r_   ire   messageHashmarketIdargtradesfirsttradeSymbols                  rV   ri   zoxfun.watch_trades_for_symbols]   s     !!!%%gtU;q#g,' 	AQZF(61K  -~~f-HX%CKK	 ..}dFKK??NN61b1E**5(;KOOK7E))&%TRR! 	" Ls#   DDBD$D%ADDclientc                    | j                  |dg       }t        dt        |            D ]  }| j                  ||i       }| j	                  |      }| j                  |d      }d|z   }|| j                  vr5| j                  | j                  dd      }	t        |	      | j                  |<   | j                  |   }
|
j                  |       |j                  |
|        y )Ndatar   re   rm   tradesLimit  )	safe_listrq   rr   rv   parse_ws_traderw   r~   safe_integerrO   r   rs   resolve)rT   r   messager   rz   tradeparsedTradere   r{   r   storeds              rV   handle_tradeszoxfun.handle_trades|   s    " ~~gvr2q#d)$ 
	0ANN4B/E--e4K%%k8<F#f,Kdkk)"//mTR&0&=F#[[(FMM+&NN6;/
	0rW   c                 p   | j                  |d      }| j                  ||      }| j                  |d      }| j                  ||| j	                  |      |d   | j                  |d      d d | j                  |d      | j                  |d      | j                  |d      | j                  |d      d d d	      S )
N
marketCodern   re   tradeId	matchTypesidepricequantity)inforn   datetimere   idordertypetakerOrMakerr   r   amountcostfee)rw   safe_marketr   
safe_tradeiso8601safe_string_lowersafe_number)rT   r   marketr|   rn   s        rV   r   zoxfun.parse_ws_trade   s     ##E<8!!(F3%%e[9	"Y/X&""5)4 225+F**5&9%%eW5&&uj9 
  	rW   r=   c                   K   | j                          d{    | j                  |      }| j                  | j                  di       }| j	                  |||      }d|z   dz   |d   z   }	d|z   dz   |z   }
| j
                  d   d   }d	|	gd
}| j                  ||
| j                  ||      |
       d{   }| j                  r|j                  ||      }| j                  |||dd      S 7 7 9w)a  
        watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://docs.ox.fun/?json#candles

        :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
        :param int|str [params.tag]: If given it will be echoed in the reply and the max size of tag is 32
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        NrJ   candles:r   ohlcv:r0   r   rY   rZ   r   T)ro   r   rv   rO   rw   rN   watchr^   ru   rx   ry   )rT   re   	timeframerf   rg   ra   r   rJ   intervalr\   r{   rb   rc   ohlcvss                 rV   watch_ohlcvzoxfun.watch_ohlcv   s     !!!V$^^DLL,C
##J	9E8#c)F4L8'#-	9iit$F
 zz#{DKK4PR]^^??OOFE2E))&%4HH 	" _s"   C0C,BC04C.58C0.C0symbolsAndTimeframesc                   K   t        |      }|dk(  st        |d   t              st        | j                  dz         | j                          d{    g }g }| j                  | j                  di       }t        dt        |            D ]m  }	||	   }
|
d   }|
d   }| j                  |      }| j                  |||      }d|z   dz   |z   }|j                  |       d|z   dz   |z   }|j                  |       o | j                  |||       d{   \  }}}| j                  r|j                  ||      }| j                  |||dd	      }| j!                  |||      S 7 7 Qw)
a  
        watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://docs.ox.fun/?json#candles

        :param str[][] symbolsAndTimeframes: array of arrays containing unified symbols and timeframes to fetch OHLCV data for, example [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]
        :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
        :param int|str [params.tag]: If given it will be echoed in the reply and the max size of tag is 32
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r   zw watchOHLCVForSymbols() requires a an array of symbols and timeframes, like  [['BTC/USDT:OX', '1m'], ['OX/USDT', '5m']]NrJ      r   r   zmulti:ohlcv:T)rr   
isinstancelistr   r   ro   rv   rO   rq   rt   rw   rs   rd   ru   rx   ry   create_ohlcv_object)rT   r   rf   rg   ra   symbolsLengthr\   r_   rJ   rz   symbolAndTimeframesymtfr|   r   r}   r{   re   r   r   filtereds                        rV   watch_ohlcv_for_symbolszoxfun.watch_ohlcv_for_symbols   s     01AZ0DQ0G%N#DGG  /h  %h  i  i!!!^^DLL,C
q#234 		.A!5a!8$Q'C#A&B~~c*H''
B;Hh&,x7CKK(3.4r9K  -		. ,0+B+B=RVX^+_%_"	7??$$VU3E--gueQM''	8DD% 	" &`s&   AE&E!C E&E$AE&$E&c                    | j                  |d      }|j                  d      }| j                  |dd      }| j                  |      }| j                  |dg       }| j	                  |di       }| j                  |d      }	| j                  |	      }
| j                  |	|
      }|| j                  vri | j                  |<   || j                  |   vr8| j                  | j                  dd	      }t        |      | j                  |   |<   | j                  |d
g       }| j                  ||
      }| j                  |   |   }|j                  |       d|z   dz   |z   }|j                  ||       d|z   }|j                  |||g|       y )Ntabler   r    r   r   r   
OHLCVLimitr   candler   r   zmulti:)rw   splitfind_timeframer   rv   r   safe_symbolr   r   rO   r   parse_ws_ohlcvrs   r   )rT   r   r   r   partstimeframeIdr   messageDatar   r|   r   re   rg   r   parsedr   r{   messageHashForMultis                     rV   handle_ohlcvzoxfun.handle_ohlcv   s   (   '2I&&&ua4''4	nnWfb9~~k1b1##D,7!!(+!!(F3$++%"$DKKT[[00%%dllL$GE-B5-IDKK	*h3$$VV4V$Y/f'#-	9v{+ '4	624GHrW   r   c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   r               )r   r   )rT   ohlcvr   s      rV   r   zoxfun.parse_ws_ohlcv)  sn     eQ'UA&UA&UA&UA&UA&
 	
rW   c                 F   K   | j                  |g||       d{   S 7 w)a_  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://docs.ox.fun/?json#fixed-size-order-book
        https://docs.ox.fun/?json#full-order-book

        :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)watch_order_book_for_symbols)rT   re   rg   ra   s       rV   watch_order_bookzoxfun.watch_order_book>  s%      66xOOOOs   !!c                   K   | j                          d{    | j                  |      }d}| j                  | j                  di       }| j	                  |d      }||}n||dk  rd}n|dk  rd}n|d	k  rd
}g }g }t        dt        |            D ]G  }	||	   }
d|
z   }|j                  |       | j                  |
      }|dz   |z   }|j                  |       I | j                  |||       d{   }|j                         S 7 7 w)a  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://docs.ox.fun/?json#fixed-size-order-book
        https://docs.ox.fun/?json#full-order-book

        :param str[] symbols: unified array of symbols
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int|str [params.tag]: If given it will be echoed in the reply and the max size of tag is 32
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        NrI   r"   rH      depthL5
   depthL10   depthL25r   
orderbook:r   )ro   rp   rv   rO   rw   rq   rr   rs   rt   rd   rg   )rT   rk   rg   ra   rH   rO   defaultChannelr\   r_   rz   re   r{   r|   r}   	orderbooks                  rV   r   z"oxfun.watch_order_book_for_symbolsL  s,     !!!%%g.../?D))'9=%$Gz#"$"$q#g,' 	AQZF&/K  -~~f-HC-(*CKK	 11-vNN	  1 	". Os"   DD	CD4D5DDc                    | j                  |di       }| j                  |d      }| j                  |      }| j                  |d      }d|z   }|| j                  vr| j                  i       | j                  |<   | j                  |   }| j                  |||dd      }	|j                  |	       | j                  |d      |d<   || j                  |<   |j                  ||       y )	Nr   r   rn   r   asksbidsseqNumnonce)	rv   rw   r   r   
orderbooks
order_bookparse_order_bookresetr   )
rT   r   r   r   r|   re   rn   r{   r   snapshots
             rV   handle_order_bookzoxfun.handle_order_books  s    * ~~gvr2##D,7!!(+%%dK8	"V+$//)&*oob&9DOOF#OOF+	((vy&&Q!!..tX>	'"+y+.rW   c                 h   K   | j                  |g|       d{   }| j                  ||      S 7 w)a&  

        https://docs.ox.fun/?json#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
        :param int|str [params.tag]: If given it will be echoed in the reply and the max size of tag is 32
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        N)watch_tickers
safe_value)rT   re   ra   tickers       rV   watch_tickerzoxfun.watch_ticker  s5      ))6(F;;vv.. <s   202c                   K   | j                          d{    |du }|}g }|r| j                  }|j                  d       g }t        dt	        |            D ]E  }||   }d|z   }	|j                  |	       | j                  |      }
|r2|j                  d|
z          G | j                  |||       d{   }| j                  ri }|||d   <   |S | j                  | j                  d|      S 7 7 ;w)a8  

        https://docs.ox.fun/?json#ticker

        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
        :param int|str [params.tag]: If given it will be echoed in the reply and the max size of tag is 32
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nz
ticker:allr   tickers:zticker:re   )
ro   rk   rs   rq   rr   rt   rd   ru   filter_by_arraytickers)rT   rk   ra   
allSymbolsr   r\   r_   rz   re   r{   r|   	newTickerresults                rV   r   zoxfun.watch_tickers  s     !!!o
,,CKK%q#c(# 	2AVF)F2K  -~~f-HI01	2 11-vNN	??F*3F9X&'M##DLL(GDD) 	" Os(   C5C1A3C5,C57C38:C53C5c                     | j                  |dg       }t        dt        |            D ]Q  }| j                  ||i       }| j	                  |      }|d   }d|z   }|| j
                  |<   |j                  ||       S y )Nr   r   re   r   )r   rq   rr   rv   parse_tickerr   r   )	rT   r   r   r   rz   	rawTickerr   re   r{   s	            rV   handle_tickerzoxfun.handle_ticker  s    0 ~~gvr2q#d)$ 	0AtQ3I&&y1FH%F$v-K#)DLL NN6;/	0rW   c                   K   | j                          d{    | j                  |dd      }g }g }t        dt        |            D ]D  }| j	                  ||         }|j                  d|d   z          |j                  d|d   z          F | j                  |||       d{   }| j                  ri }|||d   <   |S | j                  | j                  d|      S 7 7 ;w)ah  

        https://docs.ox.fun/?json#best-bid-ask

        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>`
        NFr   zbestBidAsk:r   bidask:re   )
ro   rp   rq   rr   r   rs   rd   ru   r   bidsasks)	rT   rk   ra   r_   r\   rz   r   
newTickersr   s	            rV   watch_bids_askszoxfun.watch_bids_asks  s      !!!%%gtU;q#g,' 	?A[[,FKKt45  VH-=!=>	?  22=$OO
??G,6GJx()N##DMM8WEE 	" Ps"   C"CBC"$C %:C" C"c                     | j                  |di       }| j                  |      }|d   }|| j                  |<   d|z   }|j                  ||       y )Nr   re   r   )rv   parse_ws_bid_askr   r   )rT   r   r   r   parsedTickerre   r{   s          rV   handle_bid_askzoxfun.handle_bid_ask  sV    & ~~gvr2,,T2h' ,f&(|[1rW   c                    | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |dg       }| j                  |dg       }| j	                  ||| j                  |      | j                  |d      | j                  |d      | j                  |d      | j                  |d      |d|      S )	Nr   re   rn   askbidr   r   )re   rn   r   r  	askVolumer  	bidVolumer   )rw   r   r   r   safe_tickerr   r   )rT   r   r   r|   re   rn   r  r  s           rV   r   zoxfun.parse_ws_bid_ask  s    ##FL9!!(F3!!&(3%%fk:	nnVUB/nnVUB/"Y/##C+))#q1##C+))#q1	!
 	 		rW   c                    K   | j                          d{    | j                          d}d}| j                  d   d   }d|gd}| j                  ||| j	                  ||      |       d{   S 7 \7 w)a  

        https://docs.ox.fun/?json#balance-channel

        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
        :param int|str [params.tag]: If given it will be echoed in the reply and the max size of tag is 32
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nzbalance:allbalancer0   r   rY   rZ   )ro   authenticaterN   r   r^   )rT   ra   r\   r{   rb   rc   s         rV   watch_balancezoxfun.watch_balance+  s      !!!iit$F
 ZZ[$++gv2NP[\\\ 	" ]s"   A7A3AA7.A5/A75A7c                    | j                  |d      }| j                  |d      }|| j                  d<   || j                  d<   | j                  |      | j                  d<   t	        dt        |            D ]  }| j                  ||i       }| j                  |d      }| j                  |      }|| j                  vr| j                         | j                  |<   | j                  |   }	| j                  |d      |	d<   | j                  |d      |	d	<   | j                  |d
      |	d<   |	| j                  |<    | j                  | j                        | _        |j                  | j                  d       y )Nr   rn   r   r   r   instrumentIdtotalreservedused	availablefreer  )r   r   r  r   rq   rr   rv   rw   safe_currency_codeaccountsafe_balancer   )
rT   r   r   balancesrn   rz   r  
currencyIdcoder  s
             rV   handle_balancezoxfun.handle_balance@  sP   ( >>'62%%g{;	&V$-[!#'<<	#:Z q#h-( 
	)AnnXq"5G))'>BJ**:6DDLL(%)\\^T"ll4(G#//AGG"..w
CGFO"..wDGFO!(DLL
	) ((6t||Y/rW   c                   K   | j                          d{    | j                          d{    |du }|}g }|r| j                  }|j                  d       g }t	        dt        |            D ]E  }	||	   }
d|
z   }|j                  |       | j                  |
      }|r2|j                  d|z          G | j                  |||       d{   }| j                  r|S | j                  | j                  |||d      S 7 7 7 5w)a  

        https://docs.ox.fun/?json#position-channel

        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
        :param int|str [params.tag]: If given it will be echoed in the reply and the max size of tag is 32
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/en/latest/manual.html#position-structure>`
        Nzposition:allr   
positions:z	position:T)ro   r  rk   rs   rq   rr   rt   rd   ru   filter_by_symbols_since_limit	positions)rT   rk   rf   rg   ra   r   r   r\   r_   rz   re   r{   r|   newPositionss                 rV   watch_positionszoxfun.watch_positionsg  s     !!!!!!o
,,CKK'q#c(# 	4AVF+f4K  -~~f-HK(23	4 "44]D&QQ??11$..'5RWY]^^' 	"! Rs8   DDDDA3D#,DD2DDDc                 N   | j                   t               | _         | j                   }| j                  |dg       }t        dt	        |            D ]S  }| j                  ||i       }| j                  |      }|d   }d|z   }	|j                  |       |j                  ||	       U y )Nr   r   re   r  )	r  r   r   rq   rr   rv   parse_ws_positionrs   r   )
rT   r   r   cacher   rz   rawPositionpositionre   r{   s
             rV   handle_positionszoxfun.handle_positions  s    * >>!57DN~~gvr2q#d)$ 	2A..q"5K--k:Hh'F&/KLL"NN8[1	2rW   c                    | j                  |d      }| j                  ||      }| j                  i d|dd d|d   dd ddd| j                  |d	      d
| j                  |d
      d| j                  |d      dd dd d| j                  |d      dd dd dd dd dd dd d | j	                  |d      d d d d d d d d d d      S )Nr  r   r   re   notional
marginModecrossliquidationPriceestLiquidationPrice
entryPriceunrealizedPnlpositionPnlrealizedPnl
percentage	contractsr   contractSize	markPrice	lastPricer   hedgedrn   lastUpdated)r   lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentageleveragemarginRatiostopLossPricetakeProfitPrice)rw   r   safe_positionr   r   )rT   r"  r   r|   s       rV   r  zoxfun.parse_ws_position  sw    ##Hn=!!(F3!! #
H#
$#
 fX&#
 	#

 '#
  0 0;P Q#
 $**8\B#
 T--hF#
 4#
 $#
 ))(J?#
 D#
 #
 #
 D#
  d!#
" ##
$ #'#4#4X}#M!%+/!'+!#9#
  	rW   c                   K   | j                          d{    | j                          d{    d}d}| j                  |      }||dz  }n|d|z   z  }|d|d   z   z  }d|gd}| j                  d	   d
   }	| j	                  |	|||       d{   }
| j
                  r|
j                  ||      }| j                  |
|||d      S 7 7 7 ;w)a  
        watches information on multiple orders made by the user

        https://docs.ox.fun/?json#order-channel

        :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 int|str [params.tag]: If given it will be echoed in the reply and the max size of tag is 32
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Norderszorder:allr   r   rY   rZ   r0   r   T)ro   r  r   rN   r   ru   rx   filter_by_symbol_since_limit)rT   re   rf   rg   ra   r{   r\   r   rc   rb   rA  s              rV   watch_orderszoxfun.watch_orders  s      !!!!!!!!&)>EMD3<'KC&,&&D
 iit$zz#{G[II??OOFE2E00tTT) 	"!  Js2   CC
CCA#CC8CCCc                    | j                  |dg       }d}| j                  -| j                  | j                  dd      }t	        |      | _        | j                  }t        dt        |            D ]^  }| j                  ||i       }| j                  |      }	|j                  |	       |d|	d   z   z  }|j                  | j                  |       ` y )Nr   rA  ordersLimitr   r   r   re   )r   rA  r   rO   r   rq   rr   rv   parse_orderrs   r   )
rT   r   r   r   r{   rg   rA  rz   r   parsedOrders
             rV   handle_orderszoxfun.handle_orders  s    6 ~~gvr2;;%%dllM4HE07DKq#d)$ 	5ANN4B/E**51KMM+&3X!666KNN4;;4	5rW   r   r   r   r   c                   K   | j                          d{    | j                          d{    t        | j                               }d|d}| j	                  |d      }| j                  ||||||      }	| j                  |	d      }
|
| j                         |	d<   |	|d<   | j                  d   d   }| j                  ||||       d{   S 7 7 7 w)	a`  

        https://docs.ox.fun/?json#order-commands

        create a trade order
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market', 'limit', 'STOP_LIMIT' or 'STOP_MARKET'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.clientOrderId]: a unique id for the order
        :param int [params.timestamp]: in milliseconds. If an order reaches the matching engine and the current timestamp exceeds timestamp + recvWindow, then the order will be rejected.
        :param int [params.recvWindow]: in milliseconds. If an order reaches the matching engine and the current timestamp exceeds timestamp + recvWindow, then the order will be rejected. If timestamp is provided without recvWindow, then a default recvWindow of 1000ms is used.
        :param float [params.cost]: the quote quantity that can be used alternative for the amount for market buy orders
        :param float [params.triggerPrice]: The price at which a trigger order is triggered at
        :param float [params.limitPrice]: Limit price for the STOP_LIMIT order
        :param bool [params.postOnly]: if True, the order will only be posted if it will be a maker order
        :param str [params.timeInForce]: GTC(default), IOC, FOK, PO, MAKER_ONLY or MAKER_ONLY_REPRICE(reprices order to the best maker only price if the specified price were to lead to a taker trade)
        :param str [params.selfTradePreventionMode]: NONE, EXPIRE_MAKER, EXPIRE_TAKER or EXPIRE_BOTH for more info check here {@link https://docs.ox.fun/?json#self-trade-prevention-modes}
        :param str [params.displayQuantity]: for an iceberg order, pass both quantity and displayQuantity fields in the order request
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        N
placeorderr[   tagrM  rn   r   r0   r   )
ro   r  strr   omitcreate_order_requestr   millisecondsrN   r   )rT   re   r   r   r   r   ra   r{   rc   orderRequestrn   rb   s               rV   create_order_wszoxfun.create_order_ws$  s     0 !!!!!!$**,'
 65)!66vtT6SXZ`a%%lK@	(,(9(9(;L%&iit$ZZ[';GGG 	"! Hs2   CCCCBCCCCCr   c                   K   | j                          d{    | j                          d{    t        | j                               }d|d}	| j	                  |d      }| j                  ||||||      }
| j                  |
d|i      }
| j                  |
d      }|| j                         |
d<   |
|	d<   | j                  d   d	   }| j                  |||	|       d{   S 7 7 7 w)
a  
        edit a trade order

        https://docs.ox.fun/?json#modify-order

        :param str id: order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of the currency you want to trade in units of the base currency
        :param float|None [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.timestamp]: in milliseconds. If an order reaches the matching engine and the current timestamp exceeds timestamp + recvWindow, then the order will be rejected.
        :param int [params.recvWindow]: in milliseconds. If an order reaches the matching engine and the current timestamp exceeds timestamp + recvWindow, then the order will be rejected. If timestamp is provided without recvWindow, then a default recvWindow of 1000ms is used.
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        NmodifyorderrL  rM  orderIdrn   r   r0   r   )ro   r  rN  r   rO  rP  r^   r   rQ  rN   r   )rT   r   re   r   r   r   r   ra   r{   rc   rR  rn   rb   s                rV   edit_order_wszoxfun.edit_order_wsL  s     " !!!!!!$**,'
 65)!66vtT6SXZ`a{{<)RA%%lK@	(,(9(9(;L%&iit$ZZ[';GGG 	"! Hs2   C-C'C-C)B3C-"C+#C-)C-+C-c                 l   | j                  |d      }| j                  |d      }|sX| j                  |d      }| j                  |      }| j                  |d      }| j	                  |d |j
                  |d ||d d 	       | j                  |di       }| j                  |      }	|j                  |	|       y )NrM  	submittedeventr  r   )	rw   	safe_booljsonr   handle_errorsrb   r   rG  r   )
rT   r   r   r{   rY  method	stringMsgr  r   r   s
             rV   handle_place_orderszoxfun.handle_place_ordersn  s    < &&w6NN7K8	%%gw7F		'*I$$Wf5DtT6::vtYPWY]_cdw3  &uk*rW   c                 l  K   |t        | j                  dz         | j                          d{    | j                          d{    t	        | j                               }| j                  |      |d}d||d}| j                  d   d   }| j                  ||||       d{   S 7 }7 g7 w)ar  

        https://docs.ox.fun/?json#cancel-order

        cancels an open order
        :param str id: order id
        :param str symbol: unified market symbol, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz+ cancelOrderWs() requires a symbol argument)r   rV  cancelorder)r[   rM  r   r0   r   )	r   r   ro   r  rN  r   rt   rN   r   )rT   r   re   ra   r{   r   rc   rb   s           rV   cancel_order_wszoxfun.cancel_order_ws  s      >#DGG.[$[\\!!!!!!$**,'..0

  

 iit$ZZ[';GGG 	"! Hs4   .B4B.B4B0	A B4)B2*B40B42B4idsc                 .  K   t        |      }|dkD  rt        | j                  dz         |t        | j                  dz         | j	                          d{    | j                          d{    t        | j                               }| j                  |      }g }t        d|      D ]  }|||   d}	|j                  |	        d||d}
| j                  d	   d
   }| j                  ||| j                  |
|      |       d{   S 7 7 7 w)a  

        https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-mass-cancel-order

        cancel multiple orders
        :param str[] ids: order ids
        :param str symbol: unified market symbol, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
           z0 cancelOrdersWs() accepts up to 20 ids at a timeNz, cancelOrdersWs() requires a symbol argumentr   )instIdordIdcancelorders)r[   rM  	dataArrayr0   r   )rr   r   r   r   ro   r  rN  r   rt   rq   rs   rN   r   rQ   )rT   rd  re   ra   	idsLengthr{   r|   rj  rz   r   rc   rb   s               rV   cancel_orders_wszoxfun.cancel_orders_ws  s"      H	r>TWW'YYZZ>#DGG.\$\]]!!!!!!$**,'>>&)	q)$ 	#A"QD T"	# !"

 iit$ZZ[$2B2B7F2SU`aaa# 	"!  bs7   ADDD0D1BD
DDDDc                 ,  K   | j                   d   d   }| j                  |      }d}|j                  |      }| j                  |j                  |      }|| j                          | j                         }t        |      dz   }| j                  | j                  |      | j                  | j                        t        j                  d      }	d| j                  ||	dd}
| j                  |
|      }| j                  ||||       | d {   S 7 w)	Nr0   r   authenticatedzGET/auth/self/verifybase64login)apiKeyrn   	signature)r[   r   )rN   r   futurerv   subscriptionscheck_required_credentialsrQ  rN  hmacencodesecrethashlibsha256rq  r^   r   )rT   ra   rb   r   r{   rs  rn  rn   payloadrr  rc   r   s               rV   r  zoxfun.authenticate  s     iit$S!%{+v';';[I ++-))+I)n'==G		$++g"6DKK8PRYR`R`bjkI"kk!*!*G kk'62GJJsK+>||s   DDDDc                    | j                  |dd      }d}|r.| j                  |j                  |      }|j                  d       y t	        | j                  |            }|j                  ||       ||j                  v r|j                  |= y y )NsuccessFrn  T)r[  rv   futuresr   r   r\  rejectrt  )rT   r   r   rn  r{   rs  errors          rV   handle_authentication_messagez#oxfun.handle_authentication_message  s~    w	5A%^^FNNK@FNN4 '		'(:;EMM%-f222((5 3rW   c                      y)NrK    )rT   r   s     rV   rK   z
oxfun.ping  s    rW   c                 0    | j                         |_        |S N)rQ  lastPong)rT   r   r   s      rV   handle_pongzoxfun.handle_pong  s    ++-rW   c                 *   |dk(  r| j                  ||       y | j                  |d      }| j                  |dg       }| j                  |d      }|||dk(  r| j                  ||       |dk(  r| j	                  ||       |j                  d      dkD  r| j                  ||       |j                  d	      dkD  r| j                  ||       |j                  d
      dkD  r| j                  ||       |j                  d      dkD  r| j                  ||       |j                  d      dkD  r| j                  ||       |dk(  r| j                  ||       y y |dk(  r| j                  ||       |dk(  s
|dk(  s|dk(  r| j                  ||       y y )Npongr   r   rZ  r   r   r   rI   r  r"  r   
bestBidAskrp  rK  rU  rb  )r  rw   r   r   r   findr   r   r  r#  rI  r   r  r`  )rT   r   r   r   r   rZ  s         rV   handle_messagezoxfun.handle_message  s   fVW-  '2~~gvr2  '2D$4""673 ""673zz)$r)!!&'2zz'"R'&&vw7zz)$r)##FG4zz*%*%%fg6zz'"R'""673$##FG4 % 2267C%5M+AuP]G]((9 H^rW   r  )<__name__
__module____qualname__r   rS   rd   rN  r	   r   r   rj   ri   r   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	  r  r   r  r#  r  r   r   rD  rI  r   r   floatr   rS  rW  r`  rc  rl  r  r  rK   r  r  __classcell__)rU   s   @rV   r   r      s   1# 1f IK j <@d[] S SS S Sbfglbm S OSaenp Sd3i S S[^ Suyz  vA S>0F 0<E > 8<$]ajl I IC IWZ Iquvzq{ I< aesw  AC "E$tCy/ "EZ] "Emp "EH,I6 ,I\
F 
d 
* @DB PS P PS\ P SW_a %!$s) %!C %!fo %!N!/ !/F 68 / /F / 6:" E7 E EB0F 0B 8<B FW F7 F22V 24$ *, ] ]*%0N 8<$]ajl  _W  _C  _WZ  _quv~q  _D2v 2B-& -^ 04$UYbd !U !UC !Us !Uimnsit !UF&5F &5P pt|~ &HC &Hy &H	 &H[` &Hil &H  DI &HP im{  IK  Hc  H3  Hi  Hy  Hbe  Hux  H  PU  HD(+& (+T <@ H HS Hu H8 DHPR !b$s) !bS !bF )+ .6F 66 & :V :rW   r   )"ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r   ry  ccxt.base.typesr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   async_supportr   r  rW   rV   <module>r     s`     A  A  T  T  T  T  T 4  0 . 'M:D$$ M:rW   