
    E#it                    @   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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K/J0r0   " S S\\5      r1g)    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyDepositAddressGreeksIntLedgerEntryLeverage
MarginModeMarginModificationMarketNumOptionOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeMarketInterface)List)ExchangeError)AuthenticationError)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)ExchangeNotAvailable)	TICK_SIZE)Precisec                   D  ^  \ rS rSrS\4U 4S jjrS\4S jrSgS\S\	S	\S
\S\
4
U 4S jjjr0 4S\4S jjr0 4S jr0 4S\4S jjrS0 4U 4S jjrS r0 4S\\	   4S jjrShS\S\	S\4S jjr0 4S\S\4S jjrS0 4S\S\4S jjrS0 4S\S\S\4S jjrShS\S\	S\4S jjrSS0 4S\S\S\S\\   4S jjr ShS\	S\!4S jjr"SSS0 4S\S \S\S\S\\!   4
S! jjr#S\$4S" jr%0 4S\$4S# jjr&0 4S\4S$ jjr'S0 4S\S\\(   4S% jjr)ShS&\S\	4S' jjr*S(\4S) jr+ShS*\S\	S\,4S+ jjr-S0 4S\S,\.S-\/S.\0S/\14
S0 jjr2SS0 4S1\S\S,\.S-\/S.\1S/\14S2 jjr3S0 4S1\S\4S3 jjr4S0 4S\4S4 jjr5S0 4S1\S\S\,4S5 jjr6SSS0 4S\S\S\S\\,   4S6 jjr7SSS0 4S\S\S\S\\,   4S7 jjr8SSS0 4S\S\S\4S8 jjr9SSS0 4S\S\S\4S9 jjr:SSS0 4S:\S\S\S\\;   4S; jjr<S< r=ShS=\S>\>S\;4S? jjr?0 4S:\S\@4S@ jjrAShS>\>S\@4SA jjrB0 4S\S\C4SB jjrDS0 4S\S\E4SC jjrFShS\	S\C4SD jjrG0 4S\S.\0S\H4SE jjrI0 4S\S.\0S\H4SF jjrJ0 4S\S\H4SG jjrKShSH\S\	S\H4SI jjrL0 4S\4SJ jjrMShS\	4SK jjrN0 4S\S\O4SL jjrPShSM\S\	S\O4SN jjrQS0 4SM\RS\4SO jjrSSSS0 4S\S\S\4SP jjrTSQ rUSR rV0 4S\S\W4SS jjrXShST\S\	S\W4SU jjrY0 4S\\(   4SV jjrZ0 4S\S\[4SW jjr\ShSX\S\[4SY jjr]0 4S\S\^4SZ jjr_SiS[\S>\>S\	S\^4S\ jjr`S]S^0 SS4S_ jraS:\RS`\Sa\Sb\Sc\Sd\4Se jrbSfrcU =rd$ )jdelta   returnc                    > U R                  [        [        U ]  5       0 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_S/S_E0 S0S_S1S_S2S_S3S_S4S_S5S_S6S_S7S_S8S_S9S_S:S_S;S_S<S_S=S_S>S_S?S_S@S_E0 SAS_SBS_SCS_SDS_SES _SFS _SGS_SHS_SIS _SJS _SKS_SLS_SMS_SNS_SOS_SPS_SQS_E_SRSSSTSUSVSWSXSYSZS[S\S]S^S_S`Sa._SbScSdSdSe.SfSfSe.SgSh/SiSjSk._SlSm/ SnQ0/ SoQ/ SpQ/ SqQ/ SrQSs.Se._StSuSSU R	                  Sv5      U R	                  Sw5      U R	                  Sx5      U R	                  Sv5      /U R	                  Sy5      U R	                  Sz5      /U R	                  S{5      U R	                  Sz5      /U R	                  S|5      U R	                  S}5      /U R	                  S~5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      //U R	                  Sx5      U R	                  S}5      /U R	                  Sy5      U R	                  S}5      /U R	                  S{5      U R	                  S5      /U R	                  S|5      U R	                  S5      /U R	                  S~5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      //S.S.0_SU R
                  S   _SSSSS.0_SSSSSSSS.SSSS SS.SSSSS.SSSSSSSS.S SSSSSS.S SSSSSS.S SSSSSSSSS.SS0S.	SS0SS0SS0S.SS0SS0S.S._S[        _SSSS._S[        [        [        [        [        [        [        [        [        [        [        [        [        S.0 S._5      $ )Nidr-   namezDelta Exchange	countriesVC	rateLimiti,  versionv2hasCORSspotTmarginFswapfutureoption	addMargincancelAllOrderscancelOrdercloseAllPositionsclosePositioncreateOrdercreateReduceOnlyOrder	editOrderfetchBalancefetchClosedOrdersfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchLedgerfetchLeveragefetchLeverageTiersfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchPositionfetchPositionModefetchPositionsfetchPremiumIndexOHLCVfetchSettlementHistoryfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTransferfetchTransfersfetchUnderlyingAssetsfetchVolatilityHistoryfetchWithdrawalfetchWithdrawalsreduceMarginsetLeverage	setMarginsetMarginModesetPositionModetransferwithdraw
timeframes1m3m5m15m30m1h2h4h6h1d7d1w2w30d)r~   r   r   r   r   r   r   r   r   r   r   r   r   1Murlszchttps://user-images.githubusercontent.com/1294454/99450025-3be60a00-2931-11eb-9302-f4fd8d8589aa.jpgz"https://testnet-api.delta.exchange)publicprivatezhttps://api.delta.exchangezhttps://www.delta.exchangezhttps://docs.delta.exchangezhttps://www.delta.exchange/feesz2https://www.delta.exchange/app/signup/?code=IULYNB)logotestapiwwwdocfeesreferralr   get)assetsindicesproductszproducts/{symbol}tickersztickers/{symbol}zl2orderbook/{symbol}ztrades/{symbol}statszhistory/candleszhistory/sparklinessettings)orderszorders/{order_id}z#orders/client_order_id/{client_oid}%products/{product_id}/orders/leveragezpositions/margined	positionszorders/historyfillszfills/history/download/csvzwallet/balanceszwallet/transactionszwallet/transactions/downloadz%wallets/sub_accounts_transfer_historyzusers/trading_preferencessub_accountsprofile	heartbeatzdeposits/address)r   orders/bracketorders/batchr   zpositions/change_marginzpositions/close_allz$wallets/sub_account_balance_transferzheartbeat/creater   zorders/cancel_afterzorders/leverage)r   r   r   zpositions/auto_topupzusers/update_mmpzusers/reset_mmp)r   z
orders/allr   )r   postputdeleter   tradingz0.0015z0.00100100z0.00132501000z0.0015000z0.000910000z0.0007520000z0.00065z0.0006z0.0005)takermaker)	tierBased
percentager   r   tiers	userAgentchrome39optionsnetworkszTRC20(TRON)z
BEP20(BSC))TRC20BEP20features)lastmarkindex)triggerPriceTypeprice)IOCFOKPOGTD)
marginModetriggerPricer   triggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedselfTradePreventiontrailingicebergleveragemarketBuyByCostmarketBuyRequiresPriced   i )r   limitdaysBack	untilDayssymbolRequired)r   r   triggerr   r   i     )r   r   r   daysBackCanceledr   r   r   r   r     )	sandboxrD   createOrdersr^   rd   ra   fetchOrdersrH   r_   extendsdefault)linearinverse)r   r:   r<   r=   precisionModerequiredCredentials)apiKeysecret
exceptions)insufficient_marginorder_size_exceed_availablerisk_limits_breachedinvalid_contractimmediate_liquidationout_of_bankruptcy!self_matching_disrupted_post_onlyimmediate_execution_post_only
bad_schemainvalid_api_keyinvalid_signatureopen_order_not_foundunavailable)exactbroad)deep_extendsuperr-   describeparse_number
userAgentsr*   r&   r'   r$   r%   r"   r(   r)   )self	__class__s    D/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/delta.pyr   delta.describe   s   eT ; = A@
'A@
$A@
 $A@
 	A@

 tA@
  EEE %E 	E
 %E $E TE "4E tE $TE  E tE (E TE E  $T!E" "4#E$ %E& &t'E( ()E* 1%+E,  -E. &u/E0 #D1E2 *53E4 $T5E6 t7E8 "49E: t;E<  =E> %e?E@ "4AEB #ECED +EEEF GEH !$IEJ +EKEL  MEN dOEP $TQER "4SET tUEV #EWEX dYEZ !$[E\  ]E^ $U_E` !$aEb )%cEd )$eEf tgEh tiEj kEl TmEn toEp  qEr !$sEt (uEv )%wEx "4yEz #D{E| }E~ tE@ UAEB  CED "5EEF EGEH EIEA@
Z [A@
z }BC
 ;; 41 :P{A@
\  "(U/#A]A@
` !%"&!..x8!..x8 "..s3T5F5Fx5PQ!..u5t7H7H7RS!..u5t7H7H7RS!..v68I8I'8RS!..v68I8I(8ST!..w79J9J99UV!..w79J9J99UV" "..s3T5F5Fw5OP!..u5t7H7H7QR!..u5t7H7H7RS!..v68I8I)8TU!..v68I8I(8ST!..w79J9J89TU!..w79J9J89TU"aA@
X 4YA@
Z *)[A@
f #&+(, %)$(%)-
 -2).+004%)7 $(#'"&#(	( #(/4$)#($)+027;$> %)&+!$$*%+*/& #'&+!$#($)*/( $(&+!$$*,-%+#($)*/	*  #y?B y
 "9 "9 	 "9 "9 	YTgA@
P	 YQ	A@
R	 "$S	A@
Z	  ,=3?,6(1-9)59E5A",':)<,9#7 #[	A@
 A A	    symbolc                 <   SnUR                  S5      nUR                  S5      nS nS nS nUR                  S5      S:  a7  U R                  US5      nU R                  US5      nU R                  US5      nO6U R                  US5      nU R                  US5      nU R                  US5      nUb  USS  US	S -   USS	 -   nUnU R                  US	5      n	U R                  U5      n
U R	                  U
5      n0 S
US-   U-   S-   U	-   S-   U-   _SUS-   U-   S-   U-   S-   U-   S-   U	-   S-   U-   _SU_SU_SU_SU_SU_SU_SS_SS_SS _SS _SS_SS_SS_SS_SS_SU R                  S5      UU
US:X  a  S OS!U R                  U	5      S S S".S S S#.S S S#.S S S#.S$.S S%.	E$ )&NUSDT-/r   r            r1   r  :basequotesettlebaseIdquoteIdsettleIdactiveFtyper>   r   r   r:   r<   r=   Tr;   1Ccallr   amountr   minmax)r  r   cost)	contractcontractSizeexpiryexpiryDatetime
optionTypestrike	precisionlimitsinfo)splitfindsafe_stringconvert_expire_date	parse8601r   )r   r  r  optionParts
symbolBaser  r   r"  r  r#  datetime	timestamps               r   create_expired_option_market"delta.create_expired_option_market^  s   ll3'\\#&

;;sb ##J2D%%k15F))+q9J##K3D%%k15F))+q9JABZ&1+-q;F!!+q1++F3NN8,	+
*s"T)C/&83>G+
dSj5(3.7#=FLvUX[[^hh+
 D+
 U	+

 f+
 d+
 u+
 +
 e+
 H+
 d+
 t+
 E+
 E+
 e+
  d!+
" e#+
$  --c2&%/3%6&U''/  
  
   U+
 +	
r  NmarketIdmarket	delimiter
marketTypec                 B  > US L=(       aY    UR                  S5      =(       dA    UR                  S5      =(       d)    UR                  S5      =(       d    UR                  S5      nU(       a   XR                  ;  a  U R                  U5      $ [        [
        U ]  XX45      $ )Nz-Cz-PzC-zP-)endswith
startswithmarkets_by_idr0  r   r-   safe_market)r   r2  r3  r4  r5  isOptionr   s         r   r:  delta.safe_market  s    D(  e0A0A$0G  0dXM^M^_cMd  0djrj}j}  C  kD  0d  JR  J]  J]  ^b  JcX););;44X>>UD-h	VVr  c                 p    U R                  U5      nU R                  US0 5      nU R                  USS5      $ )z
fetches the current integer timestamp in milliseconds from the exchange server
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the exchange server
resultserver_timeMbP?)publicGetSettings	safe_dictsafe_integer_product)r   paramsresponser>  s       r   
fetch_timedelta.fetch_time  s;     ))&1(B7((FFr  c                     U R                  U5      nU R                  US0 5      nU R                  US5      nUS:X  a  SOSnU R                  USSU R	                  5       5      nUUSSUS	.$ )
z
the latest known information on the availability of the exchange API
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
r>  under_maintenancetruemaintenanceokr?  r@  N)statusupdatedetaurlr&  )rA  rB  r)  rC  milliseconds)r   rD  rE  r>  underMaintenancerM  rN  s          r   fetch_statusdelta.fetch_status  s     ))&1l (B7++F4GH#3v#=D++FM5$J[J[J]^
 	
r  c                 ,   U R                  U5      nU R                  US/ 5      n0 n[        S[        U5      5       GH  nX5   nU R	                  US5      nU R                  US5      nU R                  U5      n	U R                  US/ 5      n
0 n[        S[        U
5      5       H  nX   nU R	                  US5      nU R                  U5      nUUU R	                  US5      UU R	                  US5      S	:H  U R	                  US
5      S	:H  U R	                  US5      S	:H  U R                  US5      U R                  US5      SS.U R                  US5      SS.S.S.	X'   M     U R                  UUU	U R	                  US5      USU R	                  US
5      S	:H  U R	                  US5      S	:H  U R                  US5      U R                  U R                  U R	                  US5      5      5      SSS.U R                  US5      SS.S.USS.5      XI'   GM     U$ )z
fetches all available currencies on an exchange

https://docs.delta.exchange/#get-list-of-all-assets

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
r>  r   r  r1   r   networkr2   rM  enableddeposit_statuswithdrawal_statusbase_withdrawal_feemin_deposit_amountNr  min_withdrawal_amount)depositr|   )	r1   rV  r2   r&  r  r]  r|   feer%  r$  )r  r|   crypto)r1   	numericIdcoder2   r&  r  r]  r|   r^  r$  r%  r   r  )publicGetAssets	safe_listrangelenr)  safe_integersafe_currency_codenetwork_id_to_codesafe_numbersafe_currency_structurer   parse_precision)r   rD  rE  
currenciesr>  icurrencyr1   r`  ra  chainsr   jchain	networkIdnetworkCodes                   r   fetch_currenciesdelta.fetch_currencies  sW    ''/b ^^Hh;
q#j/*A!}H!!(H5B))(D9I**2.D^^Hj"=FH1c&k*	 ,,UI>	"55i@#* ,,UF;!"..uh?9L#//7GHIU $ 0 08K LPY Y++E3HI $(#3#3E;O#P#'$
 $(#3#3E;R#S#'%	)%	 +0  77&((6: ++H6FG9T ,,X7JKyX''2GH!..t/C/CDDTDTU]_jDk/lm&*48#//:QR#! % '9 FL? +h r  Fc                 f  > [         [        U ]  X5      nU R                  U R                  S5      nUb  U(       a(  U R                  U R                  5      U R                  S'   U R                  U R                  S5      nUb  U(       a(  U R                  U R                  5      U R                  S'   U$ )NcurrenciesByNumericIdmarketsByNumericId)r   r-   load_marketsrB  r   index_by_stringified_numeric_idrl  markets)r   reloadrD  r{  rw  rx  r   s         r   ry  delta.load_marketsm  s    t1&A $t||=T U!)f484X4XY]YhYh4iDLL01!^^DLL:NO&6151U1UVZVbVb1cDLL-.r  c                     0 nUc  g [        UR                  5       5      n[        S[        U5      5       H&  nX4   nX   nU R	                  US5      nUc  M"  XbU'   M(     U$ )Nr   r`  )listkeysrd  re  r)  )r   inputr>  r  rm  keyitemnumericIdStrings           r   rz  %delta.index_by_stringified_numeric_idw  sl    =EJJL!q#d)$A'C:D"..t[AO&&*?# % r  c                    U R                  U5      nU R                  US/ 5      n/ n[        S[        U5      5       GH  nX5   nU R	                  US5      nUS:X  a  M"  U R                  US0 5      nU R                  US0 5      n	U R                  US5      n
U R                  US0 5      nU R	                  U	S	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5      nU R                  U5      nU R                  U5      nUS:H  nUS:H  nUS:H  nUS:H  nUS:H  nUS:H  nU=(       d    U=(       d    UnU R	                  US5      nU R	                  US5      nU R                  U5      nU R                  US5      nSnU(       a1  U R                  U R                  U R	                  US5      5      5      nOU R                  S5      nUU:H  n Sn!US-   U-   n"U(       d  U(       d  U(       ae  U"S-   U-   n"U(       d  U(       aM  U"S-   U R                  U5      -   n"U(       a,  SnSn#Sn!U(       a  Sn#Sn!OU(       a  Sn#S n!U"S-   U-   S-   U#-   n"OS!nOS"nU R	                  US#5      n$UR                  0 S
U_S$U_S	U"_S%U_S&U_S'U_S(U_S)U_S*U_S+U_SU_S,U(       a  SOS-_S"U_S!U_SU_S.U$S/:H  _S0U(       + _U(       a  SOU U(       a  SOU (       + U R                  US15      U R                  US25      U(       a  SOUUU R                  U5      U R                  U5      U!UU R                  US35      S4.SSS5.U R                  S5      U R                  US65      S5.SSS5.U R                  US75      SS5.S8.U R                  U R	                  US95      5      US:.E5        GM     U$ );z
retrieves data on all markets for delta

https://docs.delta.exchange/#get-list-of-products

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
r>  r   contract_typeoptions_combosquoting_assetunderlying_assetsettling_assetproduct_specsr  r1   call_optionsput_optionsmove_optionsr:   perpetual_futuresfuturesstrike_pricesettlement_timecontract_valueNunderlying_precisionr  r  r  r  r>   r  r  Pr   Mmover=   r<   stater`  r  r  r  r  r  r  r  r;   Fr  liver  taker_commission_ratemaker_commission_rate	tick_sizer  r  position_size_limitmin_size)r   r  r   r  launch_time)r   r   r   r   r  r   r!  r#  r"  r$  r%  createdr&  )publicGetProductsrc  rd  re  r)  rB  rf  rg  r+  ri  r   rk  yymmddappendiso8601)%r   rD  rE  r{  r>  rm  r3  r  quotingAssetunderlyingAssetsettlingAssetproductSpecsr  r  r  r1   r`  r  r  r  callOptions
putOptionsmoveOptionsr:   r<   r=   r>   r#  r!  r   r  amountPrecisionr   r"  r  letterr  s%                                        r   fetch_marketsdelta.fetch_markets  s    ))&1f ..8R8q#g,'AZF##FO<D''>>&/2FL"nnV5GLO NN63CDM>>&/2FL%%ox@F&&|X>G''x@H!!&(3B))&$7I**62D++G4E,,X6F>1K-/J>1KFND//Di'F!>Z>;F%%fn=F!--f6GHN^^N3F++F4DEL"O"&"3"3D4H4HIYIYZfh~I  5A  #B #'"3"3C"8oFJCZ%'Fv#.V#c\DKK,??F'!$%+
%%(F).J(%(F)/J!'#!6!<v!E'!D$$VW5EMM 3b3Y3 &3 	3
 3 &3 &3 73 H3 3 3 $$E3 3 &3 &3  5F?!3" H#3$ #'$F#'4Z))&2IJ))&2IJ(,, "&,,v"6++F3(-!--fkB  $#!
  $005#//8MN
  $#
  $//
C#$  >>$*:*:6=*QRe3 3u (\ r  tickerc           
         U R                  USS5      nU R                  US5      nU R                  XB5      nU R                  US5      nU R                  US0 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U R                  US5      _SU_SU_SS _SS _SS _SS _U R                  US5      U R                  US5      U R                  US5      U R                  US5      US.EU5      $ )Nr/  r@  r  closequotesr.  highlowbidbest_bid	bidVolumebid_sizeaskbest_ask	askVolumeask_sizevwapopenr   previousClosechanger   averagevolumeturnover
mark_price
spot_price)
baseVolumequoteVolume	markPrice
indexPricer&  )rC  r)  safe_symbolrB  safe_tickerr  ri  )r   r  r3  r/  r2  r  r   r  s           r   parse_tickerdelta.parse_ticker  s   h --fk5I	##FH5!!(30"5 !
f!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4##FJ7!
 ))&*=!
 4##FJ7!
 ))&*=!
 D!
 D$$VV4!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **68<++FJ?))&,?**6<@-!
