
    E#i                       S SK Jr  S SKJr  S SKrS SKJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJr  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K&J'r'   " S S\\5      r(g)    )Exchange)ImplicitAPIN)AnyBalancesBool
CurrenciesCurrencyIntMarket
MarketTypeNumOrder	OrderSide	OrderTypePositionStrStringsTickerFundingRateTradeTransaction)List)ExchangeError)AuthenticationError)ArgumentsRequired)
BadRequest)InsufficientFunds)InvalidOrder)OrderNotFound)RateLimitExceeded)	TICK_SIZE)Precisec                     ^  \ rS rSrS\4U 4S jjrS\4U 4S jjr0 4S jr0 4S\	4S jjr
0 4S\\   4S jjr0 4S\\   4S	 jjr0 4S\\   4S
 jjr0 4S\\   4S jjrS\S\4S jr0 4S\S\4S jjrSUS\S\S\4S jjrSS0 4S\S\S\S\\   4S jjrSUS\S\S\4S jjrSSS0 4S\S\S\4S jjr0 4S\S\4S jjrSUS\S\4S jjrS r S r!S r"S r#S r$SVS \4S! jjr%S0 4S\S"\&S#\'S$\(S%\)4
S& jjr*SS0 4S'\S\S"\&S#\'S$\)S%\)4S( jjr+S0 4S'\S\4S) jjr,S0 4S\4S* jjr-SSS0 4S\S\S\S\\.   4S+ jjr/SSS0 4S\S\S\S\\.   4S, jjr0SSS0 4S\S\S\S\\.   4S- jjr1SSS0 4S\S\S\4S. jjr2S/\4S0 jr3S1\4S2 jr4SUS3\S\S\.4S4 jjr5SSS0 4S'\S\S\S\4S5 jjr6SSS0 4S\S\S\4S6 jjr7S0 4S7\8S\\9   4S8 jjr:SUS9\S\4S: jjr;SSS0 4S\S\S\4S; jjr<SUS\4S< jjr=0 4S\>4S= jjr?S\>4S> jr@SSS0 4S?\S\S\S\\A   4S@ jjrBSSS0 4S?\S\S\S\\A   4SA jjrCSUSB\SC\DS\A4SD jjrES1\4SE jrFSF\SG\4SH jrGSF\SG\4SI jrHSJ\ISK\SL\SM\SN\SO\4SP jrJSQSR0 SS4SS jrKSTrLU =rM$ )Wderive   returnc                  
  > 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_S/S_S0S
_E0 S1S
_S2S_S3S
_S4S
_S5S_S6S7_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
Se.E_SfSgShSiSjSkSlSmSnSoSpSqSrSsStSu._SvSw_SxSySzS{S|.S}S~S|.SSSSS._SS// SQS.S/ SQ0S|._S0 _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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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[
        _GS [
        _GS[
        _GS[
        _GS[
        _GS[
        _E[
        [
        [
        GS.E0 GS._GS[        _0 GSGS	GS
.GS.E5      $ (  Nidr$   name	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fetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledAndClosedOrdersfetchCanceledOrdersfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeverageTiersfetchLiquidationsfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCV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2h4h8h12h1d3d1w1M)r   r   r   r   r   r   r   r   r   r   r   r   r   r   hostnamez
derive.xyzurlszOhttps://github.com/user-attachments/assets/f835b95f-033a-43dd-b6bb-24e698fc498czhttps://api.lyra.finance/publicz https://api.lyra.finance/private)publicprivatez$https://api-demo.lyra.finance/publicz%https://api-demo.lyra.finance/privatezhttps://www.derive.xyz/zhttps://docs.derive.xyz/docs/z)https://docs.derive.xyz/reference/fees-1/z#https://www.derive.xyz/invite/3VB0B)logoapitestwwwdocfeesreferralr   get_all_currencies)2build_register_session_key_txregister_session_keyderegister_session_keylogin
statisticsr   get_currencyget_instrumentget_all_instrumentsget_instruments
get_tickerget_latest_signed_feedsget_option_settlement_pricesget_spot_feed_historyget_spot_feed_history_candlesget_funding_rate_historyget_trade_historyget_option_settlement_historyget_liquidation_historyget_interest_rate_historyget_transaction
get_marginmargin_watchvalidate_invite_code
get_pointsget_all_pointsget_points_leaderboardget_descendant_treeget_tree_rootsget_swell_percent_pointsget_vault_assetsget_etherfi_effective_balancesget_kelp_effective_balancesget_bridge_balancesget_ethena_participantsget_vault_shareget_vault_statisticsget_vault_balancesestimate_integrator_pointscreate_subaccount_debugdeposit_debugwithdraw_debugsend_quote_debugexecute_quote_debugget_invite_coderegister_inviteget_timeget_live_incidentsget_maker_programsget_maker_program_scores)getpostr   )>get_accountcreate_subaccountget_subaccountget_subaccountsget_all_portfolioschange_subaccount_labelget_notificationsvupdate_notificationsdepositr   transfer_erc20transfer_positiontransfer_positionsorderreplaceorder_debug	get_order
get_ordersget_open_orderscancelcancel_by_labelcancel_by_noncecancel_by_instrument
cancel_allcancel_trigger_orderget_order_historyr   get_deposit_historyget_withdrawal_historysend_rfq
cancel_rfqcancel_batch_rfqsget_rfqs	poll_rfqs
send_quotecancel_quotecancel_batch_quotes
get_quotespoll_quotesexecute_quoterfq_get_best_quoter   get_collateralsget_positionsr   get_subaccount_value_historyexpired_and_cancelled_historyget_funding_historyget_interest_historyget_erc20_transfer_historyr   	liquidateget_liquidator_historysession_keysedit_session_keyregister_scoped_session_keyget_mmp_configset_mmp_config	reset_mmpset_cancel_on_disconnectr   r   r   requiredCredentials)apiKeysecretwalletAddress
privateKey
exceptionsz-32000z-32100z-32700z-32600z-32601z-32602z-326039000100001000110002100031000410005100061000710008100091001010011100121001310014110001100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281105011051110521105311054110551110011101111021110311104111051110611107112001120111202112031200012001120021200313000140001400114002140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321600016001161001700017001170021700317004170051700617007180001800118002180031800418005)180061800719000)exactbroadprecisionMode *0x0ad42b8e602c2d3d475ae52d678cf63d84ab2749)deriveWalletAddressr(   )commonCurrenciesoptions)deep_extendsuperr$   describer    r   r   r   r   r   r   r!   )self	__class__s    S/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/async_support/derive.pyr  derive.describe   s   fd < > RA
(RA
HRA
 RA
 t	RA

 RA
 RA
 4RA
 4RA
  \\\ %\ 	\
 %\ %\ U\ $U\ '\ "4\ '\ t\ \ )%\ $U\   !\" /#\$ ,U%\& 0'\( t)\* +\, (-\. "5/\0 %e1\2 T3\4  5\6 7\8 &u9\: +E;\< )%=\> /?\@ &tA\B $TC\D 'E\F (G\H "4I\J &uK\L (M\N  O\P *:Q\R +ES\T &tU\V #DW\X *4Y\Z $U[\\ "5]\^ *5_\` +Ea\b tc\d  e\f %eg\h $Ui\j "4k\l +Em\n o\p !%q\r &us\t  u\v ew\x $Uy\z +E{\| %e}\~ "4\@ eA\B !%C\D tE\F #DG\H  I\J $UK\L !$M\N %eO\P )%Q\R tS\T U\V TW\X tY\Z "5[\\ #E]\^  _\` !%a\b "5c\d #De\f g\h #Ei\j &uk\l  $!&#(!!w\RA
