
    E#i,                       S SK Jr  S SKJ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K%J&r&   " S S\\5      r'g)    )Exchange)ImplicitAPI)AnyBalancesCurrencyGreeksIntLeverage
MarginModeMarketNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTickersTradeTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)OperationRejected)InvalidOrder)	TICK_SIZE)Precisec                   `  ^  \ rS rSrS\4U 4S jjr0 4S\4S jjr0 4S jr0 4S\	\
   4S jjrS\S\
4S jrS	S
S
0 4S\S\S\S\S\	\   4
S jjrScS\
S\4S jjrS
0 4S\S\4S jjr0 4S\S\4S jjrScS\S\
S\4S jjrS
0 4S\S\S\4S jjrS
S
0 4S\S\S\S\	\   4S jjrScS\S\
S\4S jjr0 4S\4S jjrScS\
4S jjrS rS r S r!S r"SdS  jr#S! r$0 4S" jr%0 4S# jr&ScS$\S\
S\'4S% jjr(S&\)4S' jr*S(\)4S) jr+S*\)4S+ jr,S,\4S- jr-S.\4S/ jr.S
0 4S\S*\/S0\0S1\1S2\24
S3 jjr3S
0 4S4\S\)4S5 jjr4S
0 4S\)4S6 jjr5S
0 4S4\S\)4S7 jjr6S
S
S
0 4S\)S\S\S\	\'   4S8 jjr7S
S
S
0 4S\)S\S\S\	\'   4S9 jjr80 4S\94S: jjr:S\94S; jr;S
S
S
0 4S\)S\S\4S< jjr<0 4S\4S= jjr=S
0 4S\S\	\>   4S> jjr?ScS?\S\
4S@ jjr@S
S
0 4S\S\S\4SA jjrAScS\
4SB jjrBS
S
S
0 4SC\)S\S\S\	\C   4SD jjrDS
S
S
0 4SC\)S\S\S\	\C   4SE jjrEScSF\SG\FS\C4SH jjrGS(\)4SI jrH0 4S\S\I4SJ jjrJScSK\S\I4SL jjrKS
0 4SM\S\)4SN jjrL0 4S\S\M4SO jjrNScSP\S\
S\M4SQ jjrOSR rPS
0 4SP\QS\)4SS jjrR0 4S\S\S4ST jjrTS
0 4S\S\	\S   4SU jjrUScSV\S\
S\S4SW jjrVSXSY0 S
S
4SZ jrWS[\QS\\S]\S^\S_\S`\4Sa jrXSbrYU =rZ$ )eparadex   returnc                 r  > U R                  [        [        U ]  5       0 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_S/S_S0S_S1S_E0 S2S_S3S_S4S_S5S_S6S_S7S_S8S_S9S_S:S_S;S_S<S_S=S_S>S_S?S_S@S_SAS_SBS_E0 SCS_SDS_SES_SFS_SGS_SHS_SIS_SJS_SKS_SLS_SMS_SNS_SOS_SPS_SQS_SRS_SSS_E0 STS_SUS_SVS_SWS_SXS_SYS_SZS_S[S_S\S_S]S_S^S_S_S_S`S_SaS_SbS_ScS_SdS_ESSSSSSSSe.E_SfSgShSiSjSkSlSm._SnSo_SpSqSSr0SSs0StSuSvSwSx._SySz0 S{Sg_S|Sg_S}Sg_S~Sg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SgSgS.E00 SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SSg_SgSgSgSgSgSgSgSgS.ESgSgSgSgSgSgSgSgSgSgS.
SSg0SgSgSgSgS.S.S._SU R	                  S5      U R	                  S5      S.U R	                  S5      U R	                  S5      S.S._SSSSSS._S0 S[
        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _0 S[        _S[
        _S[        _S[        _S[        _S[        _S[        _S[
        _S[
        _S[
        _S[        _S[        _S[        _S[        _S[        _S[
        _S[        _E0 S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _E[        [        [
        [
        [        S.ES[
        0S._S[        _0 S 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SSSSS.SSSSS.SSSSSS.SSSSSSSS.S SS 0S.	SS0S S.S S S.S.S.E5      $ )Nidr$   nameParadex	countriesversionv1	rateLimit2   	certifiedFproTdexhasCORSspotmarginswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscancelOrdersForSymbolscloseAllPositionsclosePositioncreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreateReduceOnlyOrdercreateStopOrdercreateTriggerOrder	editOrderfetchAccountsfetchAllGreeksfetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeverageTiersfetchLiquidationsfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransferfetchTransfersfetchWithdrawalfetchWithdrawalsreduceMarginrepayCrossMargin)repayIsolatedMarginsandboxsetLeveragesetMarginModesetPositionModetransferwithdraw
timeframes               <   )1m3m5m15m30m1hhostnamezparadex.tradeurlszOhttps://github.com/user-attachments/assets/84628770-784e-4ec4-a759-ec2fbb2244eazhttps://api.prod.{hostname}/v1z!https://api.testnet.{hostname}/v1zhttps://www.paradex.trade/z'https://docs.api.testnet.paradex.trade/z7https://docs.paradex.trade/getting-started/trading-feesz"https://app.paradex.trade/r/ccxt24)logoapitestwwwdocfeesreferralr   getzbbo/{market}zfunding/datamarketszmarkets/klineszmarkets/summaryzorderbook/{market}	insurancezreferrals/configzsystem/configzsystem/statezsystem/timetradesvaultszvaults/balancezvaults/configzvaults/historyzvaults/positions)zvaults/summaryzvaults/transfersaccountzaccount/infozaccount/historyzaccount/marginzaccount/profilezaccount/subaccountsbalancefillszfunding/payments	positions
tradebuststransactionsliquidationsorderszorders-historyorders/by_client_id/{client_id}orders/{order_id})zpoints_data/{market}/{program}zreferrals/qr-codezreferrals/summary	transfersalgo/orderszalgo/orders-historyalgo/orders/{algo_id}zvaults/account-summary)
zaccount/margin/{market}zaccount/profile/max_slippagezaccount/profile/referral_codezaccount/profile/usernameauth
onboardingr   zorders/batchr   r   )r   r   r   r   )r   postputdelete)publicprivater   z0.0002)takermaker)r7   r5   requiredCredentials)apiKeysecretwalletAddress
privateKey
exceptionsVALIDATION_ERRORBINDING_ERRORINTERNAL_ERROR	NOT_FOUNDSERVICE_UNAVAILABLEINVALID_REQUEST_PARAMETERORDER_ID_NOT_FOUNDORDER_IS_CLOSEDORDER_IS_NOT_OPEN_YETCLIENT_ORDER_ID_NOT_FOUNDDUPLICATED_CLIENT_IDINVALID_PRICE_PRECISIONINVALID_SYMBOLINVALID_TOKENINVALID_ETHEREUM_ADDRESSINVALID_ETHEREUM_SIGNATUREINVALID_STARKNET_ADDRESSINVALID_STARKNET_SIGNATURE&STARKNET_SIGNATURE_VERIFICATION_FAILEDBAD_STARKNET_REQUESTETHEREUM_SIGNER_MISMATCHETHEREUM_HASH_MISMATCHNOT_ONBOARDEDINVALID_TIMESTAMPINVALID_SIGNATURE_EXPIRATIONACCOUNT_NOT_FOUNDINVALID_ORDER_SIGNATUREPUBLIC_KEY_INVALIDUNAUTHORIZED_ETHEREUM_ADDRESS"ETHEREUM_ADDRESS_ALREADY_ONBOARDEDMARKET_NOT_FOUNDALLOWLIST_ENTRY_NOT_FOUNDUSERNAME_IN_USEGEO_IP_BLOCKETHEREUM_ADDRESS_BLOCKEDPROGRAM_NOT_FOUNDINVALID_DASHBOARDMARKET_NOT_OPENINVALID_REFERRAL_CODE PARENT_ADDRESS_ALREADY_ONBOARDEDINVALID_PARENT_ACCOUNTINVALID_VAULT_OPERATOR_CHAIN VAULT_OPERATOR_ALREADY_ONBOARDEDVAULT_NAME_IN_USEBATCH_SIZE_OUT_OF_RANGE ISOLATED_MARKET_ACCOUNT_MISMATCHPOINTS_SUMMARY_NOT_FOUNDz-32700z-32600z-32601z-32602)z-32603100401104011140112zmissing or malformed jwt)exactbroadprecisionModeCCXT)paradexAccountbroker)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergd   i )r  limitdaysBack	untilDayssymbolRequired)r  triggerr  r  )r  r  r  r  r  )r  r  r  r  r  r  r  r  )	r   rG   rH   rn   rs   rr   ru   rT   ro   extendsforSwap)linearinverse)r5   r  r7   r8   )commonCurrenciesoptionsfeatures)deep_extendsuperr$   describeparse_numberr   r   r   r   r    r   r!   )self	__class__s    T/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/async_support/paradex.pyr"  paradex.describe   s   gt = ? fB
)fB
IfB
 fB
 t	fB

 fB
 fB
 4fB
 4fB
  ]]] %] 	]
 %] %] U] $U] '] "4] '] u] ] )%] $U]   !]" /#]$ ,U%]& 0']( t)]* +], (-]. "4/]0 %d1]2 U3]4  5]6 !$7]8 9]: &u;]< +E=]> )%?]@ &uA]B $UC]D 'E]F (G]H "5I]J &uK]L (M]N  O]P *5Q]R +ES]T &uU]V #EW]X *5Y]Z $U[]\ t]]^ "5_]` *5a]b +Ec]d ue]f  g]h %ei]j $Tk]l "4m]n +Eo]p q]r !%s]t &uu]v  w]x dy]z $T{]| +E}]~ "4]@ dA]B !$C]D tE]F #EG]H  I]J $UK]L !$M]N %eO]P )%Q]R tS]T tU]V W]X TY]Z t[]\ "5]]^ #E_]`  a]b !%c]d "5e]f #Dg]h i]j #Ek]l (-#!%#(!!y]fB