. / 	r  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US0 5      nU R                  Xc5      $ )a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://docs.delta.exchange/#get-ticker-for-a-product-by-symbol

: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>`
r  r1   r>  )ry  r3  publicGetTickersSymbolextendrB  r  r   r  rD  r3  requestrE  r>  s          r   fetch_tickerdelta.fetch_tickerE  so     	V$fTl
 ..t{{7/KLz (B7  00r  symbolsc                 &   U R                  5         U R                  U5      nU R                  U5      nU R                  US/ 5      n0 n[	        S[        U5      5       H  nU R                  XF   5      nUS   nXuU'   M!     U R                  USU5      $ )a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://docs.delta.exchange/#get-tickers-for-products

: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>`
r>  r   r  )ry  market_symbolspublicGetTickersrc  rd  re  r  filter_by_array_tickers)	r   r  rD  rE  r   r>  rm  r  r  s	            r   fetch_tickersdelta.fetch_tickers  s     	%%g.((0F ..8R8q#g,'A&&wz2FH%F#6N ( ++FHgFFr  r   c           	          U R                  5         U R                  U5      nSUS   0nUb  X%S'   U R                  U R                  XS5      5      nU R	                  US0 5      nU R                  XtS   SSSSS	5      $ )
a  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://docs.delta.exchange/#get-l2-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
r  r1   Ndepthr>  buysellr   size)ry  r3  publicGetL2orderbookSymbolr  rB  parse_order_book)r   r  r   rD  r3  r  rE  r>  s           r   fetch_order_bookdelta.fetch_order_bookk  s     	V$fTl
 $G224;;w3OP& (B7$$VH-=tUFT[]cddr  tradec                 r   U R                  US5      nU R                  US5      nU R                  U R                  US5      5      nU R                  USSU5      nU R                  US5      nU R                  US5      nU R                  US0 5      nU R                  US	5      n	U R	                  X5      n
U R                  US
5      nU R                  US5      nUc  US:X  a  SnOUS:X  a  SnU R                  US5      nU R                  US0 5      nU R                  US5      nUb  UR                  SS5      nU R                  US5      nS nUb;  U R                  US0 5      nU R                  US	5      nU R                  U5      nUUS.nU R                  UUUU R                  U5      U
UUUUS UUUS.U5      $ )Nr1   order_id
created_atr/  r@  r   r  productr  seller_rolesider   r  r   r  role	meta_data
order_type_order 
commissionr  r  rn  )r1   orderr/  r.  r  r  r  r   r  r  takerOrMakerr^  r&  )	r)  r+  rC  rB  r  replacerg  
safe_trader  )r   r  r3  r1   orderIdr/  priceStringamountStringr  r2  r  
sellerRoler  r  metaDatar  feeCostStringr^  r  feeCurrencyIdfeeCurrencyCodes                        r   parse_tradedelta.parse_trade  s   ` eT*""5*5NN4#3#3E<#HI	--e[%S	&&ug6''v6..	26##GX6!!(3%%e];
v.<W$w&''v6>>%b9,7<<"-D((=$ NN74DbIM ,,]HEM"55mDO%+C "Y/ "( 
  	r  sincec                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  Xd5      5      nU R	                  US/ 5      nU R                  XX#5      $ )a  
get the list of most recent trades for a particular symbol

https://docs.delta.exchange/#get-public-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
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
r  r1   r>  )ry  r3  publicGetTradesSymbolr  rc  parse_trades)	r   r  r  r   rD  r3  r  rE  r>  s	            r   fetch_tradesdelta.fetch_trades  sp     	V$fTl
 --dkk'.JK  (B7  >>r  c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Ntimer  r  r  r  r  )safe_timestampri  )r   ohlcvr3  s      r   parse_ohlcvdelta.parse_ohlcv  sn     v.UF+UF+UE*UG,UH-
 	
r  r~   	timeframec                    U R                  5         U R                  U5      nSU R                  U R                  X"5      0nU R	                  U5      nU(       a  UOSnU R                  USS5      n	U	SLn
U
(       a  U R                  U	5      n	Uc(  U
(       a  U	OU R                  5       nXS'   XU-  -
  US'   O8U R                  US-  5      nXS'   U
(       a  U	OU R                  XU-  5      US'   U R                  US	5      nUS
:X  a  SUS   -   US'   OUS:X  a  US   S   S   US'   OUS   US'   U R                  US	S/5      nU R                  U R                  Xu5      5      nU R                  US/ 5      nU R                  XX#U5      $ )a  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://docs.delta.exchange/#delta-exchange-api-v2-historical-ohlc-candles-sparklines

: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 str [params.until]: timestamp in ms of the latest candle to fetch
:returns int[][]: A list of candles ordered, open, high, low, close, volume

resolutionr   untilr@  Nendstarti  r   r   zMARK:r1   r  r   r&  
spot_indexr>  )ry  r3  r)  r}   parse_timeframerC  parse_to_intsecondssumomitpublicGetHistoryCandlesr  rc  parse_ohlcvs)r   r  r  r  r   rD  r3  r  durationr  untilIsDefinedr  r  r   rE  r>  s                   r   fetch_ohlcvdelta.fetch_ohlcv*  s    	V$$**4??IQ
 ''	2D))&'5At+%%e,E=)%t||~C EN"X%55GG%%edl3E$G&4U$((5RZJZ:[GEN  1F? '&, 6GHg &v| <X FGH &tGH6GW#56//G0LM (B7  5IIr  c                    U R                  US/ 5      nSU0nU R                  U R                  S0 5      n[        S[	        U5      5       Hr  nX%   nU R                  US5      nU R                  XG5      nUc  UOUS   n	U R                  5       n
U R                  US5      U
S'   U R                  US	5      U
S
'   XU	'   Mt     U R                  U5      $ )Nr>  r&  rw  r   asset_idra  balancetotalavailable_balancefree)rc  rB  r   rd  re  r)  accountsafe_balance)r   rE  balancesr>  rw  rm  r#  
currencyIdrn  ra  r'  s              r   parse_balancedelta.parse_balancea  s    >>(Hb9) $t||=TVX Yq#h-(AkG))':>J~~&;HH"*"2:&9IDllnG#//CGG"..w8KLGFO"4L )   ((r  c                 f    U R                  5         U R                  U5      nU R                  U5      $ )a4  
query for balance and get the amount of funds available for trading or funds locked in orders

https://docs.delta.exchange/#get-wallet-balances

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
)ry  privateGetWalletBalancesr+  )r   rD  rE  s      r   fetch_balancedelta.fetch_balancep  s3     	008, !!(++r  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US0 5      nU R                  Xc5      $ )ae  
fetch data on a single open contract trade position

https://docs.delta.exchange/#get-position

:param str symbol: unified market symbol of the market the position is held in, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`

