
    E#iJ                         S SK rS SKJrJrJrJr  S SKrS SKJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr   " S	 S
\R@                  RB                  5      r!g)    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                     ^  \ rS rSrS\4U 4S jjr0 4S jrSS0 4S\S\S\S\	\
   4S	 jjrSS0 4S
\	\   S\S\S\	\
   4S jjrS\4S jrS8S\
4S jjrSSS0 4S\S\S\S\S\	\   4
S jjrSS0 4S\	\	\      S\S\4S jjrS\4S jrS8S\S\4S jjrS0 4S\S\S\4S jjrS0 4S
\	\   S\S\4S jjrS\4S jr0 4S\S\4S jjrS0 4S
\S\4S jjrS\4S jrS0 4S
\S\4S jjr S\4S jr!S8S jr"0 4S\#4S  jjr$S! r%SSS0 4S
\S\S\S\	\&   4S" jjr'S\4S# jr(S8S\4S$ jjr)SSS0 4S\*S\S\S\	\+   4S% jjr,S\4S& jr-S0 4S\S'\.S(\/S)\0S*\1S\+4S+ jjr2SS0 4S,\S\S'\.S(\/S)\1S*\1S\+4S- jjr3S\4S. jr4S0 4S,\S\*S\+4S/ jjr5S0 4S0\	\   S\*4S1 jjr60 4S2 jr7S\4S3 jr8S\4S4 jr9S\4S5 jr:S\4S6 jr;S7r<U =r=$ )9oxfun   returnc                    > U R                  [        [        U ]  5       0 SS_SS_SS_SS_SS_SS_SS_S	S_S
S_SS_SS_SS_SS_SS_SS_SS_SS_SSSS.0SSSSSSSSS S!S"S#.S$S%0S&.U R                  S'S(.S).5      $ )*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   describerL   )self	__class__s    H/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/oxfun.pyrT   oxfun.describe   sU   eT ; =dt ( !$	
 +D d ' t   t       t   !" !$#( 9>    !"!!""#" w#& 		"Y0@
 0 0	    c                    #    U R                   S   S   nSUS.nU R                  XAU R                  XS5      U5      I S h  vN $  N7f)Nr1   r    	subscribeopargs)rO   watch_multipleextend)rU   messageHashes	argsArrayparamsurlrequests         rW   subscribe_multipleoxfun.subscribe_multipleF   sL     iit$
 ((T[[=Y[hiiiis   =AA ANsymbolsincelimitc                 F   #    U R                  U/X#U5      I Sh  vN $  N7f)a9  
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)rU   rh   ri   rj   rc   s        rW   watch_tradesoxfun.watch_tradesN   s$      22F8U6RRRRs   !!symbolsc                   #    U R                  5       I Sh  vN   U R                  USS5      n/ n/ n[        S[        U5      5       HD  nX   nSU-   n	UR	                  U	5        U R                  U5      n
SU
-   nUR	                  U5        MF     U R                  XeU5      I Sh  vN nU R                  (       a6  U R                  US0 5      nU R                  US5      nUR                  X5      nU R                  XUSS5      $  N Na7f)	a  
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:rh   	timestampT)load_marketsmarket_symbolsrangelenappend	market_idrf   
newUpdates	safe_dictsafe_stringgetLimitfilter_by_since_limit)rU   ro   ri   rj   rc   r^   ra   irh   messageHashmarketIdargtradesfirsttradeSymbols                  rW   rl   oxfun.watch_trades_for_symbols]   s     !!!%%gtU;q#g,'AZF(61K  -~~f-HX%CKK ( ..}FKK??NN61b1E**5(;KOOK7E))&TRR! 	" Ls#   DDBD$D%A DDclientc                    U R                  US/ 5      n[        S[        U5      5       H  nU R                  X40 5      nU R	                  U5      nU R                  US5      nSU-   nXpR                  ;  a5  U R                  U R                  SS5      n	[        U	5      U R                  U'   U R                  U   n
U
R                  U5        UR                  X5        M     g )Ndatar   rh   rq   tradesLimit  )	safe_listru   rv   rz   parse_ws_trader{   r   safe_integerrP   r   rw   resolve)rU   r   messager   r~   tradeparsedTraderh   r   r   storeds              rW   handle_tradesoxfun.handle_trades|   s    " ~~gvr2q#d)$ANN4B/E--e4K%%k8<F#f,Kkk)"//mTR&0&=F#[[(FMM+&NN6/ %rY   c                 n   U R                  US5      nU R                  X25      nU R                  US5      nU R                  UUU R	                  U5      US   U R                  US5      S S U R                  US5      U R                  US5      U R                  US5      U R                  US5      S S S	.5      $ )
N
marketCoderr   rh   tradeId	matchTypesidepricequantity)inforr   datetimerh   idordertypetakerOrMakerr   r   amountcostfee)r{   safe_marketr   
safe_tradeiso8601safe_string_lowersafe_number)rU   r   marketr   rr   s        rW   r   oxfun.parse_ws_trade   s     ##E<8!!(3%%e[9	"Y/X&""5)4 225+F**5&9%%eW5&&uj9 
  	rY   r>   	timeframec                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  U R                  S0 5      nU R	                  XrU5      nSU-   S-   US   -   n	SU-   S-   U-   n
