
    E#iH                       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    F/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/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                 H    U R                  U5      nU R                  US5      $ )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
server_time)publicGetSystemTimesafe_integer)r$  paramsresponses      r&  
fetch_timeparadex.fetch_time  s)     ++F3   =99r(  c                 h    U R                  U5      nU R                  US5      nUS:X  a  SOSSSSUS.$ )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>`
statusokmaintenanceN)r2  updatedetaurlinfo)publicGetSystemStatesafe_string)r$  r-  r.  r2  s       r&  fetch_statusparadex.fetch_status  sI     ,,V4 !!(H5%~dM
 	
r(  c                 j    U R                  U5      nU R                  US5      nU R                  U5      $ )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
results)publicGetMarkets	safe_listparse_marketsr$  r-  r.  datas       r&  fetch_marketsparadex.fetch_markets  s8     ((0D ~~h	2!!$''r(  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         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      nU R                  US
/ 5      nU R                  XX#U5      $ )a  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://docs.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
r(   )
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  sY    	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
#..t{{7/KL ~~h	26  yGGr(  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         U R                  U5      nSS0nU R                  U R                  X25      5      nU R	                  US/ 5      nU R                  XQ5      $ )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>`
rF  ALLr>  )r  market_symbolspublicGetMarketsSummaryr  r@  parse_tickers)r$  r  r-  r  r.  rC  s         r&  fetch_tickersparadex.fetch_tickers  sl     	%%g.e
 //G0LM, ~~h	26!!$00r(  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US/ 5      nU R                  US0 5      nU R                  Xs5      $ )a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://docs.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>`
rF  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
 //G0LM, ~~h	26a,  00r(  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                    U R                  5         U R                  U5      nSUS   0nU R                  U R                  XS5      5      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$ )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
rF  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00W1MN( $G%%h0AB	))(84DiP	!..xB	'r(  c                    U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX4SSSS5	      $ 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      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      $ )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>`
Fr   paginatenextcursorNr  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[33M6RWagiqswy|}}V$fTl
 #(K "'J228WM''G(DE$ )R8q#f+&A $ 0 06 BFIf '  >>r(  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                 D   U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      nU R                  US/ 5      nU R                  US0 5      nU R                  Xs5      $ )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:
r`  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
 //G0LM, ~~h	26>>$2.''99r(  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       nX R                  S'   U$ )NsystemConfig)r  r  publicGetSystemConfig)r$  cachedConfigr.  s      r&  get_system_configparadex.get_system_config/  sC    !^^DLL.I#--/: (0^$r(  c                 X    U R                  5       nUSL a  SUS   SS.nU$ SUS   SS.nU$ )NTr*   l1_chain_idra  )r)   chainIdr,   starknet_chain_idr   )r#  )r$  l1r   l1Ddomains        r&  prepare_paradex_domainparadex.prepare_paradex_domainS  sP    --/:!'6C
 J#$78

 r(  c                 j   U R                  U R                  S5      nUb  U$ U R                  5         U R                  5       nU R	                  S5      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$ )
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$  '')--/,,T2!84
 k
 --fGL%%c??;	--1278

 *1%&r(  c                     U R                  5       nSS0nU R                  5       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      nU$ )Nr0  
Onboardingr/  feltr2  addressr   r  r   	publicKey
public_key)r;  r,  starknet_encode_structured_datastarknet_signprivatePostOnboarding)	r$  r-  r   reqr+  r9  r:  r  r.  s	            r&  r   paradex.onboarding|  s    '')l
 ,,.!62

 226V_N`a&&sL,AB	'{#I.y&{3|--f5r(  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       nUS-   nSSSUUS.nU R                  5       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      nU R                  US5      nXR                  S'   X`R                  S'   U$ )N	authTokenexpires   POSTz/v1/auth )methodpathbodyr  
expirationRequestrN  r?  r2  rO  rP  r  rQ  r@  r   r  r   	jwt_token)	r:  r  r  r,  r;  r,  rC  rD  privatePostAuth)r$  r-  cachedTokenr  cachedExpiresr   rJ  rF  r+  r9  r:  r  r.  tokens                 r&  authenticate_restparadex.authenticate_rest  sd   &&t||[Ajjl" --dllIFM"""''))!
 ,,.!6200$f5%v6
 226V_N`a&&sL,AB	'{#I.y!+.{"<0|''/   ;7$)[!")Yr(  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  orderIdre  r|  rJ  re  rd  	orderTypecancelReasonr2  r  r  rm  rg  rc  rj  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   ry  	POST_ONLYr:  )r$  r  timeInForcess      r&  rr  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&  rp  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&  rq  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           	         U R                  5         U R                  5         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       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       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      nU R-                  UU5      n U $ )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>`
