
    !:h                    |   d dl mZ d dl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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' 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, d dl#m-Z- d dl#m.Z. d dl#m/Z/ d dl#m0Z0 d dl#m1Z1 d dl#m2Z2 d dl3m4Z4  G d dee      Z5y)    )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                       e Zd Zdef fdZi fdee   fdZdee   fdZdefdZ	i fde
fdZdi fdedefd	Zi fd
edefdZdQdedefdZdddi fd
edededee   fdZdQdedefdZdi fd
ededefdZdi fdedefdZi fd
edefdZdQdedefdZdddi fd
ededefdZdQdefdZ dddi fd
ededefdZ!dQdefdZ"di fdede#fdZ$dQdedee%   fdZ&ddi fd
edededee'   fdZ(dddi fd
ededefdZ)dQdede'fdZ*i fde+fd Z,de+fd!Z-i fdee.   fd"Z/d# Z0i fd$ed%e1d&ed'ede2f
d(Z3dddi fd$ededefd)Z4dQd*e5fd+Z6d, Z7i fd$ede8fd-Z9dQd*e5de8fd.Z:dddi fd$edededee;   fd/Z<dddi fd$edededee;   fd0Z=dddi fd*e5dededee;   fd1Z>dQd*e5de;fd2Z?d3 Z@d4 ZAdi fd$ed%e1d5ede;fd6ZBdi fdedeeC   fd7ZDdQdefd8ZEdi fd
ed9eFd:eGd%e1d;eHdeIfd<ZJi fd=eeK   deeI   fd>ZLdi fd
ed9ed:efd?ZMi fd
ed@e1fdAZNdi fdBed
edeIfdCZOdddi fd
edededeeI   fdDZPdi fdBed
efdEZQdi fd
efdFZRdi fdGee   d
efdHZSdQdedeIfdIZTdJ ZUdK ZVdL ZWdMdNi ddfdOZXdP ZY xZZS )Roxfunreturnc           !      Z	   | j                  t        t        |          dddgdd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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
i d*d
d+d
d,dd-d
d.dd/d
d0d
d1dd2d
d3d
d4dd5dd6dd7dd8d
d9d
d:d
i d;d
d<d
d=d
d>dd?d@dAddBd
dCddDddEd
dFd
dGddHddIddJd
dKd
dLd
i dMd
dNd
dOd
dPddQd
dRd
dSd
dTd
dUd
dVddWddXd
dYddZd
d[d
d\d
d]d
i d^d
d_d
d`ddad
dbddcd
ddd
ded
dfd
dgddhd
did
djd
dkd
dld
dmddnddodidpdqdrdsdtdudvdwdxdydzd{d{d|d}d}d|d~ddddddddddddddd
iddddddddddddddddddddddddd|ddd| j	                  d      | j	                  d      | j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      gg| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      ggddit
        d
dddddddddd	ddddddddddd
ddd
dd
d d
d
d dddd
dd
d
d
dd
dddddid
dddd
dd
d
d
d
dd
d d
d
d
dd d ddid	ddiddid dd d ddi dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt         dt"        dt"        dt$        dt"        dt        dt        t        t        t        t        t&        t&        t&        t        t        d	t        t(        ddd      S )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)
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   rI   rJ   rt   ry   rx   r|   rZ   ru   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/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/oxfun.pyr  z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/3#')$. r% ',!$$*%&*/& ',#($)*/	# ',!%#($)*/( $()-#c4l y
 "9  $	 ##CJ=_=-= 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S	m@
 m m	    c                     | j                  |      | j                  |      g\  }}| j                  |dg       }| j                  |dg       }| j                  ||      }| j	                  |      S )a  
        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_marketszoxfun.fetch_markets  s     594K4KF4SUYUlUlmsUt3u00!^^,?Lr "^^,?L, ##$68JK!!'**r  c                     g }g }t        dt        |            D ]]  }||   }| j                  |d      }| j                  ||      r-|j	                  |       |j	                  | j                  |             _ |S )Nr   
marketCode)rangelensafe_stringin_arrayappendparse_market)r  r#  	marketIdsresultimarketmarketIds          r  r  zoxfun.parse_markets  s{    	q#g,' 	9AQZF''=HMM(I6  *d//78	9 r  c                    | j                  |dd      }|j                  d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }|dz   |z   }| j                  |dd      }	d }
d }|	d	k(  }|rd
}	d}
| j                  d      }|dz   |z   }|	dk(  }| j	                  i d|dd d|d|d|d|d|d|d|
d|	d|ddd
|d	dddddd||rdnd |rdnd | j
                  d   d   | j
                  d   d   |rdnd d d d d d | j                  |d      d d d d!| j                  |d"      d d!d d d!d d d!d#| j                  |d$      d |d%      S )&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   rD  rE  costlistedAt)r   r   r   r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedindexinfo)r)  splitsafe_currency_codesafe_string_lowersafe_market_structurer   safe_numbersafe_integer)r  r0  r  partsr>  r?  r;  r<  r:  r6  r@  r=  isFutureisSpots                 r  r,  z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                    | j                  |      }| j                  |dg       }i }t        dt        |            D ]r  }||   }| j	                  |dd      }|j                  d      }|d   }	| j                  |	      }
|
|vr|	|
ddddddddddddddi g d	||
<   | j                  |d
g       }t        dt        |            D ]  }||   }| j	                  |d      }| j                  |      }||d| j                  |d      | j                  |d      dd| j                  | j                  | j	                  |d                  | j                  |d      dd| j                  |d      ddd|d
||
   d   |<    | j                  ||
   dg       }|j                  |       |||
   d<   u t        |j                               }t        dt        |            D ]  }||   }
| j                  ||
         ||
<     |S )a  
        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   assetr3  .NrF  )r   rP   )r  coderP  r6  r  rA  rP   r   feerQ  r   rT  networkListnetwork
canDepositcanWithdrawtransactionPrecision
minDepositminWithdrawal)rP   r   )
r  rd  r;   rP   r   rA  rb  rP  rQ  rT  r   rT  )publicGetV3Assetsr  r'  r(  r)  rU  rV  network_id_to_code	safe_boolr  parse_precisionrY  r+  listkeyssafe_currency_structure)r  r  responser  r.  r/  currencyfullIdr[  r  ra  chainsjchain	networkIdnetworkCodeinfosallKeyss                     r  fetch_currencieszoxfun.fetch_currencies>  si    ))&1R ~~h3q#d)$ :	)AAwH%%h<FLL%EqB**2.DFN !%  "# $ $(#'%
 $(#'$	 !#+ t. ^^HmR@F1c&k* q	 ,,UI>	"55i@#*"#~~e\B $um D"!%!2!243G3GHXHXY^`vHw3x!y $(#3#3E<#H#'$
 $(#3#3E?#K#'%	 "'9tZ(5	2 NN6$<<ELL"#(F4L u:	)x v{{}%q#g,' 	FA1:D77tEF4L	F r  Nsymbolsc                     | j                          | j                  |      }| j                  |      }| j                  |dg       }| j	                  ||      S )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  rq  tickerss        r  fetch_tickerszoxfun.fetch_tickers  sX     	%%g.**62` ..626!!'733r  r:  c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  |di       }| j                  ||      S )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~  r0  r  extendr  	safe_dictparse_ticker)r  r:  r  r0  requestrq  r  tickers           r  fetch_tickerzoxfun.fetch_ticker  s     	V$&,
 **4;;w+GH* ~~h3a,  00r  r0  c           	         | j                  |d      }| j                  |d      }| j                  ||      }|d   }| j                  |d      }| j                  i d|d|d| j	                  |      d| j                  |d      d	| j                  |d
      dd dd dd dd dd d| j                  |d      d|d|dd dd dd dd | j                  |d      d | j                  |d      |d|      S )NlastUpdatedAtr&  r:  lastTradedPrice	timestampdatetimehighhigh24hlowlow24hbid	bidVolumeask	askVolumevwapopenopen24hcloselastpreviousClosechanger   averagecurrencyVolume24h	markPrice)
