
    ei0                       d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lm Z  d d
lm!Z! d dlm"Z" d dl#m$Z$ d dl%m&Z&  G d dee          Z'dS )    )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                       e Zd Zdef fdZi fdefdZi fdZi fdee	         fdZ
dede	fdZdd	d	i fd
ededededee         f
dZdade	defdZd	i fdedefdZi fd
edefdZdadede	defdZd	i fd
ededefdZd	d	i fd
edededee         fdZdadede	defdZi fd
efdZdade	fdZd Zd Zd Z d Z!dbd Z"d! Z#i fd"Z$i fd#Z%dad$ede	de&fd%Z'd&e(fd'Z)d(e(fd)Z*d*e(fd+Z+d,efd-Z,d	i fd
ed*e-d.e.d/e/d0e0f
d1Z1d	i fd2ed
e(fd3Z2d	i fd
e(fd4Z3d	i fd2ed
e(fd5Z4d	d	d	i fd
e(dededee&         fd6Z5d	d	d	i fd
e(dededee&         fd7Z6i fde7fd8Z8de7fd9Z9d	d	d	i fd
e(dedefd:Z:i fd
efd;Z;d	i fdedee<         fd<Z=dad=ede	fd>Z>d	d	i fd
ededefd?Z?dade	fd@Z@d	d	d	i fdAe(dededeeA         fdBZBd	d	d	i fdAe(dededeeA         fdCZCdadDedEeDdeAfdFZEd(e(fdGZFi fd
edeGfdHZHdadIedeGfdJZId	i fdKed
e(fdLZJi fd
edeKfdMZLdadNede	deKfdOZMdP ZNd	i fdNeOd
e(fdQZPi fd
edeQfdRZRd	i fdedeeQ         fdSZSdadTede	deQfdUZTd	d	d	i fd
e(dedefdVZUdWdXi d	d	fdYZVdZeOd[ed\ed]ed^ed_efd`ZW xZXS )cparadexreturnc                 8	   |                      t          t          |                                           i dddddg dddd	d
ddddddi dd ddddddddddddddddddddddddddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEddFddGddHddIddJddKddLddMddNddOddPddQddRddSdi dTddUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcddddddddddddedfdgdhdidjdkdldmdndodpdqddriddsidtdudvdwdxdydzi d{dgd|dgd}dgd~dgddgddgddgddgddgddgddgddgddgddgddgddgddgdgdgdii ddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgdgdgdgdgdgdgdgdgddgdgdgdgdgdgdgdgdgdgd
ddgidgdgdgdgdddd|                     d          |                     d          d|                     d          |                     d          dddddddddi dt
          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt
          dt          dt          dt          dt          dt          dt
          dt
          dt
          dt          dt          dt          dt          dt          dt
          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          t          t          t
          t
          t          dݜdt
          idߜdt          i d ddd ddddd ddd dddddddddddddd dddddddddddddddddddddddddd dd id	ddid dd d ddd          S )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)r6   r4   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   rF   rG   rm   rr   rq   rt   rS   rn   extendsforSwap)linearinverse)r4   r  r6   r7   )commonCurrenciesoptionsfeatures)deep_extendsuperr$   describeparse_numberr   r   r   r   r    r   r!   )self	__class__s    J/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/paradex.pyr!  zparadex.describe   s   gt 4 4 = = ? ? 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 &tU]V #EW]X *4Y]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 11J J{fB
P !..x88!..x88 
 "..x88!..x8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 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 9 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 9h ,%00-q9 9 9v /0Cw> >qfB
n YofB
p! #'  
 #&+(,,0,0).+06:#'#("&#(	( ( #($)$)+027/3#()$ $, %)&+!$$*%+*/& & ',#($)*/	# # ',!$#($)*/( ( ',!$$*%+#($)*/$ $ *.#o: :z "9  $	  ## GG G}fB
 fB
 fB
 f f f	    c                 X    |                      |          }|                     |d          S )ab  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://docs.paradex.trade/api/prod/system/get-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_timezparadex.fetch_time  s/     ++F33   =999r&  c                 x    |                      |          }|                     |d          }|dk    rdndddd|dS )aL  
        the latest known information on the availability of the exchange API

        https://docs.paradex.trade/api/prod/system/get-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)r/  updatedetaurlinfo)publicGetSystemStatesafe_string)r#  r+  r,  r/  s       r%  fetch_statuszparadex.fetch_status  sX     ,,V44 !!(H55%~~ddM
 
 	
r&  c                     |                      |          }|                     |d          }|                     |          S )a  
        retrieves data on all markets for bitget

        https://docs.paradex.trade/api/prod/markets/get-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_marketszparadex.fetch_markets  sA     ((00D ~~h	22!!$'''r&  marketc                     |                      |d          }|dk    }|rdnd}|dk    }|                      |d          }|                      |d          }|                      |d          }|                     |          }	|                     |          }
|                      |d          }|                     |          }|
d	z   |	z   d
z   |z   }|                     |d          }|                      |d          }|                      |d          }|                     d          }|                     d          }|r.|dk    rdnd}|dz   |z   dz   |z   }|                     d          }nd }|                     i d|d|d|
d|	d|d|d|d|d|dddd d|ddd|d |                     |d!          d"d#d$d#d|||                     d%          ||d&k    rd n|                     |          |                     |          |                     |d          |                     |d'          |                     |d(          d)d d d*d |                     |d+          d*d d d*|                     |d,          d d*d-d |d.          S )/N
asset_kindPERP_OPTIONr8   r6   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typer4   Fr5   r7   activeenableTradingcontractTr  1r   order_size_incrementprice_tick_size)amountprice)minmaxmax_order_sizemin_notional)r  r_  r`  cost)r  r   r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedr5  )	r7  safe_currency_coder*  r"  safe_market_structure	safe_booliso8601safe_string_lowersafe_number)r#  rA  	assetKindisOptionrX  isSwapmarketIdrV  rU  rS  rR  rW  rT  rE  rg  rj  strikePricetakerFeemakerFeeoptionTypeSuffixs                       r%  parse_marketzparadex.parse_market  s   Z $$V\::	.$1xx6&.##FH55""6+;<<!!&/::''00&&v..##F,ABB((22e#c)F2""6;77%%fm<<
&&v~>>$$X..$$Z00 	'1V';';ss#c\K/#58HHF((22HH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2'-{{ddf9M9M''4400GG**63IJJ))&2CDD    
  ++F4DEE 
   
  ++FNCC  $ c2+
 2+
 2+
 2 2 2	r&  r   NrE  	timeframesincer  c                     |                                   |                     |          }|                     | j        ||          |d         d}|                                 }|                     |          }	|                     |dd|          }
|                     |d          }|||d<   |                     |g d          }|3||d	<   |&|                     ||	|d
z   z  dz            d
z
  |d<   n3|
|d<   n-|
|d<   ||
|	|d
z   z  dz  z
  d
z   |d	<   n|
|	dz  dz  z
  d
z   |d	<   | 	                    | 
                    ||                    }|                     |dg           }|                     |||||          S )a-  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://docs.paradex.trade/api/prod/markets/klines

        :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
        :param str [params.price]: "last", "mark", "index", default is "last"
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r'   )
resolutionrE  untiltillr`  N
price_kind)r  r  r`  start_atr     end_ate   r:  )load_marketsrA  r7  r   millisecondsparse_timeframesafe_integer_2omitsumpublicGetMarketsKlinesextendr<  parse_ohlcvs)r#  rE  r}  r~  r  r+  rA  requestnowdurationr  r`  r,  r?  s                 r%  fetch_ohlcvzparadex.fetch_ohlcvo  s    	V$$**4?IyQQTl
 
 !!''	22##FGVSAA  11$)GL!6#=#=#=>>"'GJ $(HHUH	4JT4Q$R$RUV$V!!$)!! %GH &+h%!).Dt.K&Ka&O
