
    E#i!                    |   S SK Jr  S SK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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
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K#J-r-  S SK#J.r.  S SK#J/r/  S SK#J0r0  S SK#J1r1  S SK#J2r2  S SK3J4r4   " S S\\5      r5g)    )Exchange)ImplicitAPIN)AccountAnyBalancesBool
CurrenciesCurrencyDepositAddressIntLeverageTierLeverageTiersMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTransactionTransferEntry)List)ExchangeError)AuthenticationError)AccountNotEnabled)ArgumentsRequired)
BadRequest)	BadSymbol)MarketClosed)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)OperationFailed)NetworkError)RateLimitExceeded)RequestTimeout)	TICK_SIZEc                     ^  \ rS rSrS\4U 4S jjr0 4S\\   4S jjrS\\   4S jr	S\4S jr
0 4S\4S jjrS0 4S	\S\4S
 jjr0 4S\S\4S jjrSUS\S\4S jjrSSS0 4S\S\S\S\S\\   4
S jjrSUS\S\4S jjrS0 4S\S\S\4S jjrS0 4S	\S\4S jjr0 4S\S\4S jjrSUS\S\4S jjrSSS0 4S\S\S\4S jjr SUS\4S jjr!SSS0 4S\S\S\4S jjr"SUS\4S jjr#S0 4S	\S\$4S jjr%SUS\S\\&   4S jjr'SS0 4S\S\S\S\\(   4S jjr)SSS0 4S\S\S\4S  jjr*SUS\S\(4S! jjr+0 4S\,4S" jjr-S\,4S# jr.0 4S\\/   4S$ jjr0S% r10 4S&\S'\2S(\S)\S\34
S* jjr4SSS0 4S&\S\S\4S+ jjr5SUS,\64S- jjr7S. r80 4S&\S\94S/ jjr:SUS,\6S\94S0 jjr;SSS0 4S&\S\S\S\\<   4S1 jjr=SSS0 4S&\S\S\S\\<   4S2 jjr>SSS0 4S,\6S\S\S\\<   4S3 jjr?SUS,\6S\<4S4 jjr@S5 rAS6 rBS0 4S&\S'\2S7\S8\S\<4
S9 jjrCS0 4S	\S\\D   4S: jjrESUS\4S; jjrFS0 4S\S<\GS=\HS'\2S>\IS\J4S? jjrK0 4S@\\L   S\\J   4SA jjrMS0 4S\S<\S=\4SB jjrN0 4S\SC\24SD jjrOS0 4SE\S\S\J4SF jjrPSSS0 4S\S\S\S\\J   4SG jjrQS0 4SE\S\4SH jjrRS0 4S\4SI jjrSS0 4SJ\\   S\4SK jjrTSUS\S\J4SL jjrUSM rVSN rWSO rXSPSQ0 SS4SR jrYSS rZSTr[U =r\$ )Voxfun   returnc           #      d	  > U R                  [        [        U ]  5       SSS/SSS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_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
_E0 S*S
_S+S
_S,S_S-S
_S.S_S/S
_S0S
_S1S_S2S
_S3S
_S4S_S5S_S6S_S7S_S8S
_S9S
_S:S
_E0 S;S
_S<S
_S=S
_S>S_S?S@_SAS_SBS
_SCS_SDS_SES
_SFS
_SGS_SHS_SIS_SJS
_SKS
_SLS
_E0 SMS
_SNS
_SOS
_SPS_SQS
_SRS
_SSS
_STS
_SUS
_SVS_SWS_SXS
_SYS_SZS
_S[S
_S\S
_S]S
_E0 S^S
_S_S
_S`S_SaS
_SbS_ScS
_SdS
_SeS
_SfS
_SgS_ShS
_SiS
_SjS
_SkS
_SlS
_SmS_SnS_ESoS0ESpSqSrSsStSuSvSwSx.SySzS{S{S|.S}S}S|.S~SSS.SSSSSSSSSSSS.
0SSSSSSSSSSSSSSSS.SSSS.SSS.S.S|.SSSU R	                  S5      U R	                  S5      U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      //U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      //S.S.0[
        S
SSSSSSSSSS.	SSSSSSSSSSS.
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.SS0S
SSSS
S.S
S
S
S
S.S
S S
S
S
S.S S SS0S.	SS0SS0S S.S S S.S.0 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[        _S[        _S[        _S[        _E0 S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[         _S["        _S["        _S[$        _S["        _S[        _S[        _E[        [        [        [        [&        [&        [&        [        [        S.	E[        [(        S.S.S.5      $ )Nr2   OXFUNPAv3x   TCORSspotmarginFswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderdeposit	editOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLedgerfetchLeveragefetchLeverageTiersfetchMarketLeverageTiersemulatedfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransfersfetchWithdrawalfetchWithdrawalsfetchWithdrawalWhitelistreduceMarginrepayCrossMarginrepayIsolatedMarginsandboxsetLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdrawws60s300s900s1800s3600s7200s14400s86400s)1m5m15m30m1h2h4h1dzQhttps://github.com/ccxt/ccxt/assets/43336371/6a196124-c1ee-4fae-8573-962071b61a85z/https://ox.fun/register?shareAccountId=5ZUD4a7Gzhttps://api.ox.fun)publicprivatezhttps://stgapi.ox.funzhttps://ox.fun/zhttps://docs.ox.fun/z7https://support.ox.fun/en/articles/8819866-trading-fees)logoreferralapitestwwwdocfeesget   )
z
v3/marketsz	v3/assetsz
v3/tickerszv3/funding/estimatesz
v3/candleszv3/depthzv3/markets/operationalzv3/exchange-tradeszv3/funding/rateszv3/leverage/tiers)z
v3/accountzv3/account/namesz	v3/walletv3/transferzv3/balanceszv3/positionsz
v3/fundingzv3/deposit-addressesz
v3/depositzv3/withdrawal-addressesv3/withdrawalzv3/withdrawal-feeszv3/orders/statuszv3/orders/workingz	v3/trades)r   r   zv3/orders/place)zv3/orders/cancelzv3/orders/cancel-all)r   postdeletetradingz0.00020z0.0007002500000z0.0001025000000z0.00050z0.00040)makertaker)	tierBased
percentager   r   tiersBitcoinEthereum	AvalancheSolanaArbitrumPolygonFantomBNBSmartChainOptimism)	BTCERC20AVAXSOLARBMATICFTMBNBOPTIMISMr   r   r   r   r   r   r   BASEr   r   )
r   r   r   r   r   r   r   Baser   r   )sandboxModenetworksnetworksById)IOCFOKPOGTD)EXPIRE_MAKEREXPIRE_TAKEREXPIRE_BOTHNONE)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergmax
   i  i    )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   r   )	r   rJ   rK   ru   rz   ry   r}   r[   rv   extendsdefault)linearinverse)r  r;   r=   r>   z-0010z-429z-05001z-10001z-20000-20001z-20002z-20003z-20005z-20006z-20007z-20008z-20009z-20010z-20011z-20012z-20013z-20014z-20015z-20016z-20017z-20018z-20019z-20020z-20021z-20022z-20023z-20024z-20025z-20026z-20027z-20028z-20029z-20030z-20031z-20032z-20033z-20034z-20050z-30001z-35034z-35046z-40001z-50001z-300001z-300011z-300012z-100005z-100006z-100008z-100015)	z-710001z-710002z-710003z-710004z-710005z-710006z-710007z-000101z-000201)r  z-200050)exactbroad)idname	countriesversion	rateLimitprohas
timeframesurlsr   r   precisionModeoptionsfeatures
exceptions)deep_extendsuperr2   describeparse_numberr0   r,   r.   r"   r!   r%   r+   r$   r&   r'   r-   r#   r)   r*   r(   r/   )self	__class__s    D/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/oxfun.pyr  oxfun.describe   s   eT ; =hhh %h 	h
 %h %h Uh "4h th h $Uh  h 'h /h ,Uh  0!h" t#h$ %h& &t'h( ()h* '+h, (-h. "4/h0 51h2 U3h4  5h6 7h8  9h: &u;h< +E=h> )%?h@ &uAhB #EChD $UEhF 'GhH (IhJ "4KhL MhN &tOhP (QhR 1%ShT  UhV *5WhX +EYhZ &t[h\ #D]h^ *4_h` $Tahb "5chd *5ehf +Eghh #Eihj ukhl  mhn %dohp +Jqhr sht !%uhv  whx dyhz +E{h| !%}h~ "4h@ dAhB !$ChD "5EhF uGhH #EIhJ  KhL 'MhN $UOhP !$QhR *5ShT (UhV %eWhX )%YhZ u[h\ t]h^ _h` Uahb tchd "5ehf #Eghh %eihj &ukhl 'mhn $Uohp !$qhr "5sht #Duhv +Ewhx yhz #E{h| &u}h~ 4h@ uAhB UChD  EhF "5GhH %IhJ DKhL DMhN dOhT 	 lM23
 66 )-Q" &'%&&'01&'$%23./,--.  '(,-%&'('(()&'01&'34)*./,--.%&$ ())*+, -.01/+Z !%"&!..y9!..y9 "..s3T5F5Fy5QR!..y94;L;LY;WX!..z:D<M<Mc<RS" "..s3T5F5Fy5QR!..y94;L;LY;WX!..z:D<M<Mi<XY"( '  %$''#%&#* *
  % '!'# %&#"%* *!8  $&+(,,1,0).+06:#'#'"&#(	( #($)$)+/27,0,0+/$(	0 $(3$8 r% ',!$$*%&*/& ',#($)*/	# ',!%#($)*/( $()-#m9v y
 "9  $	 ##IHT=_=-= 1= m	=
 j= j= j= l= 1= j= 1= j= j= /= /=  /!=" /#=$ j%=& i'=( j)=* j+=, j-=. j/=0 j1=2 j3=4 /5=6 /7=8 m9=: 1;=< j==> j?=@ jA=B jC=D jE=F lG=H lI=J jK=L jM=N mO=P jQ=R 1S=T 1U=V mW=X mY=Z 0[=\ |]=^ |_=` }a=b |c=d ze=f |g=h  -)))000++y=~ .-C]	r@
 r r	    c                     U R                  U5      U R                  U5      /u  p#U R                  US/ 5      nU R                  US/ 5      nU R                  XE5      nU R	                  U5      $ )z
retrieves data on all markets for bitmex

https://docs.ox.fun/?json#get-v3-markets

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
data)publicGetV3MarketspublicGetV3Tickers	safe_listarray_concatparse_markets)r  paramsresponseFromMarketsresponseFromTickersmarketsFromMarketsmarketsFromTickersmarketss          r  fetch_marketsoxfun.fetch_markets  sy     594K4KF4SUYUlUlmsUt3u0!^^,?Lr "^^,?L, ##$6K!!'**r  c                    / n/ n[        S[        U5      5       Hb  nX   nU R                  US5      nU R                  Xb5      (       a  M1  UR	                  U5        UR	                  U R                  U5      5        Md     U$ )Nr   
marketCode)rangelensafe_stringin_arrayappendparse_market)r  r)  	marketIdsresultimarketmarketIds          r  r#  oxfun.parse_markets  su    	q#g,'AZF''=HMM(66  *d//78 ( r  c                    U R                  USS5      nUR                  S5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nUS-   U-   nU R                  USS5      n	S n
S nU	S	:H  nU(       a  S
n	Sn
U R                  S5      nUS-   U-   nU	S:H  nU R	                  0 SU_SS _SU_SU_SU_SU_SU_SU_SU
_SU	_SU_SS_S
U_S	S_SS_SS_SU_U(       a  SOS U(       a  SOS U R
                  S   S   U R
                  S   S   U(       a  SOS S S S S S U R                  US5      S .S S S!.U R                  US"5      S S!.S S S!.S S S!.S#.U R                  US$5      S US%.E5      $ )&Nr-   -r   r   /typer;   r>   r=   OX:r  	numericIdsymbolbasequotesettlebaseIdquoteIdsettleIdr<   Fr?   activeTcontractr   r   r   tickSize)amountpriceminr   minSize)r   rL  rM  costlistedAt)r  r  r   r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedindexinfo)r0  splitsafe_currency_codesafe_string_lowersafe_market_structurer   safe_numbersafe_integer)r  r7  r  partsrF  rG  rC  rD  rB  r>  rH  rE  isFutureisSpots                 r  r3  oxfun.parse_market  sr   flB7!!%+""5!,&&v.''0e#%%fff=H$DH,,T2Fc\F*F)) 4+
"4+
4+
 f4+
 D	4+

 U4+
 f4+
 f4+
 w4+
 4+
 D4+
 F4+
 e4+
 H4+
 e4+
 e4+
  d!4+
" #4+
$ 'dD (udYYy)'2YYy)'2!)At"))&*=  
  ++FI>
  
  $ ((<g4+
 4 4	r  c                    U R                  U5      nU R                  US/ 5      n0 n[        S[        U5      5       GHp  nX5   nU R	                  USS5      nUR                  S5      nUS   n	U R                  U	5      n
X;  a  U	U
SSSSSSSSSS.SSS.S.0 / S	.XJ'   U R                  US
/ 5      n[        S[        U5      5       H  nX   nU R	                  US5      nU R                  U5      nUUSU R                  US5      U R                  US5      SSU R                  U R                  U R	                  US5      5      5      U R                  US5      SS.U R                  US5      SS.S.US.
XJ   S   U'   M     U R                  XJ   S/ 5      nUR                  U5        UXJ   S'   GMs     [        UR                  5       5      n[        S[        U5      5       H  nUU   n
U R                  XJ   5      XJ'   M     U$ )z
fetches all available currencies on an exchange

https://docs.ox.fun/?json#get-v3-assets

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
r  r   assetr;  .NrN  )r   rQ   )r  coderX  r>  r  rI  rQ   r   feerY  r   r\  networkListnetwork
canDepositcanWithdrawtransactionPrecision
minDepositminWithdrawal)rQ   r   )
r  rm  r<   rQ   r   rI  rk  rX  rY  r\  r   r\  )publicGetV3Assetsr!  r.  r/  r0  r]  r^  network_id_to_code	safe_boolr  parse_precisionra  r2  listkeyssafe_currency_structure)r  r$  responser  r5  r6  currencyfullIdrc  r  rj  chainsjchain	networkIdnetworkCodeinfosallKeyss                     r  fetch_currenciesoxfun.fetch_currenciesC  sF    ))&1R ~~h3q#d)$AwH%%h<FLL%EqB**2.DN !%  "# $ $(#'%
 $(#'$	 !#+ . ^^HmR@F1c&k*	 ,,UI>	"55i@#*"#~~e\B $um D"!%!2!243G3GHXHXY^`vHw3x!y $(#3#3E<#H#'$
 $(#3#3E?#K#'%	 "'9Z(5	 +2 NN6<<ELL"#(FL u %x v{{}%q#g,'A1:D77EFL ( r  Nsymbolsc                     U R                  5         U R                  U5      nU R                  U5      nU R                  US/ 5      nU R	                  XA5      $ )a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://docs.ox.fun/?json#get-v3-tickers

:param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
r  )load_marketsmarket_symbolsr   r!  parse_tickers)r  r  r$  rz  tickerss        r  fetch_tickersoxfun.fetch_tickers  sV     	%%g.**62` ..626!!'33r  rB  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US/ 5      nU R                  US0 5      nU R                  Xs5      $ )a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://docs.ox.fun/?json#get-v3-tickers

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
r-  r  r  r   )r  r7  r   extendr!  	safe_dictparse_ticker)r  rB  r$  r7  requestrz  r  tickers           r  fetch_tickeroxfun.fetch_ticker  s     	V$&,
 **4;;w+GH* ~~h3a,  00r  r7  c           	         U R                  US5      nU R                  US5      nU R                  XB5      nUS   nU R                  US5      nU R                  0 SU_SU_SU R	                  U5      _SU R                  US5      _S	U R                  US
5      _SS _SS _SS _SS _SS _SU R                  US5      _SU_SU_SS _SS _SS _SS _U R                  US5      S U R                  US5      US.EU5      $ )NlastUpdatedAtr-  rB  lastTradedPrice	timestampdatetimehighhigh24hlowlow24hbid	bidVolumeask	askVolumevwapopenopen24hcloselastpreviousClosechanger   averagecurrencyVolume24h	markPrice)
baseVolumequoteVolumer  r\  )rb  r0  safe_marketsafe_tickeriso8601)r  r  r7  r  r8  rB  r  s          r  r  oxfun.parse_ticker@  s     %%fo>	##FL9!!(3!(9: !
f!
!
 Y/!
 D$$VY7	!

 4##FH5!
 4!
 !
 4!
 !
 D!
 D$$VY7!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **63FG))&+>+!
, - 	r  r   	timeframesincer   c                    U R                  5         U R                  U5      nU R                  U R                  X"5      nUS   US.nUb  X7S'   Ub  XGS'   U R	                  US5      nUb  XS'   U R                  US5      nOUb  U R                  US5      US'   U R                  U R                  Xu5      5      n	U R                  U	S/ 5      n
U R                  XX#U5      $ )	a  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://docs.ox.fun/?json#get-v3-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(default 24 hours ago)
:param int [limit]: the maximum amount of candles to fetch(default 200, max 500)
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest candle to fetch(default now)
:returns int[][]: A list of candles ordered, open, high, low, close, volume
r  )r-  r  	startTimer   untilendTime $r  )r  r7  r0  r  rb  omitsumpublicGetV3Candlesr  r!  parse_ohlcvs)r  rB  r  r  r   r$  r7  r  r  rz  r5  s              r  fetch_ohlcvoxfun.fetch_ohlcvm  s     	V$$$T__iK	 ,"
 #(K $G!!&'2!&IYYvw/F!%%1H!IGI**4;;w+GH8 &"5  5IIr  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      /$ )NopenedAtr  r  r  r  currencyVolume)rb  ra  )r  ohlcvr7  s      r  parse_ohlcvoxfun.parse_ohlcv  so     eZ0UF+UF+UE*UG,U$45
 	
r  c                    U R                  5         U R                  U5      nSUS   0nUb  X%S'   U R                  U R                  XS5      5      nU R	                  US0 5      nU R                  US5      nU R                  XtS   U5      $ )a   
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://docs.ox.fun/?json#get-v3-depth

: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(default 5, max 100)
: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
r-  r  levelr  r  rB  )r  r7  publicGetV3Depthr  r  rb  parse_order_book)	r  rB  r   r$  r7  r  rz  r  r  s	            r  fetch_order_bookoxfun.fetch_order_book  s     	V$&,
 $G((W)EF2 ~~h3%%dO<	$$T(+;YGGr  c                     U R                  5         U R                  U5      nU R                  U5      nU R                  US/ 5      nU R	                  XA5      $ )aR  
fetch the current funding rates for multiple markets

https://docs.ox.fun/?json#get-v3-funding-estimates

:param str[] symbols: unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Order[]: an array of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
r  )r  r  publicGetV3FundingEstimatesr!  parse_funding_ratesr  r  r$  rz  r  s        r  fetch_funding_ratesoxfun.fetch_funding_rates  sU     	%%g.33F;& ~~h3''66r  c                    U R                  5         SU R                  U5      0nU R                  U R                  X25      5      nU R	                  US/ 5      nU R                  US0 5      nU R                  X`R                  U5      5      $ )aG  
fetch the current funding rates for a symbol

https://docs.ox.fun/?json#get-v3-funding-estimates

:param str symbol: unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Order[]: an array of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
r-  r  r   )r  	market_idr  r  r!  r  parse_funding_rater7  )r  rB  r$  r  rz  r  firsts          r  fetch_funding_rateoxfun.fetch_funding_rate  s~     	$..0
 33DKK4PQ~~h3tQ+&&ukk&.ABBr  c                 @   U R                  US5      nU R                  U5      nU R                  US5      n0 SU_SUS   _SS _SS _SU R                  S5      _S	S _S