U R
                  S   S   nS	U	/S
.nU R                  XU R                  X5      U
5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XUSS5      $  N N<7f)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
NrK   candles:r   ohlcv:r1   r    r[   r\   r   T)rs   r   rz   rP   r{   rO   watchr`   ry   r|   r}   )rU   rh   r   ri   rj   rc   r   rK   intervalr^   r   rd   re   ohlcvss                 rW   watch_ohlcvoxfun.watch_ohlcv   s      !!!V$^^DLL,C
##J9E8#c)F4L8'#-	9iit$F
 zz#DKK4PR]^^??OOF2E))&4HH 	" _s"   C0C,BC01C.2;C0.C0symbolsAndTimeframesc                   #    [        U5      nUS:X  d  [        US   [        5      (       d  [        U R                  S-   5      eU R                  5       I Sh  vN   / n/ nU R                  U R                  S0 5      n[        S[        U5      5       Hl  n	X   n
U
S   nU
S   nU R                  U5      nU R                  XU5      nSU-   S-   U-   nUR                  U5        SU-   S-   U-   nUR                  U5        Mn     U R                  XvU5      I Sh  vN u  nnnU R                  (       a  UR                  UU5      nU R                  UX#SS	5      nU R!                  UUU5      $  GN NU7f)
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']]NrK      r   r   zmulti:ohlcv:T)rv   
isinstancelistr   r   rs   rz   rP   ru   rx   r{   rw   rf   ry   r|   r}   create_ohlcv_object)rU   r   ri   rj   rc   symbolsLengthr^   ra   rK   r~   symbolAndTimeframesymtfr   r   r   r   rh   r   r   filtereds                        rW   watch_ohlcv_for_symbolsoxfun.watch_ohlcv_for_symbols   s     01AZ0DQ0G%N%N#DGG  /h  %h  i  i!!!^^DLL,C
q#234A!5!8$Q'C#A&B~~c*H''
;Hh&,x7CKK(3.4r9K  - 5 ,0+B+B=X^+_%_"	7??$$VU3E--guQM''	8DD% 	" &`s&   AE/E*B?E/E-AE/-E/c                    U R                  US5      nUR                  S5      nU R                  USS5      nU R                  U5      nU R                  US/ 5      nU R	                  US0 5      nU R                  US5      n	U R                  U	5      n
U R                  X5      nXR                  ;  a  0 U R                  U'   X`R                  U   ;  a8  U R                  U R                  SS	5      n[        U5      U R                  U   U'   U R                  US
/ 5      nU R                  X5      nU R                  U   U   nUR                  U5        SU-   S-   U-   nUR                  UU5        SU-   nUR                  XU/U5        g )Ntabler   r    r   r   r   
OHLCVLimitr   candler   r   zmulti:)r{   splitfind_timeframer   rz   r   safe_symbolr   r   rP   r   parse_ws_ohlcvrw   r   )rU   r   r   r   partstimeframeIdr   messageDatar   r   r   rh   rj   r   parsedr   r   messageHashForMultis                     rW   handle_ohlcvoxfun.handle_ohlcv   sy   (   '2I&&&ua4''4	nnWfb9~~k1b1##D,7!!(+!!(3++%"$DKK[[00%%dllL$GE-B5-IDKK	*h3$$V4V$Y/f'#-	9v{+ '4624GHrY   r   c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Nr   r               )r   r   )rU   ohlcvr   s      rW   r   oxfun.parse_ws_ohlcv)  sn     eQ'UA&UA&UA&UA&UA&
 	
rY   c                 D   #    U R                  U/X#5      I Sh  vN $  N7f)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)rU   rh   rj   rc   s       rW   watch_order_bookoxfun.watch_order_book>  s"      66xOOOOs     c                 (  #    U R                  5       I Sh  vN   U R                  U5      nSnU R                  U R                  S0 5      nU R	                  US5      nUb  UnOUb  US::  a  SnOUS::  a  SnOUS	::  a  S
n/ n/ n[        S[        U5      5       HG  n	X   n
SU
-   nUR                  U5        U R                  U
5      nUS-   U-   nUR                  U5        MI     U R                  XU5      I Sh  vN nUR                  5       $  N N7f)ae  
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
NrJ   r#   rI      depthL5
   depthL10   depthL25r   
orderbook:r   )rs   rt   rz   rP   r{   ru   rv   rw   rx   rf   rj   )rU   ro   rj   rc   rI   rP   defaultChannelr^   ra   r~   rh   r   r   r   	orderbooks                  rW   r   "oxfun.watch_order_book_for_symbolsL  s!     !!!%%g.../?D))'9=%$Gz#"$"$q#g,'AZF&/K  -~~f-HC-(*CKK ( 11-vNN	  1 	". Os"   DDC"D9D:DDc                    U R                  US0 5      nU R                  US5      nU R                  U5      nU R                  US5      nSU-   nXPR                  ;  a  U R                  0 5      U R                  U'   U R                  U   nU R                  X5USS5      n	UR                  U	5        U R                  US5      US'   XR                  U'   UR                  X5        g )	Nr   r   rr   r   asksbidsseqNumnonce)	rz   r{   r   r   
orderbooks
order_bookparse_order_bookresetr   )
rU   r   r   r   r   rh   rr   r   r   snapshots
             rW   handle_order_bookoxfun.handle_order_books  s    * ~~gvr2##D,7!!(+%%dK8	"V+//)&*oob&9DOOF#OOF+	((y&&Q!!..tX>	'"+y.rY   c                 f   #    U R                  U/U5      I Sh  vN nU R                  X15      $  N7f)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)rU   rh   rc   tickers       rW   watch_tickeroxfun.watch_ticker  s2      ))6(F;;v.. <s   1/1c                   #    U R                  5       I Sh  vN   USL nUn/ nU(       a  U R                  nUR                  S5        / n[        S[	        U5      5       HK  nXG   nSU-   n	UR                  U	5        U R                  U5      n