rj  reduce_onlyr(   )rF  r  r]  r  	stopPricer  r	  r  Nr  rz  rh  iocr   re  clOrdIDre  client_order_idr[  r  TSTOP_LOSS_MARKETr]  TAKE_PROFIT_MARKETr  STOP_LOSS_LIMITTAKE_PROFIT_LIMITr  rk  r  rd  rc  )rj  r  r  re  r  ri  r  r  r  r  r	  r  rF  BUYra  2)r  rF  r  rt  r  re  r   r  r?  r2  r  rt  r@  r   r  signature_timestamp)rX  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,  rC  rD  privatePostOrdersr  rv  )!r$  rJ  r]  r  rd  re  r-  rF  rj  rt  	orderSider  r  r  r	  isMarketisTakeProfitOrderisStopLossOrderisStopOrderr  ri  re  
sizeStringr  r   r  orderReqr+  r9  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
 ,,.$f5!620$f50 &1	
 226<SZ[dSef&&sGL,AB	()1+)>%&))$++g*FG:   62r(  r(   c                 ,   U R                  5         U R                  5         0 nU R                  U/ SQ5      nSnUb%  XTS'   U R                  U R	                  XC5      5      nO$XS'   U R                  U R	                  XC5      5      nU R                  U5      $ )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>`
r  Nr[  r  )rX  r  r  %privateDeleteOrdersByClientIdClientIdr  privateDeleteOrdersOrderIdrv  r$  r(   rJ  r-  r  re  r.  s          r&  cancel_orderparadex.cancel_order  s     	 **63bc$#0K AA$++gB^_H"$J66t{{77STH ))r(  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  5         U R	                  U5      nSUS   0nU R                  U R                  XB5      5      nU R                  SU05      /$ )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>`
z- cancelAllOrders() requires a symbol argumentrF  r(   r8  )r   r(   rX  r  rF  privateDeleteOrdersr  ro  )r$  rJ  r-  rF  r  r.  s         r&  cancel_all_ordersparadex.cancel_all_orders  s     >#DGG.]$]^^ V$fTl
 ++DKK,HI  2344r(  c                 T   U R                  5         U R                  5         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      nO$XS'   U R                  U R                  XC5      5      nU R                  U5      $ )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>`
r  Nr[  r  )rX  r  r  r  "privateGetOrdersByClientIdClientIdr  privateGetOrdersOrderIdrv  r  s          r&  fetch_orderparadex.fetch_order  s     	 **63bc6#RS$#0K >>t{{7?[\H"$J33DKK4PQH6 ))r(  c                     U R                  5         U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX4SSSS5	      $ 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      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      $ )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>`
Fru   r  r  r  Nr/   r(   rF  r  r  r  r>  r   )rX  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  s;    	 88PZ[33M6RWagiqswy{||[[(F &tGH"'J#(K 228WM//G0LMF )R8++Hf=6{(|a/?1IE,&M1I  >>r(  c                    U R                  5         U R                  5         0 nSnUb  U R                  U5      nUS   US'   U R                  U R	                  XT5      5      nU R                  US/ 5      nU R                  XX#5      $ )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>  )rX  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((W)EFB )R8  >>r(  c                     U R                  5         U R                  5         U R                  5       nU R                  US/ 5      nU R	                  U5      $ )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>`
r>  )rX  r  privateGetBalancer@  parse_balancerB  s       r&  fetch_balanceparadex.fetch_balance  sO     	 ))+ ~~h	26!!$''r(  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   rW  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         U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX4SSSS5	      $ 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      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      $ )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>`
Frn   r  r  r  Nr  r(   rF  r  r  r  r>  r   )rX  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\]33OVTYciksuy{~[[(F &tGH#(K "'J228WM''G(DE0 )R8q#f+&A $ 0 06 BFIf '  >>r(  c                     U R                  5         U R                  5         U R                  U5      nU R                  US   /U5      nU R	                  US0 5      $ )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>`
rJ  r   )rX  r  rF  fetch_positionsr  )r$  rJ  r-  rF  r   s        r&  fetch_positionparadex.fetch_position  sW     	 V$((&*:);VD	~~iB//r(  c                     U R                  5         U R                  5         U R                  U5      nU R                  5       nU R	                  US/ 5      nU R                  XA5      $ )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>`
r>  )rX  r  r  privateGetPositionsr@  parse_positions)r$  r  r-  r.  rC  s        r&  r  paradex.fetch_positions#  s_     	 %%g.++-4 ~~h	26##D22r(  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                    U R                  5         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      nU R                  US/ 5      nU R                  XX#5      $ )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>`
fromr   tor>  )rX  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..t{{7/KL ~~h	26&&tUBBr(  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                    U R                  5         U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX4SSSS5	      $ 0 nUb  X6S'   Ub  X&S	'   U R	                  S
Xd5      u  pdU R                  U R                  Xd5      5      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      $ )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>`
FrZ   r  r  r  Nr  r  r  r  r>  r   kindDEPOSITrX  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  s    	 88R\]33OTRWagiqswy|}}#(K "'J228WM++DKK,HI, ~~h	26q#d)$A'C6{i'$ % &&xuDDr(  c                    U R                  5         U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX4SSSS5	      $ 0 nUb  X6S'   Ub  X&S	'   U R	                  S
Xd5      u  pdU R                  U R                  Xd5      5      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      $ )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>`
Fr   r  r  r  Nr  r  r  r  r>  r   r  
WITHDRAWALr  r  s               r&  fetch_withdrawalsparadex.fetch_withdrawals  s    	 88ASU_`334FUZdjltvz|  A  A#(K "'J228WM++DKK,HI, ~~h	26q#d)$A'C6{l*$ % &&xuDDr(  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_hashrW  r  r  r  r  deposit
withdrawalr2  rd  r8  txidr  r  networkr@  	addressToaddressFromtagtagTotagFromr]  r  r5  )internalcommentr  )r:  rs  r,  parse_transaction_statusrx  rv  )r$  r  r  r(   r@  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&  r-   paradex.parse_transaction_statusa  s*     "	
 &99r(  c                    U R                  5         U R                  5         U R                  U5      nSUS   0nU R                  U R	                  XB5      5      nU R                  US5      nU R                  U R                  US5      U5      $ )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>`
rF  r(   configsr   )rX  r  rF  privateGetAccountMarginr  r@  parse_margin_moder  r$  rJ  r-  rF  r  r.  r9  s          r&  fetch_margin_modeparadex.fetch_margin_modej  s     	 V$fTl
 //G0LM ..95%%dnnWa&@&IIr(  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$  r?  rF  r|  r  s        r&  r;  paradex.parse_margin_mode  sN    ##M8<!!(3++M=I
!X&$
 	
r(  r  c                 *   U R                  SUS5        U R                  5         U R                  5         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      $ )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  rA  )check_required_argumentrX  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:>

 224;;w3OPPr(  c                    U R                  5         U R                  5         U R                  U5      nSUS   0nU R                  U R	                  XB5      5      nU R                  US5      nU R                  U R                  US5      U5      $ )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>`
rF  r(   r9  r   )rX  r  rF  r:  r  r@  parse_leverager  r<  s          r&  fetch_leverageparadex.fetch_leverage  s     	 V$fTl
 //G0LM ..95""4>>'1#=vFFr(  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  rA  r  )r8  rJ  r  longLeverageshortLeverage)r:  r  rw  safe_symbolr,  )r$  r  rF  r|  r  s        r&  rK  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&  rF  paradex.encode_margin_mode  s$    "
 T22r(  c                 (   U R                  SUS5        U R                  5         U R                  5         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      $ )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  NrV  r(   rD  )rE  rX  r  rF  handle_margin_mode_and_paramsrF  rG  r  )r$  r  rJ  r-  rF  r  r  s          r&  set_leverageparadex.set_leverage  s     	$$]FHE V,
!??vW^_
Tl 22:>

 224;;w3OPPr(  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US/ 5      nU R                  US0 5      nU R                  Xs5      $ )a  
fetches 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>`
rF  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
 //G0LMF ~~h	26a,  00r(  c                     U R                  5         U R                  USSSS5      nSS0nU R                  U R                  X25      5      nU R	                  US/ 5      nU R                  XQ5      $ )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/	  su     	%%gtT4Fe
 //G0LMF ..9b9$$W66r(  ra  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  ra  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$  ra  rF  r|  rJ  r  
greeksDatas          r&  r`  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-TIMESTAMPrQ  zPARADEX-SIGNATURE-EXPIRATIONr   zPARADEX-ETHEREUM-ACCOUNTzContent-TyperB  rI  zBearer AuthorizationrL  )r7  rN  rP  headers)implode_hostnamer   r,   implode_paramsr  extract_params	urlencoder:  r  r  r   r  json)
r$  rO  r   rN  r-  r  rP  r7  queryrW  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  rN  r  rP  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  rN  r  rP  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   rX  r   rv  r   rr  rp  rq  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   r.  r-  r   r=  r;  rH  r
   rL  rK  rF  intr]  r   rb  rf  r`  r  r  __static_attributes____classcell__)r%  s   @r&  r$   r$      s   g# gR !# :s :" #% 