N OfB
^ _fB
` i: = 4@Q@afB
z  && "1 )!	
 *1 -a $Q +A ( ' &q !! !! )! (  )!!" +A#$ +,,-'0!1& *1 )!	
 *1 .q "1   +A $Q %a ' ' !! )!  :1!" ,Q#$ ;<-.-.%&'(/0122338 45899:45 !&'"#()'("# ,Q #$;<-.12	W11J{fB
P !..x8!..x8
 "..x8!..x8	QfB
d "!%"	$efB
p 9&(;9#%69 %m9  	9
 *=9 09 ),9 &|9 ,\9 09 +L9 ./@9 %&79 $%69 /0A9  12C!9" /0A#9$ 12C%9& =>Q'9( +J)9* /
+9, -j-9. $Z/90 (192 34G394 ()<596 ./B798 )*99: 4Z;9< 9*=9> '
?9@ 0A9B &':C9D #$4E9F /0@G9H (I9J ():K9L &zM9N ,->O9P 7
Q9R -.?S9T 34EU9V 78IW9X ():Y9Z ./@[9\ 78I]9^ /0A_9` ja9b jc9d je9f jg9h ,%00-q9v /0Cw>qfB
n YofB
p! #' 
 #&+(,,0,0).+06:#'#("&#(	( #($)$)+027/3#()$, %)&+!$$*%+*/& ',#($)*/	# ',!$#($)*/( ',!$$*%+#($)*/$ *.#o:z "9  $	 ##GG}fB
 f f	    c                 d   #    U R                  U5      I Sh  vN nU R                  US5      $  N7f)a>  
fetches the current integer timestamp in milliseconds from the exchange server

https://docs.api.testnet.paradex.trade/#get-system-time-unix-milliseconds

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the exchange server
Nserver_time)publicGetSystemTimesafe_integer)r$  paramsresponses      r&  
fetch_timeparadex.fetch_time  s4      11&99   =99 :s   0.0c                    #    U R                  U5      I Sh  vN nU R                  US5      nUS:X  a  SOSSSSUS.$  N&7f)a*  
the latest known information on the availability of the exchange API

https://docs.api.testnet.paradex.trade/#get-system-state

: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statusokmaintenance)r2  updatedetaurlinfo)publicGetSystemStatesafe_string)r$  r-  r.  r2  s       r&  fetch_statusparadex.fetch_status  sT      226:: !!(H5%~dM
 	
 ;s   A >'A c                    #    U R                  U5      I Sh  vN nU R                  US5      nU R                  U5      $  N'7f)z
retrieves data on all markets for bitget

https://docs.api.testnet.paradex.trade/#list-available-markets

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
Nresults)publicGetMarkets	safe_listparse_marketsr$  r-  r.  datas       r&  fetch_marketsparadex.fetch_markets  sD      ..v66D ~~h	2!!$''G 7s   A?(Amarketc                 p   U R                  US5      nUS:H  nU(       a  SOSnUS:H  nU R                  U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 R                  US5      nU R                  U5      nU
S	-   U	-   S
-   U-   nU R                  US5      nU R                  US5      nU R                  US5      nU R                  S5      nU R                  S5      nU(       a*  US:X  a  SOSnUS-   U-   S-   U-   nU R                  S5      nOS 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S _SU_SS_SU_S U R                  US!5      _S"S#_S$S#_SUUU R                  S%5      UUS&:X  a  S OU R                  U5      U R                  U5      U R                  US5      U R                  US'5      U R                  US(5      S).S S S*.S U R                  US+5      S*.S S S*.U R                  US,5      S S*.S-.S US..E5      $ )/N
asset_kindPERP_OPTIONr9   r7   symbolquote_currencybase_currencysettlement_currency/:	expiry_atoption_typestrike_pricez0.0003z-0.00005CALLCP-r(   basequotesettlebaseIdquoteIdsettleIdtyper5   Fr6   r8   activeenableTradingcontractTr  1r   order_size_incrementprice_tick_size)amountprice)minmaxmax_order_sizemin_notional)r  rd  re  cost)r  r   r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedr8  )	r:  safe_currency_coder,  r#  safe_market_structure	safe_booliso8601safe_string_lowersafe_number)r$  rF  	assetKindisOptionr]  isSwapmarketIdr[  rZ  rX  rW  r\  rY  rJ  rl  ro  strikePricetakerFeemakerFeeoptionTypeSuffixs                       r&  parse_marketparadex.parse_market  s   Z $$V\:	.$x6&.##FH5""6+;<!!&/:''0&&v.##F,AB((2e#c)F2""6;7%%fm<
&&v~>$$X.$$Z0'1V';s#c\K/#58HHF((2HF)) 2+
(2+
f2+
 D2+
 U	2+

 f2+
 f2+
 w2+
 2+
 D2+
 E2+
 d2+
 F2+
 e2+
 h2+
 dnnV_=2+
  !2+
" d#2+
$  --c2'-{df9M''400G**63IJ))&2CD  
  ++F4DE
  
  ++FNC$ c2+
 2 2	r(  r   NrJ  	timeframesincer  c                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  U R                  X"5      US   S.nU R	                  5       nU R                  U5      n	U R                  USSU5      n
U R                  USS/5      nUb-  X7S'   Ub!  U R                  X9US-   -  S-  5      S-
  US	'   O0XS	'   O+XS	'   Ub  XUS-   -  S-  -
  S-   US'   OXS
-  S-  -
  S-   US'   U R                  U R                  Xu5      5      I Sh  vN nU R                  US/ 5      nU R                  XX#U5      $  GN* N-7f)a  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://docs.api.testnet.paradex.trade/#ohlcv-for-a-symbol

:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: the length of time each candle represents
:param int [since]: timestamp in ms of the earliest candle to fetch
:param int [limit]: the maximum amount of candles to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest candle to fetch
:returns int[][]: A list of candles ordered, open, high, low, close, volume
Nr(   )
resolutionrJ  untiltillstart_atr     end_ate   r>  )load_marketsrF  r:  r   millisecondsparse_timeframesafe_integer_2omitsumpublicGetMarketsKlinesextendr@  parse_ohlcvs)r$  rJ  r  r  r  r-  rF  requestnowdurationr  r.  rC  s                r&  fetch_ohlcvparadex.fetch_ohlcvo  sq     !!!V$**4??IQTl
 !''	2##FGVSA6GV#45"'J $(HHU	4JT4Q$RUV$V!$)! %H &+%!).Dt.K&Ka&O