product_idr`  r>  )ry  r3  privateGetPositionsr  rB  parse_positionr  s          r   fetch_positiondelta.fetch_position  so     	V$&-
 ++DKK,HI (B7""622r  c                     U R                  5         U R                  U5      nU R                  US/ 5      nU R                  XA5      $ )a8  
fetch all open positions

https://docs.delta.exchange/#get-margined-positions

:param str[]|None 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>  )ry  privateGetPositionsMarginedrc  parse_positions)r   r  rD  rE  r>  s        r   fetch_positionsdelta.fetch_positions  sE     	33F;, (B7##F44r  positionc                 Z   U R                  US5      nU R                  X25      nUS   nU R                  USS5      nU R                  US5      nS nUb=  [        R                  " US5      (       a  SnO[        R
                  " US5      (       a  SnU R                  0 S	U_S
S _SU_SS _SS _SU R                  US5      _SU R                  US5      _SS _SS _SU R                  U5      _SU R                  US5      _SS _SU_SS _SU_SU R                  U5      _SS _S S S S S S S S S.E5      $ )Nproduct_symbolr  r/  r@  r  r   r  r  r&  r1   notionalr   liquidationPriceliquidation_price
entryPriceentry_priceunrealizedPnlr   	contractsr  r  r  r   r.  maintenanceMargin)maintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager   marginRatior   r   )
r)  r:  rC  r+   	string_gt	string_ltsafe_positionri  r   r  )r   r<  r3  r2  r  r/  
sizeStringr  s           r   r4  delta.parse_position  s   8 ##H.>?!!(3!--hUK	%%h7
!  S11"":s33!! #
H#
$#
 f#
 	#

 $#
  0 0;N O#
 $**8]C#
 T#
 $#
 **:6#
 D,,V^D#
 #
 D#
 d#
 #
  Y/!#
"  ##
$ ,0!'+!#3#
  	r  rM  c                 4    SSSSS.nU R                  X!U5      $ )Nr  closedcanceled)r  pendingrR  	cancelledr)  )r   rM  statusess      r   parse_order_statusdelta.parse_order_status  s*    #	
 &99r  r  c                 *   U R                  US5      nU R                  US5      nU R                  US5      nS nUb:  UR                  S5      S:  a  U R                  U5      nOU R                  USS5      nU R                  US5      nU R	                  U R
                  S0 5      nU R                  XU5      nUc  UOUS	   n	U R                  U R                  US
5      5      n
U R                  US5      nU R                  US5      nUb  UR                  S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S nU R                  US5      nUbC  S nUb9  U R	                  US   S0 5      nU R                  US	5      nU R                  U5      nUUS.nU R                  0 SU_SU_SU_SU_SU R                  U5      _SS _S	U	_SU_SU_SU_SU_SS _SU_S S _S!U_S"U
_S#U_S$S 0EU5      $ )%Nr1   client_order_idr  r  r   r@  r2  rx  r  r  r  r  r  r  limit_pricer  unfilled_sizeaverage_fill_pricepaid_commissionr&  r  r  clientOrderIdr/  r.  lastTradeTimestampr  r   r  r  r  filled	remainingrM  r^  trades)r)  r(  r+  rC  rB  r   
safe_valuerX  r  rg  
safe_orderr  )r   r  r3  r1   r`  	createdAtr/  r2  rx  r  rM  r  r  r   r  rc  r  r^  r  r   r  r  s                         r   parse_orderdelta.parse_order  s   t eT*((0AB$$UL9		 ~~c"a' NN95	 55e\5Q	##E<8!^^DLL:NPRS!3vF$n6(3C(()9)9%)IJv.|4<<"-D  6!!%0$$UO<	""5*>?((0AB$"O! $vf~?OQS T $ 0 0 I"&"9"9-"H%+C   
E 
" 
 ] 
 	 

 Y/ 
 !$ 
 f 
 D 
 D 
 U 
 f 
 D 
 w 
 d 
  
  f! 
" 3# 
$ d% 
& ' 	r  r  r  r  r   c                    U R                  5         US-   nU R                  U5      nUS   U R                  US   U5      UUS.n	US:X  a  U R                  US   U5      U	S'   U R	                  USS5      n
U R                  USS/5      nU
b  XS'   U R                  US	5      nU(       a  XS
'   U R                  US	5      nU R                  U R                  X5      5      nU R                  US0 5      nU R                  X5      $ )a  
create a trade order

https://docs.delta.exchange/#place-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 bool [params.reduceOnly]: *contract only* indicates if self order is to reduce the size of a position
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r  r`  r  )r2  r  r  r  r   r\  r`  r[  
reduceOnlyreduce_onlyr>  )ry  r3  amount_to_precisionprice_to_precisionsafe_string_2r  	safe_boolprivatePostOrdersr  rB  rh  )r   r  r  r  r  r   rD  	orderTyper3  r  r`  rk  rE  r>  s                 r   create_orderdelta.create_order  s    	8O	V$ -,,VH-=vF#

 7?%)%<%<VH=Mu%UGM"**6?DUV6O5F#GH$)6%&^^FL9
%/M"YYv|4F))$++g*FGJ (B7//r  r1   c                 Z   U R                  5         U R                  U5      n[        U5      US   S.n	Ub  [        U R                  X%5      5      U	S'   Ub  U R	                  X&5      U	S'   U R                  U R                  X5      5      n
U R                  U
S5      nU R                  X5      $ )aE  
edit a trade order

https://docs.delta.exchange/#edit-order

: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 the currency you want to trade in units of the base currency
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r`  r1   r2  r  r\  r>  )	ry  r3  intrm  rn  privatePutOrdersr  rB  rh  )r   r1   r  r  r  r  r   rD  r3  r  rE  r>  s               r   
edit_orderdelta.edit_order  s     	V$b' -
 !$":":6"JKGFO%)%<%<V%KGM"((W)EF$ (3//r  c                 "   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      n[	        U5      US   S.nU R                  U R                  XS5      5      nU R                  US5      nU R                  Xt5      $ )a@  
cancels an open order

https://docs.delta.exchange/#cancel-order

:param str id: order id
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
z) cancelOrder() requires a symbol argumentr`  rv  r>  )	r#   r1   ry  r3  rw  privateDeleteOrdersr  rB  rh  )r   r1   r  rD  r3  r  rE  r>  s           r   cancel_orderdelta.cancel_order  s     >#DGG.Y$YZZV$b' -
 ++DKK,HIJ (3//r  c                     Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nU R	                  U R                  XB5      5      nU R                  SU05      /$ )aN  
cancel all open orders in a market

https://docs.delta.exchange/#cancel-all-open-orders

:param str symbol: unified market symbol of the market to cancel orders in
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
z- cancelAllOrders() requires a symbol argumentr2  r`  r&  )r#   r1   ry  r3  privateDeleteOrdersAllr  rf  )r   r  rD  r3  r  rE  s         r   cancel_all_ordersdelta.cancel_all_ordersJ  s     >#DGG.]$]^^V$&-

 ..t{{7/KL OO 
 	
r  c                    U R                  5         SnUb  U R                  U5      nU R                  U/ SQ5      nU R                  U/ SQ5      n0 nSnUb%  XVS'   U R	                  U R                  Xc5      5      nO$XS'   U R                  U R                  Xc5      5      nU R                  US0 5      nU R                  X5      $ )a  
fetches information on an order made by the user

https://docs.delta.exchange/#get-order-by-id
https://docs.delta.exchange/#get-order-by-client-oid

: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]: client order id of the order
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
N)r`  
client_oid	clientOidr  r  r>  )	ry  r3  safe_string_nr  &privateGetOrdersClientOrderIdClientOidr  privateGetOrdersOrderIdrB  rh  )	r   r1   r  rD  r3  r`  r  rE  r>  s	            r   fetch_orderdelta.fetch_orderj  s     	[[(F**63_`6#OP$$1L!BB4;;wC_`H"$J33DKK4PQH2 (B7//r  c                 (    U R                  SXX45      $ )a  
fetch all unfilled currently open orders

https://docs.delta.exchange/#get-active-orders

:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch open orders for
:param int [limit]: the maximum number of open order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
privateGetOrdersfetch_orders_with_methodr   r  r  r   rD  s        r   fetch_open_ordersdelta.fetch_open_orders  s     ,,-?PU^^r  c                 (    U R                  SXX45      $ )a  
fetches information on multiple closed orders made by the user

https://docs.delta.exchange/#get-order-history-cancelled-and-closed

: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>`
privateGetOrdersHistoryr  r  s        r   fetch_closed_ordersdelta.fetch_closed_orders  s     ,,-FW\eer  c                    U R                  5         0 nS nUb  U R                  U5      nUS   US'   Ub  [        U5      S-   US'   Ub  XFS'   S nUS:X  a!  U R                  U R	                  Xe5      5      nO&US:X  a   U R                  U R	                  Xe5      5      nU R                  US/ 5      n	U R                  XX45      $ )	Nr`  product_ids000
start_time	page_sizer  r  r>  )ry  r3  strr  r  r  rc  parse_orders)
r   methodr  r  r   rD  r  r3  rE  r>  s
             r   r  delta.fetch_orders_with_method  s    	
 [[(F%+K%8GM"$'J$6GL!#(K '',,T[[-IJH0033DKK4PQH0 (B7  >>r  c                 "   U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  [        U5      S-   US'   Ub  X5S'   U R                  U R	                  XT5      5      nU R                  US/ 5      nU R                  XX#5      $ )a  
fetch all trades made by the user

https://docs.delta.exchange/#get-user-fills-by-filters

: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
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Nr`  r  r  r  r  r>  )ry  r3  r  privateGetFillsr  rc  r  )	r   r  r  r   rD  r  r3  rE  r>  s	            r   fetch_my_tradesdelta.fetch_my_trades  s     	
 [[(F%+K%8GM"$'J$6GL!#(K ''G(DE\ (B7  >>r  ra  c                     U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X5S'   U R                  U R                  XT5      5      nU R	                  US/ 5      nU R                  XX#5      $ )a  
fetch the history of changes, actions done by the user or operations that altered the balance of the user

https://docs.delta.exchange/#get-wallet-transactions

:param str [code]: unified currency code, default is None
:param int [since]: timestamp in ms of the earliest ledger entry, default is None
:param int [limit]: max number of ledger entries to return, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
Nr`  r"  r  r>  )ry  rn  privateGetWalletTransactionsr  rc  parse_ledger)	r   ra  r  r   rD  r  rn  rE  r>  s	            r   fetch_ledgerdelta.fetch_ledger>	  s     	
 }}T*H"*;"7GJ#(K 44T[[5QR, (B7  5@@r  c                 :    SSSSSSSS.nU R                  X!U5      $ )Npnltransactionr^  r  r   rebate)r  r]  
withdrawalr  
conversionreferral_bonuscommission_rebaterV  )r   r  typess      r   parse_ledger_entry_typedelta.parse_ledger_entry_typeq	  s5    $'! )!)
 T22r  r  rn  c                 x   U R                  US5      nS nS nU R                  US0 5      nU R                  US5      nS nU R                  US5      n	U	S:X  d  U	S:X  d  U	S:X  d  U	S:X  d  U	S	:X  d  U	S
:X  a  SnOU	S:X  d  U	S:X  d  U	S:X  d  U	S:X  a  SnU R                  U	5      n	U R                  US5      n
U R                  U R                  S5      nU R	                  XU5      nUc  S OUS   nU R                  US5      nU R                  U R                  US5      5      nU R                  US5      n[        R                  " S[        R                  " X5      5      nSnU R                  UUUUUUU	UU R                  U5      U R                  U5      U R                  U5      UUU R                  U5      S S.U5      $ )Nuuidr  transaction_idtransaction_typer]  r  r  r  withdrawal_cancellationpromo_creditinr  r  r  perpetual_futures_fundingoutr"  rw  ra  r  r  r#  r   rL  )r&  r1   	directionr'  referenceIdreferenceAccountr  rn  r  beforeafterrM  r/  r.  r^  )r)  rB  r  r   re  r+  r+   
string_max
string_subsafe_ledger_entryr   r  )r   r  rn  r1   r  r'  r  r  r  r  r*  rw  ra  r  r/  r  r  rM  s                     r   parse_ledger_entrydelta.parse_ledger_entry	  s     dF+	>>$R8&&x1AB&89I4+>#>DL\D\bfjobouy  ~W  vW  ]a  es  ]sIl"(<$,BV\`d\I++D1%%dJ7
 $t||=T U??#8hO (tx/?!!$1NN4#3#3D,#GH	  y1##C););E)JK%%"& 0''/''/&&u-"Y/'
  ! 	r  c                 P   U R                  5         U R                  U5      nSUS   0nU R                  US5      nUb&  U R                  XQ5      US'   U R	                  US5      nU R                  U R                  XB5      5      nU R                  US0 5      nU R                  Xs5      $ )aC  
