
    E#iO                       S SK Jr  S SKJr  S SK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  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\\5      r(g)    )Exchange)ImplicitAPIN)AnyBalancesCurrencyIntLedgerEntryLeverageMarketNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateTradeTransaction)List)ExchangeError)AuthenticationError)ArgumentsRequired)
BadRequest)InvalidOrder)NotSupported)	TICK_SIZE)Precisec                     ^  \ rS rSrS\4U 4S jjr0 4S jr0 4S\4S jjr0 4S\	\
   4S jjrS\S\
4S jr0 4S	\S\4S
 jjrS0 4S\S\4S jjrSTS\S\
S\4S jjrSSS0 4S	\S\S\S\S\	\   4
S jjrSTS\
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\S\	\   4S jjrSTS\S\
S\4S jjrS0 4S	\S\S\4S jjr0 4S	\S\4S jjr0 4S	\S\ 4S jjr!STS\
S\ 4S jjr"0 4S\#4S jjr$S\#4S jr%S0 4S	\S \&S!\'S"\(S#\)4
S$ jjr*S%\4S& jr+STS'\S\
S\,4S( jjr-S0 4S)\S	\4S* jjr.S0 4S	\4S+ jjr/0 4S	\4S, jjr0S0 4S\S\	\1   4S- jjr2STS.\S\
4S/ jjr3S0 4S)\S	\4S0 jjr4SSS0 4S	\S\S\S\	\,   4S1 jjr5SSS0 4S	\S\S\S\	\,   4S2 jjr6SSS0 4S	\S\S\S\	\,   4S3 jjr7SSS0 4S	\S\S\S\	\,   4S4 jjr8S0 4S	\S!\'S\,4S5 jjr90 4S\	\1   4S6 jjr:SSS0 4S7\S\S\S\	\;   4S8 jjr<STS9\S:\=S\;4S; jjr>S< r?S0 4S7\S"\(S=\S>\S\@4
S? jjrASTS@\S:\=S\@4SA jjrBS0 4SB\CS	\4SC jjrDSTSB\S\
S\E4SD jjrFSE rGSFSG0 SS4SH jrHSI\CSJ\SK\SL\SM\SN\4SO jrISP rJSQ\K4U 4SR jjrLSSrMU =rN$ )Udefx   returnc                   > U R                  [        [        U ]  5       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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
_S0S_S1S_S2S
_E0 S3S_S4S
_S5S
_S6S
_S7S
_S8S
_S9S
_S:S
_S;S
_S<S
_S=S
_S>S
_S?S
_S@S
_SAS_SBS
_SCS
_E0 SDS
_SES_SFS
_SGS
_SHS
_SIS_SJS
_SKS
_SLS
_SMS_SNS_SOS
_SPS
_SQS_SRS_SSS_STS_E0 SUS
_SVS_SWS
_SXS
_SYS_SZS
_S[S
_S\S_S]S_S^S_S_S_S`S_SaS
_SbS
_ScS
_SdS
_SeS
_ES
SSS
S
S
SSf.E_SgShSiSjSkSlSmSnSoSpSqSrSsSt._SuSvSwSwSx.SySySx.SzS{S|/S}/S~S0S._SSS0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSSS.E00 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSS.ESSSSSSSSSSSS.SSSSS.SS0SSSSSSS.S.Sx.0_SSSSU R	                  S5      U R	                  S5      S.0_SSS
0_SS 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
SS S S
S.S
S
S
S
S.SSS
S
S
S.S
SSSS
S
S
S.S
SSSSS
S
S
S.SS0S.	SS0S S.S S S.S._S0 _S[
        [        [        [        [        [        [        [        [        [        [        [        S.S[
        0S._S[        0E5      $ )Nidr#   namezDefx X	rateLimitd   versionv1	certifiedFprohostnamezdefx.comdexThasCORSspotmarginswapfutureoption	addMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelWithdrawcloseAllPositionsclosePositioncreateConvertTradecreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrdercreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrder$createOrderWithTakeProfitAndStopLosscreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingAmountOrdercreateTrailingPercentOrdercreateTriggerOrderfetchAccountsfetchBalancefetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchConvertCurrenciesfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchLedgerfetchLeveragefetchMarginAdjustmentHistoryfetchMarginModefetchMarketsfetchMarkOHLCVfetchMarkPricefetchMarkPricesfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsHistoryfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchTransfersfetchWithdrawals)reduceMarginsandboxsetLeverage	setMarginsetPositionModetransferwithdraw
timeframes1m3m5m15m30m1h2h4h12h1d1w1M)r   r   r   r   r   r   r   r   r   r   r   r   urlszOhttps://github.com/user-attachments/assets/4e92bace-d7a9-45ea-92be-122168dc87e4zhttps://api.{hostname})publicprivatezhttps://api.testnet.{hostname}zhttps://defx.com/homezhttps://docs.defx.com/docszhttps://api-docs.defx.com/ urlz https://app.defx.com/join/6I2CZ7)logoapitestwwwdocfeesreferralr   getzhealthcheck/ping   zsymbols/{symbol}/ohlczsymbols/{symbol}/tradeszsymbols/{symbol}/priceszsymbols/{symbol}/ticker/24hrz%symbols/{symbol}/depth/{level}/{slab}zticker/24HrAggz	c/marketszc/markets/metadatazanalytics/market/stats/newUserszanalytics/market/stats/tvlz)analytics/market/stats/volumeByInstrumentz"analytics/market/stats/liquidationz"analytics/market/stats/totalVolumez#analytics/market/stats/openInterestz"analytics/market/stats/totalTradeszanalytics/market/stats/basis)z$analytics/market/stats/insuranceFundz(analytics/market/stats/longAndShortRatioz"analytics/market/stats/fundingRatezanalytics/market/overviewzexplorer/searchzexplorer/transactionszexplorer/blocksapi/order/{orderId}z
api/orderszapi/orders/oco/{parentOrderId}z
api/tradeszapi/position/activeapi/users/metadata/leverage api/users/metadata/feeMultiplierapi/users/metadata/slippageapi/users/referralapi/users/apikeysz connection-signature-message/evmapi/users/profile/walletszapi/notificationszapi/wallet/balancezapi/wallet/transactionszapi/analytics/user/overviewzapi/analytics/user/pnl)zapi/analytics/points/overviewzapi/analytics/points/history)z	api/orderzapi/position/ocozapi/users/socket/listenKeysr   r   r   z'api/users/referral/recordReferralSignupr   r   zapi/transfers/withdrawalzapi/transfers/bridge/withdrawal)z!api/position/updatePositionMargin'api/users/socket/listenKeys/{listenKey}z$api/users/apikeys/{accessKey}/statusr   api/users/apikeys/{accessKey})zapi/orders/allOpenr   zapi/position/{positionId}zapi/position/allr   r   )r   postputpatchdeleter   tradingz0.0002z0.0005)	tierBased
percentagemakertakeroptionssandboxModefeatures)lastmarkindex)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedselfTradePreventiontrailingicebergleveragemarketBuyByCostmarketBuyRequiresPrice  )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   i  i )r   r   r   r   r   r   r   )r   r   r   daysBackCanceledr   r   r   r   r   )	r   rE   createOrdersrn   rs   rr   ru   rT   ro   extendsforDerivatives)linearinverse)r3   r   r5   r6   commonCurrencies
exceptions)404missing_auth_signatureorder_rejectedinvalid_order_idfilter_lotsize_maxqtyfilter_notional_min'failed_index_price_up_multiplier_filterno_open_ordersactive_position_not_foundposition_inactiveinvalid_position_idzInternal server errorzBad Request)exactbroadprecisionMode)
deep_extendsuperr#   describeparse_numberr   r   r   r   r    )self	__class__s    Q/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/async_support/defx.pyr   defx.describe   s0
   dD : < W?
&W?
HW?
 	W?

 tW?
 W?
 5W?
 
W?
 4W?
  ]]] %] 	]
 %] %] T] "4] '] t] !%] $T]  ] %e] ']  /!]" $U#]$ ,U%]& 0']( t)]* 7+], (-]. '/]0 &u1]2 (3]4 "55]6 (7]8 ,U9]: -e;]< %d=]>  ?]@ A]B &tC]D #EE]F $TG]H )%I]J $UK]L $UM]N +EO]P "5Q]R &uS]T (U]V 1%W]X  Y]Z +E[]\ &u]]^ '_]` (a]b #Dc]d *5e]f $Ug]h "5i]j tk]l  m]n /o]p "5q]r s]t !%u]v !%w]x "5y]z  {]| d}]~ +E]@ !%A]B "4C]D dE]F !$G]H tI]J #EK]L  M]N 'O]P $UQ]R !$S]T (U]V )%W]X tY]Z t[]\ ]]^ T_]` ta]b "5c]d #Ee]f $Ug]h !%i]j #Ek]l !&#"#(! y]W?
P QW?
l i67
 ?? /00
  =%mW?
X   . 3Q  6q  6q	 
 ;A  DQ  -a  (  1!  >q  9!  H  A!  A!  B1   A!! " ;A# $ EFHIBC9:/056/01 : 11 (!  =a  )!	 
 21  :1  ?  :1  1!  0  ?  8  0  1!  6q   :1! " 5a# $ >?<=' , *+01;<;<@A;<GH129:89?@! BCGHDE23	  <Q" 34349:01GH=>#Y4 ;RTYW?
B !%"&!..x8!..x8	CW?
R uSW?
X #&+(, %)$(%*-
 -2).+06:#'#'"&#(	( #(/4$)#($)+0273$6 %)&+!%$(%)*/& ',#($)*/	# '+!$#($)*/( ',!$$*%+#($)*/$ ',!$$*,-%+#($)*/	*  #KH#V "#3  $	 ##cUYW?
D
 E
W?
F
 %.A&2(4-9+7?K&21=)5+7-: ":G
W?
l
 Ym
W?
 W W	    c                    #    U R                  U5      I Sh  vN nSnU R                  US5      nU(       a  SnOSnUSSSUS.$  N,7f)a1  
the latest known information on the availability of the exchange API

https://api-docs.defx.com/#4b03bb3b-a0fa-4dfb-b96c-237bde0ce9e6

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
Nsuccessokerror)statusupdatedetar   info)v1PublicGetHealthcheckPing	safe_bool)r   paramsresponser   r   s        r   fetch_statusdefx.fetch_statusr  s]      88@@ ..95FF
 	
 As   AA-Ac                 d   #    U R                  U5      I Sh  vN nU R                  US5      $  N7f)a4  