U(       a  M7  UR                  SU
-   5        MM     U R                  XeU5      I Sh  vN nU R                  (       a  0 nXUS   '   U$ U R                  U R                  SU5      $  N N?7f)a   

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:rh   )
rs   ro   rw   ru   rv   rx   rf   ry   filter_by_arraytickers)rU   ro   rc   
allSymbolsr   r^   ra   r~   rh   r   r   	newTickerresults                rW   r   oxfun.watch_tickers  s      !!!o
,,CKK%q#c(#AVF)F2K  -~~f-H:I01 $ 11-vNN	??F*39X&'M##DLL(GDD) 	" Os(   DD A:D-DD>DDc                     U R                  US/ 5      n[        S[        U5      5       HO  nU R                  X40 5      nU R	                  U5      nUS   nSU-   nX`R
                  U'   UR                  Xh5        MQ     g )Nr   r   rh   r   )r   ru   rv   rz   parse_tickerr   r   )	rU   r   r   r   r~   	rawTickerr   rh   r   s	            rW   handle_tickeroxfun.handle_ticker  sw    0 ~~gvr2q#d)$At3I&&y1FH%F$v-K#)LL NN6/ %rY   c                   #    U R                  5       I Sh  vN   U R                  USS5      n/ n/ n[        S[        U5      5       HD  nU R	                  X   5      nUR                  SUS   -   5        UR                  SUS   -   5        MF     U R                  X4U5      I Sh  vN nU R                  (       a  0 nXxUS   '   U$ U R                  U R                  SU5      $  N N?7f)a8  

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:rh   )
rs   rt   ru   rv   r   rw   rf   ry   r   bidsasks)	rU   ro   rc   ra   r^   r~   r   
newTickersr   s	            rW   watch_bids_asksoxfun.watch_bids_asks  s      !!!%%gtU;q#g,'A[[,FKKt45  VH-=!=> (  22=OO
??G,6Jx()N##DMM8WEE 	" Ps"   C&C"BC&$C$%>C&$C&c                     U R                  US0 5      nU R                  U5      nUS   nX@R                  U'   SU-   nUR                  XF5        g )Nr   rh   r	  )rz   parse_ws_bid_askr
  r   )rU   r   r   r   parsedTickerrh   r   s          rW   handle_bid_askoxfun.handle_bid_ask  sR    & ~~gvr2,,T2h' ,f&(|1rY   c                    U R                  US5      nU R                  X25      nU R                  US5      nU R                  US5      nU R                  US/ 5      nU R                  US/ 5      nU R	                  UUU R                  U5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      US.U5      $ )	Nr   rh   rr   askbidr   r   )rh   rr   r   r  	askVolumer  	bidVolumer   )r{   r   r   r   safe_tickerr   r   )rU   r   r   r   rh   rr   r  r  s           rW   r  oxfun.parse_ws_bid_ask  s    ##FL9!!(3!!&(3%%fk:	nnVUB/nnVUB/"Y/##C+))#q1##C+))#q1	!
 	 		rY   c                    #    U R                  5       I Sh  vN   U R                  5         SnSnU R                  S   S   nSU/S.nU R                  XCU R	                  XQ5      U5      I Sh  vN $  NZ N7f)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balancer1   r    r[   r\   )rs   authenticaterO   r   r`   )rU   rc   r^   r   rd   re   s         rW   watch_balanceoxfun.watch_balance+  s~      !!!iit$F
 ZZ$++g2NP[\\\ 	" ]s"   A5A1AA5,A3-A53A5c                    U R                  US5      nU R                  US5      nX R                  S'   X@R                  S'   U R                  U5      U R                  S'   [	        S[        U5      5       H  nU R                  X50 5      nU R                  US5      nU R                  U5      nXR                  ;  a  U R                  5       U R                  U'   U R                  U   n	U R                  US5      U	S'   U R                  US5      U	S	'   U R                  US
5      U	S'   XR                  U'   M     U R                  U R                  5      U l        UR                  U R                  S5        g )Nr   rr   r   r   r   instrumentIdtotalreservedused	availablefreer  )r   r   r  r   ru   rv   rz   r{   safe_currency_codeaccountsafe_balancer   )
rU   r   r   balancesrr   r~   r  
currencyIdcoder'  s
             rW   handle_balanceoxfun.handle_balance@  sA   ( >>'62%%g{;	&V$-[!#'<<	#:Z q#h-(AnnX"5G))'>BJ**:6DLL(%)\\^T"ll4(G#//AGG"..w
CGFO"..wDGFO!(LL ) ((6t||Y/rY   c                 0  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   USL nUn/ nU(       a  U R                  nUR                  S5        / n[	        S[        U5      5       HK  n	Xi   n
SU
-   nUR                  U5        U R                  U
5      nU(       a  M7  UR                  SU-   5        MM     U R                  XU5      I Sh  vN nU R                  (       a  U$ U R                  U R                  XUS5      $  N N N97f)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)rs   r  ro   rw   ru   rv   rx   rf   ry   filter_by_symbols_since_limit	positions)rU   ro   ri   rj   rc   r   r   r^   ra   r~   rh   r   r   newPositionss                 rW   watch_positionsoxfun.watch_positionsg  s     !!!!!!o
,,CKK'q#c(#AVF+f4K  -~~f-H:K(23 $ "44]&QQ??11$..'RWY]^^' 	"! Rs8   DDDDA:D--DD6DDDc                 P   U R                   c  [        5       U l         U R                   nU R                  US/ 5      n[        S[	        U5      5       HR  nU R                  XE0 5      nU R                  U5      nUS   nSU-   n	UR                  U5        UR                  Xy5        MT     g )Nr   r   rh   r/  )	r1  r   r   ru   rv   rz   parse_ws_positionrw   r   )
rU   r   r   cacher   r~   rawPositionpositionrh   r   s
             rW   handle_positionsoxfun.handle_positions  s    * >>!57DN~~gvr2q#d)$A.."5K--k:Hh'F&/KLL"NN81 %rY   c                    U R                  US5      nU R                  X25      nU R                  0 SU_SS _SUS   _SS _SS_SU R                  US	5      _S