baseVolumequoteVolumer  rT  )rZ  r)  safe_marketsafe_tickeriso8601)r  r  r0  r  r1  r:  r  s          r  r  zoxfun.parse_ticker;  s     %%fo>	##FL9!!(F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   sincer   c                    | j                          | j                  |      }| j                  | j                  ||      }|d   |d}|||d<   |||d<   | j	                  |d      }|||d<   | j                  |d      }n|| j                  |d      |d<   | j                  | j                  ||            }	| j                  |	dg       }
| j                  |
||||      S )	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&  	timeframe	startTimer   untilendTime $r  )r~  r0  r)  r	  rZ  omitsumpublicGetV3Candlesr  r  parse_ohlcvs)r  r:  r  r  r   r  r0  r  r  rq  r.  s              r  fetch_ohlcvzoxfun.fetch_ohlcvh  s     	V$$$T__iK	 ,"
 #(GK $GG!!&'2!&GIYYvw/F!%%1H!IGI**4;;w+GH8 &"5  E5IIr  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )NopenedAtr  r  r  r  currencyVolume)rZ  rY  )r  ohlcvr0  s      r  parse_ohlcvzoxfun.parse_ohlcv  so     eZ0UF+UF+UE*UG,U$45
 	
r  c                    | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  |di       }| j                  |d      }| j                  ||d   |      S )a8  
        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  r:  )r~  r0  publicGetV3Depthr  r  rZ  parse_order_book)	r  r:  r   r  r0  r  rq  r  r  s	            r  fetch_order_bookzoxfun.fetch_order_book  s     	V$&,
 $GG((Wf)EF2 ~~h3%%dO<	$$T6(+;YGGr  c                     | j                          | j                  |      }| j                  |      }| j                  |dg       }| j	                  ||      S )a  
        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  rq  r  s        r  fetch_funding_rateszoxfun.fetch_funding_rates  sW     	%%g.33F;& ~~h3''g66r  c                    | j                          d| j                  |      i}| j                  | j                  ||            }| j	                  |dg       }| j                  |di       }| j                  || j                  |            S )aw  
        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_rater0  )r  r:  r  r  rq  r  firsts          r  fetch_funding_ratezoxfun.fetch_funding_rate  s     	$..0
 33DKK4PQ~~h3tQ+&&udkk&.ABBr  c                 @   | j                  |d      }| j                  |      }| j                  |d      }i d|d|d   dd dd d| j                  d      d	d d