fetch the deposit address for a currency associated with self account
:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: unified network code
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
asset_symbolr1   rV  r>  )	ry  rn  safe_string_uppernetwork_code_to_idr  privateGetDepositsAddressr  rB  parse_deposit_address)r   ra  rD  rn  r  rs  rE  r>  s           r   fetch_deposit_addressdelta.fetch_deposit_address	  s     	==&HTN
 ,,VY?"!%!8!8!KGIYYvy1F11$++g2NO$ (B7))&;;r  c                     U R                  US5      nU R                  US5      nU R                  US5      nU R                  U5        UU R                  XB5      U R                  U5      UU R                  US5      S.$ )Naddressr  rV  memo)r&  rn  rV  r  tag)r)  check_addressrg  rh  )r   depositAddressrn  r  r2  rr  s         r   r  delta.parse_deposit_address	  s     "">9=##NNC$$^Y?	7#"//C..y9##NF;
 	
r  c                    U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      nU R                  US0 5      nU R                  Xc5      $ )a7  
fetch the current funding rate

https://docs.delta.exchange/#get-ticker-for-a-product-by-symbol

: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>`
r<   z0 fetchFundingRate() supports swap contracts onlyr  r1   r>  )ry  r3  r%   r1   r  r  rB  parse_funding_rater  s          r   fetch_funding_ratedelta.fetch_funding_rate	  s     	V$f~DGG&XXYYfTl
 ..t{{7/KL\ (B7&&v66r  c                     U R                  5         U R                  U5      nSS0nU R                  U R                  X25      5      nU R	                  US/ 5      nU R                  XQ5      $ )ar  
fetch the funding rate for multiple markets

https://docs.delta.exchange/#get-tickers-for-products

:param str[]|None symbols: list of unified market symbols
: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-rates-structure>`, indexed by market symbols
contract_typesr  r>  )ry  r  r  r  rc  parse_funding_rates)r   r  rD  r  rE  ratess         r   fetch_funding_ratesdelta.fetch_funding_rates:
  sn     	%%g.1
 ((W)EF` x26''77r  c                    U R                  USS5      nU R                  US5      nU R                  US5      n[        R                  " US5      n0 SU_SU R	                  XB5      _SU R                  US5      _S	U R                  US
5      _SS _SS _SU_SU R                  U5      _SU R                  U5      _SS _SS _SS _SS _SS _SS _SS _SS _SS 0E$ )Nr/  r@  r  funding_rater   r&  r  r  r  r  interestRateestimatedSettlePricer.  fundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)rC  r)  r+   
string_divr  ri  r  r   )r   r  r3  r/  r2  fundingRateStringr  s          r   r  delta.parse_funding_rate|
  sh   V --hUK	##Hh7 ,,X~F(():EB
H
d&&x8
 ))(LA
 $**8\B	

 D
 #D
 
 Y/
 4,,[9
 
 t
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
r  c                 (    U R                  XSU5      $ )a@  
add margin

https://docs.delta.exchange/#add-remove-position-margin

:param str symbol: unified market symbol
:param float amount: amount of margin to add
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
addmodify_margin_helperr   r  r  rD  s       r   
add_margindelta.add_margin
  s     ((GGr  c                 (    U R                  XSU5      $ )a]  
remove margin from a position

https://docs.delta.exchange/#add-remove-position-margin

:param str symbol: unified market symbol
:param float amount: the amount of margin to remove
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
reducer  r  s       r   reduce_margindelta.reduce_margin
  s     ((6JJr  c                 ,   U R                  5         U R                  U5      n[        U5      nUS:X  a  [        R                  " US5      nUS   US.nU R                  U R                  Xd5      5      nU R                  US0 5      nU R                  X5      $ )Nr  z-1r`  )r2  delta_marginr>  )	ry  r3  r  r+   