L MRA
l mRA
n i?A
 EF 16CAoRA
L  -3	8t  ?Au|MRA
F  GRA
J "!%"	$KRA
V {/{/{ j{ j	{
 j{ l{ l{ L{ Z{ Z{ Z{ Z{ \{ Z{ Z{  Z!{" Z#{$ Z%{& \'{( .){* .+{, ]-{. ]/{0 .1{2 \3{4 \5{6 \7{8 \9{: ];{< \={> \?{@ \A{B \C{D \E{F \G{H \I{J \K{L \M{N \O{P \Q{R \S{T \U{V .W{X \Y{Z \[{\ \]{^ \_{` \a{b Zc{d \e{f \g{h \i{j \k{l \m{n \o{p \q{r \s{t \u{v \w{x \y{z \{{| \}{~ \{@ \A{B \C{D \E{F \G{H \I{J \K{L \M{N \O{P ZQ{R ZS{T ZU{V ZW{X \Y{Z Z[{\ Z]{^ Z_{` Za{b Zc{d Ze{f Zg{h \i{j Zk{l Zm{n Zo{p Zq{r Zs{t Zu{v Zw{x 0y{z \{{| Z}{~ Z{@ ZA{B 0C{D ZE{F 0G{H ZI{J 0K{L ZM{N 0O{P 0Q{R 0S{T ZU{V ZW{X ZY{Z Z[{\ Z]{^ Z_{` Za{b Zc{d Ze{f Zg{h Zi{j Zk{l Zm{n Zo{p (''u{x{WRA
V YWRA
X! (*B]RA
 R R	    enablec                 H   > [         [        U ]  U5        XR                  S'   g )NsandboxMode)r  r$   set_sandbox_moder  )r  r  r  s     r  r  derive.set_sandbox_mode  s    fd,V4&,]#r  c                 d   #    U R                  U5      I Sh  vN nU R                  US5      $  N7f)a+  
fetches the current integer timestamp in milliseconds from the exchange server

https://docs.derive.xyz/reference/post_public-get-time

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the exchange server
Nresult)publicPostGetTimesafe_integer)r  paramsresponses      r  
fetch_timederive.fetch_time  s4      //77   844 8s   0.0c                 D  #    0 nU R                  U5      I Sh  vN nU R                  US/ 5      n[        S[        U5      5       HR  nXE   nU R	                  US5      nU R                  U5      nU R                  USUSSSSSSSSS.SSS.S.US.5      X('   MT     U$  N7f)z
fetches all available currencies on an exchange

https://docs.derive.xyz/reference/post_public-get-all-currencies

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
Nr  r   currencyminmax)r   r   )r(   r)   code	precisionactivefeenetworksr   r   limitsinfo)publicGetGetAllCurrencies	safe_listrangelensafe_stringsafe_currency_codesafe_currency_structure)	r  r  r  tokenResponse
currenciesir  
currencyIdr  s	            r  fetch_currenciesderive.fetch_currencies  s      "<<VDDb ^^M8R@
q#j/*A!}H))(J?J**:6D77 !    $# 
  $#!	 !)9 FL	 +4 Y Es   B BBB c                    #    U R                  U5      nU R                  U5      nU R                  U5      n[        R                  " X#U/6 I Sh  vN u  pVnU R                  XV5      nU R                  X5      nU$  N+7f)z
retrieves data on all markets for bybit

https://docs.derive.xyz/reference/post_public-get-all-instruments

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
N)fetch_spot_marketsfetch_swap_marketsfetch_option_marketsasynciogatherarray_concat)	r  r  spotMarketsPromiseswapMarketsPromiseoptionMarketsPromisespotMarketsswapMarketsoptionMarketsr  s	            r  fetch_marketsderive.fetch_markets  s      "44V<!44V<#88@8?I[  rF  IG  9H  3H/-\ "";<""69a 3Hs   AA<A:,A<c                    #    SSS.nU R                  U R                  X!5      5      I S h  vN nU R                  US0 5      nU R                  US/ 5      nU R	                  U5      $  N;7f)NFerc20expiredinstrument_typer  instrumentspublicPostGetAllInstrumentsextend	safe_dictr  parse_marketsr  r  requestr  r  datas         r  r  derive.fetch_spot_marketsZ  sk     &
 99$++g:VWW(B7~~fmR8!!$'' X   )A)A'<A)c                    #    SSS.nU R                  U R                  X!5      5      I S h  vN nU R                  US0 5      nU R                  US/ 5      nU R	                  U5      $  N;7f)NFperpr  r  r  r  r  s         r  r  derive.fetch_swap_marketsd  sk     %
 99$++g:VWW(B7~~fmR8!!$'' Xr  c                    #    SSS.nU R                  U R                  X!5      5      I S h  vN nU R                  US0 5      nU R                  US/ 5      nU R	                  U5      $  N;7f)NFr8   r  r  r  r  r  s         r  r  derive.fetch_option_marketsn  sk     '
 99$++g:VWW(B7~~fmR8!!$'' Xr  marketc                    U R                  US5      nSnSnSnSnS nS 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S-   U-   nS nS nS nS nS nS nUS:X  a  SnS	nOUS
:X  a,  SnSnU R                  U5      nUS-   U-   S-   U-   nSnSnSnSnOUS:X  a  SnU R                  U5      nSnSn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S-   U-   S-   U-   S-   U R                  U5      -   S-   U R                  U5      -   S-   U-   nUS:X  a  SnOSnSnSnU R                  0 SU_SU_SU_SU_SU_SU	_SU
_SU_SW_S	U_S U_SU_S!S_SU_S"U R                  US#5      _S$U=(       d    U_S%U_UU(       a  S OS&UU R                  U5      U R                  US'5      U R                  US(5      UUU R                  US)5      U R                  US*5      S+.S S S,.U R                  US-5      U R                  US.5      S,.S S S,.S S S,.S/.S US0.E5      $ )1Nr  FTbase_currencyquote_currencyinstrument_name/r  r4   r  USDC:r6   r8   option_detailsexpirystrikeoption_type-Pputcallr(   symbolbasequotesettlebaseIdquoteIdsettleIdtyper5   r7   r  	is_activecontractlinear   taker_fee_ratemaker_fee_rateamount_step	tick_size)amountpricer  minimum_amountmaximum_amount)leverager  r  cost)inversecontractSizer  expiryDatetimetakermakerr  
optionTyper  r  createdr  )r  r  r  safe_timestampr  yymmddnumber_to_stringsafe_market_structure	safe_booliso8601safe_number)r  r  r  r4   r5   r6   r8   r  r  r  r  r  r  marketIdr  r  r  r  r  r  optionLetter
marketTypeoptionDetailss                          r  parse_marketderive.parse_marketx  s   (9:!!&/:""6+;<&&v.''0##F,=>e#
 7?DJV^FH,,X6FCZ%'#-6FDFGJXH,,X6FFF!J NN63CDM((AF&&}h?F++M=ILCZ%'#-6<t{{6?RRUXX[_[p[pqw[xx{~~  BN  NFs""
#
FG)) 2+
(2+
f2+
 D2+
 U	2+

 f2+
 f2+
 w2+
 2+
 J2+
 D2+
 f2+
 D2+
 e2+
 f2+
 dnnV[92+
  !2+
" f#2+
$ %)D"ll62%%f.>?%%f.>?$**6=A))&+>  
  ++F4DE++F4DE
  
  $ c2+
 2 2	r  r  c                 
  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US0 5      nU R                  Xc5      $  Nh N*7f)a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://docs.derive.xyz/reference/post_public-get-ticker

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr  r(   r  )load_marketsr  publicPostGetTickerr  r  parse_ticker)r  r  r  r  r  r  r  s          r  fetch_tickerderive.fetch_ticker  s      !!!V$vd|
 11$++g2NOOz ~~h"5  ..G 	"
 Ps!   BA??BB)BBNtickerc           
         U R                  US5      nU R                  US5      nU R                  X25      nU R                  US5      nU R                  US5      nU R	                  0 SU_SU_SU R                  U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      _SU R                  US5      _SU R                  US5      _SS _SS _SS _SS _SS _SU_S[        R                  " US5      _SS _S S U R                  US5      U R                  US5      US.EU5      $ )Nr  	timestampstatspercent_changer  datetimehighlowbidbest_bid_price	bidVolumebest_bid_amountaskbest_ask_price	askVolumebest_ask_amountvwapopencloselastpreviousClosechange
percentage100averageindex_price
mark_price)
baseVolumequoteVolume
indexPrice	markPricer  )r  safe_integer_omit_zerosafe_symbolr  safe_tickerr  r"   
string_mul)r  r'  r  r  r)  r  r*  r<  s           r  r$  derive.parse_ticker-  s   p ##F,=>//D	!!(3vw/!!%)9: !
f!
!
 Y/!
 D$$UF3	!

 4##E51!
 4##F,<=!
 ))&2CD!
 4##F,<=!
 ))&2CD!
 D!
 D!
 T!
 D!
 T!
 f!
  ',,VU;!!