U_SU R	                  U5      _SU R                  US5      _SS _SS _SS _SS _SS _SS _SS _SS _SS 0E$ )Nr-  	fundingAtr\  rB  r  
indexPriceinterestRater   estimatedSettlePricer  r  fundingRateestFundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r0  r7  rb  r  r  ra  )r  r  r7  rB  estFundingRateTimestamps        r  r  oxfun.parse_funding_rate%  s>    !!+|<V$"&"3"3K"M
K
fX&
 
 $	

 D--c2
 #D
 0
 %<=
 4++K9IJ
 
 t
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
r  c                 N   U R                  5         U R                  U5      nSUS   0nUb  X&S'   Ub  X6S'   U R                  US5      nUb  XvS'   U R                  US5      nU R	                  U R                  Xd5      5      nU R                  US/ 5      n	U R                  XX#5      $ )aA  
Fetches the history of funding rates

https://docs.ox.fun/?json#get-v3-funding-rates

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch(default 24 hours ago)
:param int [limit]: the maximum amount of trades to fetch(default 200, max 500)
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest trade to fetch(default now)
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
r-  r  r  r   r  r  r  )r  r7  rb  r  publicGetV3FundingRatesr  r!  parse_funding_rate_histories
r  rB  r  r   r$  r7  r  r  rz  r  s
             r  fetch_funding_rate_history oxfun.fetch_funding_rate_historyE  s     	V$&,
 #(K $G!!&'2!&IYYvw/F//G0LM$ ~~h300uLLr  c                     U R                  US5      nU R                  X25      nUS   nU R                  US5      nUUU R                  US5      UU R	                  U5      S.$ )Nr-  rB  	createdAtr  )r\  rB  r  r  r  )r0  r  rb  ra  r  )r  r\  r7  r8  rB  r  s         r  parse_funding_rate_history oxfun.parse_funding_rate_historyt  sq    $ ##D,7!!(3!%%dK8	++D-@"Y/
 	