##&+hnt.C&Ca&G
#..t{{7F/K/KLL ~~h	266  vy%GGGr&  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r      r      r   )r*  rs  )r#  ohlcvrA  s      r%  parse_ohlcvzparadex.parse_ohlcv  s     eQ''UA&&UA&&UA&&UA&&UA&&
 	
r&  symbolsc                    |                                   |                     |          }ddi}|                     |                     ||                    }|                     |dg           }|                     ||          S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://docs.paradex.trade/api/prod/markets/get-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>`
        rA  ALLr:  )r  market_symbolspublicGetMarketsSummaryr  r<  parse_tickers)r#  r  r+  r  r,  r?  s         r%  fetch_tickerszparadex.fetch_tickers  s     	%%g..e
 //GV0L0LMM, ~~h	266!!$000r&  c                 B   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     |di           }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://docs.paradex.trade/api/prod/markets/get-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>`
        rA  r'   r:  r   )r  rA  r  r  r<  	safe_dictparse_ticker)r#  rE  r+  rA  r  r,  r?  tickers           r%  fetch_tickerzparadex.fetch_ticker  s     	V$$fTl
 //GV0L0LMM, ~~h	266a,,  000r&  r  c           	         |                      |d          }|t          j        |d          }|                      |d          }|                      |d          }|                     ||          }|d         }|                     |d          }|                     i d|d|d|                     |          dd d	d d
|                      |d
          dd d|                      |d          dd dd dd d|d|dd dd d|dd d |                      |d          |                      |d          |d|          S )Nprice_change_rate_24hr   last_traded_pricerE  
created_at	timestampdatetimehighlowbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechange
percentageaverage
volume_24h
mark_price)
baseVolumequoteVolume	markPricer5  )r7  r"   
string_mulsafe_marketr*  safe_tickerrq  )r#  r  rA  r  r  rw  rE  r  s           r%  r  zparadex.parse_ticker  s   $ %%f.EFF
! +J>>J(;<<##FH55!!(F33!%%fl;;	 !
f!
!
 Y//!
 D	!

 4!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  *!!
" t#!
$ ++FLAA))&,??+!
 !
 !
, -  	r&  c                 d   |                                   |                     |          }d|d         i}|                     |                     ||                    }|||d<   |                     |d          }|                     ||d         |          }|                     |d          |d<   |S )	a5  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://docs.paradex.trade/api/prod/markets/get-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
        rA  r'   Ndepthlast_updated_atrE  seq_nononce)r  rA  publicGetOrderbookMarketr  r*  parse_order_book)	r#  rE  r  r+  rA  r  r,  r  	orderbooks	            r%  fetch_order_bookzparadex.fetch_order_book@  s     	V$$!6$<000Wf1M1MNN( $GG%%h0ABB	))(F84DiPP	!..xBB	'r&  c                 \   |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S |                     |          }d|d	         i}|||d
<   |||d<   |                     d||          \  }}|                     |                     ||                    }|                     |dg           }	t          dt          |	                    D ]!}
| 
                    |d          |	|
         d<   "|                     |	|||          S )a  
        get the list of most recent trades for a particular symbol

        https://docs.paradex.trade/api/prod/trades/trades

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :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  rA  r'   	page_sizer  r  r:  r   )r  handle_option_and_paramsfetch_paginated_call_cursorrA  handle_until_optionpublicGetTradesr  r<  rangelenr7  parse_trades)r#  rE  r~  r  r+  r  rA  r  r,  r   is              r%  fetch_tradeszparadex.fetch_tradesi  s]    	88PZ[[& 	~33M65RWY_agiqswy|}}}V$$fTl
 #(GK "'GJ228WfMM''GV(D(DEE$ )R88q#f++&& 	C 	CA $ 0 06 B BF1If  >>>r&  tradec                    |                      |d          }|                     ||          }|                      |d          }|                     |d          }|                      |d          }|                      |d          }|                     |d          }|                     |dd          }	|	dk    }