|d| j	                  |      d| j                  |d      dd dd dd dd dd dd dd dd dd iS )Nr&  	fundingAtrT  r:  r  
indexPriceinterestRater   estimatedSettlePricer  r  fundingRateestFundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r)  r0  rZ  r  r  rY  )r  r  r0  r:  estFundingRateTimestamps        r  r  z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                 T   | j                          | j                  |      }d|d   i}|||d<   |||d<   | j                  |d      }|||d<   | j                  |d      }| j	                  | j                  ||            }| j                  |dg       }	| j                  |	|||      S )a  
        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~  r0  rZ  r  publicGetV3FundingRatesr  r  parse_funding_rate_histories
r  r:  r  r   r  r0  r  r  rq  r  s
             r  fetch_funding_rate_historyz oxfun.fetch_funding_rate_history@  s     	V$&,
 #(GK $GG!!&'2!&GIYYvw/F//GV0LM$ ~~h300vueLLr  c                     | j                  |d      }| j                  ||      }|d   }| j                  |d      }||| j                  |d      || j	                  |      dS )Nr&  r:  	createdAtr  )rT  r:  r  r  r  )r)  r  rZ  rY  r  )r  rT  r0  r1  r:  r  s         r  parse_funding_rate_historyz oxfun.parse_funding_rate_historyo  ss    $ ##D,7!!(F3!%%dK8	++D-@"Y/
 	
r  c                 T   | j                          | j                  |      }d|d   i}|||d<   |||d<   | j                  |d      }|||d<   | j                  |d      }| j	                  | j                  ||            }| j                  |dg       }	| j                  |	|||      S )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~  r0  rZ  r  privateGetV3Fundingr  r  parse_incomes)
r  r:  r  r   r  r0  r  r  rq  r.  s
             r  fetch_funding_historyzoxfun.fetch_funding_history  s     	V$&,
 #(GK $GG!!&'2!&GIYYvw/F++DKK,HI6 &"5!!&&%??r  c           	      0   | j                  |d      }| j                  ||      }| j                  |d      }| j                  d      }| j                  |d      }| j	                  |d      }| j                  |d      }	||||| j                  |      |||	dS )Nr&  paymentr7  r  r  r  )rT  r:  ra  r  r  r  rD  rate)r)  safe_symbolrY  rV  safe_timestampr  )
r  incomer0  r1  r:  rD  ra  r  r  r  s
             r  parse_incomezoxfun.parse_income  s     ##FL9!!(F3!!&)4&&t,fd+''<	6"Y/	
 		