fetches the current integer timestamp in milliseconds from the exchange server

https://api-docs.defx.com/#4b03bb3b-a0fa-4dfb-b96c-237bde0ce9e6

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the exchange server
Nt)r  safe_integer)r   r  r  s      r   
fetch_timedefx.fetch_time  s5      88@@   3// As   0.0c                   #    SS0nU R                  U R                  X!5      5      U R                  U R                  X!5      5      /n[        R                  " U6 I Sh  vN nU R                  US   S5      nU R                  US5      nU R                  US   S5      n[        S[        U5      5       H  nXx   S   n	Sn
X;   a  Xi   S   n
XU   S'   M!     U R                  U5      $  N7f)	a5  
retrieves data on all markets for defx

https://api-docs.defx.com/#73cce0c8-f842-4891-9145-01bb6d61324d
https://api-docs.defx.com/#24fd4e5b-840e-451e-99e0-7fea47c7f371

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
typeperpsNr   datamarketr   r   )
v1PublicGetCMarketsextendv1PublicGetCMarketsMetadataasynciogather	safe_listindex_byrangelenparse_markets)r   r  requestpromises	responsesactiveMarketsactiveMarketsByTypemarketMetadatasimarketIdr   s              r   fetch_marketsdefx.fetch_markets  s      G
 $$T[[%AB,,T[[-IJ
 "..(33	L y|V<"mmM8D..1v>q#o./A&)(3HF.,6x@+1Ax( 0 !!/22_ 4s   AC)C'B
C)r  c                 v   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5      nU R                  U5      nUS-   U-   S-   U-   nU R                  US/ 5      n	U R	                  US0 5      n
U R                  U	S	5      nU R	                  US
0 5      nU R	                  US0 5      nU R	                  US0 5      nU R	                  US0 5      n0 SU_SU_SU_SU_SU_SU_SU_SU_SS_SS_SS_SS_SS_SS_SU R                  USS 5      S:H  _S!S_S"S_SU R                  U
S#5      U R                  U
S$5      U R                  S%5      S S S S U R                  US&5      U R                  US'5      S(.S U R                  US)5      S*.U R                  US+5      U R                  US,5      S*.U R                  US-5      U R                  US.5      S*.U R                  US/5      S S*.U R                  US+5      U R                  US,5      S*.S0.S US1.E$ )2Nr  _r   r   /:filtersr   
filterTypePRICE_FILTERLOT_SIZEMARKET_LOT_SIZENOTIONALr'   symbolbasequotesettlebaseIdquoteIdsettleIdr  r5   r3   Fr4   Tr6   r7   activer   r   contractr   r   r   1stepSizetickSize)amountpricecappedLeverage)minmaxminQtymaxQtyminPricemaxPriceminNotional)r   r;  r<  costr  )r   r   r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedr   )safe_stringsplitsafe_currency_coder  	safe_dictr  safe_numberr   )r   r  r"  partsr3  r4  r0  r1  r/  r)  r   filtersByTypepriceFilter	lotFiltermarketLotFilternotionalFilters                   r   parse_marketdefx.parse_marketH  s   ##FH5s#!!%+""5!,&&v.''0e#c)E1..B7~~ffb1g|<nn]NBGNN=*bA	..8I2Nz2F6
(6
f6
 D6
 U	6

 e6
 f6
 w6
 6
 F6
 E6
 e6
 D6
 e6
 e6
 d&&vx<H6
  !6
" d#6
$ %%dG4%%dG4 --c2"**9jA))+zB  ++F4DE
  ++Ix@++Ix@
  ++KD++KD
  ++NMJ
  ++OXF++OXF#, k6
 6	
r   r/  c                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  XS5      $  NU N7f)a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://api-docs.defx.com/#fe6f81d0-2f3a-4eee-976f-c8fc8f4c5d56

: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>`
Nr/  r'   )load_marketsr  "v1PublicGetSymbolsSymbolTicker24hrr  parse_tickerr   r/  r  r  r  r  s         r   fetch_tickerdefx.fetch_ticker  ss      !!!V$fTl
 @@WA]^^0   22; 	"
 _!   A0A,?A0A.A0.A0Nsymbolsc                   #    U R                  5       I Sh  vN   SnUb7  U R                  U5      nU R                  US5      nUb  U R                  U5      nSnU R	                  SX25      u  pRUS:X  a  [        U R                  S-   U-   S-   5      eU R                  U5      I Sh  vN nU R                  Xa5      $  N N7f)a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://api-docs.defx.com/#8c61cfbd-40d9-410e-b014-f5b36eba51d1

: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>`
Nr   r   r3   z% fetchTickers() is not supported for z markets)	r\  market_symbolsrN  r  handle_market_type_and_paramsr   r'   v1PublicGetTicker24HrAggparse_tickers)r   rc  r  r  firstSymbolr  r  s          r   fetch_tickersdefx.fetch_tickers  s      !!!))'2G**7A6K&[199.&Y6>tww)PPSWWZddee66v>>  !!(447 	" ?s"   B?B;BB?%B=&B?=B?tickerc           
      8   U R                  US5      nUb  U R                  U5      nUS   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5      n
U R                  US5      nU R                  US	5      nU R                  US
5      nUS:X  a  S nU R                  U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	                  0 SU_SU_SU_SU_SU_SU_SU_SU_SU_SS _SU_SU_SS _SS _SU_SU_SS _U
U	U R                  US 5      U R                  US!5      US".EU5      $ )#Nr/  	openPrice	highPricelowPrice	lastPricequoteVolumevolumepriceChangePercentpriceChange	closeTimer   bestBidPrice
bestBidQtybestAskPrice
bestAskQty	timestampdatetimehighlowbid	bidVolumeask	askVolumevwapopencloser   previousClosechanger   average	markPrice
indexPrice)
baseVolumerr  r  r  r   )rN  r  r	  iso8601safe_ticker)r   rl  r  r"  r/  r  r}  r~  r  rr  r  r   r  tsr|  r  r  r  r  s                      r   r^  defx.parse_ticker  sO   f ##FH5[[*F!44vz2  5&&v}=%%fh7
%%f.BC
!!&-8v{37B<<#v~6$$V\:	v~6$$V\:	 !
f!
!
 !
 D	!

 3!
 3!
 !
 3!
 !
 D!
 D!
 U!
 D!
 T!
 f!
  *!!
" t#!
$ %&))&+>**6<@-!
. / 	r   r   	timeframesincer   c                 @  #    U R                  5       I Sh  vN   U R                  U5      nSnUc  Un[        Xt5      nUS   U R                  U R                  X"5      US.nU R                  USS5      n	U R                  USS/5      nU	c  U R                  5       OU	US'   Uc  SUS	'   O5X8S	'   U	c.  U R                  U5      n
U
S-  nXK-  nU R                  X<5      US'   U R                  U R                  X5      5      I Sh  vN nU R                  XX#U5      $  GN N7f)
a  

