
    ei0                         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         j!                  Z!dS )    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                   H    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d6de	fdZdddi fde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d6d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 d6d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'd6d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d0Z5i fd1Z6defd2Z7defd3Z8defd4Z9defd5Z: xZ;S )7oxfunreturnc                 &   |                      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    L/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/pro/oxfun.pyrS   zoxfun.describe   s~   eT 2 2 ; ; = =dt ( !$	
 +D d ' t   t       t   !" !$#( 9>     !"!!""#"  w# & 	" Y0@
 0@
 0 0 0	    c                    K   | j         d         d         }d|d}|                     |||                     ||          |           d {V S )Nr0   r   	subscribeopargs)rN   watch_multipleextend)rT   messageHashes	argsArrayparamsurlrequests         rV   subscribe_multiplezoxfun.subscribe_multipleF   sg      it$
 
 ((mT[[RX=Y=Y[hiiiiiiiiirW   Nsymbolsincelimitc                 D   K   |                      |g|||           d{V S )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   s6       22F8UE6RRRRRRRRRrW   symbolsc                 R  K   |                                   d{V  |                     |dd          }g }g }t          dt          |                    D ]S}||         }d|z   }	|                    |	           |                     |          }
d|
z   }|                    |           T|                     |||           d{V }| j        rC|                     |di           }| 	                    |d          }|
                    ||          }|                     |||dd          S )	aA  
        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]   sO      !!!!!!!!!%%gtU;;q#g,,'' 	 	AQZF(61K  ---~~f--HX%CKK..}dFKKKKKKKK? 	8NN61b11E**5(;;KOOK77E))&%TRRRrW   clientc                    |                      |dg           }t          dt          |                    D ]}|                     ||i           }|                     |          }|                     |d          }d|z   }|| j        vr3|                     | j        dd          }	t          |	          | j        |<   | j        |         }
|

                    |           |                    |
|           d S )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2q#d))$$ 
	0 
	0ANN4B//E--e44K%%k8<<F#f,Kdk))"//mTRR&0&=&=F#[(FMM+&&&NN6;////
	0 
	0rW   c                    |                      |d          }|                     ||          }|                     |d          }|                     |||                     |          |d         |                      |d          d d |                     |d          |                     |d          |                     |d          |                     |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8!!(F33%%e[99	"Y//X&""5)44 225+FF**5&99%%eW55&&uj99 
  
   	rW   r=   	timeframec                   K   |                                   d{V  |                     |          }|                     | j        di           }|                     |||          }d|z   dz   |d         z   }	d|z   dz   |z   }
| j        d         d         }d	|	gd
}|                     ||
|                     ||          |
           d{V }| j        r|	                    ||          }| 
                    |||dd          S )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   r   rf   rg   ra   r   rJ   intervalr\   r{   rb   rc   ohlcvss                 rV   watch_ohlcvzoxfun.watch_ohlcv   s/      !!!!!!!!!V$$^^DL,CC
##J	9EE8#c)F4L8'#-	9it$F
 
 zz#{DKK4P4PR]^^^^^^^^? 	3OOFE22E))&%4HHHrW   symbolsAndTimeframesc                 ,  K   t          |          }|dk    st          |d         t                    st          | j        dz             |                                  d{V  g }g }|                     | j        di           }t          dt          |                    D ]}	||	         }
|
d         }|
d         }| 	                    |          }| 
                    |||          }d|z   dz   |z   }|                    |           d|z   dz   |z   }|                    |           |                     |||           d{V \  }}}| j        r|                    ||          }|                     |||dd	          }|                     |||          S )
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1AZ0DQ0G%N%N#DG  /h  %h  i  i  i!!!!!!!!!^^DL,CC
q#23344 		. 		.A!5a!8$Q'C#A&B~~c**H''
B;;Hh&,x7CKK(3.4r9K  ----+/+B+B=RVX^+_+_%_%_%_%_%_%_"	7? 	4$$VU33E--gueQMM''	8DDDrW   c                 p   |                      |d          }|                    d          }|                      |dd          }|                     |          }|                     |dg           }|                     |di           }|                      |d          }	|                     |	          }
|                     |	|
          }|| j        vr