|
rdnd	}|                      |d
          }|                     |          }|                     |||                      |d          ||                     |          |d         d ||||d |                      |d          |d dd|          S )NrA  r'   r  r`  sizeside	liquidityr   r   fee_currencyorder_idrE  fee)re  currencyrate)r5  r'   orderr  r  rE  rX  takerOrMakerr  r`  r_  re  r  )r7  r  r*  rr  rn  
safe_traderq  )r#  r  rA  rw  r'   r  priceStringamountStringr  	liabilityisTakerr  
currencyIdcodes                 r%  parse_tradezparadex.parse_trade  s|   @ ##E844!!(F33eT**%%e\::	&&ug66''v66%%eV44**5+wGG	w&#*8ww%%e^<<
&&z22%%eZ88"Y//X&( "((66   
  
$ %  	r&  c                    |                                   |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                    }|                     |dg           }|                     |di           }|                     ||          S )an  
        retrieves the open interest of a contract trading pair

        https://docs.paradex.trade/api/prod/markets/get-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 onlyrA  r'   r:  r   )	r  rA  r   r'   r  r  r<  r  parse_open_interest)r#  rE  r+  rA  r  r,  r?  interests           r%  fetch_open_interestzparadex.fetch_open_interest  s     	V$$j! 	^TW'\\]]]fTl
 //GV0L0LMM, ~~h	266>>$2..''&999r&  c           	         |                      |d          }|                     |d          }|                     ||          }|d         }|                     ||                     |d          d ||                     |          |d|          S )Nr  rE  open_interest)rE  openInterestAmountopenInterestValuer  r  r5  )r*  r7  r  safe_open_interestrq  )r#  r  rA  r  rw  rE  s         r%  r  zparadex.parse_open_interest  s    $ %%h==	##Hh77!!(F33!&&"&"2"28_"M"M!%"Y//(
 (
   	r&  c                 6    d|                      |dd          z   S )N0xkeccakhex)hash)r#  messages     r%  hash_messagezparadex.hash_message&  s    dii59999r&  c                 6   |                      |dd          |dd          dd           }|d         }|d         }|                     |                     d|d                             }d|                    dd	          z   |                    dd	          z   |z   S )
N	secp256k1rs   vr  @   0)ecdsaint_to_base16r  rjust)r#  r  r   	signaturer   r  r  s          r%  	sign_hashzparadex.sign_hash)  s    JJtCDDz:cdd+;[$OO	cNcNtxxIcN;;<<aggb#&&&S)9)99A==r&  c                 d    |                      |                     |          |dd                    S )Nr  )r
  r  )r#  r  r   s      r%  sign_messagezparadex.sign_message0  s-    ~~d//88*STT:JKKKr&  c                     |                      | j        d          }||S |                                 }|| j        d<   |S )NsystemConfig)r  r  publicGetSystemConfig)r#  cachedConfigr,  s      r%  get_system_configzparadex.get_system_config3  sG    !^^DL.II#--//: (0^$r&  Fc                 j    |                                  }|du rd|d         dd}|S d|d         dd}|S )NTr)   l1_chain_idr\  )r(   chainIdr+   starknet_chain_idr   )r  )r#  l1r  l1Ddomains        r%  prepare_paradex_domainzparadex.prepare_paradex_domainW  s_    --//::!'6 C
 J#$78
 

 r&  c                    |                      | j        d          }||S |                                  |                                 }|                     d          }ddddgi}ddi}|                     |||          }|                     || j                  }|                     ||d         |d	                   }|| j        d<   |S )
Nr   TConstantactionstringr(   rX  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_accountzparadex.retrieve_accountg  s    "nnT\;KLL$  '')))--//,,T22!844
 k
 --flGLL%%c4?;;	--1278
 

 *1%&r&  c                 B   |                                  }ddi}|                                 }ddddgi}|                     ||||d                   }|                     ||d                   }||d<   |d         |d	<   |d
         |d<   |                     |          }|S )Nr  
Onboardingr  feltr  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   zparadex.onboarding  s    ''))l
 ,,..!622

 226<gV_N`aa&&sGL,ABB	'{#I.y&{3|--f55r&  c                    |                      | j        d          }|                                 }|#|                     | j        d          }||k     r|S |                                 }|dz   }ddd||d}|                                 }dd	d
ddd
ddd
ddd
ddd
dgi}	|                     ||	||d                   }
|                     |
|d                   }||d<   |d         |d<   |d         |d<   |d         |d<   |                     |          }|                      |d          }|| j        d<   || j        d<   |S )N	authTokenexpires   POSTz/v1/auth )methodpathbodyr  
expirationRequestr8  r*  r  r9  r:  r  r;  r+  r   r	  r   	jwt_token)	r7  r  r  r*  r'  r  r.  r/  privatePostAuth)r#  r+  cachedTokenr  cachedExpiresr   r4  r1  r  r%  r&  r	  r,  tokens                 r%  authenticate_restzparadex.authenticate_rest  s   &&t|[AAjjll" --dlIFFM]""""'')))!
 
 ,,..!6220000$f55%v66
 226<gV_N`aa&&sGL,ABB	'{#I.y!+.{"<0|''//   ;77$)[!")Yr&  r  c                    |                      |d          }|                     |d          }|                     |                     |d                    }|                     |d          }|                     ||          }|d         }|                     |d          }|                     |d          }	|                     |d          }
|                     |d	          }|                     |d
          }||dk    s|dk    rd}nd}|                     |d          }|                     |                     |d                    }|                     |                     |d                    }|                      |d          }|                     |dg           }d }d|v rd}|                     i d|d|d|d|                     |          dd d|d
|                     |          d|d| 	                    |
          d| 
                    |                     |d                    dd d|d|d|d|                     |d           d!d d"d ||	d |d d d d d#|d$|          S )%Nr  r'   	client_idrA  rE  r`  r  rX  cancel_reasonr/  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  )re  r  )r  r_  filled	remainingre  r   r  r5  )r*  r7  	omit_zeror  rr  r<  