" t#!
$ **6=A))&,?-!
. / 	r  sincelimitc                   #    U R                  5       I Sh  vN   0 nSnUb  U R                  U5      nUS   US'   Ub  US:  a  SnX5S'   Ub  X%S'   U R                  US5      nU R                  US/5      nUb  XuS'   U R	                  U R                  XT5      5      I Sh  vN nU R                  US	0 5      n	U R                  U	S
/ 5      n
U R                  XX#5      $  N N>7f)a,  
get the list of most recent trades for a particular symbol

https://docs.derive.xyz/reference/post_public-get-trade-history

: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
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
Nr(   r  i  	page_sizefrom_timestampuntilto_timestampr  trades)	r"  r  r  omitpublicPostGetTradeHistoryr  r  r  parse_trades)r  r  rK  rL  r  r  r  rP  r  r  r  s              r  fetch_tradesderive.fetch_trades  s     !!![[(F)/G%&t|#(K (-$%!!&'26G9-&+N#77G8TUUB (B7~~fh3  u<<g 	"  Vs"   C!CB	C! C!=C!C!tradec                    U R                  US5      nU R                  X25      nU R                  US5      nSU R                  US5      S.nU R                  UU R                  US5      U R                  US5      UU R	                  US5      S U R                  US	5      U R                  US
5      U R                  US5      S UU R                  U5      US.U5      $ )Nr  r)  r  	trade_fee)r  r  trade_idorder_id	directionliquidity_roletrade_pricetrade_amount)r  r(   r   r  sider  takerOrMakerr  r  r  r)  r,  r  )r  rG  r  
safe_tradesafe_string_lowerr  )r  rX  r  r  r  r)  r  s          r  parse_tradederive.parse_trade  s    2 ##E+<=!!(3%%e[9	$$UK8
 ""5*5%%eZ8**5+> ,,U4DE%%e];&&un="Y/ 
  	r  c           
        #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nUb  X&S'   U R                  US5      nU R                  US/5      nUb  XvS'   U R	                  U R                  Xd5      5      I Sh  vN nU R                  US0 5      n	U R                  U	S/ 5      n