U R                  US
5      _SU R                  US5      _SS _SS _SU R                  US5      _SS _SS _SS _SS _SS _SS _S U R	                  US5      S S S S S S S S S S.E5      $ )Nr   r   r   rh   notional
marginModecrossliquidationPriceestLiquidationPrice
entryPriceunrealizedPnlpositionPnlrealizedPnl
percentage	contractsr   contractSize	markPrice	lastPricer   hedgedrr   lastUpdated)r   lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentageleveragemarginRatiostopLossPricetakeProfitPrice)r{   r   safe_positionr   r   )rU   r9  r   r   s       rW   r6  oxfun.parse_ws_position  su    ##Hn=!!(3!! #
H#
$#
 fX&#
 	#

 '#
  0 0;P Q#
 $**8\B#
 T--hF#
 4#
 $#
 ))(J?#
 D#
 #
 #
 D#
  d!#
" ##
$ #'#4#4X}#M!%+/!'+!#9#
  	rY   c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnSnU R                  U5      nUc  US-  nOUSU-   -  nUSUS   -   -  nSU/S.nU R                  S	   S
   n	U R	                  XX5      I Sh  vN n
U R
                  (       a  U
R                  X5      nU R                  XX#S5      $  N N N=7f)aA  
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   r[   r\   r1   r    T)rs   r  r   rO   r   ry   r|   filter_by_symbol_since_limit)rU   rh   ri   rj   rc   r   r^   r   re   rd   rZ  s              rW   watch_ordersoxfun.watch_orders  s      !!!!!!!!&)>EMD3<'KC&,&&D
 iit$zz#GII??OOF2E00tTT) 	"!  Js2   CCCCA"CC:CCCc                    U R                  US/ 5      nSnU R                  c-  U R                  U R                  SS5      n[	        U5      U l        U R                  n[        S[        U5      5       H^  nU R                  X70 5      nU R                  U5      n	UR                  U	5        USU	S   -   -  nUR                  U R                  U5        M`     g )Nr   rZ  ordersLimitr   r   r   rh   )r   rZ  r   rP   r   ru   rv   rz   parse_orderrw   r   )