0 $& ,($v, ,(\V4 VF Vp 9=4^bkm 4H# 4H# 4HS 4HX[ 4Hrvw{r| 4Hl
 
4 
( 04B &1W &17 &1P 02 '13 '1f '1R04 0 06 0d :>b 's '3 'Y 'R 6:UW 1?3 1?s 1?# 1?\`af\g 1?f> >v > >@ 79 ):# ):VF >:>L"H 2 !# & (* *XR Rv R RhAs A	 	9S 9_ _4 4 gksu S3 Si Sy SRW S`c Sj 37r *s *C *: /32 5 50 26b 3*c 3*3 3*j *.Dt\^ I?3 I?c I? I?cghmcn I?V /3TXac 5? 5?3 5?c 5?hlmrhs 5?n $& (( (4	) 	) -1tRV_a 9?c 9? 9?C 9?v 24 0S 0  26b (3w (3T(^ (3T6t 6V 6p <@d[] !C !CS !C !CFV * *.Dt\^ 6E3 6Ec 6E 6Ecghsct 6Ep -1tRV_a 6Ec 6E 6EC 6Efjkvfw 6Ep2
T 2
X 2
Q\ 2
h:s : 57 J J: J@
t 
Z 
 >B" Q# Qs Q2 24 GS G G@

t 

V 

x 

3 9=R QS Q# Q2 02 413 41f 41l 37r 37 37d6l 37j:
4 :
 :
6 :
x &eBSW .P`c 3 S # X\ dg  r(  r$   N)(ccxt.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_    ( - I  I  I  I  I  I  * 0 - . ' . ) 4 %K'h K'r(  