safe_orderrq  parse_order_statusparse_order_typeparse_time_in_force)r#  r  rA  r  orderIdrN  rw  rE  r`  r_  	orderTypecancelReasonr/  r  r  rV  rP  rL  rS  s                      r%  parse_orderzparadex.parse_order  s&   : %%e\::	""5$//t'7'7{'K'KLL##E844!!(F33!  00!!%00$$UF33	''??!!%22#222lFd6d6d##%%eV44..!1!1%9I!J!JKKNN4#3#3E;K#L#LMM	"//7HIIugr22
E!!J  
' 
] 
  
 Y//	 

 !$ 
 "#6 
 d--f55 
 f 
 D)))44 
 433D4D4DUM4Z4Z[[ 
  
 * 
 D 
 U 
 D,,UODD 
  t! 
" T# 
$ "   9 
  
  
: ;  	r&  r
  c                 <    dddd}|                      ||d           S )Nr   GTCr  )r   ra  	POST_ONLYr7  )r#  r
  timeInForcess      r%  r[  zparadex.parse_time_in_force  s1    
 

 k4@@@r&  r/  c                 F    |ddddd}|                      |||          S |S )Nr  closed)NEWUNTRIGGEREDOPENCLOSEDrc  r#  r/  statusess      r%  rY  zparadex.parse_order_status  s?    %"	 H ##Hff===r&  rX  c                 >    ddddd}|                      |||          S )Nr  rA  )LIMITMARKET
STOP_LIMITSTOP_MARKET)rr  )r#  rX  typess      r%  rZ  zparadex.parse_order_type&  s4    !#	
 
 %%eT4888r&  numc                 ,    t          j        |d          S )N	100000000)r"   r  )r#  rs  s     r%  scale_numberzparadex.scale_number/  s    !#{333r&  r  r_  r`  c           	         |                                   |                                  |                     |          }|                     |dd          }|                                }	|                                }
|d         |
|	d}|                     |dd          }|                     |d          }|                     |d          }|	d	k    }|d
u}|d
u}|d
up|p|}|                     |d          }|                     |d
|          }|s|rd|d<   n|dk    rd|d<   || 	                    ||          |d<   | 
                    |g d          }|||d<   d}d
}|r|rr|r| 	                    ||          }d}d|d<   n|r| 	                    ||          }d}d|d<   n| 	                    ||          }|                     ||          }d|d<   n|r| 	                    ||          }d}d|d<   nh|r| 	                    ||          }d}d|d<   nH| 	                    ||          }|                     ||          }d|d<   n|                     ||          }|||d<   ||d<   |rdg|d<   |                     |g d           }|                                 }|                                 }|d!z  |                     |d"                   |
d#k    rd$nd%|                     |d                   |                     |d                   |rdn|                     |d                   d&}|                                 }d'd(d)d*d"d)d*d+d)d*d,d)d*dd)d*dd)d*gi}|                     ||||d-                   }|                     ||d.                   }||d/<   |d(         |d0<   |                     |                     ||                    }|                     ||          } | S )1a  
        create a trade order

        https://docs.paradex.trade/api/prod/orders/new

        :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>`
        rS  reduce_onlyr'   )rA  r  rX  r  	stopPricer  r  ro  Nr
  rb  rQ  iocr   r`  clOrdIDrN  client_order_idrD  r  TSTOP_LOSS_MARKETrX  TAKE_PROFIT_MARKETrq  STOP_LOSS_LIMITTAKE_PROFIT_LIMITrp  rT  r  rM  rL  )rS  rx  r|  rN  r}  rR  r
  ry  r  r  r  r  rA  BUYr\  2)r  rA  r  r]  r  r`  r   r  r*  r  r  r]  r+  r   r	  signature_timestamp)rB  r  rA  safe_bool_2uppersafe_string_2r7  safe_string_upperis_post_onlyprice_to_precisionsafe_string_namount_to_precisionr  r'  r  string_to_base16rv  r  r.  r/  privatePostOrdersr  r_  )!r#  rE  rX  r  r_  r`  r+  rA  rS  r]  	orderSider  r  r  r  isMarketisTakeProfitOrderisStopLossOrderisStopOrderr
  rR  rN  