r  c                 N   U R                  5         U R                  U5      nSUS   0nUb  X&S'   Ub  X6S'   U R                  US5      nUb  XvS'   U R                  US5      nU R	                  U R                  Xd5      5      nU R                  US/ 5      n	U R                  XX#5      $ )a>  
fetches the history of funding payments

https://docs.ox.fun/?json#get-v3-funding

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch(default 24 hours ago)
:param int [limit]: the maximum amount of trades to fetch(default 200, max 500)
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest trade to fetch(default now)
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
r-  r  r  r   r  r  r  )r  r7  rb  r  privateGetV3Fundingr  r!  parse_incomes)
r  rB  r  r   r$  r7  r  r  rz  r5  s
             r  fetch_funding_historyoxfun.fetch_funding_history  s     	V$&,
 #(K $G!!&'2!&IYYvw/F++DKK,HI6 &"5!!&%??r  c           	      .   U R                  US5      nU R                  X25      nU R                  US5      nU R                  S5      nU R                  US5      nU R	                  US5      nU R                  US5      n	UUUUU R                  U5      UUU	S.$ )Nr-  paymentr?  r  r  r  )r\  rB  rj  r  r  r  rL  rate)r0  safe_symbolra  r^  safe_timestampr  )
r  incomer7  r8  rB  rL  rj  r  r  r  s
             r  parse_incomeoxfun.parse_income  s     ##FL9!!(3!!&)4&&t,fd+''<	6"Y/	
 		