r  c                     | j                          | j                  |      }| j                  |dg       }| j                  ||d      S )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_tierszoxfun.fetch_leverage_tiers  sJ     	008T ~~h3((wEEr  c                    | j                  |d      }| j                  ||      }| j                  |dg       }g }t        dt	        |            D ]  }||   }|j                  | j                  |d      | j                  ||      |d   | j                  |d      | j                  |d      | j                  |d      | j                  |d	      |d
        |S )Nr&  r   r   tierr=  positionFloorpositionCapmaintenanceMarginr   )r  r:  rr  minNotionalmaxNotionalmaintenanceMarginRatemaxLeveragerT  )r)  r  r  r'  r(  r+  rY  r  )r  rT  r0  r1  listOfTiersr   ru  r  s           r  parse_market_leverage_tiersz!oxfun.parse_market_leverage_tiers  s    " ##D,7!!(F3nnT7B7q#k*+ 	Aq>DLL((v6**8V<"8,#//oF#//mD)-)9)9$@S)T#//jA	 		 r  c                    | j                          | j                  |      }d|d   i}|||d<   |||d<   | j                  |d      }|||d<   | j                  |d      }n|| j	                  |d      |d<   | j                  | j                  ||            }| j                  |dg       }	| j                  |	|||      S )	a  
        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~  r0  rZ  r  r  publicGetV3ExchangeTradesr  r  parse_tradesr  s
             r  fetch_tradeszoxfun.fetch_trades>  s     	V$&,
 #(GK $GG!!&'2!&GIYYvw/F!%%1H!IGI11$++gv2NO" ~~h3  vue<<r  c                    | j                          i }d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  |d      }|||d<   | j                  |d      }n|| j	                  |d      |d<   | j                  | j                  ||            }| j                  |d	g       }	| j                  |	|||      S )
aZ  
        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~  r0  rZ  r  r  privateGetV3Tradesr  r  r  )
r  r:  r  r   r  r  r0  r  rq  r.  s
             r  fetch_my_tradeszoxfun.fetch_my_tradesn  s     	[[(F$*4LGL!#(GK $GG!!&'2!&GIYYvw/F!%%1H!IGI**4;;w+GH. &"5  >>r  c                    | j                  |d      }| j                  ||      }|d   }| j                  |d      }| j                  |d      | j                  | j                  |d            d}| j	                  | j                  |d      || j                  |      |d | j                  |d      | j                  |d	      | j                  |d
d      | j                  |d      | j                  |dd      d ||d|      S )Nr&  r:  	matchedAtrb  feeAssetrI  rr  matchIdorderIdside	matchTypeorderMatchType
matchPricematchQuantitymatchedQuantity)r  r  r  r:  r6  orderr  takerOrMakerrE  rD  rI  rb  rT  )	r)  r  rZ  rV  
safe_trader  rW  safe_string_lower_2safe_string_2)r  trader0  r1  r:  r  rb  s          r  parse_tradezoxfun.parse_trade  s   @ ##E<8!!(F3!%%e[9	$$UE2//0@0@
0ST
 ""5)4"Y/%%eY7**5&9 44UKIYZ%%e\:((ARS 
  	r  c                 2   | j                          | j                  |      }| j                  |dg       }|d   }| j                  |d      }|:t	        dt        |            D ]"  }||   }| j                  |d      }||k(  s |} n | j                  |      S )aP  
        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  r)  r'  r(  parse_balance)	r  r  rq  r  balancer  r/  br  s	            r  fetch_balancezoxfun.fetch_balance  s     	,,V4< ~~h3q'!!&(31c$i( G''626>G !!'**r  c                 ~   d|i}| j                  |dg       }t        dt        |            D ]~  }||   }| j                  |d      }| j	                  |      }| j                         }| j                  |d      |d<   | j                  |d      |d<   | j                  |d      |d	<   |||<    | j                  |      S )
NrT  balancesr   r_  total	availablefreereservedused)r  r'  r(  r)  rV  accountsafe_balance)	r  r  r.  r  r/  balanceEntry
currencyIdra  r!  s	            r  r  zoxfun.parse_balance  s    2 G
 >>':r:q#h-( 	#A#A;L)),@J**:6DllnG#//gFGG"..|[IGFO"..|ZHGFO"F4L	#   ((r  c                     | j                          | j                  |      }| j                  |dg       }| j                  ||      S )aS  
        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  rq  r  s       r  fetch_accountszoxfun.fetch_accounts:  sG     	008 ~~h3""400r  c                 0    | j                  |d      d d |dS )N	accountId)r  r6  ra  rT  r)  )r  r!  s     r  parse_accountzoxfun.parse_accountU  s'     ""7K8	
 	
r  ra  rD  fromAccount	toAccountc                    | j                          | j                  |      }|d   | j                  ||      ||d}| j                  | j	                  ||            }| j                  |di       }	| j                  |	|      S )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  )r_  quantityr-  r.  r  )r~  rr  currency_to_precisionprivatePostV3Transferr  r  parse_transfer)
r  ra  rD  r-  r.  r  rr  r  rq  r  s
             r  r   zoxfun.transferc  s     	==&d^224@&"	
 --dkk'6.JK$ ~~h3""422r  c                    | j                          i }d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  |d      }|||d<   | j                  |d      }n|| j	                  |d      |d<   | j                  | j                  ||            }| j                  |d	g       }	| j                  |	|||      S )