https://api-docs.defx.com/#54b71951-1472-4670-b5af-4c2dc41e73d0

fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: the length of time each candle represents
:param int [since]: timestamp in ms of the earliest candle to fetch
:param int [limit]: max=1000, max=100 when since is defined and is less than(now - (999 * (timeframe in ms)))
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch orders for
:returns int[][]: A list of candles ordered, open, high, low, close, volume
Nr   r'   )r/  intervalr   untiltillendTimer   	startTime)r\  r  r>  rN  r   safe_integer_2omitmillisecondsparse_timeframesumv1PublicGetSymbolsSymbolOhlcr  parse_ohlcvs)r   r/  r  r  r   r  r  maxLimitr  r  timeframeInSecondstimeframeInMillisecondstotalTimeframeInMillisecondsr  s                 r   fetch_ohlcvdefx.fetch_ohlcv?  s<     !!!V$=EH$Tl(()O

 ##FGV<6GV#455:]T..0	=#$GK #(K }%)%9%9)%D"*<t*C'/4/N,%)XXe%R	"::4;;w;WXX(   9UKKW 	". Ys"   DDC*DDDD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startr  r}  r~  r  rs  )r	  rR  )r   ohlcvr  s      r   parse_ohlcvdefx.parse_ohlcvz  sn     eW-UF+UF+UE*UG,UH-
 	