/ n[        S	[        U
5      5       HR  nX   nU R                  US
5      nUR                  UUS   U R                  US5      UU R                  U5      S.5        MT     U R                  US
5      nU R                  XS   X#5      $  GN2 N7f)a  
fetches historical funding rate prices

https://docs.derive.xyz/reference/post_public-get-funding-rate-history

: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 to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
Nr  r(   start_timestamprP  rQ  r  funding_rate_historyr   r)  r  funding_rate)r  r  fundingRater)  r,  )r"  r  r  rS  publicPostGetFundingRateHistoryr  r  r  r  r  appendr  r  sort_byfilter_by_symbol_since_limit)r  r  rK  rL  r  r  r  rP  r  r  r  ratesr  entryr)  sorteds                   r  fetch_funding_rate_history!derive.fetch_funding_rate_history  sa     !!!V$vd|
 ).%&!!&'26G9-&+N#==dkk'>Z[[ (B7~~f&<bAq#d)$AGE))%=ILL *#//~F& LL3  % e[1009I5XXO 	" \s#   EEA2E	E
B?EEc                    #    U R                  USSU5      I Sh  vN nU R                  US5      nU R                  U5      $  N'7f)a>  
fetch the current funding rate

https://docs.derive.xyz/reference/post_public-get-funding-rate-history

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
Nr  r   )rs  r  parse_funding_rate)r  r  r  r  r  s        r  fetch_funding_ratederive.fetch_funding_rate*  sI      88q&QQ ~~h*&&t,,! Rs   AA(Ac                     U R                  US5      nU R                  US5      n0 SU_SU_SS _SS _SS _SS _SS _SS _S	U R                  US	5      _S
U_SU R                  U5      _SS _SS _SS _SS _SS _SS _SS 0E$ )Nr  r)  r  rE  rD  interestRateestimatedSettlePricer,  rk  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  r  r  r  )r  r   r  r  r|  s        r  rv  derive.parse_funding_rateF  s   !!(H5,,X{C
H
f
 
 $	

 D
 #D
 
 
 4++HmD
  0
 t||,<=
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
r  c                 &   U R                  U R                  / SQU5      SS5      nU R                  U R                  SS5      nU(       a  SOSnU R	                  U5      nU R	                  S5      nU R                  U R                  XeU5      SS	5      $ )
N)bytes32uint256r  addressr  r  r  r  keccakbinaryr  F@9bcf4dc06df5d8bf23af818d5716491b995020f377d3b7b64c29ed14e3dd1105@d96e5f90797da7ec8dc4e276260c7f3f87fedf68775fbe1ef116e996fc60441b1901hex)hasheth_abi_encoder  r  base16_to_binarybinary_concat)r  r   accountHashr  DOMAIN_SEPARATORbinaryDomainSeparatorprefixs          r  hash_order_messagederive.hash_order_message^  s    ii 3 3 5
!X' nnT\\=%Hbm]  uw $ 5 56F G&&v.yy++F;WYachiir  c                 T    U R                  U5      nU R                  USS  USS  5      $ N)r  	sign_hash)r  r   r  	hashOrders       r  
sign_orderderive.sign_orderh  s0    ++E2	~~ioz#$/?@@r  c           
      R   U R                  U5      nU R                  U5      nU R                  S5      nU R                  S5      nU R                  X@R                  S5      XPR                  U R	                  U5      5      5      nSU R                  U R                  Xb5      SS5      -   $ )N190azEthereum Signed Message:0xr  r  )encodebinary_lengthr  r  r  r  )r  messagebinaryMessagebinaryMessageLengthx19newliner  s          r  hash_messagederive.hash_messagel  s    G,"00?##D)''-##C5O)PRY[f[fgkg|g|  ~Q  hR  \S  Tdii 2 26 I8UZ[[[r  c                    U R                  5         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-   $ )
Nr  	secp256k1rs   vr  @   0)check_required_credentialsecdsaint_to_base16sumrjust)r  r  r  	signaturer  r  r  s          r  r  derive.sign_hasht  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      $ r  )r  r  )r  r  r  s      r  sign_messagederive.sign_message|  s%    ~~d//8*ST:JKKr  numc                 .    [         R                  " X5      $ N)r"   rI  )r  r  decs      r  parse_unitsderive.parse_units  s    !!#++r  r  ra  r  r  c                   #    U R                  5       I Sh  vN   U R                  U5      nUc  [        U R                  S-   5      eSnU R	                  SU5      u  pU R                  USS5      n	U R                  USS5      n
U R                  USS	5      nU R                  US
5      nUR                  5       nUR                  5       nU R                  5       nU R                  USU R                  5       S-   5      nU R                  S5      nU R                  U R                  SS5      nU(       a  SOSnU R                  U5      nSnU R                  USS5      u  nnUc  [        U R                  S-   5      eU R                  U5      nU R                  U5      nU R!                  U R#                  / SQUS   S   U R%                  US   S   5      U R'                  U R)                  U5      5      U R'                  U R)                  U R+                  UU5      5      5      U R'                  U R)                  U5      5      UUS:H  /5      SS5      nSnU R-                  SU5      u  nnU R/                  UUUUUUUU R0                  /U R2                  5      nUS   UUUUUUUUU R5                  U R                  SS5      U R0                  S.nU
b+  U
US'   U
(       a  U(       a  [7        U R                  S-   5      eUb  SUS	'   OUb  UUS	'   U R9                  US5      nU R9                  US 5      nU R5                  US!S"5      nUb#  U R5                  US#U5      nUUS$'   S%US&'   UUS!'   O%Ub"  U R5                  US#U5      n U US$'   S'US&'   UUS!'   U R5                  US(5      n!U!b  U!US)'   UUS*'   U R;                  U/ S+Q5      nSn"U	(       a*  U R=                  U R?                  UU5      5      I Sh  vN n"O)U RA                  U R?                  UU5      5      I Sh  vN n"U RC                  U"S,5      n#U RC                  U#S-5      n$U$c  U RC                  U#S.5      n$U RE                  U$U5      n%UU%S/'   U%$  GNV N N[7f)0a'  
create a trade order

https://docs.derive.xyz/reference/post_private-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 fulfilled, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.subaccount_id]: *required* the subaccount id
:param float [params.triggerPrice]: The price a trigger order is triggered at
:param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered(perpetual swap markets only)
:param float [params.takeProfit.triggerPrice]: take profit trigger price
:param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered(perpetual swap markets only)
:param float [params.stopLoss.triggerPrice]: stop loss trigger price
:param float [params.max_fee]: *required* the maximum fee you are willing to pay for the order
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nz( createOrder() requires a price argumentrF   r   F
reduceOnlyreduce_onlytimeInForcetime_in_forcepostOnlysignature_expiry_sec v @4d7a9f27c403ff9c0f19bce61d76d82f9aa29f8d6d4b0c5474607d9770d1af17r  *0x87F2863866D85E3192a35A73b388BD625D83f2be*0xB8D20c2B7a1Ad2EE33Bc50eF10876eD3035b5e7bmax_feez4 createOrder() requires a max_fee argument in paramsr  uintintr  r  r  boolr  base_asset_addressbase_asset_sub_idbuyr  r  r(   r  )r  r]  
order_typenoncer  limit_pricer  subaccount_idr  referral_codesigner4 cannot use reduce only with post only time in force	post_onlystopLoss
takeProfittrigger_price_typemarktriggerPricetrigger_pricestoplosstrigger_type
takeprofitclientOrderIdlabelr  )r  r  r  r  r  r   r  	stopPricer  r  r  r  r  r  raw_datar   r  )#r"  r  r   r(   handle_derive_subaccount_idr  safe_bool_2safe_string_lower_2lowermillisecondsr  secondsr  r  r  handle_option_and_paramsr  r  parse_to_numericconvert_to_big_intr  amount_to_precisionhandle_derive_wallet_addressr  r  r  r  r   
safe_valuerS  privatePostOrderDebugr  privatePostOrderr  parse_order)&r  r  r  ra  r  r  r  r  subaccountIdr   r  r  r  	orderType	orderSider  signatureExpiryACTION_TYPEHASHr  TRADE_MODULE_ADDRESSpriceStringmaxFeemaxFeeStringamountStringtradeModuleDataHashr  r  r  r  r  triggerPriceTypestopLossPricetakeProfitPricer  r  r  rawOrderr   s&                                         r  create_orderderive.create_order  s    * !!!V$=#DGG.X$XYY#??vV~~ffe4%%flMJ
..v}oV>>&*5JJL	JJL	!!#++F4JDLLN]dLde//0rsnnT\\=%HP[K  cO++E266v}iX>#DGG.d$dee,,V4,,V4"ii(;(; =
 6N/0!!&.1D"EF##D$4$4[$AB##D$4$4T5M5MfVb5c$de##D$4$4\$BC

) h
  #&*&G&GW]&^#VOO 	%
 ??		  &d|"#"&#)$3!--dllDBno((
 !%/GM"h"477-c#cdd'2GO$$'2GO$??6:6__V\:
++F4H&Q ,,X~xPM'4GO$&0GN#,<G()#"..z>:VO'6GO$&2GN#,<G()((A$,GG(6  $d  e!77GV8TUUH!224;;w3OPPHH (3>>&*5~~fg6H  62fK 	"r VPs5   Q3Q,OQ3+Q/,)Q3Q1AQ3/Q31Q3r(   c                 T  #    U R                  5       I Sh  vN   U R                  U5      nSn	U R                  SU5      u  pU R                  USS5      n
U R	                  USS5      nU R                  US5      nUR                  5       nUR                  5       nU R                  5       nU R                  USU R                  5       S	-   5      nU R                  S
5      nU R                  U R                  SS5      nU(       a  SOSnU R                  U5      nU R                  USS5      nU R                  U5      nU R                  U R                  / SQUS   S   U R!                  US   S   5      U R#                  U R%                  U5      5      U R#                  U R%                  U R'                  UU5      5      5      U R#                  U R%                  U5      5      U	US:H  /5      SS5      nSnU R)                  SU5      u  nnU R+                  UU	UUUUUU R,                  /U R.                  5      nUS   UUUUUUUU	UU R,                  S.nU
b+  U
US'   U
(       a  U(       a  [1        U R2                  S-   5      eUb  SUS'   OUb  UUS'   U R                  US5      nUb  UUS'   UUS'   U R5                  U/ SQ5      nU R7                  U R9                  UU5      5      I Sh  vN nU R;                  US 5      nU R;                  US!5      nU R=                  UU5      nU$  GN N?7f)"a  
edit a trade order

https://docs.derive.xyz/reference/post_private-replace

:param str id: order id
:param str symbol: unified symbol of the market to create an order in
:param str type: 'market' or 'limit'
:param str side: 'buy' or 'sell'
:param float amount: how much of currency you want to trade in units of base currency
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.subaccount_id]: *required* the subaccount id
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
NrK   r  r  r  r  r  r  r  r  r  Fr  r  r  r  r  r  r  r  r  r  r  r(   )r  order_id_to_cancelr]  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  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r(   rS  privatePostReplacer  r  r  ) r  r(   r  r  ra  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   s                                    r  
edit_orderderive.edit_order>  s^      !!!V$#??VT%%flMJ
..v}oV>>&*5JJL	JJL	!!#**63I4<<>\cKcd//0rsnnT\\=%HP[K  cO++E2''	3?,,V4"ii(;(; =
 6N/0!!&.1D"EF##D$4$4[$AB##D$4$4T5M5MfVb5c$de##D$4$4\$BC

) h
  #&*&G&GU[&\#VOO 	%
 ??		  &d|"$"#"&#)$3((
 !%/GM"h"477-c#cdd'2GO$$'2GO$((A$,GG(6#}~00Wf1MNNV (3>>&'2  62c 	"F Os"   L(L#KL(&L&'=L(&L(c                 R  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nU R	                  USSS5      nSnU R                  SU5      u  pcU R                  USS/5      nUS   US.nU R                  US	5      nU R                  US