a  
        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  r_  r  r   r  r  r  r  )	r~  rr  rZ  r  r  privateGetV3Transferr  r  parse_transfers)
r  ra  r  r   r  r  rr  r  rq  r  s
             r  fetch_transferszoxfun.fetch_transfers  s     	!}}T*H'~GG#(GK $GG!!&'2!&GIYYvw/F!%%1H!IGI,,T[[&-IJ$ ~~h3##D(E5AAr  rr  c                 ^   | j                  |d      }| j                  |d      }| j                  |d      || j                  |      | j                  ||      | j	                  |d      | j                  |d      | j                  |d      | j                  | j                  |d            |d	S )	NtransferredAtr_  r  r0  r-  r.  status)	r  r  r  rr  rD  r-  r.  r:  rT  )rZ  r)  r  rV  rY  parse_transfer_status)r  r   rr  r  r$  s        r  r3  zoxfun.parse_transfer  s     %%h@	%%h8
""8T2"Y///
HE&&x<++HmD))(K@001A1A(H1UV

 
	
r  c                 0    ddi}| j                  |||      S N	COMPLETEDokr+  r  r:  statusess      r  r;  zoxfun.parse_transfer_status  %    
 &&99r  c                    | j                  |d      }| j                  ||      }|t        | j                  dz         | j	                          | j                  |      }|d   |d}| j                  |d      }| j                  | j                  ||            }| j                  |di       }| j                  ||      S )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>`
        rd  z0 fetchDepositAddress() require network parameterr  )r_  rd  r  )r)  network_code_to_idr%   r  r~  rr  r  privateGetV3DepositAddressesr  r  parse_deposit_address)	r  ra  r  rx  rw  rr  r  rq  r  s	            r  fetch_deposit_addresszoxfun.fetch_deposit_address  s     &&vy9++K>	TWW'YYZZ==&d^ 
 69-44T[[&5QR ~~h3))$99r  c                 ^    | j                  |d      }| j                  |       ||d   d |d dS )Naddressra  )rT  rr  rd  rI  tag)r)  check_address)r  depositAddressrr  rI  s       r  rF  zoxfun.parse_deposit_address   sB     "">9=7#" (
 	
r  c                    | j                          i }d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  |d      }|||d<   | j                  |d      }| j	                  | j                  ||            }| j                  |dg       }	t        d	t        |	            D ]
  }
d
|	|
   d<    | j                  |	|||      S )a  
        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  r_  r  r   r  r  r  r   rP   r6  )
r~  rr  rZ  r  privateGetV3Depositr  r  r'  r(  parse_transactionsr  ra  r  r   r  r  rr  r  rq  r  r/  s              r  fetch_depositszoxfun.fetch_deposits  s     	!}}T*H'~GG#(GK $GG!!&'2!&GIYYvw/F++DKK,HI$ ~~h3q#d)$ 	(A'DGFO	(&&tXueDDr  c                    | j                          i }d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  |d      }|||d<   | j                  |d      }| j	                  | j                  ||            }| j                  |dg       }	t        d	t        |	            D ]
  }
d
|	|
   d<    | j                  |	|||      S )a  
        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  r_  r  r   r  r  r  r   
withdrawalr6  )
r~  rr  rZ  r  privateGetV3Withdrawalr  r  r'  r(  rO  rP  s              r  fetch_withdrawalszoxfun.fetch_withdrawals@  s     	!}}T*H'~GG#(GK $GG!!&'2!&GIYYvw/F..t{{7F/KL( ~~h3q#d)$ 	+A*DGFO	+&&tXueDDr  c                    g }t        dt        |            D ]@  }| j                  ||   |      ||<   | j                  ||   |      }|j	                  |       B | j                  |d      }||d   nd }	| j                  ||	||      S )Nr   r  ra  )r'  r(  r  parse_transactionr+  sort_byfilter_by_currency_since_limit)
r  transactionsrr  r  r   r  r.  r/  transactionra  s
             r  rO  zoxfun.parse_transactionst  s    q#l+, 	'A"kk,q/6BLO00a(KKMM+&	' fk2$,$8xt2264NNr  c                 "   | j                  |d      }| j                  |d      }| j                  |d      }d }d }d }|dk(  r4| j                  |d      }| j                  | j                  |d            }n8|dk(  r3| j                  |d      }| j                  | j                  |d            }| j                  |d      }| j                  |d      }	| j	                  |	|      }
| j                  |d	      }| j                  |      }| j                  |d
d      }| j                  |d      }| j                  |d      }d }|||
d}i d|d|d|d|d| j                  |      d	|d|d|dd dd dd dd d|d|d|
d|dd d d |dS )Nr  r6  rP   rI  r:  rS  txIdr_  rd  
creditedAtrequestedAtr0  rb  r  rT  txidr  r  	addressToaddressFromrJ  tagTotagFromrD  rr  updated)internalcommentrb  )	r)  r  parse_deposit_statusparse_withdrawal_statusrV  rk  safe_integer_2rY  r  )r  r[  rr  r  r6  rI  ra  r:  r`  r$  ra  rd  rx  r  rD  feeCostrb  s                    r  rW  zoxfun.parse_transaction~  sJ   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;
&&z8<"";	:--g6''\=Q	!!+z:"";6 C
K
"
 D
 	

 Y/
 {
 w
 
 4
 4
 T
 t
 D
 f
 
  f!
" t#
$ )
 	