r  c                     U R                  5         U R                  U5      nU R                  US/ 5      nU R                  XAS5      $ )a  
retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes, if a market has a leverage tier of 0, then the leverage tiers cannot be obtained for self market

https://docs.ox.fun/?json#get-v3-leverage-tiers

:param str[] [symbols]: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`, indexed by market symbols
r  r-  )r  publicGetV3LeverageTiersr!  parse_leverage_tiersr  s        r  fetch_leverage_tiersoxfun.fetch_leverage_tiers  sH     	008T ~~h3((EEr  c                    U R                  US5      nU R                  X25      nU R                  US/ 5      n/ n[        S[	        U5      5       H  nXF   nUR                  U R                  US5      U R                  X25      US   U R                  US5      U R                  US5      U R                  US5      U R                  US	5      US
.5        M     U$ )Nr-  r   r   tierrE  positionFloorpositionCapmaintenanceMarginr   )r  rB  r{  minNotionalmaxNotionalmaintenanceMarginRatemaxLeverager\  )r0  r  r!  r.  r/  r2  ra  r  )r  r\  r7  r8  listOfTiersr   r~  r  s           r  parse_market_leverage_tiers!oxfun.parse_market_leverage_tiers   s    " ##D,7!!(3nnT7B7q#k*+A>DLL((v6**8<"8,#//oF#//mD)-)9)9$@S)T#//jA	 	 , r  c                    U R                  5         U R                  U5      nSUS   0nUb  X&S'   Ub  X6S'   U R                  US5      nUb  XvS'   U R                  US5      nOUb  U R	                  US5      US'   U R                  U R                  Xd5      5      nU R                  US/ 5      n	U R                  XX#5      $ )	aY  
get the list of most recent trades for a particular symbol

https://docs.ox.fun/?json#get-v3-exchange-trades

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch(default 24 hours ago)
:param int [limit]: the maximum amount of trades to fetch(default 200, max 500)
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest trade to fetch(default now)
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
r-  r  r  r   r  r  r  r  )	r  r7  rb  r  r  publicGetV3ExchangeTradesr  r!  parse_tradesr  s
             r  fetch_tradesoxfun.fetch_tradesC  s     	V$&,
 #(K $G!!&'2!&IYYvw/F!%%1H!IGI11$++g2NO" ~~h3  u<<r  c                    U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X%S'   Ub  X5S'   U R                  US5      nUb  XuS'   U R                  US5      nOUb  U R	                  US5      US'   U R                  U R                  XT5      5      nU R                  US	/ 5      n	U R                  XX#5      $ )
a  
fetch all trades made by the user

https://docs.ox.fun/?json#get-v3-trades

:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum amount of trades to fetch(default 200, max 500)
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest trade to fetch(default now)
:returns Trade[]: a list of `trade structures <https://github.com/ccxt/ccxt/wiki/Manual#trade-structure>`
Nr  r-  r  r   r  r  r  r  )	r  r7  rb  r  r  privateGetV3Tradesr  r!  r  )
r  rB  r  r   r$  r  r7  r  rz  r5  s
             r  fetch_my_tradesoxfun.fetch_my_tradess  s     	[[(F$*4LGL!#(K $G!!&'2!&IYYvw/F!%%1H!IGI**4;;w+GH. &"5  >>r  c                     U R                  US5      nU R                  X25      nUS   nU R                  US5      nU R                  US5      U R                  U R                  US5      5      S.nU R	                  U R                  US5      UU R                  U5      US U R                  US5      U R                  US	5      U R                  US
S5      U R                  US5      U R                  USS5      S UUS.U5      $ )Nr-  rB  	matchedAtrk  feeAssetrQ  r{  matchIdorderIdside	matchTypeorderMatchType
matchPricematchQuantitymatchedQuantity)r  r  r  rB  r>  orderr!  takerOrMakerrM  rL  rQ  rk  r\  )	r0  r  rb  r^  
safe_trader  r_  safe_string_lower_2safe_string_2)r  trader7  r8  rB  r  rk  s          r  parse_tradeoxfun.parse_trade  s   @ ##E<8!!(3!%%e[9	$$UE2//0@0@
0ST
 ""5)4"Y/%%eY7**5&9 44UKIYZ%%e\:((ARS 
  	r  c                 6   U R                  5         U R                  U5      nU R                  US/ 5      nUS   nU R                  US5      nUb;  [	        S[        U5      5       H"  nX6   nU R                  US5      nX:X  d  M   Un  O   U R                  U5      $ )a  
query for balance and get the amount of funds available for trading or funds locked in orders

https://docs.ox.fun/?json#get-v3-balances

:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.asset]: currency id, if empty the exchange returns info about all currencies
:param str [params.subAcc]: Name of sub account. If no subAcc is given, then the response contains only the account linked to the API-Key.
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
r  r   subAccr  )r  privateGetV3Balancesr!  r0  r.  r/  parse_balance)	r  r$  rz  r  balancer0  r6  br  s	            r  fetch_balanceoxfun.fetch_balance  s     	,,V4< ~~h3q'!!&(31c$i(G''62>G ) !!'**r  c                 ~   SU0nU R                  US/ 5      n[        S[        U5      5       H}  nX4   nU R                  US5      nU R	                  U5      nU R                  5       nU R                  US5      US'   U R                  US5      US'   U R                  US5      US	'   XU'   M     U R                  U5      $ )
Nr\  balancesr   rh  total	availablefreereservedused)r!  r.  r/  r0  r^  accountsafe_balance)	r  r3  r5  r8  r6  balanceEntry
currencyIdrj  r>  s	            r  r2  oxfun.parse_balance  s    2 G
 >>':r:q#h-(A#;L)),@J**:6DllnG#//gFGG"..|[IGFO"..|ZHGFO"4L )   ((r  c                     U R                  5         U R                  U5      nU R                  US/ 5      nU R                  X15      $ )a+  