U5      n	U	SLn
SnU
(       aA  XS
'   U R                  US	S
/5      nU R                  U R                  Xs5      5      I Sh  vN nO\XS'   U(       a)  U R                  U R                  Xs5      5      I Sh  vN nO(U R                  U R                  Xs5      5      I Sh  vN nSU0nU R                  US5      nU
(       a  XS'   U R                  U R                  X5      U5      $  GNm N Nt NM7f)a  

https://docs.derive.xyz/reference/post_private-cancel

cancels an open order
:param str id: order id
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.trigger]: whether the order is a trigger/algo order
:param str [params.subaccount_id]: *required* the subaccount id
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nz) cancelOrder() requires a symbol argumenttriggerstopFr>   r(   )r  r  r  r  r\  r  r  client_order_id)r   r(   r"  r  r  r  rS  r  privatePostCancelByLabelr  privatePostCancelTriggerOrderprivatePostCancelr  r  )r  r(   r  r  r  	isTriggerr  r  clientOrderIdUnifiedclientOrderIdExchangeSpecificisByClientOrderr  extendParamsr   s                 r  cancel_orderderive.cancel_order  s     >#DGG.Y$YZZ!!!V,$$VYF	#??vV6Iv#67%d|)
  $//H(,(8(8J^(_%7tC<GYYv'ABF!::4;;w;WXXH"$J!%!C!CDKKPWD`!aa!%!7!7G8T!UUX '/x2.K*+{{4++E:LIIO 	"" Y bUsG   /F'FCF':F!;3F'.F#/(F'F%AF'!F'#F'%F'c                   #    U R                  5       I Sh  vN   SnUb  U R                  U5      nSnU R                  SU5      u  pBSU0nSnUb1  US   US'   U R                  U R	                  XR5      5      I Sh  vN nO(U R                  U R	                  XR5      5      I Sh  vN nU R                  SU05      /$  N NC N7f)a  

https://docs.derive.xyz/reference/post_private-cancel-by-instrument
https://docs.derive.xyz/reference/post_private-cancel-all

cancel all open orders in a market
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.subaccount_id]: *required* the subaccount id
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr<   r  r(   r  r  )r"  r  r  privatePostCancelByInstrumentr  privatePostCancelAll
safe_order)r  r  r  r  r  r  r  s          r  cancel_all_ordersderive.cancel_all_orders9  s      !!![[(F#??@QSYZ\
 )/G%&!??G@\]]H!66t{{77STTH  23449 	" ^Ts4   CB=A$C;B?<(C$C%C?CCc           	        #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4SS5      I Sh  vN $ U R                  USSS5      nU R	                  USS/5      nSnU R                  SU5      u  ptS	U0nSn	Ub  U R                  U5      n	U	S
   US'   Ub  X8S'   OSUS'   U(       a  SUS'   U R                  U R                  X5      5      I Sh  vN n
U R                  U
S5      nU R                  US5      nUb+  U R                  US5      nU R                  US5      nX:  a  / $ U R                  US5      nU R                  XX#5      $  GNW GN N7f)a  
fetches information on multiple orders made by the user

https://docs.derive.xyz/reference/post_private-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 boolean [params.paginate]: set to True if you want to fetch orders with pagination
:param boolean [params.trigger]: whether the order is a trigger/algo order
:param str [params.subaccount_id]: *required* the subaccount id
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NFru   paginatepage  r  r  r  r(   r  rN  untriggeredstatusr  
pagination	num_pagesorders)r"  r   fetch_paginated_call_incrementalr  rS  r  r  privatePostGetOrdersr  r  r  r  r  parse_orders)r  r  rK  rL  r  r(  r  r  r  r  r  r  r)  r-  currentPager/  s                   r  fetch_ordersderive.fetch_ordersc  s     !!!88PZ[>>}f]blrtwxxx$$VYF	6Iv#67#??vV\
 [[(F)/G%&#(K #&GK  -GH224;;w3OPP\ x2  0l;J++JDK!	h/  >>Y 	" y$ Qs5   E5E-:E5E0B E52E33A;E50E53E5c                    #    U R                  5       I Sh  vN   U R                  USS05      nU R                  XX55      I Sh  vN $  N2 N7f)K  
fetches information on multiple orders made by the user

https://docs.derive.xyz/reference/post_private-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 boolean [params.paginate]: set to True if you want to fetch orders with pagination
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr,  r8  r"  r  r4  r  r  rK  rL  r  extendedParamss         r  fetch_open_ordersderive.fetch_open_orders  sL      !!!Vh-?@&&veLLL 	"L!   AA	-AAAAc                    #    U R                  5       I Sh  vN   U R                  USS05      nU R                  XX55      I Sh  vN $  N2 N7f)r7  Nr,  filledr8  r9  s         r  fetch_closed_ordersderive.fetch_closed_orders  sL      !!!Vh-AB&&veLLL 	"Lr=  c                    #    U R                  5       I Sh  vN   U R                  USS05      nU R                  XX55      I Sh  vN $  N2 N7f)a  
fetches information on multiple canceled orders made by the user

https://docs.derive.xyz/reference/post_private-get-orders

:param str symbol: unified market symbol of the market the 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 boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr,  	cancelledr8  r9  s         r  fetch_canceled_ordersderive.fetch_canceled_orders  sL      !!!Vh-DE&&veLLL 	"Lr=  r  c                 4    SSSSS.nU R                  X!S 5      $ )NIOCFOKGTCPO)iocfokgtcr  r  )r  r  timeInForcess      r  parse_time_in_forcederive.parse_time_in_force  s*    	
 4@@r  r,  c                 @    Ub  SSSSSS.nU R                  X!U5      $ U$ )Nr8  closedcanceledrejected)r8  r+  r?  rC  r  rN  r  r,  statusess      r  parse_order_statusderive.parse_order_status  s8    %"'%H ##Hf==r  r  c                 *   U R                  US5      nUc  UnU R                  USS5      nU R                  US5      nU R                  US5      nUb  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 R	                  US5      nU R                  US5      nU R                  US5      nUc  U(       a  SnOSnU R                  US5      nS nS nS nUb  U R                  US5      nUS:X  a  UnOUnU R                  US5      nU R                  US5      nU R                  US5      nU R                  0 SU_SU R                  US5      _SU_SU R                  U5      _SS _SU_SU R                  U5      _SU_SU_S U R                  U5      _S!S _S"U R                  US#5      _S$U_S%U_S&U_S'U_S(U_U	U
US S S US)S*.US+.EU5      $ ),Nr  creation_timestampr  r\  r  r  r  average_pricedesired_amountfilled_amount	order_feer  is_bidr]  r  sellr  r  r  last_update_timestamporder_statusr  r(   r  r  r)  r,  lastTradeTimestamplastUpdateTimestampr,  r  r  r  r  r  ra  r  r  r
  r	  r  )r  r  )r?  r  r?  	remainingr  rR  r  r  )r  safe_integer_2r  safe_marketrd  r  r  r$  r  rX  rP  )r  r  r  r   r)  orderIdr  r  r  r?  r  r?  r  r  isBidra  triggerTyper	  r
  r  re  r,  r  s                          r  r  derive.parse_order  s   h x0=E''2FP	""5*5##E+<=%%h7F!  6""5/:!!%)9:!!%9uk2**5,?	uh/{3<&&un="++E?CLj( ,"."//:QR!!%8&&uo>  
' 
T--eW= 
  
 Y/	 

 !$ 
 "#6 
 d--f5 
 f 
 I 
 433K@ 
  
 $..> 
 D 
 U 
 L 
  ! 
" ]# 
$ " 9 
: ; 	r  c                   #    U R                  5       I Sh  vN   SnU R                  SU5      u  peUUS.nSnUb  U R                  U5      nUS   US'   Ub  XGS'   Ub  X7S'   U R                  U R	                  Xu5      5      I Sh  vN n	U R                  U	S0 5      n
U R                  U
S	/ 5      nU R                  XX4U5      $  N N?7f)
a  
fetch all the trades made from a single order

https://docs.derive.xyz/reference/post_private-get-trade-history