r   c                   #    U R                  5       I Sh  vN   U R                  U5      nSnUc  Un[        Xc5      nUS   US.nU R                  U R	                  Xt5      5      I Sh  vN nU R                  XX#5      $  Ni N7f)a  
get the list of most recent trades for a particular symbol

https://api-docs.defx.com/#5865452f-ea32-4f13-bfbc-03af5f5574fd

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
N2   r'   )r/  r   )r\  r  r>  v1PublicGetSymbolsSymbolTradesr  parse_trades)	r   r/  r  r   r  r  r  r  r  s	            r   fetch_tradesdefx.fetch_trades  s      !!!V$=EH$Tl
 <<T[[=YZZ   5@@- 	" [s"   BB AB)B*BBc                 B  #    U R                  5       I Sh  vN   0 nUb  U R                  U5      nUS   US'   Ub  Sn[        Xs5      nX5S'   U R                  U R	                  XT5      5      I Sh  vN nU R                  US/ 5      n	U R                  U	SX#5      $  N N,7f)a  
fetch all trades made by the user

https://api-docs.defx.com/#06b5b33c-2fc6-48de-896c-fc316f5871a7

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
Nr'   rc  r*   pageSizer  )r\  r  r>  v1PrivateGetApiTradesr  r  r  )
r   r/  r  r   r  r  r  r  r  r  s
             r   fetch_my_tradesdefx.fetch_my_trades  s      !!![[(F!'GIH(E"'J33DKK4PQQ& ~~h3  tU::; 	" Rs"   BBAB0B1+BBtradec                 X   U R                  US5      nU R                  USU R                  U5      5      nU R                  US5      nU R                  XR5      nUS   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	5      nU R	                  US
5      nUb  U(       a  SnOSnU R                  U	UU R                  U5      UUUUS U
US U R                  US5      SS.US.U5      $ )Ntimer{  r/  r<  qtyr'   orderIdrole
buyerMakersidesellbuyfeeUSDCrE  currency)r'   r{  r|  r/  r  r<  r;  rE  ordertakerOrMakerr  r  r   )rN  r	  	parse8601safe_marketsafe_string_lowerr  
safe_trader  )r   r  r  r  r{  r"  r/  r<  r;  r'   oidr  r  r  s                 r   parse_tradedefx.parse_trade  sP   2 v.%%e[$..:NO	##E84!!(3!  0!!%/eT*ui0--eV<^^E<8
%%eV4!"Y/(((6" ! 
" # 	r   c           	        #    U R                  5       I Sh  vN   U R                  U5      nUc  SnU R                  US0 5      nU R                  US/ 5      nUS   UU R	                  US5      S.nU R                  U R                  Xs5      5      I Sh  vN nU R                  US5      n	U R                  XU	S	S
SS5      $  N N.7f)a@  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://api-docs.defx.com/#6c1a2971-8325-4e7d-9962-e0bfcaacf9c4

:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.slab]: slab from market.info.depthSlabs
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
N
   r   
depthSlabsr'   r   )r/  levelslabr{  bidsasksr<  r  )	r\  r  rQ  r  rN  &v1PublicGetSymbolsSymbolDepthLevelSlabr  r	  parse_order_book)
r   r/  r   r  r  
marketInfor  r  r  r{  s
             r   fetch_order_bookdefx.fetch_order_book  s      !!!V$=E^^FFB7
~~j,;Tl$$T1-

 DDT[[QXEabb, %%h<	$$Xy&&RY[`aaE 	" cs"   CC A<CC-CCc                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  XS5      $  NU N7f)a  
fetches mark price for the market

https://api-docs.defx.com/#12168192-4e7b-4458-a001-e8b80961f0b7

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.subType]: "linear" or "inverse"
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr/  r'   )r\  r  v1PublicGetSymbolsSymbolPricesr  r^  r_  s         r   fetch_mark_pricedefx.fetch_mark_priceA  ss      !!!V$fTl
 <<T[[=YZZ   22! 	"
 [rb  c                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  XS5      $  NU N7f)a7  
fetch the current funding rate

https://api-docs.defx.com/#12168192-4e7b-4458-a001-e8b80961f0b7

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
Nr/  r'   )r\  r  r  r  parse_funding_rater_  s         r   fetch_funding_ratedefx.fetch_funding_rate^  ss      !!!V$fTl
 <<T[[=YZZ &&x88! 	"
 [rb  c                 t   U R                  US5      nU R                  US5      nU R                  US5      n[        R                  " US5      nU R	                  US5      n0 SU_SUS   _SU_SU_SS _S	S _S
S _SS _SU R                  U5      _SU_SU R                  U5      _SS _SS _SS _SS _SS _SS _SS 0E$ )Nr  r  payoutFundingRate100nextFundingPayoutr   r/  interestRateestimatedSettlePricer{  r|  fundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )rR  rN  r!   
string_divr	  r   r  )r   r7  r  r  r  fundingRateRawr  fundingTimes           r   r  defx.parse_funding_ratez  sW    $$X{;	%%h=
))(4GH((?''2EF
H
fX&
 
 *	

 D
 #D
 
 
 4,,[9
 
 t||K8
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
r   c                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  US5      nU R                  U5      $  N@ N)7f)aC  
query for balance and get the amount of funds available for trading or funds locked in orders

https://api-docs.defx.com/#26414338-14f7-40a1-b246-f8ea8571493f

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nassets)r\  v1PrivateGetApiWalletBalancer  parse_balancer   r  r  r  s       r   fetch_balancedefx.fetch_balance  sW      !!!::6BB ~~h1!!$'' 	"Bs   AAAA(AAc                     SU0n[        S[        U5      5       HQ  nX   nU R                  U R                  US5      5      nU R	                  5       nU R                  US5      US'   XbU'   MS     U R                  U5      $ )Nr   r   assetbalancetotal)r  r  rP  rN  accountsafe_balance)r   balancesresultr!  r  coder  s          r   r  defx.parse_balance  s    H
 q#h-(AkG**4+;+;GW+MNDllnG#//CGG"4L )   ((r   r  r  r;  r<  c                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  USS5      nU R                  USS/5      nUR	                  5       n	UR	                  5       n
US   U
U	S.nU R                  US5      nU R                  USS5      nU	S	:H  nU	S
:H  nU R                  US5      nUb  UUS'   OU(       a  SUS'   U(       a  XS'   U R                  US5      nUb  UUS'   Uc  UbU  SUS'   Ub'  U R                  X5      US'   U(       a  SUS'   O,SUS'   O&U R                  X5      US'   U(       a  SUS'   OSUS'   U(       a  Ub  U R                  X5      US'   U R                  X5      US'   U R                  U/ SQ5      nU R                  U R                  X5      5      I Sh  vN nU R                  US5      nU R                  UU5      $  GN N+7f)a|  
create a trade order

https://api-docs.defx.com/#ba222d88-8856-4d3c-87a9-7cec07bb2622

:param str symbol: unified symbol of the market to create an order in
:param str type: 'market' or 'limit'
:param str side: 'buy' or 'sell'
:param float amount: how much of 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 float [params.triggerPrice]: The price a trigger order is triggered at
:param str [params.reduceOnly]: for swap and future reduceOnly is a string 'true' or 'false' that cant be sent with close position set to True or in hedge mode. For spot margin and option reduceOnly is a boolean.
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
N
reduceOnlyreduce_onlyr'   )r/  r  r  r   	stopPricer   MARKETLIMITr   GTCclientOrderIdnewClientOrderId
MARK_PRICEworkingTypeTAKE_PROFIT_MARKETr  TAKE_PROFIT_LIMITSTOP_MARKET
STOP_LIMITr<  quantity)clOrdIDr  client_order_idpostOnlyr   r  r   r   r  )r\  r  safe_bool_2r  upperrN  safe_string_2safe_string_upperprice_to_precisionamount_to_precisionv1PrivatePostApiOrderr  rQ  parse_order)r   r/  r  r  r;  r<  r  r  r  	orderType	orderSider  r   r   isMarketisLimitr   r  r  r  s                       r   create_orderdefx.create_order  s      !!!V$%%flMJ
6L-#@AJJL	JJL	Tl

 **63DE))&+~N(w&,,V]C"%0GM").&$.L!((A$*7G&'#'B%1GM"*'+'>'>v'W$&:GFO&9GFO'+'>'>v'T$&3GFO&2GFOu(#66vEGG"66vF
6  $^  _33DKK4PQQ. ~~h/f--K 	"Z Rs"   G)G$F$G);G'<)G)'G)r   c                 @    Ub  SSSSSS.nU R                  X!U5      $ U$ )Nr  canceledrejectedclosed)NEWOPEN	CANCELLEDREJECTEDFILLEDrN  )r   r   statusess      r   parse_order_statusdefx.parse_order_status  s8    '&"H ##Hf==r   r  c                 >   U R                  US5      nU R                  US5      nU R                  US5      nU R                  XR5      nUS   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 R                  US	5      5      nU R                  U R                  US
5      5      nU R                  US5      nS nS nU	b:  U	R	                  S5      S:  a  U R                  US5      nOU R                  US5      nU R                  U R                  US5      5      nU R                  U R                  US5      5      nU R                  0 SU_SU_SU_SU R                  U5      _SU_SU_SU R                  U
5      _SU_SU	_SU_SU R                  US5      _SU R                  US5      _SU_SU_SU_SU_SS _UUUS S S U R                  US5      SS.US.EU5      $ )Nr  r  r/  r<  origQtyr  r   r  executedQtyavgPricer   take_profitr   r  	createdAt	updatedAtr'   r{  r|  lastTradeTimestamplastUpdateTimestampr  r  r   r   r   totalFeer  r  )r  r;  filled	remainingrE  tradesr  r   )
rN  r  r  	omit_zerofindr  
safe_orderr  r0  r  )r   r  r  r  r  r"  r/  r<  r;  r  r   r  r<  r  r   r   r   r{  r9  s                      r   r  defx.parse_order&  s   4 ""5)4((@##E84!!(3!  0!!%3**5&9	!!%2%%eV4 0 0 FG..!1!1%!DE,,UMB#  ~~m,1"&"2"25+"F#//{CNN4#3#3E;#GH	!^^D,<,<UK,PQ  
' 
] 
  
 Y/	 

 !"4 
 "#5 
 d--f5 
 f 
 I 
 ; 
 uj9 
 $..= 
 D 
 U 
 L 
  ! 
" T# 
$ ((
;" 9 
: ; 	r   r'   c                   #    U R                  5       I Sh  vN   USS.nU R                  U/ SQ5      nUSLnU(       a=  Uc  [        U R                  S-   5      eU R	                  U5      nXTS'   SUS'   US   US	'   U R                  U/ SQ5      nU R                  U R                  XC5      5      I Sh  vN nS	U0n	U(       a  XYS'   OXS'   U R                  U R                  U5      U	5      $  N N;7f)
aV  

https://api-docs.defx.com/#09186f23-f8d1-4993-acf4-9974d8a6ddb0

cancels an open order
: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
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r  idTyper  r  r  z) cancelOrder() requires a symbol argumentr  rE  r'   r/  )	r\  safe_string_nr   r'   r  r  v1PrivateDeleteApiOrderOrderIdr  r  )
r   r'   r/  r  r  r  isByClientOrderr  r  extendParamss
             r   cancel_orderdefx.cancel_orderu  s     !!!
 **63bc't3~'2](]^^[[(F!.I /GH &tGH6#RS<<T[[=YZZ '/,9)!#{{4++H5|DD5 	" [s"   C1C-BC13C/4:C1/C1c                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   /0nU R                  U R                  XB5      5      I Sh  vN nU R	                  SU05      /$  NY N7f)a|  
cancel all open orders

https://api-docs.defx.com/#db5531da-3692-4a53-841f-6ad6495f823a

: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[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nrc  r'   r   )r\  r  v1PrivateDeleteApiOrdersAllOpenr  rA  r_  s         r   cancel_all_ordersdefx.cancel_all_orders  s{      !!!V$t~
 ==dkk'>Z[[  2344 	"
 \s"   A4A0A A4A2A42A4c                 f  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nSUS   0nU R	                  U R                  XB5      5      I Sh  vN nU R                  US/ 5      nU R                  US0 5      nU R                  Xs5      $  N{ N=7f)a{  
fetch data on a single open contract trade position

https://api-docs.defx.com/#d89dbb86-9aba-4f59-ac5d-a97ff25ea80e

:param str symbol: unified market symbol of the market the position is held in, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
Nz+ fetchPosition() requires a symbol argumentr/  r'   r  r   )	r   r'   r\  r  v1PrivateGetApiPositionActiver  r  rQ  parse_position)r   r/  r  r  r  r  r  firsts           r   fetch_positiondefx.fetch_position  s      >#DGG.[$[\\!!!V$fTl
 ;;DKK<XYY" ~~h3tQ+""5111 	"
 Zs!   /B1B-?B11B/2<B1/B1c                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  US/ 5      nU R                  XA5      $  NA N*7f)aA  
fetch all open positions

https://api-docs.defx.com/#d89dbb86-9aba-4f59-ac5d-a97ff25ea80e

:param str[] [symbols]: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
Nr  )r\  rR  r  parse_positions)r   rc  r  r  	positionss        r   fetch_positionsdefx.fetch_positions  sY      !!!;;FCC" NN8VR8	##I77' 	"Cs   AAAA)AApositionc                    U R                  US5      nU R                  X25      n[        R                  " U R                  US5      5      nU R	                  US5      nU R                  U R                  US5      5      nU R                  U R                  US5      5      nU R                  US5      nU R                  0 SU_SU R                  US	5      _SUS   _S
S _SS _SS _SU R                  U5      _SS _SS _SS _SU R                  U5      _SS _SS _SU R                  U5      _SS _SU R                  U5      _SU R                  US5      _S S S S S S US S S S S.E5      $ )Nr/  r  positionSidepnl
entryPricemarginAmountr   r'   
positionIdr{  r|  r:  initialMargininitialMarginPercentagemaintenanceMarginmaintenanceMarginPercentagenotionalr   unrealizedPnlrealizedPnl	contractsrF  )marginRatioliquidationPricer  rq  
collateralr   r  r   r   r   r   )	rN  r  r!   
string_absr  r?  safe_positionr   rR  )	r   r\  r  r"  sizer  unrealisedPnlr`  rc  s	            r   rS  defx.parse_position  s    ##Hh7!!(3!!$"2"28Z"HI%%h?t'7'7%'HI^^D$4$4X|$LM
((>B!! #
H#
$""8\:#
 fX&#
 	#

 #
 "4#
 T..}=#
 &t#
  #
 *4#
 $++J7#
 #
 #
 T..}=#
 4#
  **40!#
" D,,V^D##
$   $!#9#
  	r   c                   #    U R                  5       I Sh  vN   USS.nU R                  U/ SQ5      nU R                  U/ SQ5      nUb=  Uc  [        U R                  S-   5      eU R                  U5      nXTS'   SUS'   US   US	'   U R                  U R                  XC5      5      I Sh  vN nU R                  US
5      nU R                  U5      $  N N)7f)au  
fetches information on an order made by the user

https://api-docs.defx.com/#44f82dd5-26b3-4e1f-b4aa-88ceddd65237

:param str id: the 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
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr  rD  rF  z( fetchOrder() requires a symbol argumentr  rE  r'   r/  r  )
r\  rG  r  r   r'   r  v1PrivateGetApiOrderOrderIdr  rQ  r  )	r   r'   r/  r  r  r  r  r  r  s	            r   fetch_orderdefx.fetch_order-  s      !!!
 **63bc6#RS$~'2\(\]][[(F!.I /GH &tGH99$++g:VWW4 ~~h/%%S 	" Xs"   CCBC+C,(CCc                   #    U R                  5       I Sh  vN   0 nUb  U R                  U5      nUS   US'   U R                  US5      nUb&  U R                  US5      nU R	                  U5      US'   Ub  U R	                  U5      US'   Ub  Sn[        X5      nX5S'   U R                  U R                  XT5      5      I Sh  vN n	U R                  U	S	/ 5      n
U R                  U
SX#5      $  N N,7f)
a$  
fetches information on multiple orders made by the user

https://api-docs.defx.com/#ab200038-8acb-4170-b05e-4fcb4cc13751

: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 order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch orders for
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr'   rc  r  endr  r*   r  r  )
r\  r  r	  r  r  r>  v1PrivateGetApiOrdersr  r  parse_orders)r   r/  r  r   r  r  r  r  r  r  r  s              r   fetch_ordersdefx.fetch_ordersc  s     !!![[(F!'GI!!&'2YYvw/F!\\%0GEN#||E2GGH(E"'J33DKK4PQQ< ~~h3  tU::] 	" Rs"   C1C-B+C1C/+C1/C1c           	      h   #    SS0nU R                  XX0R                  XT5      5      I Sh  vN $  N7f)a  
fetch all unfilled currently open orders

https://api-docs.defx.com/#ab200038-8acb-4170-b05e-4fcb4cc13751

: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 order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch orders for
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
r/  r*  Nr{  r  r   r/  r  r   r  reqs         r   fetch_open_ordersdefx.fetch_open_orders  s7      
 &&ve[[=UVVVV   )202c           	      h   #    SS0nU R                  XX0R                  XT5      5      I Sh  vN $  N7f)a+  
fetches information on multiple closed orders made by the user

https://api-docs.defx.com/#ab200038-8acb-4170-b05e-4fcb4cc13751

: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 order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch orders for
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
r/  r-  Nr~  r  s         r   fetch_closed_ordersdefx.fetch_closed_orders  s7      
 &&ve[[=UVVVVr  c           	      h   #    SS0nU R                  XX0R                  XT5      5      I Sh  vN $  N7f)a-  
fetches information on multiple canceled orders made by the user

https://api-docs.defx.com/#ab200038-8acb-4170-b05e-4fcb4cc13751

: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 order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch orders for
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
r/  CANCELEDNr~  r  s         r   fetch_canceled_ordersdefx.fetch_canceled_orders  s7      

 &&ve[[=UVVVVr  c                 H  #    U R                  5       I Sh  vN   U R                  US5      nUc  [        U R                  S-   5      eU R	                  US5      nUc  [        U R                  S-   5      eU R                  US5      nUc  [        U R                  S-   5      eUUUS.nUS	:w  a1  U R                  US
5      nUc  [        U R                  S-   5      eXS
'   U R                  U/ SQ5      nU R                  U R                  Xs5      5      I Sh  vN n	U	$  GN N	7f)a  
closes an open position for a market

https://api-docs.defx.com/#b2c08074-c4d9-4e50-b637-0d6c498fa29e

:param str symbol: unified CCXT market symbol
:param str [side]: one-way mode: 'buy' or 'sell', hedge-mode: 'long' or 'short'
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.positionId]: the position id you want to close
:param str [params.type]: 'MARKET' or 'LIMIT'
:param str [params.quantity]: how much of currency you want to trade in units of base currency
:param str [params.price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nrb  z& closePosition() requires a positionIdr  z  closePosition() requires a typer  z$ closePosition() requires a quantity)rb  r  r  r  r<  z! closePosition() requires a price)rb  r  r  r<  )r\  rN  r   r'   r  r  $v1PrivateDeleteApiPositionPositionIdr  )
r   r/  r  r  rb  r  r  r  r<  r  s
             r   close_positiondefx.close_position  s,     !!!%%fl;
#DGG.V$VWW%%ff5<#DGG.P$PQQ##FJ7#DGG.T$TUU$ 

 8$$VW5E}'2U(UVV$G6#NOBB4;;wC_`` 3 	"* as"   D"DC?D"D D" D"c                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  US/ 5      nU R                  USU5      $  NC N,7f)a  
closes all open positions for a market type

https://api-docs.defx.com/#d6f63b43-100e-47a9-998c-8b6c0c72d204

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: A list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
Nr  )r\  v1PrivateDeleteApiPositionAllr  rX  r  s       r   close_all_positionsdefx.close_all_positions   s]      !!!;;FCC ~~h3##D$77 	"Cs   AAAA+AAr  c                   #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ 0 nUb  X&S'   OSUS'   U R                  US5      nUb  U R	                  US5      nXvS'   OU R                  5       US'   U R                  U R                  Xd5      5      I Sh  vN nU R                  US	/ 5      n	U R                  U	SX#5      $  N N N.7f)
a  
fetch the history of changes, actions done by the user or operations that altered the balance of the user

https://api-docs.defx.com/#38cc8974-794f-48c0-b959-db045a0ee565

:param str [code]: unified currency code
:param int [since]: timestamp in ms of the earliest ledger entry
:param int [limit]: max number of ledger entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest ledger entry
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
NFrf   paginater  r   r  rx  transactions)
r\  handle_option_and_paramsfetch_paginated_call_dynamicr	  r  r  !v1PrivateGetApiWalletTransactionsr  r  parse_ledger)
r   r  r  r   r  r  r  r  r  r  s
             r   fetch_ledgerdefx.fetch_ledger  s     !!!88PZ[::=$W\eee$G GG!!&'2YYvw/F"EN!..0GEN??G@\]]~~h;  tU::% 	" f ^s4   C6C08C6C2A5C6C4+C62C64C6itemr  c                    U R                  US5      nU R                  US5      nU R                  XB5      nU R                  XB5      nU R                  US5      nU R                  US5      nU R	                  UU R                  US5      S S S S U R                  U5      UU R                  U5      UU R                  U5      S S S S S.U5      $ )Nr;  r  r{  r  r'   )r   r'   	directionr  referenceAccountreferenceIdr  r  r;  r{  r|  beforeafterr   r  )rN  rP  safe_currencyr	  safe_ledger_entryparse_ledger_entry_typer   r  )r   r  r  r;  
currencyIdr  r{  r  s           r   parse_ledger_entrydefx.parse_ledger_entry:  s     !!$1%%dG4
&&z<%%j;%%dK8	f-%%""4. $006''/"Y/'
  ! 	r   c           	      <    SSSSSSSSS.nU R                  X!U5      $ )Nr  r  r   r   
commission)
FundingFee	FeeRebateFeeKickbackRealizedPnlLiquidationClearanceTransferReferralPayout
Commissionr.  )r   r  
ledgerTypes      r   r  defx.parse_ledger_entry_type]  s6     "$+"(&	

 
$77r   addresstagc                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  X5      US   S.nU R                  U R	                  Xu5      5      I Sh  vN nU R                  X5      $  Ne N7f)a  
make a withdrawal

https://api-docs.defx.com/#2600f503-63ed-4672-b8f6-69ea5f03203b

: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
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr'   )r;  r  )r\  r  currency_to_precision)v1PrivatePostApiTransfersBridgeWithdrawalr  parse_transaction)	r   r  r;  r  r  r  r  r  r  s	            r   r   defx.withdrawj  s      !!!==&00>d^
 GGT[Hdee %%h99 	" fs"   B A<AB &A>'B >B transactionc                     U R                  US5      n0 SU_SS _SU_SS _SS _SS _SS _S	S _S
S _SS _SS _SS _SS _SS _SU R                  S U5      _SS _SS _S S S S.E$ )NtransactionIdr   r'   txidr{  r|  networkr  	addressToaddressFromr  tagTotagFromr  r;  r  r   r   )internalcommentr  )rN  rP  )r   r  r  r  s       r   r  defx.parse_transaction  s    _=
K
$
 D
 	

 
 t
 t
 
 4
 4
 T
 t
 D
 d
 //h?
  d!
" t#
$ )
 	
r   r   c                 h  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   SU R                  U5      0nU R	                  U5      nUS   US'   U R                  U R                  XC5      5      I Sh  vN nU R                  US0 5      nU R                  Xu5      $  N| N*7f)a6  
set the level of leverage for a market

https://api-docs.defx.com/#4cb4ecc4-6c61-4194-8353-be67faaf7ca7

:param float leverage: the rate of leverage
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
Nz) setLeverage() requires a symbol argumentr   r'   r/  r  )	r   r'   r\  number_to_stringr  %v1PrivatePostApiUsersMetadataLeverager  rQ  parse_leverage)r   r   r/  r  r  r  r  r  s           r   set_leveragedefx.set_leverage  s      >#DGG.Y$YZZ!!!--h7
 V$"4LCCDKKPWD`aa ~~h3""400# 	" bs"   /B2B.AB2B0)B20B2c                 x    U R                  US5      nU R                  US5      nUU R                  X25      S UUS.$ )Nr/  r   )r   r/  r   longLeverageshortLeverage)rN  r	  safe_symbol)r   r   r  r"  leverageValues        r   r  defx.parse_leverage  sL     ##Hh7))(J?&&x8)*
 	