fetch subaccounts associated with a profile

https://docs.ox.fun/?json#get-v3-account-names

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
r  )r  privateGetV3AccountNamesr!  parse_accounts)r  r$  rz  r  s       r  fetch_accountsoxfun.fetch_accounts?  sE     	008 ~~h3""400r  c                 0    U R                  US5      S S US.$ )N	accountId)r  r>  rj  r\  r0  )r  r>  s     r  parse_accountoxfun.parse_accountZ  s'     ""7K8	
 	
r  rj  rL  fromAccount	toAccountc                     U R                  5         U R                  U5      nUS   U R                  X5      UUS.nU R                  U R	                  Xu5      5      nU R                  US0 5      n	U R                  X5      $ )a  
transfer currency internally between wallets on the same account

https://docs.ox.fun/?json#post-v3-transfer

:param str code: unified currency code
:param float amount: amount to transfer
:param str fromAccount: account id to transfer from
:param str toAccount: account id to transfer to
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
r  )rh  quantityrM  rN  r  )r  r{  currency_to_precisionprivatePostV3Transferr  r  parse_transfer)
r  rj  rL  rM  rN  r$  r{  r  rz  r  s
             r  r   oxfun.transferh  s     	==&d^224@&"	
 --dkk'.JK$ ~~h3""422r  c                    U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X%S'   Ub  X5S'   U R                  US5      nUb  XuS'   U R                  US5      nOUb  U R	                  US5      US'   U R                  U R                  XT5      5      nU R                  US	/ 5      n	U R                  XX#5      $ )
aj  
fetch a history of internal transfers made on an account

https://docs.ox.fun/?json#get-v3-transfer

:param str code: unified currency code of the currency transferred
:param int [since]: the earliest time in ms to fetch transfers for(default 24 hours ago)
:param int [limit]: the maximum number of transfer structures to retrieve(default 50, max 200)
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch transfers for(default time now)
:returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
Nr  rh  r  r   r  r  r  r  )	r  r{  rb  r  r  privateGetV3Transferr  r!  parse_transfers)
r  rj  r  r   r$  r  r{  r  rz  r  s
             r  fetch_transfersoxfun.fetch_transfers  s     	!}}T*H'~GG#(K $G!!&'2!&IYYvw/F!%%1H!IGI,,T[[-IJ$ ~~h3##DEAAr  r{  c                 \   U R                  US5      nU R                  US5      nU R                  US5      UU R                  U5      U R                  XB5      U R	                  US5      U R                  US5      U R                  US5      U R                  U R                  US5      5      US.	$ )	NtransferredAtrh  r  rP  rM  rN  status)	r  r  r  r{  rL  rM  rN  r\  r\  )rb  r0  r  r^  ra  parse_transfer_status)r  r   r{  r  rA  s        r  rS  oxfun.parse_transfer  s     %%h@	%%h8
""8T2"Y///
E&&x<++HmD))(K@001A1A(H1UV

 
	
r  c                 .    SS0nU R                  X!U5      $ N	COMPLETEDokrJ  r  r\  statusess      r  r]  oxfun.parse_transfer_status  #    
 &99r  c                 |   U R                  US5      nU R                  X15      nUc  [        U R                  S-   5      eU R	                  5         U R                  U5      nUS   US.nU R                  US5      nU R                  U R                  Xb5      5      nU R                  US0 5      nU R                  X5      $ )a  
fetch the deposit address for a currency associated with self account

https://docs.ox.fun/?json#get-v3-deposit-addresses

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: network for fetch deposit address
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
rm  z0 fetchDepositAddress() require network parameterr  )rh  rm  r  )r0  network_code_to_idr%   r  r  r{  r  privateGetV3DepositAddressesr  r  parse_deposit_address)	r  rj  r$  r  r  r{  r  rz  r  s	            r  fetch_deposit_addressoxfun.fetch_deposit_address  s     &&vy9++K>	TWW'YYZZ==&d^ 
 69-44T[[5QR ~~h3))$99r  c                 ^    U R                  US5      nU R                  U5        UUS   S US S.$ )Naddressrj  )r\  r{  rm  rn  tag)r0  check_address)r  depositAddressr{  rn  s       r  rj  oxfun.parse_deposit_address  sB     "">9=7#" (
 	
r  c                    U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X%S'   Ub  X5S'   U R                  US5      nUb  XuS'   U R                  US5      nU R	                  U R                  XT5      5      nU R                  US/ 5      n	[        S	[        U	5      5       H
  n
S
X   S'   M     U R                  XX#5      $ )aV  
fetch all deposits made to an account

https://docs.ox.fun/?json#get-v3-deposit

:param str code: unified currency code of the currency transferred
:param int [since]: the earliest time in ms to fetch transfers for(default 24 hours ago)
:param int [limit]: the maximum number of transfer structures to retrieve(default 50, max 200)
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch transfers for(default time now)
:returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
Nr  rh  r  r   r  r  r  r   rQ   r>  )
r  r{  rb  r  privateGetV3Depositr  r!  r.  r/  parse_transactionsr  rj  r  r   r$  r  r{  r  rz  r  r6  s              r  fetch_depositsoxfun.fetch_deposits  s     	!}}T*H'~GG#(K $G!!&'2!&IYYvw/F++DKK,HI$ ~~h3q#d)$A'DGFO %&&tuDDr  c                    U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X%S'   Ub  X5S'   U R                  US5      nUb  XuS'   U R                  US5      nU R	                  U R                  XT5      5      nU R                  US/ 5      n	[        S	[        U	5      5       H
  n
S
X   S'   M     U R                  XX#5      $ )ad  
fetch all withdrawals made from an account

https://docs.ox.fun/?json#get-v3-withdrawal