sizeStringry  r   r  orderReqr  r%  r&  r	  r,  r  s!                                    r%  create_orderzparadex.create_order2  s   , 	   V$$%%flMJJ
JJLL	JJLL	Tl
 

 ))&.+NN((AA**63DEE(,D8(4#4/X4EX,,V]CC$$XtV<< 	/ /)4&&%%).&#66vuEEGG**63b3b3bcc$#0GK 
	 	B 3" 4 $ 7 7 N NI!%J&8GFOO& 4 $ 7 7 P PI!%J&:GFOO $ 7 7 M MI!%!9!9&&!I!IJ&3GFOO" 3 $ 7 7 N NI!%J&7GFOO& 3 $ 7 7 P PI!%J&9GFOO $ 7 7 M MI!%!9!9&&!I!IJ&2GFOO11&&AAJ '0GO$$ 	 GG 6  $L  $L  $L  M  M''))jjllt++GH,=>>%..CCS..wv??%%gfo66%OSSD,=,=gg>N,O,O
 
 ,,..$f55!62200$f5500 &11	
 226<SZ[dSeff&&sGL,ABB	()1+)>%&))$++gv*F*FGG:   622r&  r'   c                 r   |                                   |                                  i }|                     |g d          }d}|/||d<   |                     |                     ||                    }n.||d<   |                     |                     ||                    }|                     |          S )a
  
        cancels an open order

        https://docs.paradex.trade/api/prod/orders/cancel
        https://docs.paradex.trade/api/prod/orders/cancel-by-client-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{  NrD  r  )rB  r  r  %privateDeleteOrdersByClientIdClientIdr  privateDeleteOrdersOrderIdr_  r#  r'   rE  r+  r  rN  r,  s          r%  cancel_orderzparadex.cancel_order  s     	   **63b3b3bcc$#0GK AA$++gW]B^B^__HH"$GJ66t{{7F7S7STTH )))r&  c                 D   |t          | j        dz             |                                  |                                  |                     |          }d|d         i}|                     |                     ||                    }|                     d|i          gS )a~  
        cancel all open orders in a market

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

        :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 argumentrA  r'   r5  )r   r'   rB  r  rA  privateDeleteOrdersr  rX  )r#  rE  r+  rA  r  r,  s         r%  cancel_all_orderszparadex.cancel_all_orders  s     >#DG.]$]^^^   V$$fTl
 ++DKK,H,HII  23344r&  c                    |                                   |                                  i }|                     |g d          }|                     |g d          }d}|/||d<   |                     |                     ||                    }n.||d<   |                     |                     ||                    }|                     |          S )a#  
        fetches information on an order made by the user

        https://docs.paradex.trade/api/prod/orders/get
        https://docs.paradex.trade/api/prod/orders/get-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{  NrD  r  )rB  r  r  r  "privateGetOrdersByClientIdClientIdr  privateGetOrdersOrderIdr_  r  s          r%  fetch_orderzparadex.fetch_order  s     	   **63b3b3bcc6#R#R#RSS$#0GK >>t{{7TZ?[?[\\HH"$GJ33DKK4P4PQQH6 )))r&  c                    |                                   |                                  d}|                     |dd          \  }}|r|                     d||||dddd	  	        S i }d}| |                     |          }|d         |d	<   |||d