r   c                 "    U R                  5       $ N)r  )r   s    r   nonce
defx.nonce  s      ""r   r   GETc                 :   US   nUS   nU R                  X5      n	U R                  U R                  S   U   5      n
U
SU-   S-   -  n
U R                  X@R	                  U5      5      nU R                  U5      nUS:X  a'  U
SU	-   -  n
U(       a  U
SU R                  U5      -   -  n
OU R                  5         SS	0nU
S
U	-   -  n
[        U R                  5       5      nUnUS:X  d  US:X  a2  XR                  U5      -  nU(       a  U
SU R                  U5      -   -  n
OUb  U R                  U5      nX-  nSUS'   U R                  U R                  U5      U R                  U R                  5      [        R                  5      nU R                   US'   XS'   XS'   XXeS.$ )Nr   r   r   r'  r   zopen/?zX-DEFX-SOURCEccxtzauth/r  r   zapplication/jsonzContent-TypezX-DEFX-APIKEYzX-DEFX-TIMESTAMPzX-DEFX-SIGNATURE)r   methodbodyheaders)implode_paramsimplode_hostnamer   r  extract_paramskeysort	rawencodecheck_required_credentialsstrr  jsonhmacencodesecrethashlibsha256apiKey)r   pathsectionr  r  r  r  r+   accesspathWithParamsr   r  payload	signatures                 r   sign	defx.sign  s   !*,,T:##DIIe$4V$<=sW}s""6#6#6t#<=f%X7^++CsT^^F333++-&/G7^++C))+,EG$*?"?>>&113!777C%99V,DOG*<'		$++g"6DKK8PRYR`R`aI'+{{GO$*/&'*3&'dOOr   httpCodereasonr   r  r  r  c
                 P   U(       d  g U R                  US5      n
U R                  USU5      nU R                  USS5      nU
(       d_  U R                  S-   U R	                  U5      -   nU R                  U R                  S   Xm5        U R                  U R                  S   X5        g )Nr   err	errorCoder   r   r   )r  rQ  r  r'   r  throw_broadly_matched_exceptionr   throw_exactly_matched_exception)r   r  r  r   r  r  r  r  requestHeadersrequestBodyr   r  r  feedbacks                 r   handle_errorsdefx.handle_errors  s     ..95nnXuh7&&sK@	ww}tyy'::H001I4Z001I9_r   c                     U R                  U5      nUS   n[        UR                  5       5      n[        S[	        U5      5       H  nXE   nUS:X  d  M  Us  $    U R                  US5      $ )Nnetworksr   ETH)r  listkeysr  r  
safe_value)r   r  currencyItemr  networkKeysr!  r  s          r   !default_network_code_for_currency&defx.default_network_code_for_currency  sg    }}T*
+8==?+q#k*+A!nG% ,
 {A..r   enablec                 H   > [         [        U ]  U5        XR                  S'   g )Nr   )r   r#   set_sandbox_moder   )r   r  r   s     r   r  defx.set_sandbox_mode  s    dD*62&,]#r    r  )O__name__
__module____qualname____firstlineno__r   r   r  r   r
  r   r   r#  dictrY  r  r   r`  r   r   rj  r^  r  r  r  r   r  r   r  r  r   r  r  r   r  r  r   r  r  r   r   floatr   r#  r0  r   r  rK  rO  rU  r   rZ  rS  ru  r{  r  r  r  r  r  r	   r  r   r  r  r   r   r  intr  r
   r  r  r  r   r
  boolr  __static_attributes____classcell__)r   s   @r   r#   r#      sz   X# Xt
 )+ 