:param str code: unified currency code of the currency transferred
:param int [since]: the earliest time in ms to fetch transfers for(default 24 hours ago)
:param int [limit]: the maximum number of transfer structures to retrieve(default 50, max 200)
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch transfers for(default time now)
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr  rh  r  r   r  r  r  r   
withdrawalr>  )
r  r{  rb  r  privateGetV3Withdrawalr  r!  r.  r/  ru  rv  s              r  fetch_withdrawalsoxfun.fetch_withdrawalsE  s     	!}}T*H'~GG#(K $G!!&'2!&IYYvw/F..t{{7/KL( ~~h3q#d)$A*DGFO %&&tuDDr  c                    / n[        S[        U5      5       H>  nU R                  X   U5      X'   U R                  X   U5      nUR	                  U5        M@     U R                  US5      nUb  US   OS n	U R                  XiX45      $ )Nr   r  rj  )r.  r/  r  parse_transactionr2  sort_byfilter_by_currency_since_limit)
r  transactionsr{  r  r   r$  r5  r6  transactionrj  s
             r  ru  oxfun.parse_transactionsy  s    q#l+,A"kk,/6BLO00(KKMM+& - fk2$,$8xt226NNr  c                 &   U R                  US5      nU R                  US5      nU R                  US5      nS nS nS nUS:X  a4  U R                  US5      nU R                  U R                  US5      5      nO9US:X  a3  U R                  US5      nU R                  U R                  US5      5      nU R                  US5      nU R                  US5      n	U R	                  X5      n
U R                  US	5      nU R                  U5      nU R                  US
S5      nU R                  US5      nU R                  US5      nS nUb  UU
S.n0 SU_SU_SU_SU_SU R                  U5      _S	U_SU_SU_SS _SS _SS _SS _SU_SU_SU
_SU_SS _S S US.E$ )Nr  r>  rQ   rn  r\  rz  txIdrh  rm  
creditedAtrequestedAtrP  rk  r  r\  txidr  r  	addressToaddressFromro  tagTotagFromrL  r{  updated)internalcommentrk  )	r0  r  parse_deposit_statusparse_withdrawal_statusr^  rt  safe_integer_2ra  r  )r  r  r{  r  r>  rn  r  r\  r  rA  rj  rm  r  r  rL  feeCostrk  s                    r  r  oxfun.parse_transaction  sH   R k40V4iiV4	9&&{I>G..t/?/?X/VWF\!((i@I11$2B2B;PX2YZFV4%%k7;
&&z<"";	:--g6''\=Q	!!+z:"";6 C
K
"
 D
 	

 Y/
 {
 w
 
 4
 4
 T
 t
 D
 f
 
  f!
" t#
$ )
 	
r  c                 .    SS0nU R                  X!U5      $ r`  rJ  rc  s      r  r  oxfun.parse_deposit_status  rf  r  c                 :    SSSSSSSS.nU R                  X!U5      $ )Nrb  pendingcanceledfailed)ra  
PROCESSINGzIN SWEEPINGPENDINGzON HOLDCANCELEDFAILEDrJ  rc  s      r  r  oxfun.parse_withdrawal_status  s3    #$  "
 &99r  rn  ro  c                    U R                  XE5      u  pEU R                  5         U R                  U5      nU R                  X5      nUS   UUS.nUb  XHS'   Sn	U R	                  U5      u  pU	b  U R                  U	5      US'   SUS'   U R                  U R                  X5      5      n
U R                  U
S0 5      nS	US
'   U R                  X5      $ )a  
       make a withdrawal

       https://docs.ox.fun/?json#post-v3-withdrawal

       :param str code: unified currency code
       :param float amount: the amount to withdraw
       :param str address: the address to withdraw to
       :param str tag:
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :param str [params.network]: network for withdraw
       :param bool [params.externalFee]: if False, then the fee is taken from the quantity, also with the burn fee for asset SOLO

EXCHANGE SPECIFIC PARAMETERS
       :param str [params.tfaType]: GOOGLE, or AUTHY_SECRET, or YUBIKEY, for 2FA
       :param str [params.code]: 2FA code
       :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
       r  )rh  rn  rP  Nmemorm  FexternalFeer  rz  r>  )
handle_withdraw_tag_and_paramsr  r{  rQ  handle_network_code_and_paramsrh  privatePostV3Withdrawalr  r  r  )r  rj  rL  rn  ro  r$  r{  stringAmountr  r  rz  r  s               r  r   oxfun.withdraw  s    & 99#F==&11$?d^$

 ?!FO"AA&I"!%!8!8!EGI!&//G0LM" ~~h3#V%%d55r  c                 :   U R                  5         U R                  U5      nU R                  U5      nU R                  US/ 5      n/ n[	        S[        U5      5       H+  nXF   nU R                  US/ 5      nU R                  XX5      nM-     U R                  XQ5      $ )aO  
fetch all open positions

https://docs.ox.fun/?json#get-v3-positions

:param str[]|None symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.subAcc]:
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
r  r   	positions)r  r  privateGetV3Positionsr!  r.  r/  r"  parse_positions)	r  r  r$  rz  r  allPositionsr6  r>  r  s	            r  fetch_positionsoxfun.fetch_positions'  s     	%%g.--f5X ~~h3q#d)$AgGwR@I,,\EL % ##L::r  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U R                  US5      _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  rB  notionalr   crossliquidationPriceestLiquidationPrice
entryPriceunrealizedPnlpositionPnlrealizedPnlr   	contractspositionrS  r  	lastPricer!  r   r  r  )r  lastUpdateTimestampr
  maintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager   marginRatior   r   )r0  r  safe_positionra  rb  )r  r  r7  r8  s       r  parse_positionoxfun.parse_positionk  s    ##Hl;!!(3!! #
H#
$#
 fX&#
 	#

 '#
  0 0;P Q#
 $**8\B#
 T--hF#
 4#
 $#
 ))(J?#
 D#
 ))(K@#
 #
 D#
  d!#
" ##
$ #'#4#4X#O!%+/!'+!#9#
  	r  r>  r!  rM  c                    U R                  5         U R                  USS5      U R                  USU R                  5       5      S.nU R	                  USS/5      nU R                  US5      nUb  XS'   U R	                  US5      nU R                  XX4XV5      n	U	/US'   U R                  U5      n
U R                  U
S/ 5      nU R                  US0 5      nU R                  U5      $ )	a  
create a trade order

https://docs.ox.fun/?json#post-v3-orders-place

: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 str [params.responseType]: FULL or ACK
: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.selfTradePrevention]: 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>`
responseTypeFULLr  )r  r  
recvWindowordersr  r   )
r  r0  rb  millisecondsr  create_order_requestprivatePostV3OrdersPlacer!  r  parse_order)r  rB  r>  r!  rL  rM  r$  r  r  orderRequestrz  r  r'  s                r  create_orderoxfun.create_order  s    2 	 ,,V^VL**6;@Q@Q@ST
 6NK#@A&&v|<
!$.L!YYv|4F00tU[)N009j ~~h3tQ+&&r  r  c           	      8   U R                  5         / n[        S[        U5      5       H  nX   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S5      n
U R                  US0 5      nU R                  XgXX5      nUR                  U5        M     SU R                  5       US	.nU R                  U R                  X5      5      nU R                  US
/ 5      nU R                  U5      $ )a  
create a list of trade orders

https://docs.ox.fun/?json#post-v3-orders-place

:param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.timestamp]: *for all orders* in milliseconds. If orders reach the matching engine and the current timestamp exceeds timestamp + recvWindow, then all orders will be rejected.
:param int [params.recvWindow]: *for all orders* in milliseconds. If orders reach the matching engine and the current timestamp exceeds timestamp + recvWindow, then all orders will be rejected. If timestamp is provided without recvWindow, then a default recvWindow of 1000ms is used.
:param str [params.responseType]: *for all orders* FULL or ACK
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r   rB  r>  r!  rL  rM  r$  r  )r  r  r  r  )r  r.  r/  r0  ra  r  r  r2  r  r  r  r!  parse_orders)r  r  r$  ordersRequestsr6  rawOrderrB  r>  r!  rL  rM  orderParamsr  r  rz  r  s                   r  create_ordersoxfun.create_orders8	  s    	q#f+&AyH%%h9F##Hf5D##Hf5D%%h9F$$Xw7E..8R@K44V4QVdL!!,/ ' #**,$

 00W1MN~~h3  &&r  c                    U R                  U5      nUS   UR                  5       SS.nU R                  USS5      n	U	b  XS'   U R                  USS/5      nOXHS'   U R                  USS	5      n