#&+nt.C&Ca&G
#44T[[5QRR ~~h	26  yGGM 	", Ss"   EE C>EE+EEc           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Nr   r      r      r   )r,  rx  )r$  ohlcvrF  s      r&  parse_ohlcvparadex.parse_ohlcv  sn     eQ'UA&UA&UA&UA&UA&
 	
r(  symbolsc                   #    U R                  5       I Sh  vN   U R                  U5      nSS0nU R                  U R                  X25      5      I Sh  vN nU R	                  US/ 5      nU R                  XQ5      $  Ne N*7f)a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://docs.api.testnet.paradex.trade/#list-available-markets-summary

: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>`
NrF  ALLr>  )r  market_symbolspublicGetMarketsSummaryr  r@  parse_tickers)r$  r  r-  r  r.  rC  s         r&  fetch_tickersparadex.fetch_tickers  s      !!!%%g.e
 55dkk'6RSS, ~~h	26!!$009 	"
 Ts!   B A<<B A>)B >B c                 0  #    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  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://docs.api.testnet.paradex.trade/#list-available-markets-summary

: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>`
NrF  r(   r>  r   )r  rF  r  r  r@  	safe_dictparse_ticker)r$  rJ  r-  rF  r  r.  rC  tickers           r&  fetch_tickerparadex.fetch_ticker  s      !!!V$fTl
 55dkk'6RSS, ~~h	26a,  00; 	"
 T!   BB?BB<BBr  c           	      (   U R                  US5      nUb  [        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                  0 SU_SU_SU R                  U5      _SS _S	S _S
U R                  US
5      _SS _SU R                  US5      _SS _SS _SS _SU_SU_SS _SS _SU_SS _S U R                  US5      U R                  US5      US.EU5      $ )Nprice_change_rate_24hr   last_traded_pricerJ  
created_at	timestampdatetimehighlowbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechange
percentageaverage
volume_24h
mark_price)
baseVolumequoteVolume	markPricer8  )r:  r"   
string_mulsafe_marketr,  safe_tickerrv  )r$  r  rF  r  r  r|  rJ  r  s           r&  r  paradex.parse_ticker
  s   $ %%f.EF
! ++J>J(;<##FH5!!(3!%%fl;	 !
f!
!
 Y/!
 D	!

 4!
 4##FE2!
 !
 4##FE2!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  *!!
" t#!
$ ++FLA))&,?+!
, - 	r(  c                 L  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XS5      5      I Sh  vN nUb  X%S'   U R	                  US5      nU R                  XdS   U5      nU R	                  US5      US'   U$  N NK7f)	a  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://docs.api.testnet.paradex.trade/#get-market-orderbook

:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
NrF  r(   depthlast_updated_atrJ  seq_nononce)r  rF  publicGetOrderbookMarketr  r,  parse_order_book)	r$  rJ  r  r-  rF  r  r.  r  	orderbooks	            r&  fetch_order_bookparadex.fetch_order_book<  s      !!!V$!6$<066t{{77STT( $G%%h0AB	))(84DiP	!..xB	'9 	" Us"   B$B ?B$B"A
B$"B$c                 4  #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4SSSS5	      I Sh  vN $ U R                  U5      nSUS	   0nUb  X7S
'   Ub  X'S'   U R	                  SXt5      u  ptU R                  U R                  Xt5      5      I Sh  vN nU R                  US/ 5      n	[        S[        U	5      5       H  n
U R                  US5      X   S'   M     U R                  XX#5      $  N N N`7f)a  
get the list of most recent trades for a particular symbol

https://docs.api.testnet.paradex.trade/#trade-tape

: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
:param int [params.until]: the latest time in ms to fetch trades for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
NFr   paginatenextcursorr  rF  r(   	page_sizer  r  r>  r   )r  handle_option_and_paramsfetch_paginated_call_cursorrF  handle_until_optionpublicGetTradesr  r@  rangelenr:  parse_trades)r$  rJ  r  r  r-  r  rF  r  r.  r   is              r&  fetch_tradesparadex.fetch_tradese  s>     !!!88PZ[99-X]gmowy}  @C  D  D  DV$fTl
 #(K "'J228WM--dkk'.JKK$ )R8q#f+&A $ 0 06 BFIf '  >>G 	" D Ls5   DD<DDA!D5D6ADDDtradec                 4   U R                  US5      nU R                  X25      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  USS5      n	U	S:H  n