string_mul privatePostPositionsChangeMarginr  rB  parse_margin_modification)	r   r  r  r  rD  r3  r  rE  r>  s	            r   r  delta.modify_margin_helper
  s    V$V8''5F -"
 88W9UV0 (B7--f==r  datac                     U R                  US5      nU R                  X25      nUUS   S SS U R                  US5      S S S S S.
$ )Nr>  r  isolatedr;   )
r&  r  r  r   r  r$  ra  rM  r/  r.  )r)  r:  ri  )r   r  r3  r2  s       r   r  delta.parse_margin_modification
  sa    * ##D*:;!!(3X&$%%dH5
 	
r  c                    U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      nU R                  US0 5      nU R                  Xc5      $ )a7  
retrieves the open interest of a derivative market

https://docs.delta.exchange/#get-ticker-for-a-product-by-symbol

:param str symbol: unified 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 onlyr  r1   r>  )ry  r3  r$   r1   r  r  rB  parse_open_interestr  s          r   fetch_open_interestdelta.fetch_open_interest#  s     	V$j!TWW'\\]]fTl
 ..t{{7/KLj (B7''77r  c                 >   U R                  USS5      nU R                  US5      nU R                  U R                  XB5      U R	                  US5      U R	                  US5      U R	                  US5      U R	                  US5      UU R                  U5      US.U5      $ )	Nr/  r@  r  oi_valueoi_value_usdoi_contractsoi)r  r  r  openInterestAmountopenInterestValuer/  r.  r&  )rC  r)  safe_open_interestr  ri  r  )r   interestr3  r/  r2  s        r   r  delta.parse_open_interestl  s    d --hUK	##Hh7&&&&x8**8Z@++HnE"&"2"28^"L!%!1!1(D!A"Y/	(
 	 		r  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US0 5      nU R                  Xc5      $ )a$  