UR                  5       nU
b)  US
:X  a  SnOUS:X  a  SnXS	'   U R                  USS	/5      nXS'   US:X  a  XXS'   OUb  XXS'   SnUS
:H  =(       d    US:H  nU R	                  USU5      u  pU R                  US5      nU(       a  US:w  a  SUS'   SnU R                  USS5      u  pUb  UR                  5       US'   U R                  X5      $ )ai  
: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 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.selfTradePrevention]: 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
r  i  )r-  r!  sourcerQ  rL  NrP  r   	stopPriceMARKETSTOP_MARKETLIMIT
STOP_LIMIT	orderType
limitPricerM  Fr   MAKER_ONLY_REPRICE
MAKER_ONLYrJ   r   selfTradePreventionMode)r7  upperr+  r  handle_post_onlysafe_string_upperhandle_option_and_paramsr  )r  rB  r>  r!  rL  rM  r$  r7  r  rQ  r   r  postOnlyisMarketOrderr   r   s                   r  r  oxfun.create_order_requestZ	  s   " V$ ,JJL

 !!&&(; $HYYv'9:F"(J))&.+NJJL	#H$)	g%(	#/K YYv'DEF($$)L!$G"h.OI4N00vN,,V]C(<<%1GM""&*&C&CFM[p&q#*1D1J1J1LG-.{{7++r  rQ  c                     U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSU0nU R	                  USSSSU R                  XS5      5      $ )a  
create a market buy order by providing the symbol and cost

https://open.big.one/docs/spot_orders.html#create-order

:param str symbol: unified symbol of the market to create an order in
:param float cost: how much you want to trade in units of the quote currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r;   z9 createMarketBuyOrderWithCost() supports spot orders onlyrQ  r7  buyN)r  r7  r+   r  r  r  )r  rB  rQ  r$  r7  r  s         r  !create_market_buy_order_with_cost'oxfun.create_market_buy_order_with_cost	  sm     	V$f~tww)ddeeD
   5$dkkRYFbccr  r  c                     U R                  5         SU0nU R                  U R                  XC5      5      nU R                  US0 5      nU R	                  U5      $ )a  

https://docs.ox.fun/?json#get-v3-orders-status

fetches information on an order made by the user
:param str id: a unique id for the order
:param str [symbol]: not used by oxfun fetchOrder
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.clientOrderId]: the client order id of the order
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r   r  )r  privateGetV3OrdersStatusr  r  r  )r  r  rB  r$  r  rz  r  s          r  fetch_orderoxfun.fetch_order	  s\     	r
 00W1MN0 ~~h3%%r  c                     U R                  5         0 nSnUb  U R                  U5      nU R                  U R                  XT5      5      nU R	                  US/ 5      nU R                  XX#5      $ )a=  
fetch all unfilled currently open orders

https://docs.ox.fun/?json#get-v3-orders-working

:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch open orders for
:param int [limit]: the maximum number of  open orders structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.orderId]: a unique id for the order
:param int [params.clientOrderId]: the client order id of the order
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr  )r  r7  privateGetV3OrdersWorkingr  r!  r  )	r  rB  r  r   r$  r  r7  rz  r  s	            r  fetch_open_ordersoxfun.fetch_open_orders	  sl     	[[(F11$++g2NO~~h3  u<<r  c                    Uc  [        U R                  S-   5      eU R                  U5      nUS   nU R                  5       SS.nUUS.nU R	                  US5      nUb  XS'   U/US'   U R                  U R                  Xc5      5      n	U R                  U	S/ 5      n
U R                  U
S	0 5      nU R                  U5      $ )
a  
cancels an open order

https://docs.ox.fun/?json#delete-v3-orders-cancel

:param str id: order id
:param str symbol: unified symbol of the market the order was made in
: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
:param int [params.recvWindow]: in milliseconds
:param str [params.responseType]: 'FULL' or 'ACK'
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
z) cancelOrder() requires a symbol argumentr  r  r  r  r-  r   clientOrderIdr  r  r   )
r$   r  r7  r  rb  privateDeleteV3OrdersCancelr  r!  r  r  )r  r  rB  r$  r7  r8  r  r  r  rz  r  r'  s               r  cancel_orderoxfun.cancel_order	  s     >#DGG.Y$YZZV$$<**,"

 #
 ))&/B$,9))N33DKK4PQ~~h3tQ+&&r  c                     0 nUb  U R                  U5      nUS   US'   U R                  U R                  X25      5      nU R                  SU05      /$ )a<  
cancel all open orders

https://docs.ox.fun/?json#delete-v3-orders-cancel-all