U
(       a  SOS	nU R                  US
5      nU R	                  U5      nU R                  UUU R                  US5      UU R                  U5      US   S UUUUS U R                  US5      US S.S.U5      $ )NrF  r(   r  re  sizeside	liquidityr   r   fee_currencyorder_idrJ  fee)rj  currencyrate)r8  r(   orderr  r  rJ  r]  takerOrMakerr  re  rd  rj  r  )r:  r  r,  rw  rs  
safe_traderv  )r$  r  rF  r|  r(   r  priceStringamountStringr  	liabilityisTakerr  
currencyIdcodes                 r&  parse_tradeparadex.parse_trade  s?   @ ##E84!!(3eT*%%e\:	&&ug6''v6%%eV4**5+wG	w&#*w%%e^<
&&z2%%eZ8"Y/X&( "((6  
$ % 	r(  c                 t  #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      e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)aG  
retrieves the open interest of a contract trading pair

https://docs.api.testnet.paradex.trade/#list-available-markets-summary

:param str symbol: unified CCXT market symbol
:param dict [params]: exchange specific parameters
:returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
Nr`  z3 fetchOpenInterest() supports contract markets onlyrF  r(   r>  r   )	r  rF  r   r(   r  r  r@  r  parse_open_interest)r$  rJ  r-  rF  r  r.  rC  interests           r&  fetch_open_interestparadex.fetch_open_interest  s      !!!V$j!TWW'\\]]fTl
 55dkk'6RSS, ~~h	26>>$2.''99? 	" Ts"   B8B4A!B88B69<B86B8c           	          U R                  US5      nU R                  US5      nU R                  XB5      nUS   nU R                  UU R                  US5      S UU R	                  U5      US.U5      $ )Nr  rJ  open_interest)rJ  openInterestAmountopenInterestValuer  r  r8  )r,  r:  r  safe_open_interestrv  )r$  r  rF  r  r|  rJ  s         r&  r  paradex.parse_open_interest  s    $ %%h=	##Hh7!!(3!&&"&"2"28_"M!%"Y/(
  	r(  c                 .    SU R                  USS5      -   $ )N0xkeccakhex)hash)r$  messages     r&  hash_messageparadex.hash_message"  s    dii5999r(  c                     U R                  USS  USS  SS 5      nUS   nUS   nU R                  U R                  SUS   5      5      nSUR                  SS	5      -   UR                  SS	5      -   U-   $ )
N	secp256k1rs   vr  @   0)ecdsaint_to_base16r  rjust)r$  r
  r   	signaturer  r  r  s          r&  	sign_hashparadex.sign_hash%  s    JJtCDz:cd+;[$O	cNcNtxxIcN;<aggb#&&S)99A==r(  c                 J    U R                  U R                  U5      USS  5      $ )Nr  )r  r  )r$  r  r   s      r&  sign_messageparadex.sign_message,  s%    ~~d//8*ST:JKKr(  c                    #    U R                  U R                  S5      nUb  U$ U R                  5       I S h  vN nX R                  S'   U$  N7f)NsystemConfig)r  r  publicGetSystemConfig)r$  cachedConfigr.  s      r&  get_system_configparadex.get_system_config/  sN     !^^DLL.I#3355: (0^$= 6s   5AAAc                 t   #    U R                  5       I S h  vN nUSL a  SUS   SS.nU$ SUS   SS.nU$  N7f)NTr*   l1_chain_idra  )r)   chainIdr,   starknet_chain_idr   )r$  )r$  l1r!  l1Ddomains        r&  prepare_paradex_domainparadex.prepare_paradex_domainS  s[     !3355:!'6C
 J#$78

  6s   86 8c                   #    U R                  U R                  S5      nUb  U$ U R                  5         U R                  5       I S h  vN nU R	                  S5      I S h  vN nSSSS./0nSS0nU R                  X4U5      nU R                  X`R                  5      nU R                  UUS   US	   5      nXR                  S'   U$  N Nh7f)
Nr   TConstantactionstringr)   r]  z	STARK Keyparaclear_account_hashparaclear_account_proxy_hash)	r  r  check_required_credentialsr$  r-  eth_encode_structured_datar  r   retrieve_stark_account)	r$  cachedAccountr!  r,  messageTypesr  msgr  r   s	            r&  retrieve_accountparadex.retrieve_accountc  s     "nnT\\;KL$  '')!335522488!84
 k
 --fGL%%c??;	--1278

 *1%&% 68s%   ACCC C	!A'C	Cc                 >  #    U R                  5       I S h  vN nSS0nU R                  5       I S h  vN nSSSS./0nU R                  XEX2S   5      nU R                  XbS   5      nXqS'   US   US	'   US
   US'   U R	                  U5      I S h  vN nU$  N Nf N