i | j        |<   || j        |         vr9|                     | j	        dd	          }t          |          | j        |         |<   |                     |d
g           }|                     ||
          }| j        |         |         }|                    |           d|z   dz   |z   }|                    ||           d|z   }|                    |||g|           d S )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2I&&&&ua44''44	nnWfb99~~k1b11##D,77!!(++!!(F33$+%%"$DKT[000%%dlL$GGE-B5-I-IDK	*h33$$VV44V$Y/f'#-	9v{+++ '4	624GHHHHHrW   r   c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r               )r   r   )rT   ohlcvr   s      rV   r   zoxfun.parse_ws_ohlcv)  s     eQ''UA&&UA&&UA&&UA&&UA&&
 	
rW   c                 B   K   |                      |g||           d{V S )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>  s4       66xOOOOOOOOOrW   c                 `  K   |                                   d{V  |                     |          }d}|                     | j        di           }|                     |d          }||}n||dk    rd}n|dk    rd}n|d	k    rd
}g }g }t          dt          |                    D ]V}	||	         }
d|
z   }|                    |           |                     |
          }|dz   |z   }|                    |           W| 	                    |||           d{V }|
                                S )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  so      !!!!!!!!!%%g..../?DD))'9==%$GGzz#"$"$q#g,,'' 	 	AQZF&/K  ---~~f--HC-(*CKK11-vNNNNNNNN	   rW   c                    |                      |di           }|                     |d          }|                     |          }|                     |d          }d|z   }|| j        vr|                     i           | j        |<   | j        |         }|                     |||dd          }	|                    |	           |                     |d          |d<   || j        |<   |                    ||           d S )	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2##D,77!!(++%%dK88	"V+$/))&*oob&9&9DOF#OF+	((vy&&QQ!!!!..tX>>	'"+y+.....rW   c                 l   K   |                      |g|           d{V }|                     ||          S )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  sE       ))6(F;;;;;;;;vv...rW   c                 
  K   |                                   d{V  |du }|}g }|r| j        }|                    d           g }t          dt	          |                    D ]S}||         }d|z   }	|                    |	           |                     |          }
|s|                    d|
z              T|                     |||           d{V }| j        ri }|||d         <   |S |                     | j	        d|          S )a6  

        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  sB      !!!!!!!!!o
 	&,CKK%%%q#c((## 	2 	2AVF)F2K  ---~~f--H 2I011111-vNNNNNNNN	? 	F*3F9X&'M##DL(GDDDrW   c                 &   |                      |dg           }t          dt          |                    D ][}|                     ||i           }|                     |          }|d         }d|z   }|| j        |<   |                    ||           \d S )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2q#d))$$ 	0 	0AtQ33I&&y11FH%F$v-K#)DL NN6;////	0 	0rW   c                   K   |                                   d{V  |                     |dd          }g }g }t          dt          |                    D ]Y}|                     ||                   }|                    d|d         z              |                    d|d         z              Z|                     |||           d{V }| j        ri }|||d         <   |S |                     | j	        d|          S )af  

        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55  VH-=!=>>>>22=$OOOOOOOO
? 	G,6GJx()N##DM8WEEErW   c                     |                      |di           }|                     |          }|d         }|| j        |<   d|z   }|                    ||           d S )Nr   re   r   )rv   parse_ws_bid_askr   r   )rT   r   r   r   parsedTickerre   r{   s          rV   handle_bid_askzoxfun.handle_bid_ask  sf    & ~~gvr22,,T22h' ,f&(|[11111rW   c                    |                      |d          }|                     ||          }|                      |d          }|                     |d          }|                     |dg           }|                     |dg           }|                     |||                     |          |                     |d          |                     |d          |                     |d          |                     |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9!!(F33!!&(33%%fk::	nnVUB//nnVUB//"Y//##C++))#q11##C++))#q11	!
 	!
 	 	 		rW   c                    K   |                                   d{V  |                                  d}d}| j        d         d         }d|gd}|                     |||                     ||          |           d{V S )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       !!!!!!!!!it$F
 
 ZZ[$++gv2N2NP[\\\\\\\\\rW   c                    |                      |d          }|                     |d          }|| j        d<   || j        d<   |                     |          | j        d<   t	          dt          |                    D ]}|                     ||i           }|                     |d          }|                     |          }|| j        vr| 	                                | j        |<   | j        |         }	|                     |d          |	d<   |                     |d          |	d	<   |                     |d
          |	d<   |	| j        |<   | 
                    | j                  | _        |                    | j        d           d S )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@  ss   ( >>'622%%g{;;	&V$-[!#'<<	#:#:Z q#h--(( 
	) 
	)AnnXq"55G))'>BBJ**:66DDL((%)\\^^T"l4(G#//AAGG"..w
CCGFO"..wDDGFO!(DL((66t|Y/////rW   c                 (  K   |                                   d{V  |                                  d{V  |du }|}g }|r| j        }|                    d           g }t	          dt          |                    D ]S}	||	         }
d|
z   }|                    |           |                     |
          }|s|                    d|z              T|                     |||           d{V }| j        r|S | 	                    | j
        |||d          S )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  sY      !!!!!!!!!!!!!!!!!!o
 	(,CKK'''q#c((## 	4 	4AVF+f4K  ---~~f--H 4K(2333!44]D&QQQQQQQQ? 	 11$.'5RWY]^^^rW   c                 ~   | j         t                      | _         | j         }|                     |dg           }t          dt	          |                    D ]f}|                     ||i           }|                     |          }|d         }d|z   }	|                    |           |                    ||	           gd S )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77DN~~gvr22q#d))$$ 	2 	2A..q"55K--k::Hh'F&/KLL"""NN8[1111	2 	2rW   c                    |                      |d          }|                     ||          }|                     i d|dd d|d         dd ddd|                     |d	          d
|                     |d
          d|                     |d          dd dd d|                     |d          dd dd dd dd dd dd d |                     |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  s    ##Hn==!!(F33!! #
H#
$#
 fX&#
 	#

 '#
  0 0;P Q Q#
 $**8\BB#
 T--hFF#
 4#
 $#
 ))(J??#
 D#
 #
 #
 D#
  d!#
" ##
$ #'#4#4X}#M#M!%+/!'+!#9#
 #
 #
   	rW   c                   K   |                                   d{V  |                                  d{V  d}d}|                     |          }||dz  }n|d|z   z  }|d|d         z   z  }d|gd}| j        d	         d
         }	|                     |	|||           d{V }
| j        r|
                    ||          }|                     |
|||d          S )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*      !!!!!!!!!!!!!!!!!!!!&))>EMDD3<'KC&,&&D
 
 it$zz#{G[IIIIIIII? 	3OOFE22E00tTTTrW   c                    |                      |dg           }d}| j        0|                     | j        dd          }t	          |          | _        | j        }t          dt          |                    D ]l}|                     ||i           }|                     |          }	|	                    |	           |d|	d         z   z  }|
                    | j        |           md S )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2;%%dlM4HHE077DKq#d))$$ 	5 	5ANN4B//E**511KMM+&&&3X!666KNN4;4444	5 	5rW   r   r   r   r   c                   K   |                                   d{V  |                                  d{V  t          |                                           }d|d}|                     |d          }|                     ||||||          }	|                     |	d          }
|
|                                 |	d<   |	|d<   | j        d         d         }| 	                    ||||           d{V S )	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a%%lK@@	(,(9(9(;(;L%&it$ZZ[';GGGGGGGGGrW   r   c                   K   |                                   d{V  |                                  d{V  t          |                                           }d|d}	|                     |d          }|                     ||||||          }
|                     |
d|i          }
|                     |
d          }||                                 |
d<   |
|	d<   | j	        d         d	         }| 
                    |||	|           d{V S )
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  s7     " !!!!!!!!!!!!!!!!!!$**,,''
 
 65))!66vtT6SXZ`aa{{<)RAA%%lK@@	(,(9(9(;(;L%&it$ZZ[';GGGGGGGGGrW   c                    |                      |d          }|                     |d          }|sc|                      |d          }|                     |          }|                     |d          }|                     |d|j        |i ||i i 	  	         |                     |di           }|                     |          }	|                    |	|           d S )NrM  	submittedeventr  r   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6NN7K88	 	]%%gw77F		'**I$$Wf55DtRVRGUWY[\\\w33  &&uk*****rW   c                   K   |t          | j        dz             |                                  d{V  |                                  d{V  t	          |                                           }|                     |          |d}d||d}| j        d         d         }|                     ||||           d{V S )ap  

        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       >#DG.[$[\\\!!!!!!!!!!!!!!!!!!$**,,''..00
 

  
 

 it$ZZ[';GGGGGGGGGrW   idsc                 d  K   t          |          }|dk    rt          | j        dz             |t          | j        dz             |                                  d{V  |                                  d{V  t          |                                           }|                     |          }g }t          d|          D ]"}|||         d}	|
                    |	           #d||d}
| j        d	         d
         }|                     |||                     |
|          |           d{V S )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  sk       HH	r>>TW'YYZZZ>#DG.\$\]]]!!!!!!!!!!!!!!!!!!$**,,''>>&))	q)$$ 	# 	#A"Q D T"""" "
 

 it$ZZ[$2B2B7F2S2SU`aaaaaaaaarW   c                 T  K   | j         d         d         }|                     |          }d}|                    |          }|                     |j        |          }||                                  |                                 }t          |          dz   }|                     | 	                    |          | 	                    | j
                  t          j        d          }	d| j        ||	dd}
|                     |
|          }|                     ||||           | d {V S )	Nr0   r   authenticatedzGET/auth/self/verifybase64login)apiKeyrn   	signature)r[   r   )rN   r   reusableFuturerv   subscriptionscheck_required_credentialsrQ  rN  hmacencodesecrethashlibsha256rq  r^   r   )rT   ra   rb   r   r{   futurern  rn   payloadrr  rc   r   s               rV   r  zoxfun.authenticate  s)     it$S!!%&&{33v';[II ++---))++I)nn'==G		$++g"6"6DK8P8PRYR`bjkkI"k!*!*  G kk'622GJJsK+>>>||||||rW   c                 6   |                      |dd          }d}|r2|                     |j        |          }|                    d           d S t	          |                     |                    }|                    ||           ||j        v r
|j        |= d S d S )NsuccessFrn  T)r[  rv   futuresr   r   r\  rejectrt  )rT   r   r   rn  r{   r{  errors          rV   handle_authentication_messagez#oxfun.handle_authentication_message  s    w	5AA% 	6^^FNK@@FNN4     '		'(:(:;;EMM%---f222(555 32rW   c                     dS )NrK    )rT   r   s     rV   rK   z
oxfun.ping  s    vrW   c                 8    |                                  |_        |S N)rQ  lastPong)rT   r   r   s      rV   handle_pongzoxfun.handle_pong  s    ++--rW   c                    |dk    r|                      ||           d S |                     |d          }|                     |dg           }|                     |d          }|F|C|dk    r|                     ||           |dk    r|                     ||           |                    d          dk    r|                     ||           |                    d	          dk    r|                     ||           |                    d
          dk    r|                     ||           |                    d          dk    r| 	                    ||           |                    d          dk    r| 
                    ||           |dk    r|                     ||           d S d S |dk    r|                     ||           |dk    s|dk    s|dk    r|                     ||           d S d S )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---F  '22~~gvr22  '22D$4""67333  ""67333zz)$$r))!!&'222zz'""R''&&vw777zz)$$r))##FG444zz*%%**%%fg666zz'""R''""67333$$##FG44444 %$ 2267CCC%%5M+A+AuP]G]G]((99999 H^G]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 1 1 1 1 1f IK j j j j <@d[] S S SS S Sbfglbm S S S S OSaenp S Sd3i S S[^ Suyz  vA S S S S>0F 0 0 0 0< E    > ?CQUdhqs I I I I3 I^a Ix|  ~B  yC I I I I< aesw  AC "E "E$tCy/ "EZ] "Emp "E "E "E "EH,I6 ,I ,I ,I ,I\
 
F 
d 
 
 
 
* @DB P PS P PS\ P P P P SW_a %! %!$s) %!C %!fo %! %! %! %!N!/ !/ !/ !/ !/F 68 / / /F / / / / 6:" E E7 E E E E EB0F 0 0 0 0B 8<B F FW F7 F F F F22V 2 2 2 24   $ *, ] ] ] ] ] ]*%0 %0 %0N 8<$]ajl  _  _W  _C  _WZ  _quv~q  _  _  _  _D2v 2 2 2 2B- -& - - - -^ 04$UYbd !U !U !UC !Us !Uimnsit !U !U !U !UF&5F &5 &5 &5 &5P pt|~ &H &HC &Hy &H	 &H[` &Hil &H  DI &H &H &H &HP im{  IK  H  Hc  H3  Hi  Hy  Hbe  Hux  H  PU  H  H  H  HD(+& (+ (+ (+ (+T <@ H H HS Hu H H H H8 DHPR !b !b$s) !bS !b !b !b !bF )+    .6F 6 6 6 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  A  A  A  A  A  A  A  A  A  A  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T  T 4 4 4 4 4 4       0 0 0 0 0 0 . . . . . . ' ' ' ' ' 'M: M: M: M: M:D$ M: M: M: M: M:rW   