rU   r   r   r   r   rj   rZ  r~   r   parsedOrders
             rW   handle_ordersoxfun.handle_orders  s    6 ~~gvr2;;%%dllM4HE07DKq#d)$ANN4B/E**51KMM+&3X!666KNN4;;4 %rY   r   r   r   r   c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   [        U R                  5       5      nSUS.nU R	                  US5      nU R                  XX4XV5      n	U R                  U	S5      n
U
c  U R                  5       U	S'   XS'   U R                  S   S   nU R                  XX5      I Sh  vN $  N N N7f)	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]   tagrh  rr   r   r1   r    )
rs   r  strr   omitcreate_order_requestr   millisecondsrO   r   )rU   rh   r   r   r   r   rc   r   re   orderRequestrr   rd   s               rW   create_order_wsoxfun.create_order_ws$  s     0 !!!!!!$**,'
 65)!66vTSX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                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   [        U R                  5       5      nSUS.n	U R	                  US5      nU R                  X#XEXg5      n
U R                  U
SU05      n
U R                  U
S5      nUc  U R                  5       U
S'   XS'   U R                  S   S	   nU R                  XX5      I Sh  vN $  N N N7f)
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modifyorderrg  rh  orderIdrr   r   r1   r    )rs   r  ri  r   rj  rk  r`   r   rl  rO   r   )rU   r   rh   r   r   r   r   rc   r   re   rm  rr   rd   s                rW   edit_order_wsoxfun.edit_order_wsL  s     " !!!!!!$**,'
 65)!66vTSXa{{<)RA%%lK@	(,(9(9(;L%&iit$ZZ'GGG 	"! Hs2   C(C"C(C$B.C(C&C($C(&C(c                 r   U R                  US5      nU R                  US5      nU(       dW  U R                  US5      nU R                  U5      nU R                  US5      nU R	                  USUR
                  U0 Xb0 0 5	        U R                  US0 5      nU R                  U5      n	UR                  X5        g )Nrh  	submittedeventr+  r   r   )	r{   	safe_booljsonr   handle_errorsrd   r   ra  r   )
rU   r   r   r   rv  method	stringMsgr+  r   r   s
             rW   handle_place_ordersoxfun.handle_place_ordersn  s    < &&w6NN7K8	%%gw7F		'*I$$Wf5DtRVRUWY[\w3  &u*rY   c                 j  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  5       I Sh  vN   [	        U R                  5       5      nU R                  U5      US.nSUUS.nU R                  S   S   nU R                  XtXd5      I Sh  vN $  N{ Ne N7f)a:  

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   rr  cancelorder)r]   rh  r   r1   r    )	r   r   rs   r  ri  r   rx   rO   r   )rU   r   rh   rc   r   r   re   rd   s           rW   cancel_order_wsoxfun.cancel_order_ws  s      >#DGG.[$[\\!!!!!!$**,'..0

  

 iit$ZZ'GGG 	"! Hs4   /B3B-B3	B/
AB3(B1)B3/B31B3idsc                 0  #    [        U5      nUS:  a  [        U R                  S-   5      eUc  [        U R                  S-   5      eU R	                  5       I Sh  vN   U R                  5       I Sh  vN   [        U R                  5       5      nU R                  U5      n/ n[        SU5       H  nUX   S.n	UR                  U	5        M     SUUS.n
U R                  S	   S
   nU R                  XU R                  X5      U5      I Sh  vN $  N N N7f)af  

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]   rh  	dataArrayr1   r    )rv   r   r   r   rs   r  ri  r   rx   ru   rw   rO   r   rR   )rU   r  rh   rc   	idsLengthr   r   r  r~   r   re   rd   s               rW   cancel_orders_wsoxfun.cancel_orders_ws  s      H	r>TWW'YYZZ>#DGG.\$\]]!!!!!!$**,'>>&)	q)$A"D T" % !"

 iit$ZZ$2B2B72SU`aaa# 	"!  bs7   ADDD2D3BDDDDDc                 (  #    U R                   S   S   nU R                  U5      nSnUR                  U5      nU R                  UR                  U5      nUc  U R                  5         U R                  5       n[        U5      S-   nU R                  U R                  U5      U R                  U R                  5      [        R                  S5      n	SU R                  UU	S.S.n