r  c                 0    ddi}| j                  |||      S r=  r+  r@  s      r  rh  zoxfun.parse_deposit_status  rB  r  c                 <    dddddddd}| j                  |||      S )Nr?  pendingcanceledfailed)r>  
PROCESSINGzIN SWEEPINGPENDINGzON HOLDCANCELEDFAILEDr+  r@  s      r  ri  zoxfun.parse_withdrawal_status  s5    #$  "
 &&99r  rI  c                    | j                  ||      \  }}| j                          | j                  |      }| j                  ||      }|d   ||d}|||d<   d}	| j	                  |      \  }	}|	| j                  |	      |d<   d|d<   | j                  | j                  ||            }
| j                  |
di       }d	|d
<   | j                  ||      S )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  )r_  rI  r0  Nmemord  FexternalFeer  rS  r6  )
handle_withdraw_tag_and_paramsr~  rr  r1  handle_network_code_and_paramsrD  privatePostV3Withdrawalr  r  rW  )r  ra  rD  rI  rJ  r  rr  stringAmountr  rx  rq  r  s               r  r   zoxfun.withdraw  s    & 99#vFV==&11$?d^$

 ?!GFO"AA&IV"!%!8!8!EGI!&//GV0LM" ~~h3#V%%dH55r  c                 <   | j                          | j                  |      }| j                  |      }| j                  |dg       }g }t	        dt        |            D ],  }||   }| j                  |dg       }| j                  ||      }. | j                  ||      S )a  
        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  rq  r  allPositionsr/  r!  r}  s	            r  fetch_positionszoxfun.fetch_positions"  s     	%%g.--f5X ~~h3q#d)$ 	FA1gGwR@I,,\9EL	F ##L'::r  c                    | j                  |d      }| j                  ||      }| j                  i d|dd d|d   dd ddd| j                  |d	      d
| j                  |d
      d| j                  |d      dd dd d| j                  |d      dd d| j                  |d      dd dd dd dd d | j	                  |d      d d d d d d d d d d      S )Nr&  rT  r  r:  notionalr   crossliquidationPriceestLiquidationPrice
entryPriceunrealizedPnlpositionPnlrealizedPnlr   	contractspositionrK  r  	lastPricer  r   r  r  )r  lastUpdateTimestampr  maintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager   marginRatior   r   )r)  r  safe_positionrY  rZ  )r  r  r0  r1  s       r  parse_positionzoxfun.parse_positionf  s    ##Hl;!!(F3!! #
H#
$#
 fX&#
 	#

 '#
  0 0;P Q#
 $**8\B#
 T--hF#
 4#
 $#
 ))(J?#
 D#
 ))(K@#
 #
 D#
  d!#
" ##
$ #'#4#4X#O!%+/!'+!#9#
  	r  r6  r  rE  c                    | j                          | j                  |dd      | j                  |d| j                               d}| j	                  |ddg      }| j                  |d      }|||d<   | j	                  |d      }| j                  ||||||      }	|	g|d<   | j                  |      }