7f)Nr1  
Onboardingr0  feltr3  addressr   r  r   	publicKey
public_key)r<  r-  starknet_encode_structured_datastarknet_signprivatePostOnboarding)	r$  r-  r   reqr,  r:  r;  r  r.  s	            r&  r   paradex.onboarding|  s     --//l
 2244!62

 226V_N`a&&sL,AB	'{#I.y&{3|33F;;! 0 5 <s2   BBBBABBBBBc                   #    U R                  U R                  S5      nU R                  5       nUb#  U R                  U R                  S5      nX4:  a  U$ U R	                  5       I S h  vN nUS-   nSSSUUS.nU R                  5       I S h  vN nSS	S
S.SS
S.SS
S.SS
S.SS
S./0n	U R                  XXuS   5      n
U R                  XS   5      nXS'   US   US'   US   US'   US   US'   U R                  U5      I S h  vN nU R                  US5      nXR                  S'   X`R                  S'   U$  N N N87f)N	authTokenexpires   POSTz/v1/auth )methodpathbodyr  
expirationRequestrO  r@  r3  rP  rQ  r  rR  rA  r   r  r   	jwt_token)	r:  r  r  r,  r<  r-  rD  rE  privatePostAuth)r$  r-  cachedTokenr  cachedExpiresr   rK  rG  r,  r:  r;  r  r.  tokens                 r&  authenticate_restparadex.authenticate_rest  s    &&t||[Ajjl" --dllIFM"""--//)!
 2244!6200$f5%v6
 226V_N`a&&sL,AB	'{#I.y!+.{"<0|--f55   ;7$)[!")YG 0 5  6s7   A&D>(D8)$D>D:A5D>D<5D>:D><D>r  c                    U R                  US5      nU R                  US5      nU R                  U R                  US5      5      nU R                  US5      nU R                  Xb5      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b  US:X  d  US:X  a  SnOS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                  US/ 5      nS nSU;   a  SnU R                  0 SU_SU_SU_SU R                  U5      _SS _SU_S
U R                  U5      _SU_SU R                  U
5      _SU R                  U R                  US5      5      _SS _SU_SU_SU_SU R                  US 5      _S!S _S"S _UU	S US S S S S#.US$.EU5      $ )%Nr  r(   	client_idrF  rJ  re  r  r]  cancel_reasonr2  NOT_ENOUGH_MARGINORDER_EXCEEDS_POSITION_LIMITrejectedcanceledr  avg_fill_priceremaining_sizer  flagsREDUCE_ONLYTclientOrderIdr  r  lastTradeTimestamplastUpdateTimestampr  instructionpostOnly
reduceOnlyr  trigger_pricer	  r  )rj  r  )r  rd  filled	remainingrj  r   r  r8  )r,  r:  	omit_zeror  rw  r@  
safe_orderrv  parse_order_statusparse_order_typeparse_time_in_force)r$  r  rF  r  orderIdrf  r|  rJ  re  rd  	orderTypecancelReasonr2  r  r  rn  rh  rd  rk  s                      r&  parse_orderparadex.parse_order  s   : %%e\:	""5$/t'7'7{'KL##E84!!(3!  0!!%0$$UF3	''?!!%2#22lFd6d##%%eV4..!1!1%9I!JKNN4#3#3E;K#LM	"//7HIugr2
E!J  
' 
] 
  
 Y/	 

 !$ 
 "#6 
 d--f5 
 f 
 D)))4 
 433D4D4DUM4Z[ 
  
 * 
 D 
 U 
 D,,UOD 
  t! 
" T# 
$ "  9 
: ; 	r(  r  c                 2    SSSS.nU R                  X!S 5      $ )Nr   GTCr  )r   rz  	POST_ONLYr:  )r$  r  timeInForcess      r&  rs  paradex.parse_time_in_force  s'    

 4@@r(  r2  c                 >    Ub  SSSSS.nU R                  X!U5      $ U$ )Nr  closed)NEWUNTRIGGEREDOPENCLOSEDr|  r$  r2  statusess      r&  rq  paradex.parse_order_status  s5    %"	H ##Hf==r(  r]  c                 4    SSSSS.nU R                  X!U5      $ )Nr  rF  )LIMITMARKET
STOP_LIMITSTOP_MARKET)rw  )r$  r]  typess      r&  rr  paradex.parse_order_type"  s*    !#	
 %%e488r(  strc                 f    SU R                  U R                  U R                  U5      5      5      -   $ )Nr  )binary_to_base16base64_to_binarystring_to_base64)r$  r  s     r&  convert_short_stringparadex.convert_short_string+  s/    d++D,A,A$BWBWX[B\,]^^^r(  numc                 0    [         R                  " US5      $ )N	100000000)r"   r  )r$  r  s     r&  scale_numberparadex.scale_number/  s    !!#{33r(  r  rd  re  c           	      n  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  U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S5      nU R                  US5      nU R                  US	5      nU	S
:H  nUSLnUSLnUSL=(       d    U=(       d    UnU R                  US5      nU R                  USU5      nU(       d  U(       a  SUS'   OUS:X  a  SUS'   Ub  U R                  X5      US'   U R                  U/ SQ5      nUb  UUS'   SnSnU(       a  U(       ah  U(       a  U R                  X5      nSnSUS'   OU(       a  U R                  X5      nSnSUS'   OU R                  X5      nU R                  X5      nSUS'   OyU(       a  U R                  X5      nSnSUS'   OYU(       a  U R                  X5      nSnSUS'   O9U R                  X5      nU R                  X5      nSUS'   OU R                  X5      nUb  UUS'   UUS'   U(       a  S/US'   U R                  U/ S Q5      nU R                  5       I Sh  vN nU R                  5       nUS!-  U R                  US"   5      U
S#:X  a  S$OS%U R                  US   5      U R!                  US   5      U(       a  SOU R!                  US   5      S&.nU R#                  5       I Sh  vN nS'S(S)S*.S"S)S*.S+S)S*.S,S)S*.SS)S*.SS)S*./0nU R%                  UUUUS-   5      nU R'                  UUS.   5      nUUS/'   US(   US0'   U R)                  U R+                  X5      5      I Sh  vN nU R-                  UU5      n U $  GN GN} GN) N N#7f)1a  
create a trade order

https://docs.api.prod.paradex.trade/#create-order

: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 fullfilled, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:param float [params.stopPrice]: alias for triggerPrice
:param float [params.triggerPrice]: The price a trigger order is triggered at
:param float [params.stopLossPrice]: the price that a stop loss order is triggered at
:param float [params.takeProfitPrice]: the price that a take profit order is triggered at
:param str [params.timeInForce]: "GTC", "IOC", or "POST_ONLY"
:param bool [params.postOnly]: True or False
:param bool [params.reduceOnly]: Ensures that the executed order does not flip the opened position.
:param str [params.clientOrderId]: a unique id for the order
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nrk  reduce_onlyr(   )rF  r  r]  r  	stopPricer  r	  r  r  r{  ri  iocr   re  clOrdIDrf  client_order_idr\  r  TSTOP_LOSS_MARKETr]  TAKE_PROFIT_MARKETr  STOP_LOSS_LIMITTAKE_PROFIT_LIMITr  rl  r  re  rd  )rk  r  r  rf  r  rj  r  r  r  r  r	  r  rF  BUYra  2)r  rF  r  ru  r  re  r   r  r@  r3  r  ru  rA  r   r  signature_timestamp)rY  r  rF  safe_bool_2uppersafe_string_2r:  safe_string_upperis_post_onlyprice_to_precisionsafe_string_namount_to_precisionr  r<  r  r  r  r-  rD  rE  privatePostOrdersr  rw  )!r$  rJ  r]  r  rd  re  r-  rF  rk  ru  	orderSider  r  r  r	  isMarketisTakeProfitOrderisStopLossOrderisStopOrderr  rj  rf  
sizeStringr  r   r  orderReqr,  r:  r;  r  r.  r  s!                                    r&  create_orderparadex.create_order2  s    , $$&&&!!!V$%%flMJ
JJL	JJL	Tl

 ))&.+N((A**63DE(,D8(4#4/X4EX,,V]C$$XtV<)4&%).&#66vEGG**63bc$#0GK 
	" $ 7 7 NI!%J&8GFO& $ 7 7 PI!%J&:GFO $ 7 7 MI!%!9!9&!IJ&3GFO" $ 7 7 NI!%J&7GFO& $ 7 7 PI!%J&9GFO $ 7 7 MI!%!9!9&!IJ&2GFO11&AJ '0GO$$ GG 6  $L  M--//jjlt//0AB%.CS2276?C%%gfo6%SD,=,=gg>N,O
 2244$f5!620$f50 &1	
 226<SZ[dSef&&sGL,AB	()1+)>%&//G0LMM:   62{ 	'!J 0 5 NsX   N5N(N5N+IN5N.BN5N1A<N5N3N5+N5.N51N53N5r(   c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   0 nU R                  U/ SQ5      nSnUb-  XTS'   U R                  U R	                  XC5      5      I Sh  vN nO,XS'   U R                  U R	                  XC5      5      I Sh  vN nU R                  U5      $  N N NF N7f)a  
cancels an open order

https://docs.api.prod.paradex.trade/#cancel-order
https://docs.api.prod.paradex.trade/#cancel-open-order-by-client-order-id

: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 str [params.clientOrderId]: a unique id for the order
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r\  r  )rY  r  r  %privateDeleteOrdersByClientIdClientIdr  privateDeleteOrdersOrderIdrw  r$  r(   rJ  r-  r  rf  r.  s          r&  cancel_orderparadex.cancel_order  s      $$&&&!!!**63bc$#0K !GGT[HdeeH"$J!<<T[[=YZZH )) 	'! f [sD   C B8C B:AC 5B<6,C "B>#C :C <C >C c                 T  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  5       I Sh  vN   U R	                  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      /$  Np NZ N7f)aV  
cancel all open orders in a market

https://docs.api.prod.paradex.trade/#cancel-all-open-orders

:param str symbol: unified market symbol of the market to cancel orders in
: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>`
Nz- cancelAllOrders() requires a symbol argumentrF  r(   r8  )r   r(   rY  r  rF  privateDeleteOrdersr  rp  )r$  rJ  r-  rF  r  r.  s         r&  cancel_all_ordersparadex.cancel_all_orders  s      >#DGG.]$]^^$$&&&!!!V$fTl
 11$++g2NOO  2344 	'!
 Ps3   /B(B"B(	B$
?B(	B&
B($B(&B(c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   0 nU R                  U/ SQ5      nU R                  U/ SQ5      nSnUb-  XTS'   U R	                  U R                  XC5      5      I Sh  vN nO,XS'   U R                  U R                  XC5      5      I Sh  vN nU R                  U5      $  N N NF N7f)a  
fetches information on an order made by the user

https://docs.api.prod.paradex.trade/#get-order
https://docs.api.prod.paradex.trade/#get-order-by-client-id

: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
:param str [params.clientOrderId]: a unique id for the order
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r\  r  )rY  r  r  r  "privateGetOrdersByClientIdClientIdr  privateGetOrdersOrderIdrw  r  s          r&  fetch_orderparadex.fetch_order  s      $$&&&!!!**63bc6#RS$#0K !DDT[[QXEabbH"$J!99$++g:VWWH6 ))M 	'! c XsD   CCCCAC	C
,C6C7CCCCc                 |  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4SSSS5	      I Sh  vN $ 0 nSnUb  U R	                  U5      nUS   US	'   Ub  X&S
'   Ub  X6S'   U R                  SXd5      u  pdU R                  U R                  Xd5      5      I Sh  vN nU R                  US/ 5      n	U R                  US5      n
[        U	5      nU
b  US:  a  U	S   nXS'   XS'   U R                  XX#5      $  GN GN N Nd7f)a  
fetches information on multiple orders made by the user

https://docs.api.prod.paradex.trade/#get-orders

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.side]: 'buy' or 'sell'
:param boolean [params.paginate]: set to True if you want to fetch orders with pagination
:param int params['until']: timestamp in ms of the latest order to fetch
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NFru   r  r  r  r/   r(   rF  r  r  r  r>  r   )rY  r  r  r  rF  r  privateGetOrdersHistoryr  r@  r:  r  parse_orders)r$  rJ  r  r  r-  r  r  rF  r.  r   paginationCursorordersLengthfirsts                r&  fetch_ordersparadex.fetch_orders1  sr     $$&&&!!!88PZ[99-X]gmowy}  @B  C  C  C[[(F &tGH"'J#(K 228WM55dkk'6RSSF )R8++Hf=6{(|a/?1IE,&M1I  >>u 	'! C TE   D<D2D<D5<D<+D8,A)D<D:AD<5D<8D<:D<c                 P  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   0 nSnUb  U R                  U5      nUS   US'   U R                  U R	                  XT5      5      I Sh  vN nU R                  US/ 5      nU R                  XX#5      $  N Ns N-7f)a  
fetches information on multiple orders made by the user

https://docs.api.prod.paradex.trade/#paradex-rest-api-orders

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr(   rF  r>  )rY  r  rF  privateGetOrdersr  r@  r  )	r$  rJ  r  r  r-  r  rF  r.  r   s	            r&  fetch_open_ordersparadex.fetch_open_orders|  s      $$&&&!!![[(F &tGH..t{{7/KLLB )R8  >>S 	'! Ms2   B&B B&B"AB&6B$7*B&"B&$B&c                    #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  5       I Sh  vN nU R                  US/ 5      nU R	                  U5      $  NX NB N,7f)a6  
query for balance and get the amount of funds available for trading or funds locked in orders

https://docs.api.prod.paradex.trade/#list-balances

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr>  )rY  r  privateGetBalancer@  parse_balancerB  s       r&  fetch_balanceparadex.fetch_balance  sl      $$&&&!!!//11 ~~h	26!!$'' 	'!1s1   A5A/A5A1A5A3)A51A53A5c                     SU0n[        S[        U5      5       Ha  nU R                  X0 5      nU R                  US5      nU R	                  U5      nU R                  5       nU R                  US5      US'   XrU'   Mc     U R                  U5      $ )Nr8  r   rX  r  total)r  r  r  r:  rs  r   safe_balance)r$  r.  resultr  r   r  r  r   s           r&  r  paradex.parse_balance  s    )q#h-(AnnX"5G))'7;J**:6DllnG#//@GG"4L )   ((r(  c                 |  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4SSSS5	      I Sh  vN $ 0 nSnUb  U R	                  U5      nUS   US	'   Ub  X6S
'   Ub  X&S'   U R                  SXd5      u  pdU R                  U R                  Xd5      5      I Sh  vN nU R                  US/ 5      n	[        S[        U	5      5       H  n
U R                  US5      X   S'   M     U R                  XX#5      $  GN GN N Nd7f)a  
fetch all trades made by the user

https://docs.api.prod.paradex.trade/#list-fills

:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum number of trades structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
: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)
:param int [params.until]: the latest time in ms to fetch entries for
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
NFrn   r  r  r  r  r(   rF  r  r  r  r>  r   )rY  r  r  r  rF  r  privateGetFillsr  r@  r  r  r:  r  )r$  rJ  r  r  r-  r  r  rF  r.  r   r  s              r&  fetch_my_tradesparadex.fetch_my_trades  s_     $$&&&!!!88R\]99/6Z_ioqy{  BE  F  F  F[[(F &tGH#(K "'J228WM--dkk'.JKK0 )R8q#f+&A $ 0 06 BFIf '  >>W 	'! F Lr  c                    #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  U5      nU R                  US   /U5      I Sh  vN nU R	                  US0 5      $  N^ NH N7f)aN  
fetch data on an open position

https://docs.api.prod.paradex.trade/#list-open-positions

:param str symbol: unified market symbol of the market the position is held in
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
NrJ  r   )rY  r  rF  fetch_positionsr  )r$  rJ  r-  rF  r   s        r&  fetch_positionparadex.fetch_position  st      $$&&&!!!V$..x0@/A6JJ	~~iB//	 	'!Js1   A;A5A;A7.A;A9A;7A;9A;c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  U5      nU R                  5       I Sh  vN nU R	                  US/ 5      nU R                  XA5      $  Ni NS N,7f)a:  
fetch all open positions

https://docs.api.prod.paradex.trade/#list-open-positions

: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>  )rY  r  r  privateGetPositionsr@  parse_positions)r$  r  r-  r.  rC  s        r&  r  paradex.fetch_positions#  s|      $$&&&!!!%%g.11334 ~~h	26##D22= 	'!3s1   BB BB(BB)BBBpositionc           
      N   U R                  US5      nU R                  X25      nUS   nU R                  US5      nU R                  US5      nUS:w  a  [        R                  " SU5      nU R                  US5      nU R                  0 SU_S	U R                  US	5      _SU_S
U R                  US5      _SS _SS _SU R                  US5      _SU R                  US5      _SU_SU R                  U5      _SS _SU_SU R                  U5      _SS _SS _SS _SS _S S S S S S S.E5      $ )NrF  rJ  r  r  longz-1timer8  r(   
entryPriceaverage_entry_pricer  notional
collateralrj  unrealizedPnlunrealized_pnl	contractsrk  r  r  r  maintenanceMarginmaintenanceMarginPercentageinitialMargin)initialMarginPercentager  liquidationPricemarginRatior  r  )	r:  r  rw  r"   r  r,  safe_positionr#  rv  )r$  r  rF  r|  rJ  r  quantityr  s           r&  parse_positionparadex.parse_positionM  s   , ##Hh7!!(3!%%h7##Hf56>))$9H%%h7	!! #
H#
$""8T2#
 f#
 $**85JK	#

 #
 #
 $**8V<#
 T--h8HI#
 D#
 **84#
 D#
 #
 Y/#
 d#
  #
  *4!#
" T##
$ (, $/#
  	r(  c                 D  #    U R                  5       I Sh  vN   0 nUb  X%S'   OSUS'   U R                  U5      nU R                  SXT5      u  pTU R                  U R	                  XT5      5      I Sh  vN nU R                  US/ 5      nU R                  XX#5      $  N N+7f)a*  
retrieves the public liquidations of a trading pair

https://docs.api.prod.paradex.trade/#list-liquidations

:param str symbol: unified CCXT market symbol
:param int [since]: the earliest time in ms to fetch liquidations for
:param int [limit]: the maximum number of liquidation structures to retrieve
:param dict [params]: exchange specific parameters for the huobi api endpoint
:param int [params.until]: timestamp in ms of the latest liquidation
:returns dict: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
Nfromr   tor>  )rY  rF  r  privateGetLiquidationsr  r@  parse_liquidations)	r$  rJ  r  r  r-  r  rF  r.  rC  s	            r&  fetch_liquidationsparadex.fetch_liquidations  s      $$&&&#FOGFOV$224I44T[[5QRR ~~h	26&&tUBB) 	' Ss"   B BAB 2B3*B B c                 |    U R                  US5      nU R                  US S S S S S S UU R                  U5      S.
5      $ )Nr  )
r8  rJ  r  rk  re  r  	baseValue
quoteValuer  r  )r,  safe_liquidationrv  )r$  liquidationrF  r  s       r&  parse_liquidationparadex.parse_liquidation  sU     %%k<@	$$ "Y/&
  	r(  r  c                 V  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4SSSS5	      I Sh  vN $ 0 nUb  X6S'   Ub  X&S	'   U R	                  S
Xd5      u  pdU R                  U R                  Xd5      5      I Sh  vN nU R                  US/ 5      n/ n	[        S[        U5      5       H#  n
X   nUS   S:X  d  M  U	R                  U5        M%     U R                  U	SX#5      $  GN
 N N No7f)a  
fetch all deposits made to an account

https://docs.api.prod.paradex.trade/#paradex-rest-api-transfers

:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch deposits for
:param int [limit]: the maximum number of deposits 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 entries for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
NFrZ   r  r  r  r  r  r  r  r>  r   kindDEPOSITrY  r  r  r  r  privateGetTransfersr  r@  r  r  appendparse_transactionsr$  r  r  r  r-  r  r  r.  rowsdepositsr  rows               r&  fetch_depositsparadex.fetch_deposits  sG     $$&&&!!!88R\]99/4X]gmowy}  @C  D  D  D#(K "'J228WM11$++g2NOO, ~~h	26q#d)$A'C6{i'$ % &&xuDDQ 	'! D PJ   D)D D)D#<D)+D%,AD)7D'8<D)8)D)#D)%D)'D)c                 V  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4SSSS5	      I Sh  vN $ 0 nUb  X6S'   Ub  X&S	'   U R	                  S
Xd5      u  pdU R                  U R                  Xd5      5      I Sh  vN nU R                  US/ 5      n/ n	[        S[        U5      5       H#  n
X   nUS   S:X  d  M  U	R                  U5        M%     U R                  U	SX#5      $  GN
 N N No7f)a  
fetch all withdrawals made from an account

https://docs.api.prod.paradex.trade/#paradex-rest-api-transfers

:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch withdrawals for
:param int [limit]: the maximum number of withdrawals 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 withdrawals for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
NFr   r  r  r  r  r  r  r  r>  r   r  
WITHDRAWALr  r  s               r&  fetch_withdrawalsparadex.fetch_withdrawals  sM     $$&&&!!!88ASU_`99:Ld[`jprz  }A  CF  G  G  G#(K "'J228WM11$++g2NOO, ~~h	26q#d)$A'C6{l*$ % &&xuDDQ 	'! G Pr  transactionr  c                 .   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                  Xb5      nU R                  US5      nU R                  US5      n	U R                  US5      n
U
S:X  a  S	OS
n
U R                  U R                  US5      5      nU R	                  US5      n0 SU_SU_SU_SU_SU R                  U5      _SS _SU_SU_SS _SS _SS _SS _SU
_SU_SU_SU_SU	_S S S S.E$ )Nr(   r   txn_hashrX  r  r  r  r  deposit
withdrawalr2  rd  r8  txidr  r  networkrA  	addressToaddressFromtagtagTotagFromr]  r  r5  )internalcommentr  )r:  rs  r,  parse_transaction_statusrx  rv  )r$  r"  r  r(   rA  r'  r  r  r  r5  r]  r2  rd  s                r&  parse_transactionparadex.parse_transaction-  s   $ k40"";	:Z8%%k7;
&&z<%%k<@	##K1BCV4!Y.y\..t/?/?X/VW!!+x8
K
"
 D
 	

 Y/
 t
 w
 
 4
 4
 T
 t
 D
 f
 
  f!