:param str id: order id
: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 to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.subaccount_id]: *required* the subaccount id
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Nrv   )r\  r  r(   r  rN  rO  r  rR  )r"  r  r  privatePostGetTradeHistoryr  r  r  rU  )r  r(   r  rK  rL  r  r  r  r  r  r  rR  s               r  fetch_order_tradesderive.fetch_order_trades~  s      !!!#??@RTZ[)
 [[(F)/G%&#(K (-$%88W9UVVJ (B7"5  vFFm 	" Ws"   CCA.CC>CCc           	        #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4SS5      I Sh  vN $ SnU R                  SU5      u  pdSU0nSnUb  U R	                  U5      nUS   US	'   Ub  X7S
'   Ub  X'S'   U R                  U R                  Xt5      5      I Sh  vN n	U R                  U	S0 5      n
U R                  US5      nUb+  U R                  U
S5      nU R                  US5      nX:  a  / $ U R                  U
S/ 5      nU R                  XX#U5      $  GN' N N7f)a[  
fetch all trades made by the user

https://docs.derive.xyz/reference/post_private-get-trade-history

: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]: set to True if you want to fetch trades with pagination
:param str [params.subaccount_id]: *required* the subaccount id
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
NFrm   r(  r)  r*  r  r(   r  rN  rO  r  r-  r.  rR  )r"  r  r0  r  r  rn  r  r  r  r  rU  )r  r  rK  rL  r  r(  r  r  r  r  r  r)  r-  r3  rR  s                  r  fetch_my_tradesderive.fetch_my_trades  sv     !!!88R\]>>PV_dntvyzzz#??QWX\
 [[(F)/G%&#(K (-$%88W9UVVJ (B7  0=J++JDK!	"5  vFF 	" { Ws5   ED=:EE A-E?E A>E EEsymbolsc                 Z  #    U R                  5       I Sh  vN   SnU R                  SU5      u  p2SU0nU R                  US/5      nU R                  U R	                  XB5      5      I Sh  vN nU R                  US0 5      nU R                  US/ 5      nU R                  Xq5      $  N N=7f)a  
fetch all open positions

https://docs.derive.xyz/reference/post_private-get-positions

:param str[] [symbols]: not used by kraken fetchPositions()
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.subaccount_id]: *required* the subaccount id
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
Nry   r  r  	positions)r"  r  rS  privatePostGetPositionsr  r  r  parse_positions)r  rt  r  r  r  r  r  rv  s           r  fetch_positionsderive.fetch_positions  s      !!!#??@PRXY\
 6O#4555dkk'6RSSN (B7NN6;;	##I77a 	" Ts"   B+B'AB++B),<B+)B+positionc                    U R                  US5      nU R                  X25      nU R                  US5      nS n[        R                  " US5      (       a  SnO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	[        R
                  " U5      n[        R                  " XG5      n
U R                  0 S
U_SS _SU R                  US5      _SU_SU R                  U5      _SS _SU R                  US5      _SS _SU R                  US5      _SS _SS _SU R                  U
5      _SU R                  US5      _SU R                  U	5      _SU R                  U5      _SU R                  U5      _SS _U R                  US5      U R                  U5      S S S US S S S S.
E5      $ )Nr  r  r  longshortr  rA  r[  unrealized_pnlr  r(   r  r)  r,  re  initialMargininitial_margininitialMarginPercentagemaintenanceMarginmaintenance_marginmaintenanceMarginPercentage
entryPricenotionalr  unrealizedPnl	contractsmarginRatioliquidation_price)
liquidationPricerE  	lastPrice
collateral
marginModera  r=  hedgedr	  r
  )r  rh  r"   	string_gtr  
string_absrI  safe_positionr  parse_numberr  )r  r{  r  r   sizera  r  rE  r)  unrealisedPnlr  s              r  parse_positionderive.parse_positionP  sN   > ##H.?@!!(3(3T3''DD''?$$X|<	%%h0DE	((3CD!!$'%%d6!! #
H#
$#
 d&&vx8#
 	#

 Y/#
 "4#
 T--h8HI#
 &t#
  !1!1(<P!Q#
 *4#
 $#
 ))(3#
 ((:>#
 T..}=#
 **40#
  D--l;!#
" 4##
$ !% 0 0;N O**95!#7#
  	r  c           	        #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4SS5      I Sh  vN $ SnU R                  SU5      u  pdSU0nSnUb  U R	                  U5      nUS   US	'   Ub  X'S
'   Ub  X7S'   U R                  U R                  Xt5      5      I Sh  vN n	U R                  U	S0 5      n
U R                  US5      nUb+  U R                  U
S5      nU R                  US5      nX:  a  / $ U R                  U
S/ 5      nU R                  XX#5      $  GN& N N7f)a  
fetch the history of funding payments paid and received on self account

https://docs.derive.xyz/reference/post_private-get-funding-history

:param str [symbol]: unified market symbol
:param int [since]: the earliest time in ms to fetch funding history for
:param int [limit]: the maximum number of funding history 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 [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
NFr]   r(  r)  r*  r  r(   r  rh  rN  r  r-  r.  events)r"  r  r0  r  r  privatePostGetFundingHistoryr  r  r  r  parse_incomes)r  r  rK  rL  r  r(  r  r  r  r  r  r)  r-  r3  r  s                  r  fetch_funding_historyderive.fetch_funding_history  s     !!!88AVXbc>>?TV\ejtz|  A  A  A#??@UW]^\
 [[(F)/G%&).%&#(K ::4;;w;WXX@ (B7  0=J++JDK!	"5!!&%??u 	" A Ys5   ED<:ED?A-E?E A=E?EEc           	          U R                  US5      nU R                  X25      nU R                  US5      nU R                  S5      nU R                  US5      nUUUUU R	                  U5      S S US.$ )Nr  fundingr  r)  )r  r  r  r)  r,  r(   r  rate)r  rG  r  r  r  )r  incomer  r  r  r  r  r)  s           r  parse_incomederive.parse_income  s     ##F,=>!!(3	2&&v.%%fk:	"Y/	
 		
r  c                   #    U R                  5       I Sh  vN   SnU R                  SU5      u  p!SU0nU R                  U R                  X15      5      I Sh  vN nU R	                  US5      nU R                  U5      $  Ni N)7f)aE  
query for balance and get the amount of funds available for trading or funds locked in orders

https://docs.derive.xyz/reference/post_private-get-all-portfolios

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
NrM   walletr  )r"  r  privatePostGetAllPortfoliosr  r  parse_balance)r  r  r  r  r  r  s         r  fetch_balancederive.fetch_balance  s      !!!"&*&G&GX^&_#)
 99$++g:VWWb (3!!&))q 	" Xs"   BB ABB(BBc                    SU0n[        S[        U5      5       H  nX   nU R                  US/ 5      n[        S[        U5      5       H  nXV   nU R                  U R	                  US5      5      nU R                  X(5      n	U	c&  U R                  5       n	U R	                  US5      U	S'   O/U R	                  US5      n
[        R                  " U	S   U
5      U	S'   XU'   M     M     U R                  U5      $ )Nr  r   collateralsr  r  total)
r  r  r  r  r  r  accountr"   
string_addsafe_balance)r  r  r  r  
subaccountr  jbalancer  r  r  s              r  r  derive.parse_balance@	  s    H
 q#h-(A!J..]BGK1c+./%...t/?/?/TU..6?"llnG'+'7'7'JGG$!--gx@F'.'9'9'':JF'SGG$&t 0 )   ((r  r  c                 f  #    U R                  5       I Sh  vN   SnU R                  SU5      u  pTSU0nUb  X&S'   U R                  U R                  Xd5      5      I Sh  vN nU R	                  U5      nU R                  US0 5      n	U R                  U	S5      n
U R                  XX#U5      $  N NO7f)a  
fetch all deposits made to an account

https://docs.derive.xyz/reference/post_private-get-deposit-history

: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 str [params.subaccount_id]: *required* the subaccount id
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
NrY   r  rh  r  r  )r"  r  privatePostGetDepositHistoryr  safe_currencyr  r  parse_transactionsr  r  rK  rL  r  r  r  r  r  r  r  s              r  fetch_depositsderive.fetch_depositsT	  s      !!!#??QWX\
 ).%&::4;;w;WXX& %%d+(B71&&vvNN= 	" Y#   B1B-AB1B/ AB1/B1c                 f  #    U R                  5       I Sh  vN   SnU R                  SU5      u  pTSU0nUb  X&S'   U R                  U R                  Xd5      5      I Sh  vN nU R	                  U5      nU R                  US0 5      n	U R                  U	S5      n
U R                  XX#U5      $  N NO7f)a"  
fetch all withdrawals made from an account

https://docs.derive.xyz/reference/post_private-get-withdrawal-history

: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 str [params.subaccount_id]: *required* the subaccount id
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr   r  rh  r  r  )r"  r  privatePostGetWithdrawalHistoryr  r  r  r  r  r  s              r  fetch_withdrawalsderive.fetch_withdrawals	  s      !!!#??@RTZ[\
 ).%&==dkk'>Z[[& %%d+(B71&&vvNN= 	" \r  transactionr  c                 p   U R                  US5      nU R                  US5      nU R                  US5      nUS:X  a  S n0 SU_SS _SU_SU_SU R                  U5      _S	S _S
S _SS _SS _SS _SS _SS _SU R                  US5      _SU_SU R	                  U R                  US5      5      _SS _SS _S S S S.E$ )Nassetr)  tx_hash0x0r  r(   txidr,  r  addressFrom	addressTotagtagFromtagTor  r  r  r,  	tx_statusupdatedcomment)internalr  network)r  r  r  r  parse_transaction_status)r  r  r  r  r)  txIds         r  parse_transactionderive.parse_transaction	  sW    W5%%k;?	Y75=D
K
$
 D
 	

 Y/
 t
 4
 
 4
 t
 T
 D
 d&&{H=
 
 d33D4D4D[R]4^_
  t!
" t#
$ )
 	