| j                  |
dg       }| j                  |di       }| j                  |      S )	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.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>`
        responseTypeFULLr  )r  r  
recvWindowordersr  r   )
r~  r)  rZ  millisecondsr  create_order_requestprivatePostV3OrdersPlacer  r  parse_order)r  r:  r6  r  rD  rE  r  r  r  orderRequestrq  r  r  s                r  create_orderzoxfun.create_order  s    2 	 ,,V^VL**6;@Q@Q@ST
 6NK#@A&&v|<
!$.GL!YYv|4F00tVUTZ[)N009j ~~h3tQ+&&r  r  c           	      >   | j                          g }t        dt        |            D ]  }||   }| j                  |d      }| j                  |d      }| j                  |d      }| j	                  |d      }	| j	                  |d      }
| j                  |di       }| j                  ||||	|
|      }|j                  |        d| j                         |d	}| j                  | j                  ||            }| j                  |d
g       }| j                  |      S )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   r:  r6  r  rD  rE  r  r  )r  r  r  r  )r~  r'  r(  r)  rY  r  r  r+  r  r  r  r  parse_orders)r  r  r  ordersRequestsr/  rawOrderr:  r6  r  rD  rE  orderParamsr  r  rq  r  s                   r  create_orderszoxfun.create_orders3	  s)    	q#f+& 		0AayH%%h9F##Hf5D##Hf5D%%h9F$$Xw7E..8R@K44VT4QVXcdL!!,/		0 #**,$

 00Wf1MN~~h3  &&r  c                 *   | j                  |      }|d   |j                         dd}| j                  |dd      }	|	|	|d<   | j                  |ddg      }n||d<   | j                  |dd	      }
|j                         }|
(|d
k(  rd}n|dk(  rd}|
|d	<   | j                  |dd	g      }||d<   |dk(  r||d<   n|||d<   d}|d
k(  xs |dk(  }| j	                  |d|      \  }}| j                  |d      }|r
|dk7  rd|d<   | j                  ||      S )a  
        :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.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
        r  i  )r&  r  sourcerI  rD  Nr0  r   	stopPriceMARKETSTOP_MARKETLIMIT
STOP_LIMIT	orderType
limitPricerE  Fr   MAKER_ONLY_REPRICE
MAKER_ONLY)r0  upperr  r  handle_post_onlysafe_string_upperr  )r  r:  r6  r  rD  rE  r  r0  r  rI  r   r  postOnlyisMarketOrderr   s                  r  r  zoxfun.create_order_requestU	  se   " V$ ,JJL

 !!&&(; $GHYYv'9:F"(GJ))&.+NJJL	#H$)	g%(	#/GK YYv'DEF($$)GL!$GG"h.OI4N00vN&,,V]C(<<%1GM"{{7F++r  rI  c                     | j                          | j                  |      }|d   st        | j                  dz         d|i}| j	                  |dddd| j                  ||            S )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 onlyrI  r0  buyN)r~  r0  r+   r  r  r  )r  r:  rI  r  r0  r  s         r  !create_market_buy_order_with_costz'oxfun.create_market_buy_order_with_cost	  sp     	V$f~tww)ddeeD
   5$dkkRY[aFbccr  r  c                     | j                          d|i}| j                  | j                  ||            }| j                  |di       }| j	                  |      S )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  r:  r  r  rq  r  s          r  fetch_orderzoxfun.fetch_order	  s^     	r
 00Wf1MN0 ~~h3%%r  c                     | j                          i }d}|| j                  |      }| j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )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~  r0  privateGetV3OrdersWorkingr  r  r  )	r  r:  r  r   r  r  r0  rq  r  s	            r  fetch_open_orderszoxfun.fetch_open_orders	  sr     	[[(F11$++gv2NO~~h3  vue<<r  c                    |t        | j                  dz         | j                  |      }|d   }| j                         dd}||d}| j	                  |d      }|||d<   |g|d<   | j                  | j                  ||            }	| j                  |	dg       }
| j                  |
d	i       }| j                  |      S )
an  
        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  r0  r  rZ  privateDeleteV3OrdersCancelr  r  r  r  )r  r  r:  r  r0  r1  r  r  r  rq  r  r  s               r  cancel_orderzoxfun.cancel_order	  s     >#DGG.Y$YZZV$$<**,"

 #
 ))&/B$,9L))N33DKK4PQ~~h3tQ+&&r  c                 ~    i }|| j                  |      }|d   |d<   | j                  | j                  ||            S )al  
        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&  )r0  privateDeleteV3OrdersCancelAllr  )r  r:  r  r  r0  s        r  cancel_all_orderszoxfun.cancel_all_orders
  sI     [[(F$*4LGL! 224;;w3OPPr  idsc                    |t        | j                  dz         | j                          | j                  |      }|d   }| j	                         dd}g }t        dt        |            D ]  }|||   d}	|j                  |	        ||d<   | j                  | j                  ||            }
| j                  |
dg       }| j                  ||      S )	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~  r0  r  r'  r(  r+  r  r  r  r  )r  r  r:  r  r0  r1  r  r  r/  r  rq  r  s               r  cancel_orderszoxfun.cancel_orders
  s     >#DGG.Z$Z[[V$$<**,"
 q#c(# 	!A&q6E MM% 	! #33DKK4PQ~~h3  v..r  c           
         | j                  |d      }| j                  ||      }| j                  |d      }d }| j                  |d      }|$| j                  |      | j	                  |d      d}| j                  |d      }| j                  |d      }|d}| j                  |d	      }	| j                  i d
| j                  |d      d| j                  |d      d|d| j                  |      d| j                  |d      d| j                  |d      d| j                  |      d|d   d| j                  | j                  |d            d| j                  | j                  |d            d| j                  |d      d| j                  |g d      dd d| j                  |dd      d| j                  |dd       d!| j                  |d"      d#|	|	| j                  | j                  |d            d ||d$|      S )%Nr&  r  feeInstrumentIdr   )rr  rI  r:  ra  rejectedr  r  r  r  r  r  lastTradeTimestamplastMatchedAtr  lastModifiedAtr:  r6  r  r   r  rE  )rE  r	  r  r  rD  totalQuantityr0  filledcumulativeMatchedQuantityr
  	remainingremainQuantityr   )r   rI  tradesrb  rT  )r)  r  rZ  rV  rY  
safe_orderr  parse_order_statusparse_order_typeparse_order_time_in_forcerW  safe_string_nr  	omit_zero)
r  r  r0  r1  r  rb  feeCurrencyr:  ra  r   s
             r  r  zoxfun.parse_order@
  s   ` ##E<8!!(F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                 D    dddddddddddd}| j                  |||      S )Nr  closedro  r  )OPENPARTIALLY_FILLEDPARTIAL_FILLFILLEDrs  CANCELED_BY_USERCANCELED_BY_MAKER_ONLYCANCELED_BY_FOKCANCELED_ALL_BY_IOCCANCELED_PARTIAL_BY_IOC!CANCELED_BY_SELF_TRADE_PROTECTIONr+  r@  s      r  r  zoxfun.parse_order_status
  sA     &"" *&0)#-'11;
 &&99r  c                 6    ddddd}| j                  |||      S )Nr   r0  )r  r  r  r  r+  r  r6  typess      r  r  zoxfun.parse_order_type
  s,    !#	
 tT22r  c                 8    dddddd}| j                  |||      S )NGTCr   r   r   )r  r   r   r  r  r+  r  s      r  r  zoxfun.parse_order_time_in_force
  s/    "&
 tT22r  r   GETc                    | j                   d   |   }|dz   |z   }d}	|dk(  r'| j                  |      }	t        |	      dk7  r|d|	z   z  }|dk(  r| j                          | j	                         }
| j                  |
      }|j                  d      }|d   }| j                         }|j                  d	      }|d