" w#
$ )
 	
r(  c                 4    SSSSS.nU R                  X!U5      $ )Npendingr3  failed)PENDING	AVAILABLE	COMPLETEDFAILEDr|  r  s      r&  r0   paradex.parse_transaction_statusa  s*     "	
 &99r(  c                 ^  #    U R                  5       I Sh  vN   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 R                  US5      U5      $  N Nz N<7f)ai  
fetches the margin mode of a specific symbol

https://docs.api.testnet.paradex.trade/#get-account-margin-configuration

: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: a `margin mode structure <https://docs.ccxt.com/#/?id=margin-mode-structure>`
NrF  r(   configsr   )rY  r  rF  privateGetAccountMarginr  r@  parse_margin_moder  r$  rJ  r-  rF  r  r.  r<  s          r&  fetch_margin_modeparadex.fetch_margin_modej  s      $$&&&!!!V$fTl
 55dkk'6RSS ..95%%dnnWa&@&II) 	'!
 T1   B-B'B-B)?B-.B+/9B-)B-+B-rawMarginModec                 ~    U R                  US5      nU R                  X25      nU R                  US5      nUUS   US.$ )NrF  margin_typerJ  )r8  rJ  r  )r:  r  rw  )r$  rC  rF  r|  r  s        r&  r>  paradex.parse_margin_mode  sN    ##M8<!!(3++M=I
!X&$
 	
r(  r  c                 n  #    U R                  SUS5        U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  U5      nSnU R	                  USSS5      u  pSUS   UU R                  U5      S.nU R                  U R                  Xc5      5      I Sh  vN $  N No N7f)ao  
set margin mode to 'cross' or 'isolated'

https://docs.api.testnet.paradex.trade/#set-margin-configuration

:param str marginMode: 'cross' or 'isolated'
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:param float [params.leverage]: the rate of leverage
:returns dict: response from the exchange
r   rJ  Nr  r   r(   rF  r  rE  )check_required_argumentrY  r  rF  r  encode_margin_modeprivatePostAccountMarginMarketr  )r$  r  rJ  r-  rF  r  r  s          r&  set_margin_modeparadex.set_margin_mode  s      	$$_fhG$$&&&!!!V,88R\^_`Tl 22:>

 88W9UVVV 	'! Ws4   'B5B/B5B1A(B5*B3+B51B53B5c                 ^  #    U R                  5       I Sh  vN   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 R                  US5      U5      $  N Nz N<7f)a=  
fetch the set leverage for a market

https://docs.api.testnet.paradex.trade/#get-account-margin-configuration

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
NrF  r(   r<  r   )rY  r  rF  r=  r  r@  parse_leverager  r?  s          r&  fetch_leverageparadex.fetch_leverage  s      $$&&&!!!V$fTl
 55dkk'6RSS ..95""4>>'1#=vFF) 	'!
 TrB  r  c                     U R                  US5      nU R                  X25      nU R                  US5      nUU R                  X25      UU R	                  US5      U R	                  US5      S.$ )NrF  rE  r  )r8  rJ  r  longLeverageshortLeverage)r:  r  rw  safe_symbolr,  )r$  r  rF  r|  r  s        r&  rO  paradex.parse_leverage  st    ##Hh7!!(3++HmD
&&x8$ --h
C!..xD
 	
r(  c                 0    SSS.nU R                  X!U5      $ )NCROSSISOLATED)crossisolatedr|  )r$  modemodess      r&  rJ  paradex.encode_margin_mode  s$    "
 T22r(  c                 l  #    U R                  SUS5        U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  U5      nSnU R	                  SUS5      u  pSUS   UU R                  U5      S.nU R                  U R                  Xc5      5      I Sh  vN $  N Nn N7f)a  
set the level of leverage for a market

https://docs.api.testnet.paradex.trade/#set-margin-configuration

:param float leverage: the rate of leverage
:param str [symbol]: unified market symbol(is mandatory for swap markets)
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: 'cross' or 'isolated'
:returns dict: response from the exchange
r   rJ  NrZ  r(   rH  )rI  rY  r  rF  handle_margin_mode_and_paramsrJ  rK  r  )r$  r  rJ  r-  rF  r  r  s          r&  set_leverageparadex.set_leverage  s      	$$]FHE$$&&&!!!V,
!??vW^_
Tl 22:>

 88W9UVVV 	'! Ws4   'B4B.B4B0A'B4)B2*B40B42B4c                 0  #    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  
fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract

https://docs.api.testnet.paradex.trade/#list-available-markets-summary

:param str symbol: unified symbol of the market to fetch greeks for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `greeks structure <https://docs.ccxt.com/#/?id=greeks-structure>`
NrF  r(   r>  r   )r  rF  r  r  r@  r  parse_greeks)r$  rJ  r-  rF  r  r.  rC  greekss           r&  fetch_greeksparadex.fetch_greeks  s      !!!V$fTl
 55dkk'6RSSF ~~h	26a,  00U 	"
 Tr  c                   #    U R                  5       I Sh  vN   U R                  USSSS5      nSS0nU R                  U R                  X25      5      I Sh  vN nU R	                  US/ 5      nU R                  XQ5      $  Ni N*7f)a  