fetch the set leverage for a market

https://docs.delta.exchange/#get-order-leverage

: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>`
r2  r`  r>  )ry  r3  )privateGetProductsProductIdOrdersLeverager  rB  parse_leverager  s          r   fetch_leveragedelta.fetch_leverage  so     	V$&-
 AA$++gB^_ (B7""622r  r   c                     U R                  US5      nU R                  US5      nUU R                  X25      U R                  US5      UUS.$ )Nindex_symbolr   margin_mode)r&  r  r   longLeverageshortLeverage)r)  rf  r  safe_string_lower)r   r   r3  r2  leverageValues        r   r  delta.parse_leverage  sW    ##Hn=))(J?&&x800=I)*
 	
r  c                     Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUS   US.nU R	                  U R                  XS5      5      $ )a)  
set the level of leverage for a market

https://docs.delta.exchange/#change-order-leverage

:param float leverage: the rate of leverage
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
z) setLeverage() requires a symbol argumentr`  )r2  r   )r#   r1   ry  r3  *privatePostProductsProductIdOrdersLeverager  )r   r   r  rD  r3  r  s         r   set_leveragedelta.set_leverage  sf     >#DGG.Y$YZZV$ - 
 >>t{{7?[\\r  c                 :   U R                  5         SnUb  U R                  U5      nSS0nUb  X6S'   U R                  U R                  Xd5      5      nU R	                  US/ 5      nU R                  X5      n	U R                  U	S5      n
U R                  XS   X#5      $ )a  
fetches historical settlement records

https://docs.delta.exchange/#get-product-settlement-prices

:param str symbol: unified market symbol of the settlement history
:param int [since]: timestamp in ms
:param int [limit]: number of records
:param dict [params]: exchange specific params
:returns dict[]: a list of `settlement history objects <https://docs.ccxt.com/#/?id=settlement-history-structure>`
Nstatesexpiredr  r>  r/  r  )ry  r3  r  r  rc  parse_settlementssort_byfilter_by_symbol_since_limit)r   r  r  r   rD  r3  r  rE  r>  settlementssorteds              r   fetch_settlement_historydelta.fetch_settlement_history  s     	[[(Fi
 #(K ))$++g*FGv (B7,,V<k;7009I5XXr  c                     U R                  US5      nU R                  US5      nUU R                  XB5      U R                  US5      U R                  U5      US.$ )Nr  r  settlement_price)r&  r  r   r/  r.  )r)  r  ri  r+  )r   
settlementr3  r.  r2  s        r   parse_settlementdelta.parse_settlementK  se    l ##J0AB##J9&&x8%%j2DE1 
 	
r  c                     / n[        S[        U5      5       H&  nUR                  U R                  X   U5      5        M(     U$ )Nr   )rd  re  r  r1  )r   r*  r3  r>  rm  s        r   r'  delta.parse_settlements  s=    q#k*+AMM$//GH ,r  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US0 5      nU R                  Xc5      $ )a  
fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract

https://docs.delta.exchange/#get-ticker-for-a-product-by-symbol

: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>`
r  r1   r>  )ry  r3  r  r  rB  parse_greeksr  s          r   fetch_greeksdelta.fetch_greeks  so     	V$fTl
 ..t{{7/KLj (B7  00r  greeksc                    U R                  USS5      nU R                  US5      nU R                  XB5      nU R                  US0 5      nU R                  US0 5      n0 SU_SU_SU R	                  U5      _SU R                  US5      _SU R                  US5      _S	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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 _U R                  US5      US.E$ )Nr/  r@  r  r9  r  r.  r-   gammathetavegarhobidSizer  askSizer  bidImpliedVolatilitybid_ivaskImpliedVolatilityask_ivmarkImpliedVolatilitymark_ivbidPricer  askPricer  r  r  	lastPricer  )underlyingPricer&  )rC  r)  r  rB  r  ri  )r   r9  r3  r/  r2  r  r   r  s           r   r6  delta.parse_greeks  s   d --fk5I	##FH5!!(3vx4"5
f

 Y/
 T%%eW5	

 T%%eW5
 T%%eW5
 D$$UF3
 4##E51
 t''
;
 t''
;
 #D$4$4VX$F
 #D$4$4VX$F
 $T%5%5fi%H
 ((<
 ((<
  ))&,?!
" #
$  $//E'
 	
r  c                     U R                  5         SSS.nU R                  U R                  X!5      5      nU R                  U R	                  US0 5      5      nU/$ )a9  
closes all open positions for a market type

https://docs.delta.exchange/#close-all-positions

:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.user_id]: the users id
:returns dict[]: A list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
T)close_all_portfolioclose_all_isolatedr>  )ry  privatePostPositionsCloseAllr  r4  rB  )r   rD  r  rE  r<  s        r   close_all_positionsdelta.close_all_positions%  s_     	#'"&

 44T[[5QR &&t~~h"'MNzr  c                     U R                  5         SnUb  U R                  U5      nU R                  U5      nU R                  US0 5      nU R	                  XS5      $ )aJ  
fetches the margin mode of a trading pair

https://docs.delta.exchange/#get-user

:param str symbol: unified symbol of the market to fetch the margin mode for
: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>`
Nr>  )ry  r3  privateGetProfilerB  parse_margin_mode)r   r  rD  r3  rE  r>  s         r   fetch_margin_modedelta.fetch_margin_mode<  s_     	[[(F))&1@ (B7%%f55r  r   c                 B    S nUb  US   nUUU R                  US5      S.$ )Nr  r  )r&  r  r   rV  )r   r   r3  r  s       r   rT  delta.parse_margin_mode  s7    H%F**:}E
 	