k(  s|dk(  r| j                  |      }|}	|dz   t        |      z   dz   |z   dz   |d   z   dz   |z   dz   |	z   }| j                  | j                  |      | j                  | j                        t        j                  d      }d| j                  ||t        |      d}||||dS )Nr   r5  r3  r  r   ?r   r`  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  rU  noncejsonstrhmacencodesecrethashlibsha256apiKey)r  pathr   r  r  r  r  baseUrlr  queryStringr  isoDatetimedatetimePartsr  r  urlParts	msgString	signatures                     r  signz
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 fdwOOr  c
                     |y |dk7  rp| j                  |dd       }
| j                  dz   |z   }| j                  | j                  d   ||       | j	                  | j                  d   |
|       t        |      y )N   ra   r  r   )r)  r  throw_broadly_matched_exceptionr  throw_exactly_matched_exceptionr!   )r  ra  reasonr  r  r  r  rq  requestHeadersrequestBodyresponseCodefeedbacks               r  handle_errorszoxfun.handle_errors  s~    3;++HfdCLww}t+H001I4QYZ001I<Yab))r  )N)[__name__
__module____qualname__r   r  r    r   r$  r  r,  r	   r{  r   r   r  r  r   r  r  r   rn  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,  floatr   r   r7  r
   r3  r;  r   rG  rF  r   rQ  rU  rO  rW  rh  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  __classcell__)r  s   @r  r2   r2      s   n# n` $& Z+$v, Z+x	V 	Ff FP ') TZ Tl 04B =4W =47 =4~ 02 &13 &1f &1P+6 +V +Z 26DW[df <J# <Jc <JQT <Jkoptku <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:
: DHPR 66S 66% 66# 66Wb 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 1,3 1,c 1, 1,f RT d d5 d( 26b )&c )&3 )&U )&V /3TXac = =3 =c =hlmrhs =. 37r "'s "'C "'H /32 Q Q6 ;?r !/c !/C !/FV V5 Vp: 33 &eBSW P<	r  r2   )6ccxt.base.exchanger   ccxt.abstract.oxfunr   r  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  <module>r*     s    ( +  k  k  k  k  k  k  k  k  * 0 . . ' & ) . ) * ) , ) . + 4E,Hk E,r  