fetches all option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract

https://docs.api.testnet.paradex.trade/#list-available-markets-summary

:param str[] [symbols]: unified symbols of the markets to fetch greeks for, all markets are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `greeks structure <https://docs.ccxt.com/#/?id=greeks-structure>`
NTrF  r  r>  )r  r  r  r  r@  parse_all_greeks)r$  r  r-  r  r.  r>  s         r&  fetch_all_greeksparadex.fetch_all_greeks/	  s      !!!%%gtT4Fe
 55dkk'6RSSF ..9b9$$W66S 	"
 Ts"   BB A BB)BBre  c                    U R                  US5      nU R                  X2S S5      nUS   nU R                  US5      nU R                  US0 5      n0 SU_SU_SU R	                  U5      _SU R                  US5      _SU R                  US5      _S	S _S
U R                  US
5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SS _SS _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _U R                  US5      U R                  US5      U R                  US5      US.E$ )NrJ  r9   r  re  r  r  deltagammathetavegarhovannavolgabidSizeaskSizebidImpliedVolatilitybid_ivaskImpliedVolatilityask_ivmarkImpliedVolatilitymark_ivbidPricer  askPricer  r  r  underlying_price)r  	lastPriceunderlyingPricer8  )r:  r  r,  r  rv  rx  )r$  re  rF  r|  rJ  r  
greeksDatas          r&  rd  paradex.parse_greeksd	  s   > ##FH5!!(D(C!%%fl;	^^FHb9