<   |||d<   |                     d||          \  }}|                     |                     ||                    }|                     |dg           }	| 	                    |d          }
t          |	          }|
|dk    r|	d         }|
|d<   ||	d<   |                     |	|||          S )a  
        fetches information on multiple orders made by the user

        https://docs.paradex.trade/api/prod/orders/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>`
        Frt   r  r  r  Nr.   r'   rA  r  r  r  r:  r   )rB  r  r  r  rA  r  privateGetOrdersHistoryr  r<  r7  r  parse_orders)r#  rE  r~  r  r+  r  r  rA  r,  r   paginationCursorordersLengthfirsts                r%  fetch_orderszparadex.fetch_orders1  s    	   88PZ[[& 	}33M65RWY_agiqswy{|||[[((F &tGH"'GJ#(GK 228WfMM//GV0L0LMMF )R88++Hf==6{{(|a/?/?1IE,E&MF1I  >>>r&  c                 N   |                                   |                                  i }d}| |                     |          }|d         |d<   |                     |                     ||                    }|                     |dg           }|                     ||||          S )a0  
        fetches information on multiple orders made by the user

        https://docs.paradex.trade/api/prod/orders/get-open-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'   rA  r:  )rB  r  rA  privateGetOrdersr  r<  r  )	r#  rE  r~  r  r+  r  rA  r,  r   s	            r%  fetch_open_orderszparadex.fetch_open_orders|  s     	   [[((F &tGH((Wf)E)EFFB )R88  >>>r&  c                     |                                   |                                  |                                 }|                     |dg           }|                     |          S )aa  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://docs.paradex.trade/api/prod/account/get-balance

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        r:  )rB  r  privateGetBalancer<  parse_balancer>  s       r%  fetch_balancezparadex.fetch_balance  sd     	   ))++ ~~h	266!!$'''r&  c                 \   d|i}t          dt          |                    D ]v}|                     ||i           }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |||<   w|                     |          S )Nr5  r   rA  r  total)r  r  r  r7  rn  r   safe_balance)r#  r,  resultr  r   r  r  r   s           r%  r  zparadex.parse_balance  s    )q#h--(( 	# 	#AnnXq"55G))'7;;J**:66DllnnG#//@@GG"F4LL  (((r&  c                    |                                   |                                  d}|                     |dd          \  }}|r|                     d||||dddd	  	        S i }d}| |                     |          }|d         |d	<   |||d
<   |||d<   |                     d||          \  }}|                     |                     ||                    }|                     |dg           }	t          dt          |	                    D ]!}
|                     |d          |	|
         d<   "|                     |	|||          S )a6  
        fetch all trades made by the user

        https://docs.paradex.trade/api/prod/account/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>`
        Frm   r  r  r  Nr  r'   rA  r  r  r  r:  r   )rB  r  r  r  rA  r  privateGetFillsr  r<  r  r  r7  r  )r#  rE  r~  r  r+  r  r  rA  r,  r   r  s              r%  fetch_my_tradeszparadex.fetch_my_trades  s{    	   88R\]]& 	@33OVUTY[aciksuy{~[[((F &tGH#(GK "'GJ228WfMM''GV(D(DEE0 )R88q#f++&& 	C 	CA $ 0 06 B BF1If  >>>r&  c                     |                                   |                                  |                     |          }|                     |d         g|          }|                     |di           S )a}  
        fetch data on an open position

        https://docs.paradex.trade/api/prod/account/get-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>`
        rE  r   )rB  r  rA  fetch_positionsr  )r#  rE  r+  rA  r   s        r%  fetch_positionzparadex.fetch_position  sl     	   V$$((&*:);VDD	~~iB///r&  c                     |                                   |                                  |                     |          }|                                 }|                     |dg           }|                     ||          S )ai  
        fetch all open positions

        https://docs.paradex.trade/api/prod/account/get-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:  )rB  r  r  privateGetPositionsr<  parse_positions)r#  r  r+  r,  r?  s        r%  r  zparadex.fetch_positions#  sy     	   %%g..++--4 ~~h	266##D'222r&  positionc           
         |                      |d          }|                     ||          }|d         }|                     |d          }|                      |d          }|dk    rt          j        d|          }|                     |d          }|                     i d|d	|                      |d	          d|d
|                      |d          dd dd d|                      |d          d|                      |d          d|d|                     |          dd d|d|                     |          dd dd dd dd d d d d d d d          S )NrA  rE  r  r  longz-1timer5  r'   
entryPriceaverage_entry_pricer  notional
collateralre  unrealizedPnlunrealized_pnl	contractsrf  r  r  r  maintenanceMarginmaintenanceMarginPercentageinitialMargin)initialMarginPercentager  liquidationPricemarginRatior  r  )	r7  r  rr  r"   r  r*  safe_positionr"  rq  )r#  r  rA  rw  rE  r  quantityr  s           r%  parse_positionzparadex.parse_positionM  s   , ##Hh77!!(F33!%%h77##Hf556>>)$99H%%h77	!! #
H#
$""8T22#
 f#
 $**85JKK	#

 #
 #
 $**8V<<#
 T--h8HII#
 D#
 **844#
 D#
 #
 Y//#
 d#
  #
  *4!#
" T##
$ (, $/#
 #
 #
   	r&  c                 V   |                                   i }|||d<   nd|d<   |                     |          }|                     d||          \  }}|                     |                     ||                    }|                     |dg           }|                     ||||          S )a{  
        retrieves the public liquidations of a trading pair

        https://docs.paradex.trade/api/prod/liquidations/get-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:  )rB  rA  r  privateGetLiquidationsr  r<  parse_liquidations)	r#  rE  r~  r  r+  r  rA  r,  r?  s	            r%  fetch_liquidationszparadex.fetch_liquidations  s     	   #GFOOGFOV$$224&II..t{{7F/K/KLL ~~h	266&&tVUEBBBr&  c                     |                      |d          }|                     |d d d d d d d ||                     |          d
          S )Nr  )
r5  rE  r  rf  r`  r  	baseValue
quoteValuer  r  )r*  safe_liquidationrq  )r#  liquidationrA  r  s       r%  parse_liquidationzparadex.parse_liquidation  se     %%k<@@	$$ "Y//&
 &
   	r&  r  c                 b   |                                   |                                  d}|                     |dd          \  }}|r|                     d||||dddd	  	        S i }|||d<   |||d	<   |                     d
||          \  }}|                     |                     ||                    }|                     |dg           }g }	t          dt          |                    D ]+}
||
         }|d         dk    r|	
                    |           ,|                     |	d||          S )aA  
        fetch all deposits made to an account

        https://docs.paradex.trade/api/prod/transfers/get

        :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>`
        FrY   r  r  r  Nr  r  r  r  r:  r   kindDEPOSITrB  r  r  r  r  privateGetTransfersr  r<  r  r  appendparse_transactionsr#  r  r~  r  r+  r  r  r,  rowsdepositsr  rows               r%  fetch_depositszparadex.fetch_deposits  s^    	   88R\]]& 	~33OT5RWY_agiqswy|}}}#(GK "'GJ228WfMM++DKK,H,HII, ~~h	266q#d))$$ 	% 	%Aq'C6{i''$$$&&xueDDDr&  c                 b   |                                   |                                  d}|                     |dd          \  }}|r|                     d||||dddd	  	        S i }|||d<   |||d	<   |                     d
||          \  }}|                     |                     ||                    }|                     |dg           }g }	t          dt          |                    D ]+}
||
         }|d         dk    r|	
                    |           ,|                     |	d||          S )aP  
        fetch all withdrawals made from an account

        https://docs.paradex.trade/api/prod/transfers/get

        :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_withdrawalszparadex.fetch_withdrawals  si    	   88ASU_``& 	A334FeUZ\bdjltvz|  A  A  A#(GK "'GJ228WfMM++DKK,H,HII, ~~h	266q#d))$$ 	% 	%Aq'C6{l**$$$&&xueDDDr&  transactionr  c                    |                      |d          }|                      |d          }|                      |d          }|                      |d          }|                     ||          }|                     |d          }|                     |d          }	|                      |d          }
|
dk    rd	nd
}
|                     |                      |d                    }|                     |d          }i d|d|d|d|d|                     |          dd d|d|dd dd dd dd d|
d|d|d|d|	d d d dS )Nr'   r   txn_hashrA  r  r  r  r  deposit
withdrawalr/  r_  r5  txidr  r  networkr+  	addressToaddressFromtagtagTotagFromrX  r  r2  )internalcommentr  )r7  rn  r*  parse_transaction_statusrs  rq  )r#  r  r  r'   r+  r  r  r  r  r2  rX  r/  r_  s                r%  parse_transactionzparadex.parse_transaction-  s   $ k400"";	::Z88%%k7;;
&&z8<<%%k<@@	##K1BCCV44!Y..yy\..t/?/?X/V/VWW!!+x88
K
"
 D
 	

 Y//
 t
 w
 
 4
 4
 T
 t
 D
 f
 
  f!
" w#
$ )
 
 
 	
r&  c                 >    ddddd}|                      |||          S )Npendingr0  failed)PENDING	AVAILABLE	COMPLETEDFAILEDrc  rk  s      r%  r  z paradex.parse_transaction_statusa  s4     "	
 
 &&999r&  c                 b   |                                   |                                  |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     |                     |d          |          S )a  
        fetches the margin mode of a specific symbol

        https://docs.paradex.trade/api/prod/account/get-account-margin

        :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>`
        rA  r'   configsr   )rB  r  rA  privateGetAccountMarginr  r<  parse_margin_moder  r#  rE  r+  rA  r  r,  r  s          r%  fetch_margin_modezparadex.fetch_margin_modej  s     	   V$$fTl
 //GV0L0LMM ..955%%dnnWa&@&@&IIIr&  rawMarginModec                     |                      |d          }|                     ||          }|                     |d          }||d         |dS )NrA  margin_typerE  )r5  rE  r  )r7  r  rr  )r#  r
  rA  rw  r  s        r%  r  zparadex.parse_margin_mode  s^    ##M8<<!!(F33++M=II
!X&$
 
 	
r&  r  c                 t   |                      d|d           |                                  |                                  |                     |          }d}|                     |ddd          \  }}|d         ||                     |          d}|                     |                     ||                    S )a  
        set margin mode to 'cross' or 'isolated'

        https://docs.paradex.trade/api/prod/account/upsert-account-margin

        :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   rE  Nr  r   r'   rA  r  r  )check_required_argumentrB  r  rA  r  encode_margin_modeprivatePostAccountMarginMarketr  )r#  r  rE  r+  rA  r  r  s          r%  set_margin_modezparadex.set_margin_mode  s     	$$_fhGGG   V,,88R\^_``&Tl 22:>>
 

 224;;w3O3OPPPr&  c                 b   |                                   |                                  |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     |                     |d          |          S )aa  
        fetch the set leverage for a market

        https://docs.paradex.trade/api/prod/account/get-account-margin

        :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>`
        rA  r'   r  r   )rB  r  rA  r  r  r<  parse_leverager  r  s          r%  fetch_leveragezparadex.fetch_leverage  s     	   V$$fTl
 //GV0L0LMM ..955""4>>'1#=#=vFFFr&  r  c                    |                      |d          }|                     ||          }|                     |d          }||                     ||          ||                     |d          |                     |d          dS )NrA  r  r  )r5  rE  r  longLeverageshortLeverage)r7  r  rr  safe_symbolr*  )r#  r  rA  rw  r  s        r%  r  zparadex.parse_leverage  s    ##Hh77!!(F33++HmDD
&&x88$ --h
CC!..xDD
 
 	
r&  c                 :    ddd}|                      |||          S )NCROSSISOLATED)crossisolatedrc  )r#  modemodess      r%  r  zparadex.encode_margin_mode  s.    "
 
 tT222r&  c                 r   |                      d|d           |                                  |                                  |                     |          }d}|                     d|d          \  }}|d         ||                     |          d}|                     |                     ||                    S )a  
        set the level of leverage for a market

        https://docs.paradex.trade/api/prod/account/upsert-account-margin

        :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   rE  Nr  r'   r  )r  rB  r  rA  handle_margin_mode_and_paramsr  r  r  )r#  r  rE  r+  rA  r  r  s          r%  set_leveragezparadex.set_leverage  s     	$$]FHEEE   V,,
!??vW^__
FTl 22:>>
 

 224;;w3O3OPPPr&  c                 B   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     |di           }|                     ||          S )a  
        fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract

        https://docs.paradex.trade/api/prod/markets/get-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>`
        rA  r'   r:  r   )r  rA  r  r  r<  r  parse_greeks)r#  rE  r+  rA  r  r,  r?  greekss           r%  fetch_greekszparadex.fetch_greeks  s     	V$$fTl
 //GV0L0LMMF ~~h	266a,,  000r&  c                    |                                   |                     |dddd          }ddi}|                     |                     ||                    }|                     |dg           }|                     ||          S )a  
        fetches all option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract

        https://docs.paradex.trade/api/prod/markets/get-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>`
        NTrA  r  r:  )r  r  r  r  r<  parse_all_greeks)r#  r  r+  r  r,  r:  s         r%  fetch_all_greekszparadex.fetch_all_greeks/	  s     	%%gtT4FFe
 //GV0L0LMMF ..9b99$$Wg666r&  r&  c                    |                      |d          }|                     ||d d          }|d         }|                     |d          }|                     |di           }i d|d|d|                     |          d|                     |d          d|                     |d          d	d d
|                     |d
          d|                     |d          d|                     |d          d|                     |d          dd dd d|                     |d          d|                     |d          d|                     |d          d|                     |d          d|                     |d          |                     |d          |                     |d          |                     |d          |dS )NrE  r8   r  r&  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underlyingPricer5  )r7  r  r*  r  rq  rs  )r#  r&  rA  rw  rE  r  
greeksDatas          r%  r%  zparadex.parse_greeksd	  sC   > ##FH55!!(FD(CC!%%fl;;	^^FHb99

f

 Y//
 T%%j'::	

 T%%j'::
 T
 D$$Z88
 4##J66
 T%%j'::
 T%%j'::
 t
 t
 #D$4$4VX$F$F
 #D$4$4VX$F$F
 $T%5%5fi%H%H
  ((77!
" ((77#
$ ))&,??))&2EFF#//8JKK+
 
 
 	
r&  c           	      @   |t          | j        dz             |                                  |                     |          }d|d         i}|t	          |d          |d<   nd|d<   |||d<   |                     |d	          }||                     |d	          }||d
<   |                     |                     ||                    }| 	                    |dg           }	g }
t          dt          |	                    D ]j}|	|         }|                     |d          }|                     |          }|
                    ||d         |                     |d          ||d           k|                     |
d          }|                     ||d         ||          S )a  
        fetches historical funding rate prices

        https://docs.paradex.trade/api/prod/markets/get-funding-data

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: timestamp in ms of the earliest funding rate to fetch
        :param int [limit]: the maximum amount of funding rate structures
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest funding rate to fetch
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentrA  r'   i  r  r  r  r  r  r:  r   r  rE  funding_rate)r5  rE  fundingRater  r  r  )r   r'   r  rA  ra  r*  r  publicGetFundingDatar  r<  r  r  rq  r  rs  sort_byfilter_by_symbol_since_limit)r#  rE  r~  r  r+  rA  r  r  r,  r:  ratesr  r  r  r  sorteds                   r%  fetch_funding_rate_historyz"paradex.fetch_funding_rate_history	  s    >#DG.e$efffV$$fTl
 #&ud#3#3GK  #'GK "'GJ!!&'22YYvw//F %GH,,T[[&-I-IJJ$ ..9b99q#g,,'' 
	 
	A1:D))$==I||I..HLL *#//nEE&$      e[11009I5RWXXXr&  r   GETc                    |                      | j        d         | j                           dz   |                     ||          z   }|                     ||                     |                    }|dk    r|r|d|                     |          z   z  }n1|dk    r*d|                     | j        dd          d	}|d
k    rG|d         |d<   |d         |d<   t          |d                   |d<   t          |d                   |d<   n|dk    rg| j
        |d<   |d         |d<   |d         |d<   t          |                                           |d<   d|d<   |                     d|d         i          }nQ| j        d         }	d|	z   |d<   |dk    rd|d<   |                     |          }n|dz   |                     |          z   }||||dS )Nr   rI  r   ?r   zapplication/jsonr   r   )AcceptzPARADEX-PARTNERr   r   zPARADEX-STARKNET-ACCOUNTr	  zPARADEX-STARKNET-SIGNATUREr  zPARADEX-TIMESTAMPr;  zPARADEX-SIGNATURE-EXPIRATIONr   zPARADEX-ETHEREUM-ACCOUNTzContent-Typer-  r3  zBearer Authorizationr6  )r4  r8  r:  headers)implode_hostnamer   r+   implode_paramsr  extract_params	urlencoder7  r  strr   r  json)
r#  r9  r   r8  r+  rO  r:  r4  queryrA  s
             r%  signzparadex.sign	  s   ##DIe$4T\$BCCcIDL_L_`dflLmLmm		&$"5"5d";";<<(?? 3sT^^E2222I,#'#3#3DL(F#S#S G
 v~~6;I6F238=k8J45/253E/F/F+,:=eL>Q:R:R677%%6:6H236;I6F238=k8J45/24::<</@/@+,*<'yy %"5"   [1+4u+<(V##.@GN+99U++DD)dnnU&;&;;C fdwOOOr&  httpCodereasonr4  r8  rO  r:  c
                     |sd S |                      |d          }
|
`| j        dz   |z   }|                     | j        d         ||           |                     | j        d         |
|           t          |          d S )Nerror r   r   )r7  r'   throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr   )r#  rX  rY  r4  r8  rO  r:  r,  requestHeadersrequestBody	errorCodefeedbacks               r%  handle_errorszparadex.handle_errors
  s     	4 $$Xw77	 w}t+H001I4QYZZZ001I9V^___)))tr&  )N)F)Y__name__
__module____qualname__r   r!  r	   r-  r8  r   r   r@  dictr|  rT  listr  r  r   r   r  r   r  r  r   r  r   r  r  r  r  r  r
  r  r  r  r'  r   rB  r   r_  r   r[  rY  rZ  rv  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  r  r
   r  r  r  intr#  r   r'  r*  r%  rI  rW  rc  __classcell__)r$  s   @r%  r$   r$      sN
       g# g g g g g gR !# : :s : : : :" #% 
 
 
 
0 $& ,( ,($v, ,( ,( ,( ,(\V4 VF V V V Vp 9=4^bkm 8H 8H# 8H# 8HS 8HX[ 8Hrvw{r| 8H 8H 8H 8Ht
 
 
4 
 
 
 
( 04B &1 &1W &17 &1 &1 &1 &1P 02 '1 '13 '1f '1 '1 '1 '1R0 04 0 06 0 0 0 0d :>b ' 's '3 'Y ' ' ' 'R 6:UW 1? 1?3 1?s 1?# 1?\`af\g 1? 1? 1? 1?f> > >v > > > > >@ 79 ): ):# ): ): ): ):V F    >: : :> > >L L L" " "H      2 !#    & (* * * * *XR R Rv R R R R RhAs A A A A	 	 	 	 	9S 9 9 9 94 4 4 4 4 gksu S S3 Si Sy SRW S`c S S S Sj 37r * *s *C * * * *: /32 5 5 5 5 5 50 26b 3* 3*c 3*3 3* 3* 3* 3*j *.Dt\^ I? I?3 I?c I? I?cghmcn I? I? I? I?V /3TXac 5? 5? 5?3 5?c 5?hlmrhs 5? 5? 5? 5?n $& ( (( ( ( ( (4	) 	) 	) 	) 	) -1tRV_a 9? 9?c 9? 9?C 9? 9? 9? 9?v 24 0 0S 0 0 0 0  26b (3 (3w (3T(^ (3 (3 (3 (3T6 6t 6V 6 6 6 6p <@d[] !C !C !CS !C !C !C !C !CF V    * *.Dt\^ 6E 6E3 6Ec 6E 6Ecghsct 6E 6E 6E 6Ep -1tRV_a 6E 6Ec 6E 6EC 6Efjkvfw 6E 6E 6E 6Ep2
 2
T 2
X 2
Q\ 2
 2
 2
 2
h:s : : : : 57 J J J: J J J J@
 
t 
Z 
 
 
 
 >B" Q Q# Qs Q Q Q Q2 24 G GS G G G G G@

 

t 

V 

x 

 

 

 

3 3 3 9=R Q QS Q# Q Q Q Q2 02 41 413 41f 41 41 41 41l 37r 37 37 37d6l 37 37 37 37j:
 :
4 :
 :
6 :
 :
 :
 :
x 8<$]ajl >Y >Y >YC >YWZ >Y >Y >Y >Y@ &eBSW .P .P .P .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%  <module>rt     s'   ( ' ' ' ' ' - - - - - - I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' . . . . . . ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %K( K( K( K( K(h K( K( K( K( K(r&  