r  c                 0    SSS.nU R                  X!U5      $ )Nokfailed)settledrevertedrN  rV  s      r  r  derive.parse_transaction_status	  s$     
 &99r  
methodNamer  c                     S nU R                  X!S5      u  p2Ub  US:w  a  X0R                  S'   X2/$ U R                  U R                  S5      nUb  XB/$ [        U R                  S-   U-   S-   5      e)Nr  r   z^() requires a subaccount_id parameter inside 'params' or exchange.options['subaccount_id']=ID.r  r  r  r   r(   )r  r  r  derivesubAccountIdoptionsWallets        r  r  "derive.handle_derive_subaccount_id	  s    !%)%B%B6Wf%g"*1Cr1I,>LL)&//((G$!**#
 :  >b  !b  c  	cr  c                     S nU R                  X!S5      u  p2Ub  US:w  a  X0R                  S'   X2/$ U R                  U R                  S5      nUb  XB/$ [        U R                  S-   U-   S-   5      e)Nr  r  r  z() requires a deriveWalletAddress parameter inside 'params' or exchange.options['deriveWalletAddress'] = ADDRESS, the address can find in HOME => Developers tab.r  )r  r  r  r  r  s        r  r  #derive.handle_derive_wallet_address	  s    "&*&C&CFXm&n#+2E2K2ELL./'00((7LM$!**#
 :  >e  !e  f  	fr  httpCodereasonurlmethodheadersbodyc
                 6   U(       d  g U R                  US5      n
U
b|  U R                  U
S5      nU R                  S-   U R                  U5      -   nU R	                  U R
                  S   Xl5        U R                  U R
                  S   X5        [        U5      eg )Nerrorr  r  r  r  )r  r  r(   jsonthrow_broadly_matched_exceptionr  throw_exactly_matched_exceptionr   )r  r  r  r  r  r  r  r  requestHeadersrequestBodyr  	errorCodefeedbacks                r  handle_errorsderive.handle_errors	  s    x1((7Iww}tyy'::H001I4Z001I9_))r  r   GETc                 4   U R                   S   U   S-   U-   nUS:X  av  SS0nUS:X  a[  [        U R                  5       5      nU R                  XR                  5      n	U R                  U R                  S5      US'   XS	'   XS
'   U R                  U5      nXsXeS.$ )Nr   r  POSTzContent-Typezapplication/jsonr   r  zX-LyraWalletzX-LyraTimestampzX-LyraSignature)r  r  r  r  )r   strr  r  r  r  r  r  )
r  pathr   r  r  r  r  r  nowr  s
             r  signderive.sign	  s    iis#c)D0V 2G i$++-. --c??C	*.*:*:4<<I^*_'-0)*-6)*99V$DdOOr   r  )1000000000000000000)N__name__
__module____qualname____firstlineno__r   r  r  r  r  r   r  r   r   r  r  r  r  dictr  r  r   r%  r$  r
   r   rV  re  r   rs  r   rw  rv  r  r  r  r  r  r  r   r   floatr   r  r  r  r%  r   r4  r;  r@  rD  rP  rX  r  ro  rr  r   r   ry  r  r  r  r   r  r  r   r  r  r	   r  r  r  r  r  r  r  __static_attributes____classcell__)r  s   @r  r$   r$      s   S# Sj-t - ') 5$ -/ V: Vp *, <V <| /1 (T&\ ( /1 (T&\ ( 13 (tF| (d4 dF dL 68 M/ M/F M/^T4 T T6 Tl <@d[] @= @=S @= @=bfglbm @=D. .v . .` >BPTcgpr 3Ys 3Y# 3Y]` 3Yj <> -s -+ -8
6 
[ 
0jA\>L,s , mqy{ z zI zY zX] zfi zx fjx|  FH a3 a a9 aI a_b aru aF 9=R VJS VJ# VJp 59 (5c (5T 04$UYbd [? [?C [?s [?imnsit [?z 59tZ^gi Mc M MTW Mnrsxny M" 7;\`ik M M3 MVY Mptuzp{ M" 9=4^bkm M# MS MX[ M"As A
 
tD t& tE tl ?CQUdhqs DG3 DG DG3 DG^a DGL 37TX\eg MGC MGs MGRU MG^ 8<B ;8W ;84PX> ;8zIt IV IV 9=4^bkm G@# G@S G@X[ G@R
6 
2 *, A* A*F) )( 04$UYbd +O +OC +Os +Oimnyiz +OZ 37TX\eg +OC +Os +ORU +Olpq|l} +OZ&
T &
X &
Q\ &
P:s :	cc 	c4 	c	fs 	fD 	f
c 
3 
S 
# 
X\ 
dg 
 &eBSW P Pr  r$   )) ccxt.async_support.base.exchanger   ccxt.abstract.deriver   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r   r   r    ccxt.base.decimal_to_precisionr!   ccxt.base.preciser"   r$   r  r  r  <module>r     sg    6 ,  B  B  B  B  B  B  * 0 . ' . ) * . 4 %u'PX{ u'Pr  