f

 Y/
 T%%j':	

 T%%j':
 T
 D$$Z8
 4##J6
 T%%j':
 T%%j':
 t
 t
 #D$4$4VX$F
 #D$4$4VX$F
 $T%5%5fi%H
  ((7!
" ((7#
$ ))&,?))&2EF#//8JK+
 	
r(  r   GETc                 (   U R                  U R                  S   U R                     5      S-   U R                  X5      -   nU R	                  X@R                  U5      5      nUS:X  a   U(       a  USU R                  U5      -   -  nGOUS:X  Ga  SU R                  U R                  SS5      S	.nUS
:X  a3  US   US'   US   US'   [        US   5      US'   [        US   5      US'   OUS:X  aW  U R                  US'   US   US'   US   US'   [        U R                  5       5      US'   SUS'   U R                  SUS   05      nOKU R                  S   n	SU	-   US'   US:X  a  SUS'   U R                  U5      nOUS-   U R                  U5      -   nXsXeS.$ )Nr   rN  r   ?r   zapplication/jsonr   r   )AcceptzPARADEX-PARTNERr   r   zPARADEX-STARKNET-ACCOUNTr  zPARADEX-STARKNET-SIGNATUREr  zPARADEX-TIMESTAMPrR  zPARADEX-SIGNATURE-EXPIRATIONr   zPARADEX-ETHEREUM-ACCOUNTzContent-TyperC  rJ  zBearer AuthorizationrM  )r7  rO  rQ  headers)implode_hostnamer   r,   implode_paramsr  extract_params	urlencoder:  r  r  r   r  json)
r$  rP  r   rO  r-  r  rQ  r7  queryrX  s
             r&  signparadex.sign	  s   ##DIIe$4T\\$BCcIDL_L_`dLmm		&"5"5d";<(?sT^^E222I,#'#3#3DLL(F#SG
 v~6;I6F238=k8J45/253E/F+,:=eL>Q:R67%6:6H6H236;I6F238=k8J45/24::</@+,*<'yy %"5"  [1+4u+<(V#.@GN+99U+D)dnnU&;;C dOOr(  httpCodereasonr7  rO  r  rQ  c
                     U(       d  g U R                  US5      n
U
b[  U R                  S-   U-   nU R                  U R                  S   Xk5        U R	                  U R                  S   X5        [        U5      eg )Nerror r   r   )r:  r(   throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr   )r$  r  r  r7  rO  r  rQ  r.  requestHeadersrequestBody	errorCodefeedbacks               r&  handle_errorsparadex.handle_errors	  st     $$Xw7	 ww}t+H001I4Z001I9_))r(   )N)F)[__name__
__module____qualname____firstlineno__r   r"  r	   r/  r;  r   r   rD  dictr  r  listr  r  r   r   r  r   r  r  r   r  r   r  r  r  r  r  r  r  r$  r-  r<  r   rY  r   rw  r   rs  rq  rr  r  r  r   r   floatr   r  r  r  r  r  r  r   r  r  r  r  r   r  r   r  r  r   r  r   r   r1  r0  r   r@  r>  rL  r
   rP  rO  rJ  intra  r   rf  rj  rd  r  r  __static_attributes____classcell__)r%  s   @r&  r$   r$      s   g# gR ') :S :" )+ 
0 *, ,(V ,(\V4 VF Vp ?CQUdhqs 4H 4H 4H3 4H^a 4Hx|  ~B  yC 4Hl
 
4 
( 6:" &17 &1 &1P 68 '1 '1F '1R04 0 06 0d @DB 'S ' 'S\ 'R <@d[] 1? 1?S 1? 1?bfglbm 1?f> >v > >@ =? ): ):VF >:>L"H 2 ') & .0 *XR Rv R RhAs A	 	9S 9_ _4 4 mqy{ S SI SY SX] Sfi Sj 9=R *S *# *: 59 5c 50 8<B 3*C 3* 3*j 04$UYbd I? I?C I?s I?imnsit I?V 59tZ^gi 5?c 5? 5?TW 5?nrsxny 5?n *, ( (4	) 	) 37TX\eg 9?C 9?s 9?RU 9?v 8: 03 0  8<B (3W (34PX> (3T6t 6V 6p BFTXac !Cs !C3 !Cc !CFV * 04$UYbd 6E 6EC 6Es 6Eimnyiz 6Ep 37TX\eg 6EC 6Es 6ERU 6Elpq|l} 6Ep2
T 2
X 2
Q\ 2
h:s : ;= Jc J J@
t 
Z 
 DHPR W WS W2 8: G3 Gh G@

t 

V 

x 

3 ?C2 W3 W W2 68 41 41F 41l 9=R 37g 37DQWL 37j:
4 :
 :
6 :
x &eBSW .P`c 3 S # X\ dg  r(  r$   N)( ccxt.async_support.base.exchanger   ccxt.abstract.paradexr   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   r    ccxt.base.decimal_to_precisionr!   ccxt.base.preciser"   r$   r  r(  r&  <module>r     s_    6 - I  I  I  I  I  I  * 0 - . ' . ) 4 %K'h K'r(  