@ ') 0S 0( *, `3V `3DE
4 E
F E
N 68 '3 '3F '3R 6:" %57 %5 %5N^4 ^ ^6 ^@ ?CQUdhqs 9L 9L 9L3 9L^a 9Lx|  ~B  yC 9Lv	
 	
4 	
 <@d[] "A "AS "A "Abfglbm "AH 37TX\eg );C );s );RU );lpqvlw );V; ;v ; ;z @DB .bS .b .bS\ .b` :< 3S 3 3: <> 9s 9+ 98#
6 #
[ #
J *, ( (0
) 
) mqy{ U. U.I U.Y U.X] U.fi U.n
 
M Mv M M^ 9=R %ES %E# %EN 59 5c 52 8: $23 $2L 8<B 8W 84PX> 8>1t 1V 1f 8<B 4&C 4& 4&l 04$UYbd ;; ;;C ;;s ;;imnsit ;;z 59tZ^gi Wc W WTW Wnrsxny W$ 7;\`ik W W3 WVY Wptuzp{ W$ 9=4^bkm W# WS WX[ Wrvw|r} W$ CGr (3 (i (V[ (T 02 8d8n 80 .2SW`b  ;s  ;#  ;S  ;gklwgx  ;D!t !x !; !F8 QU]_ :3 : : :# :do ::
T 
X 
Q\ 
@ ?C2 13 1 1@
t 
V 
x 
"# "*%DW[ PBc 3 S # X\ dg 	/-t - -r   r#   )) ccxt.async_support.base.exchanger   ccxt.abstract.defxr   r  r  ccxt.base.typesr   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   ccxt.base.decimal_to_precisionr    ccxt.base.preciser!   r#   r  r   r   <module>r"     sb    6 *   O  O  O  O  O  O  * 0 . ' ) ) 4 %B -8[ B -r   