U R                  X5      nU R                  X$X5        UI S h  vN $  N7f)	Nr1   r    authenticatedzGET/auth/self/verifybase64login)apiKeyrr   	signature)r]   r   )rO   r   reusableFuturerz   subscriptionscheck_required_credentialsrl  ri  hmacencodesecrethashlibsha256r  r`   r   )rU   rc   rd   r   r   futurer  rr   payloadr  re   r   s               rW   r  oxfun.authenticate  s     iit$S!%&&{3v';';[I ++-))+I)n'==G		$++g"6DKK8PRYR`R`bjkI"kk!*!*G kk'2GJJs>||s   D	DDDc                 (   U R                  USS5      nSnU(       a.  U R                  UR                  U5      nUR                  S5        g [	        U R                  U5      5      nUR                  Xd5        XAR                  ;   a  UR                  U	 g g )NsuccessFr  T)rx  rz   futuresr   r   ry  rejectr  )rU   r   r   r  r   r  errors          rW   handle_authentication_message#oxfun.handle_authentication_message  sz    w	5A%^^FNNK@FNN4 '		'(:;EMM%-222((5 3rY   c                     g)NrL    )rU   r   s     rW   rL   
oxfun.ping  s    rY   c                 0    U R                  5       Ul        U$ N)rl  lastPong)rU   r   r   s      rW   handle_pongoxfun.handle_pong  s    ++-rY   c                 2   US:X  a  U R                  X5        g U R                  US5      nU R                  US/ 5      nU R                  US5      nUGb	  UGb  US:X  a  U R                  X5        US:X  a  U R	                  X5        UR                  S5      S:  a  U R                  X5        UR                  S	5      S:  a  U R                  X5        UR                  S
5      S:  a  U R                  X5        UR                  S5      S:  a  U R                  X5        UR                  S5      S:  a  U R                  X5        US:X  a  U R                  X5        g g US:X  a  U R                  X5        US:X  d  US:X  d  US:X  a  U R                  X5        g g )Npongr   r   rw  r   r   r   rJ   r  r9  r   
bestBidAskr  rf  rq  r  )r  r{   r   r   r  findr   r   r,  r:  rc  r  r  r}  )rU   r   r   r   r   rw  s         rW   handle_messageoxfun.handle_message  s   fV-  '2~~gvr2  '2D$4""63 ""63zz)$r)!!&2zz'"R'&&v7zz)$r)##F4zz*%*%%f6zz'"R'""63$##F4 % 226C%5M+AuP]G]((9 H^rY   )r  rZ  r1  r  )>__name__
__module____qualname____firstlineno__r   rT   rf   ri  r	   r   r   rm   rl   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   r3  r:  r6  r   r   r]  rc  r   r   floatr   rn  rs  r}  r  r  r  r  rL   r  r  __static_attributes____classcell__)rV   s   @rW   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 > ?CQUdhqs I I I3 I^a Ix|  ~B  yC 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 : :rY   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   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   async_supportr   r  rY   rW   <module>r     s`     A  A  T  T  T  T  T 4  0 . 'M:D$$ M:rY   