r  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US0 5      nU R                  USU5      $ )aW  
fetches option data that is commonly found in an option chain

https://docs.delta.exchange/#get-ticker-for-a-product-by-symbol

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `option chain structure <https://docs.ccxt.com/#/?id=option-chain-structure>`
r  r1   r>  N)ry  r3  r  r  rB  parse_optionr  s          r   fetch_optiondelta.fetch_option  ss     	V$fTl
 ..t{{7/KLj (B7  v66r  rq  c                 "   U R                  US5      nU R                  XC5      nU R                  US0 5      nU R                  USS5      n0 SU_SS _SUS   _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U R                  US5      _SS _SS _SU R                  US5      _SS _$ )Nr  r  r/  r@  r&  rn  r.  impliedVolatilityrF  openInterestr  rG  r  rH  r  midPriceimpact_mid_pricer  r  rI  rJ  r  r  r   r  r  r  )r)  r:  rB  rC  r  ri  )r   rq  rn  r3  r2  r  r/  s          r   rZ  delta.parse_option  s   d ##E84!!(3x4--e[%H	
E

 fX&
 	

 Y/
  !1!1&)!D
 D,,UD9
 ((<
 ((<
 ((1CD
 ))%>
 
 t//|D
 d
 $
  $**5(;!
" 4#
 	
r  r   GETc                    SU R                   -   S-   U R                  X5      -   nU R                  S   U   U-   nU R                  X@R	                  U5      5      n	US:X  a  U	(       a  USU R                  U	5      -   -  nOUS:X  a  U R                  5         [        U R                  5       5      n
U R                  U
S.nX:-   U-   nUS:X  a$  U	(       a  SU R                  U	5      -   nX-  nX-  nOU R                  U	5      nX-  nSUS	'   U R                  U R                  U5      U R                  U R                  5      [        R                  5      nXS
'   XXeS.$ )Nr  r   r   ?r   )zapi-keyr/  rc  zapplication/jsonzContent-Type	signature)rP  r  bodyheaders)r6   implode_paramsr   r  extract_params	urlencodecheck_required_credentialsr  r  r   jsonhmacencoder   hashlibsha256)r   pathr   r  rD  rh  rg  requestPathrP  queryr/  authqueryStringrf  s                 r   sign
delta.sign(  sI   DLL(3.1D1DT1RRiis#k1		&"5"5d";<(?sT^^E222I++-DLLN+I;;&G %3D"%u(="=K'D&Cyy'*<'		$++d"3T[[5Mw~~^I#,K dOOr  reasonrP  r  rh  rg  c
                    Uc  g U R                  US0 5      n
U R                  U
S5      nUb[  U R                  S-   U-   nU R                  U R                  S   X5        U R                  U R                  S   X5        [        U5      eg )Nerrorra   r   r   )rB  r)  r1   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr!   )r   ra  ry  rP  r  rh  rg  rE  requestHeadersrequestBodyr{  	errorCodefeedbacks                r   handle_errorsdelta.handle_errorsD  s     x"5$$UF3	 ww}t+H001I9_001I9_))r   )NNNN)N)NN)e__name__
__module____qualname____firstlineno__r   r   r  r0  r   r   r   r:  r   rF  rS  r   rt  ry  rz  r    r  dictr   r  r  r   r   r  r   r  r   r  r  r  r  r  r   r+  r/  r5  r   r:  r4  rX  r   rh  r   r   floatr   rs  ry  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  rw  r"  r,  r1  r'  r
   r7  r6  rP  r   rU  rT  r   r[  rZ  rw  r  __static_attributes____classcell__)r   s   @r   r-   r-      s#   B# BH
A
3 A
FWC W WRU Wjm W  zI W W !# 	Gs 	G #% F
P ') pZ pd #(  $& l$v, l\	P4 P P6 Pd 02 M13 M1f M1^ 04B UGW UG7 UGn :>b &es &e3 &eY &eP] ]v ] ]~ 6:UW "?3 "?s "?# "?\`af\g "?H
 
4 
( 9=4^bkm 5J# 5J# 5JS 5JX[ 5Jrvw{r| 5Jn) ) $&  ,(  ,D 24 3S 3: 26b "5w "5T(^ "5HAt AV AF: :o ov o ob gksu M03 M0i M0y M0RW M0`c M0^ `drv  @B .0S .0# .0Y .0i .0Y\ .0lo .0` 37r 90s 90C 90v /32 
 
@ 26b 40c 403 40U 40l /3TXac _ _3 _c _hlmrhs _ 154VZce f# fS fPS fjnotju f >BPTcgpr 1?s 1?# 1?]` 1?f -1tRV_a M?c M? M?C M?^ (,$TZ\ 1A 1AC 1As 1Aaefqar 1Af35t 5x 5; 5n 79 $<# $<^ $<L
h 
R` 
6 68 @7 @7K @7D 6:" @87 @8 @8DB
6 B
[ B
H =? H He HCU H @B KC K KFX K FH #>3 #>L^ #>J"
d "
F "
N` "
H 79 G8# G8R=F =~ 24 3S 3 3@	
t 	
V 	
x 	
 9=R ]S ]# ]@ 6:[_hj SYs SY# SYUX SYj>
@ 02 E13 E1f E1NK
4 K
 K
6 K
Z *, X . 57 O6 O6: O6b
D 
* 
 02 E73 E7f E7NH
$ H
( H
6 H
]c H
T &eBSW P8# s  c TX `c  r  r-   )2ccxt.base.exchanger   ccxt.abstract.deltar   rp  ccxt.base.typesr   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   typingr    ccxt.base.errorsr!   r"   r#   r$   r%   r&   r'   r(   r)   ccxt.base.decimal_to_precisionr*   ccxt.base.preciser+   r-   r  r  r   <module>r     st    ( +  m  m  m  m  m  m  m  m  * 0 . ' & . ) * 1 4 %y8Hk y8r  