:param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from exchange
r  r-  r\  )r7  privateDeleteV3OrdersCancelAllr  
safe_order)r  rB  r$  r  r7  rz  s         r  cancel_all_ordersoxfun.cancel_all_orders
  s]     [[(F$*4LGL! 66t{{77ST 2344r  idsc                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUS   nU R	                  5       SS.n/ n[        S[        U5      5       H  nUX   S.n	UR                  U	5        M     XvS'   U R                  U R                  Xc5      5      n
U R                  U
S/ 5      nU R                  X5      $ )	a  
cancel multiple orders

https://docs.ox.fun/?json#delete-v3-orders-cancel

:param str[] ids: order ids
:param str [symbol]: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.timestamp]: in milliseconds
:param int [params.recvWindow]: in milliseconds
:param str [params.responseType]: 'FULL' or 'ACK'
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
z* cancelOrders() requires a symbol argumentr  r  r  r   r  r  r  )r$   r  r  r7  r  r.  r/  r2  r  r  r!  r  )r  r  rB  r$  r7  r8  r  r  r6  r'  rz  r  s               r  cancel_ordersoxfun.cancel_orders'
  s     >#DGG.Z$Z[[V$$<**,"
 q#c(#A&6E MM%  $ #33DKK4PQ~~h3  ..r  c           
         U R                  US5      nU R                  X25      nU R                  US5      nS nU R                  US5      nUb$  U R                  U5      U R	                  US5      S.nU R                  US5      nU R                  US5      nUb  SnU R                  US	5      n	U R                  0 S
U R                  US5      _SU R                  US5      _SU_SU R                  U5      _SU R                  US5      _SU R                  US5      _SU R                  U5      _SUS   _SU R                  U R                  US5      5      _SU R                  U R                  US5      5      _SU R                  US5      _SU R                  U/ SQ5      _SS _SU R                  USS5      _SU R                  USS 5      _S!U R                  US"5      _S#U	_U	U R                  U R                  US5      5      S UUS$.EU5      $ )%Nr-  r  feeInstrumentIdr   )r{  rQ  r\  rj  rejectedr  r  r   r  r  r  lastTradeTimestamplastMatchedAtr  lastModifiedAtrB  r>  r  r   r!  rM  )rM  r$  r  r  rL  totalQuantityrP  filledcumulativeMatchedQuantityr%  	remainingremainQuantityr   )r   rQ  tradesrk  r\  )r0  r  rb  r^  ra  r   r  parse_order_statusparse_order_typeparse_order_time_in_forcer_  safe_string_nr+  	omit_zero)
r  r'  r7  r8  r  rk  feeCurrencyr\  rj  r   s
             r  r  oxfun.parse_orderJ
  s   ` ##E<8!!(3%%e[9	&&u.?@" 33K@((7C !!%2  /F''{;  
$""5)4 
T--e_E 
  
 Y/	 

 !$"3"3E?"K 
 "4#4#4U<L#M 
 d--f5 
 fX& 
 D))$*:*:5+*NO 
 499$:J:J5R_:`a 
 D**5&9 
 T''/TU 
 t 
 d((L 
 d((0K_] 
  ))%1AB! 
" L# 
$ *NN4#3#3E8#DE- 
. / 	r  c                 B    SSSSSSSSSSSS.nU R                  X!U5      $ )Nr  closedr  r	  )OPENPARTIALLY_FILLEDPARTIAL_FILLFILLEDr  CANCELED_BY_USERCANCELED_BY_MAKER_ONLYCANCELED_BY_FOKCANCELED_ALL_BY_IOCCANCELED_PARTIAL_BY_IOC!CANCELED_BY_SELF_TRADE_PROTECTIONrJ  rc  s      r  r  oxfun.parse_order_status
  s?     &"" *&0)#-'11;
 &99r  c                 4    SSSSS.nU R                  X!U5      $ )Nr   r7  )r  r  r  r  rJ  r  r>  typess      r  r  oxfun.parse_order_type
  s*    !#	
 T22r  c                 6    SSSSSS.nU R                  X!U5      $ )NGTCr   r   r   )r,  r   r   r  r  rJ  r(  s      r  r  oxfun.parse_order_time_in_force
  s-    "&
 T22r  r   GETc                    U R                   S   U   nUS-   U-   nSn	US:X  a(  U R                  U5      n	[        U	5      S:w  a  USU	-   -  nUS:X  Ga  U R                  5         U R	                  5       n
U R                  U
5      nUR                  S5      nUS   nU R                  5       nUR                  S	5      nUS
:X  d  US:X  a  U R                  U5      nUn	US-   [        U5      -   S-   U-   S-   US   -   S-   U-   S-   U	-   nU R                  U R                  U5      U R                  U R                  5      [        R                  S5      nSU R                  UU[        U5      S.nXXeS.$ )Nr   r=  r;  r.  r   ?r   ri  z//POSTDELETE
r   z
/base64zapplication/json)zContent-Type	AccessKey	Timestamp	SignatureNonce)urlmethodbodyheaders)r  	urlencoder/  check_required_credentialsr  r  r]  noncejsonstrhmacencodesecrethashlibsha256apiKey)r  pathr   r:  r$  r<  r;  baseUrlr9  queryStringr  isoDatetimedatetimePartsr  r?  urlParts	msgString	signatures                     r  sign
oxfun.sign  s~   ))E"3'md"U?..0K;1$s[(()++-))+I,,y1K'--c2M$Q'HJJLE}}T*H& f&8yy(" 4#e*4t;fDtKhWXkY\aadhhkoor}}I		$++i"8$++dkk:RT[TbTbdlmI 2![[%&UG dOOr  c
                     Uc  g US:w  an  U R                  USS 5      n
U R                  S-   U-   nU R                  U R                  S   Xk5        U R	                  U R                  S   X5        [        U5      eg )N   rj   r  r  )r0  r  throw_broadly_matched_exceptionr  throw_exactly_matched_exceptionr!   )r  rj  reasonr9  r:  r<  r;  rz  requestHeadersrequestBodyresponseCodefeedbacks               r  handle_errorsoxfun.handle_errors#  sx    3;++HfdCLww}t+H001I4Z001I<b))r   )N)]__name__
__module____qualname____firstlineno__r   r  r    r   r*  r#  r3  r	   r  r   r   r  rA  r   r  r  r   rw  r  r  r   r  r   r  r   r  r  r   r  r  r  r  r   r  r   r  r   r  r  r-  r   r5  r2  r   rF  rK  floatr   r   rX  r
   rS  r]  r   rk  rj  r   rw  r|  ru  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  rP  r\  __static_attributes____classcell__)r  s   @r  r2   r2      s-   s# sj $& Z+$v, Z+x	V 	Ff FP ') TZ Tl 04B =4W =47 =4~ 02 &13 &1f &1P+6 +V +Z 9=4^bkm <J# <J# <JS <JX[ <Jrvw{r| <J|
 
4 
* :>b -Hs -H3 -HY -H^ 6:"  77  7  7D 68 C CK C(
f 
 
@ 8<$]ajl -M -MC -MWZ -M^
v 
< 37TX\eg 6@C 6@s 6@RU 6@p
6 
< 7;2 6FG 6F- 6Fp! !$|J\ !F 6:UW .=3 .=s .=# .=\`af\g .=` -1tRV_a 5?c 5? 5?C 5?n6 65 6p $& 4+( 4+l%) %)N %' 14= 16
 [] )3S )3% )3c )3c )3an )3V +/TPT]_ 1BC 1Bs 1B# 1Bf
 
8: 79 :# :^ ::
h 
R` 
 *.Dt\^ 0E3 0Ec 0E 0Ecghsct 0Ed -1tRV_a 2Ec 2E 2EC 2Efjkvfw 2Eh EIW[jnwy O OQT Odg O  C  DO  P OX
x X
; X
t:
: KOWY 66S 66% 66# 66C 66^i 66p 26b B;w B;T(^ B;H-v -^ gksu \'3 \'i \'y \'RW \'`c \'z \'| @B  'D$6  'd5k  'D UYac 5,3 5,c 5, 5,n RT d d5 d( 26b )&c )&3 )&U )&V /3TXac = =3 =c =hlmrhs =. 37r "'s "'C "'H /32 5 58 ;?r !/c !/C !/FV V5 Vp: 33 &eBSW P<	 	r  r2   )6ccxt.base.exchanger   ccxt.abstract.oxfunr   rE  ccxt.base.typesr   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   typingr    ccxt.base.errorsr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   ccxt.base.decimal_to_precisionr0   r2   r^  r  r  <module>rl     s    ( +  k  k  k  k  k  k  k  k  * 0 . . ' & ) . ) * ) , ) . + 4O,Hk O,r  