
    ei                    L   d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z! d dl"m#Z# d dl$m%Z% d dl$m&Z& d dl$m'Z' d d	l$m(Z( d d
l$m)Z) d dl$m*Z* d dl$m+Z+ d dl$m,Z, d dl$m-Z- d dl.m/Z/ d dl0m1Z1  G d dee          Z2dS )    )Exchange)ImplicitAPIN)AnyADL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                       e Zd Zdef fdZdefdZdhdededed	ede	f
 fd
Z
i fdefdZi fdZi fdefdZdi f fd	Zd Zi fdee         fdZdidededefdZi fdedefdZdi fdedefdZdi fdededefdZdidededefdZddi fdedededee         fdZdidede fdZ!dddi fdededededee          f
d Z"de#fd!Z$i fde#fd"Z%i fdefd#Z&di fdedee'         fd$Z(did%edefd&Z)d'efd(Z*did)edede+fd*Z,di fded+e-d,e.d-e/d.e0f
d/Z1ddi fd0eded+e-d,e.d-e0d.e0fd1Z2di fd0edefd2Z3di fdefd3Z4di fd0edede+fd4Z5dddi fdedededee+         fd5Z6dddi fdedededee+         fd6Z7dddi fdededefd7Z8dddi fdededefd8Z9dddi fd9edededee:         fd:Z;d; Z<did<ed=e=de:fd>Z>i fd9ede?fd?Z@did=e=de?fd@ZAi fdedeBfdAZCdi fdedeDfdBZEdidedeBfdCZFi fded-e/deGfdDZHi fded-e/deGfdEZIi fdedeGfdFZJdidGededeGfdHZKi fdefdIZLdidefdJZMi fdedeNfdKZOdidLededeNfdMZPdi fdLeQdefdNZRdddi fdededefdOZSdP ZTdQ ZUi fdedeVfdRZWdidSededeVfdTZXi fdee'         fdUZYi fdedeZfdVZ[didWedeZfdXZ\i fdede]fdYZ^djdZed=e=dede]fd[Z_di fdedee`         fd\Zadid]edede`fd^Zbd_d`i ddfdaZcd9eQdbedceddedeedfefdgZd xZeS )kdeltareturnc                 D	   |                      t          t          |                                           i ddddddgddd	d
di dd ddddddddddddddddddddddddddddddddi dd d dd!dd"dd#d d$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/di d0dd1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@di dAddBddCddDddEddFddGd dHd dIddJddKd dLd dMddNddOddPddQddddRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddededfdgdgdfdhdigdjdkdldmdng doig dpg dqg drg dsdtdfdudvdd|                     dw          |                     dx          |                     dy          |                     dw          g|                     dz          |                     d{          g|                     d|          |                     d{          g|                     d}          |                     d~          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          gg|                     dy          |                     d~          g|                     dz          |                     d~          g|                     d|          |                     d          g|                     d}          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          ggddid| j        d         dddddidddddddddddd dddddddddddddddd ddddddd ddddddd dddddddddddid	ddiddiddidddiddidddt          dddddt          t          t          t          t          t          t          t          t          t          t          t          t          di d          S )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fetchPositionADLRankfetchPositionModefetchPositionsfetchPositionsADLRank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    V/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/delta.pyr   zdelta.describe   s
   eT 2 2 ; ; = = C@
'C@
$C@
 $C@
 	C@

 tC@
  GGG %G 	G
 %G $G TG "4G tG $TG  G tG (G TG G  $T!G" "4#G G$ %G& &t'G( ()G* 1%+G,  -G. &u/G0 #D1G2 *53G4 $T5G6 t7G8 "49G: t;G<  =G> %e?G@ "4AGB #ECGD +EEG G GF GGH !$IGJ +EKGL  MGN dOGP $TQGR "4SGT tUGV #EWGX dYGZ !$[G\  ]G^ '_G` $UaGb !$cGd (eGf )%gG G Gh )$iGj tkGl tmGn oGp TqGr tsGt  uGv !$wGx (yGz )%{G| "4}G~ #DG@ AGB tCGD UEGF  GGH "5IG GJ "!MG G GC@
^  _C@
~ }BC 
 ;;  41 :P C@
`    "  (      U/ /#A AaC@
d !%"&!..x88!..x88 "..s33T5F5Fx5P5PQ!..u55t7H7H7R7RS!..u55t7H7H7R7RS!..v668I8I'8R8RS!..v668I8I(8S8ST!..w779J9J99U9UV!..w779J9J99U9UV" "..s33T5F5Fw5O5OP!..u55t7H7H7Q7QR!..u55t7H7H7R7RS!..v668I8I)8T8TU!..v668I8I(8S8ST!..w779J9J89T9TU!..w779J9J89T9TU"  eC@
\ 4]C@
^ *) _C@
j #&+(, %)$(%)- -
 -2).+004%)7 7 $(#'"&#(	( ( #(/4$)#($)+027;$ $> %)&+!$$*%+*/& & #'&+!$#($)*/( ( $(&+!$$*,-%+#($)*/	* 	*  #y? ?B y
 "9 "9 	  "9 "9 	 YT TkC@
T	 YU	C@
V	 "$ $W	C@
^	  ,=3?,6(1-9)59E5A",':)<,9#7  # _	C@
 C C C	    symbolc                    d}|                     d          }|                     d          }d }d }d }|                    d          dk    rC|                     |d          }|                     |d          }|                     |d          }nB|                     |d          }|                     |d          }|                     |d          }| |dd          |d	d         z   |dd	         z   }|}|                     |d	          }	|                     |          }
|                     |
          }i d
|dz   |z   dz   |	z   dz   |z   d|dz   |z   dz   |z   dz   |z   dz   |	z   dz   |z   d|d|d|d|d|d|dddddd dd ddddddddddd|                     d          ||
|dk    rd nd!|                     |	          d d d"d d d#d d d#d d d#d$d d%	S )&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_marketz"delta.create_expired_option_market`  s    ll3''\\#&&

;;sb  ##J22D%%k155F))+q99JJ##K33D%%k155F))+q99JABBZ&1+-qs;F!!+q11++F3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2&%/3%6%6&&U''//    
   
     U+
 +
 +
 +	
r  NmarketIdmarket	delimiter
marketTypec                 J   |d uoS|                     d          p>|                     d          p)|                    d          p|                    d          }|r|| j        vr|                     |          S t	          t
          |                               ||||          S )Nz-Cz-PzC-zP-)endswith
startswithmarkets_by_idr1  r   r.   safe_market)r   r2  r3  r4  r5  isOptionr  s         r  r:  zdelta.safe_market  s    D(  e0A0A$0G0G  0dXM^M^_cMdMd  0djrj}j}  C  kD  kD  0d  JR  J]  J]  ^b  Jc  Jc 	?X);;;44X>>>UD!!--h	:VVVr  c                    K   |                      |           d{V }|                     |di           }|                     |dd          S )a  
        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
        Nresultserver_timeMbP?)publicGetSettings	safe_dictsafe_integer_product)r   paramsresponser=  s       r  
fetch_timezdelta.fetch_time  sZ       //77777777(B77((FFFr  c                   K   |                      |           d{V }|                     |di           }|                     |d          }|dk    rdnd}|                     |dd|                                           }||dd|d	S )
a  
        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>`
        Nr=  under_maintenancetruemaintenanceokr>  r?  )statusupdatedetaurlr'  )r@  rA  r*  rB  milliseconds)r   rC  rD  r=  underMaintenancerK  rL  s          r  fetch_statuszdelta.fetch_status  s       //77777777l (B77++F4GHH#3v#=#=D++FM5$J[J[J]J]^^
 
 	
r  c                 *  K   |                      |           d{V }|                     |dg           }i }t          dt          |                    D ]=}||         }|                     |d          }|                     |d          }|                     |          }	|                     |dg           }
i }t          dt          |
                    D ]}|
|         }|                     |d          }|                     |          }|||                     |d          ||                     |d	          d
k    |                     |d          d
k    |                     |d          d
k    |                     |d          |                     |d          dd|                     |d          dddd	||<   | 	                    |||	|                     |d          |d|                     |d          d
k    |                     |d          d
k    |                     |d          | 
                    |                     |                     |d                              ddd|                     |d          ddd|dd          ||	<   ?|S )a  
        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
        Nr=  r   r  r1   r   networkr2   rK  enableddeposit_statuswithdrawal_statusbase_withdrawal_feemin_deposit_amountr  min_withdrawal_amount)depositr~   )	r1   rS  r2   r'  r  rZ  r~   feer&  r%  )r  r~   crypto)r1   	numericIdcoder2   r'  r  rZ  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   rC  rD  
currenciesr=  icurrencyr1   r]  r^  chainsr   jchain	networkIdnetworkCodes                   r  fetch_currencieszdelta.fetch_currencies  s      --f55555555b ^^Hh;;
q#j//** 3	 3	A!!}H!!(H55B))(D99I**2..D^^Hj"==FH1c&kk**  q	 ,,UI>>	"55i@@#* ,,UF;;!"..uh??9L#//7GHHIU $ 0 08K L LPY Y++E3HII $(#3#3E;O#P#P#'$ $
 $(#3#3E;R#S#S#'% %	 	) )%%(  77&((6:: ++H6FGG9T ,,X7JKKyX''2GHH!..t/C/CDDTDTU]_jDkDk/l/lmm&*488#//:QRR#! !  % '9 9  F4LL* r  Fc                 n  K   t          t          |                               ||           d {V }|                     | j        d          }||r"|                     | j                  | j        d<   |                     | j        d          }||r"|                     | j                  | j        d<   |S )NcurrenciesByNumericIdmarketsByNumericId)r   r.   load_marketsrA  r   index_by_stringified_numeric_idri  markets)r   reloadrC  rw  rs  rt  r  s         r  ru  zdelta.load_marketso  s      eT**77GGGGGGGG $t|=T U U!)f)484X4XY]Yh4i4iDL01!^^DL:NOO&6&151U1UVZVb1c1cDL-.r  c                     i }|d S t          |                                          }t          dt          |                    D ]0}||         }||         }|                     |d          }|+|||<   1|S )Nr   r]  )listkeysra  rb  r*  )r   inputr=  r{  rj  keyitemnumericIdStrings           r  rv  z%delta.index_by_stringified_numeric_idy  s    =4EJJLL!!q#d))$$ 	+ 	+Aq'C:D"..t[AAO&&*F?##r  c                 B  K   |                      |           d{V }|                     |dg           }g }t          dt          |                    D ]}||         }|                     |d          }|dk    r(|                     |di           }|                     |di           }	|                     |d          }
|                     |d	i           }|                     |	d
          }|                     |d
          }|                     |
d
          }|                     |d
          }|                     |d          }|                     |          }|                     |          }|                     |          }|dk    }|dk    }|dk    }|dk    }|dk    }|dk    }|p|p|}|                     |d          }|                     |d          }|                     |          }| 	                    |d          }d}|r=| 
                    |                     |                     |d                              }n| 
                    d          }||k    } d}!|dz   |z   }"|s|s|rP|"dz   |z   }"|s|rB|"dz   |                     |          z   }"|r"d}d}#d}!|rd}#d}!n|rd}#d }!|"dz   |z   dz   |#z   }"nd!}nd"}|                     |d#          }$|                    i d|d$|d
|"d%|d&|d'|d(|d)|d*|d+|d|d,|rdnd-d"|d!|d|d.|$d/k    d0| |rdn| |rdn|  | 	                    |d1          | 	                    |d2          |rdn|||                     |          | 
                    |          |!|| 	                    |d3          d4ddd5| 
                    d          | 	                    |d6          d5ddd5| 	                    |d7          dd5d8|                     |                     |d9                    |d:           |S );a  
        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
        Nr=  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_value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'  )publicGetProductsr`  ra  rb  r*  rA  rc  rd  r,  rf  r   rh  yymmddappendiso8601)%r   rC  rD  rw  r=  rj  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_marketszdelta.fetch_markets  s      //77777777f ..8R88q#g,,'' m	 m	AQZF##FO<<D'''>>&/2FFL"nnV5GLLO NN63CDDM>>&/2FFL%%ox@@F&&|X>>G''x@@H!!&(33B))&$77I**622D++G44E,,X66F>1K-/J>1KFND//Di'F!>Z>;F%%fn==F!--f6GHHN^^N33F++F4DEEL"O 9"&"3"3D4H4HIYIYZfh~II  5A  5A  #B  #B #'"3"3C"8"8oFJCZ%'F "v " "#. "V "#c\DKK,?,??F ('!$%+
% 0%(F).JJ( 0%(F)/J!'#!6!<v!E'!D$$VW55EMM 3b3Y3 &3 	3
 3 &3 &3 73 H3 3 3 $1$$E3 3 &3 &3  5F?!3" H#3$ #'2$$F#'744Z))&2IJJ))&2IJJ(, >, "&,,v"6"6++F33(-!--fkBB   $#! !
  $0055#//8MNN 
  $# 
  $//
CC#  $  >>$*:*:6=*Q*QRRe3 3 3 3 3 3 3h r  tickerc           
      b   |                      |dd          }|                     |d          }|                     ||          }|                     |d          }|                     |di           }|                     i d|d|d|                     |          d|                     |d          d|                     |d          d	|                     |d
          d|                     |d          d|                     |d          d|                     |d          dd d|                     |d          d|d|dd dd dd dd |                     |d          |                     |d          |                     |d          |                     |d          |d|          S )Nr0  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'  )rB  r*  safe_symbolrA  safe_tickerr  rf  )r   r  r3  r0  r2  r  r   r  s           r  parse_tickerzdelta.parse_ticker  s6   h --fk5II	##FH55!!(F3300"55 !
f!
!
 Y//!
 D$$VV44	!

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

        https://docs.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>`
        Nr  r1   r=  )ru  r3  publicGetTickersSymbolextendrA  r  r   r  rC  r3  requestrD  r=  s          r  fetch_tickerzdelta.fetch_tickerG  s       !!!!!!!!!V$$fTl
 44T[[&5Q5QRRRRRRRRz (B77  000r  symbolsc                   K   |                                   d{V  |                     |          }|                     |           d{V }|                     |dg           }i }t	          dt          |                    D ]*}|                     ||                   }|d         }|||<   +|                     |d|          S )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>`
        Nr=  r   r  )ru  market_symbolspublicGetTickersr`  ra  rb  r  filter_by_array_tickers)	r   r  rC  rD  r   r=  rj  r  r  s	            r  fetch_tickerszdelta.fetch_tickers  s       !!!!!!!!!%%g....v66666666F ..8R88q#g,,'' 	$ 	$A&&wqz22FH%F#F6NN++FHgFFFr  r   c           	      T  K   |                                   d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |di           }|                     ||d         ddddd	          S )
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
        Nr  r1   depthr=  buysellr   size)ru  r3  publicGetL2orderbookSymbolr  rA  parse_order_book)r   r  r   rC  r3  r  rD  r=  s           r  fetch_order_bookzdelta.fetch_order_bookm  s       !!!!!!!!!V$$fTl
 $GG88Wf9U9UVVVVVVVV& (B77$$VVH-=tUFT[]cdddr  tradec                    |                      |d          }|                      |d          }|                     |                      |d                    }|                     |dd|          }|                      |d          }|                      |d          }|                     |di           }|                      |d	          }	|                     |	|          }
|                      |d
          }|                      |d          }||dk    rd}n|dk    rd}|                      |d          }|                     |di           }|                      |d          }||                    dd          }|                      |d          }d }|G|                     |di           }|                      |d	          }|                     |          }||d}|                     ||||                     |          |
||||d |||d|          S )Nr1   order_id
created_atr0  r?  r   r  productr  seller_rolesider   r  r   r  role	meta_data
order_type_order 
commissionr  r  rk  )r1   orderr0  r/  r  r  r  r   r  r  takerOrMakerr[  r'  )	r*  r,  rB  rA  r  replacerd  
safe_trader  )r   r  r3  r1   orderIdr0  priceStringamountStringr  r2  r  
sellerRoler  r  metaDatar  feeCostStringr[  r  feeCurrencyIdfeeCurrencyCodes                        r  parse_tradezdelta.parse_trade  sE   ` eT**""5*55NN4#3#3E<#H#HII	--e[%SS	&&ug66''v66..	266##GX66!!(F33%%e];;
v..<W$$w&&''v66>>%b99,77<<"--D((==$ NN74DbIIM ,,]HEEM"55mDDO%+ C "Y// "( 
  
   	r  sincec                 4  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )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>`
        Nr  r1   r=  )ru  r3  publicGetTradesSymbolr  r`  parse_trades)	r   r  r  r   rC  r3  r  rD  r=  s	            r  fetch_tradeszdelta.fetch_trades  s       !!!!!!!!!V$$fTl
 33DKK4P4PQQQQQQQQ  (B77  >>>r  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Ntimer  r  r  r  r  )safe_timestamprf  )r   ohlcvr3  s      r  parse_ohlcvzdelta.parse_ohlcv  s     v..UF++UF++UE**UG,,UH--
 	
r  r   	timeframec                   K   |                                   d{V  |                     |          }d|                     | j        ||          i}|                     |          }|r|nd}|                     |dd          }	|	du}
|
r|                     |	          }	|)|
r|	n|                                 }||d<   |||z  z
  |d<   n=|                     |dz            }||d<   |
r|	n|                     |||z            |d<   |                     |d	          }|d
k    rd|d         z   |d<   n)|dk    r|d         d         d         |d<   n|d         |d<   | 	                    |d	dg          }| 
                    |                     ||                     d{V }|                     |dg           }|                     |||||          S )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
        N
resolutionr   untilr?  endstarti  r   r   zMARK:r1   r  r   r'  
spot_indexr=  )ru  r3  r*  r   parse_timeframerB  parse_to_intsecondssumomitpublicGetHistoryCandlesr  r`  parse_ohlcvs)r   r  r  r  r   rC  r3  r  durationr  untilIsDefinedr  r  r   rD  r=  s                   r  fetch_ohlcvzdelta.fetch_ohlcv,  s$      !!!!!!!!!V$$$**4?IyQQ
 ''	22(D))&'5AAt+ 	-%%e,,E=)=%%t||~~C GEN"UX%55GG%%edl33E$GG&4[UU$((5%RZJZ:[:[GEN  11F?? '&, 6GHg &v| <X FGH &tGH6GW#56655dkk'66R6RSSSSSSSS (B77  E5IIIr  c                    |                      |dg           }d|i}|                     | j        di           }t          dt	          |                    D ]}||         }|                     |d          }|                     ||          }||n|d         }	|                                 }
|                     |d          |
d<   |                     |d	          |
d
<   |
||	<   |                     |          S )Nr=  r'  rs  r   asset_idr^  balancetotalavailable_balancefree)r`  rA  r   ra  rb  r*  accountsafe_balance)r   rD  balancesr=  rs  rj  r  
currencyIdrk  r^  r  s              r  parse_balancezdelta.parse_balancec  s    >>(Hb99) $t|=TVX Y Yq#h--(( 	# 	#AqkG))':>>J~~&;ZHHH"*"2::&9IDllnnG#//CCGG"..w8KLLGFO"F4LL  (((r  c                    K   |                                   d{V  |                     |           d{V }|                     |          S )aZ  
        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>`
        N)ru  privateGetWalletBalancesr  )r   rC  rD  s      r  fetch_balancezdelta.fetch_balancer  sg       !!!!!!!!!66v>>>>>>>>, !!(+++r  c                 0  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        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>`
        N
product_idr]  r=  )ru  r3  privateGetPositionsr  rA  parse_positionr  s          r  fetch_positionzdelta.fetch_position  s       !!!!!!!!!V$$&-
 11$++gv2N2NOOOOOOOO (B77""66222r  c                    K   |                                   d{V  |                     |           d{V }|                     |dg           }|                     ||          S )af  
        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>`
        Nr=  )ru  privateGetPositionsMarginedr`  parse_positionsr   r  rC  rD  r=  s        r  fetch_positionszdelta.fetch_positions  s~       !!!!!!!!!99&AAAAAAAA, (B77##FG444r  positionc                    |                      |d          }|                     ||          }|d         }|                     |dd          }|                      |d          }d }|/t          j        |d          rd}nt          j        |d          rd}|                     i d	|d
d d|dd dd d|                     |d          d|                     |d          dd dd d|                     |          d|                     |d          dd d|dd d|d| 	                    |          dd d d d d d d d d d          S )Nproduct_symbolr  r0  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:  rB  r,   	string_gt	string_ltsafe_positionrf  r   r  )r   r*  r3  r2  r  r0  
sizeStringr  s           r  r#  zdelta.parse_position  s   8 ##H.>??!!(F33!--hUKK	%%h77
! S11 ":s33 !! #
H#
$#
 f#
 	#

 $#
  0 0;N O O#
 $**8]CC#
 T#
 $#
 **:66#
 D,,V^DD#
 #
 D#
 d#
 #
  Y//!#
"  ##
$ ,0!'+!#3#
 #
 #
   	r  rK  c                 >    ddddd}|                      |||          S )Nr  closedcanceled)r  pendingr?  	cancelledr*  )r   rK  statusess      r  parse_order_statuszdelta.parse_order_status  s4    #	
 
 &&999r  r  c                    |                      |d          }|                      |d          }|                      |d          }d }|F|                    d          dk    r|                     |          }n|                     |dd          }|                      |d          }|                     | j        di           }|                     |||          }||n|d	         }	|                     |                      |d
                    }
|                      |d          }|                      |d          }||                    dd          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }d }|                      |d          }|Qd }|H|                     |d         di           }|                      |d	          }| 	                    |          }||d}| 
                    i d|d|d|d|d|                     |          dd d	|	d|d|d|d|dd d|d d d!|d"|
d#|d$d i|          S )%Nr1   client_order_idr  r  r   r?  r!  rt  r  r  r  r  r  r  limit_pricer  unfilled_sizeaverage_fill_pricepaid_commissionr'  r  r  clientOrderIdr0  r/  lastTradeTimestampr  r   r  r  r  filled	remainingrK  r[  trades)r*  r)  r,  rB  rA  r   
safe_valuerE  r  rd  
safe_orderr  )r   r  r3  r1   rL  	createdAtr0  r2  rt  r  rK  r  r  r   r  rO  r  r[  r  r  r  r  s                         r  parse_orderzdelta.parse_order!  s+   t eT**((0ABB$$UL99		 ~~c""a'' NN955		 55e\5QQ	##E<88!^^DL:NPRSS!3XvFF$n6(3C(()9)9%)I)IJJv..|44<<"--D  66!!%00$$UO<<	""5*>??((0ABB$"O! $vf~?OQS T T $ 0 0 I I"&"9"9-"H"H%+ C   
E 
" 
 ] 
 	 

 Y// 
 !$ 
 f 
 D 
 D 
 U 
 f 
 D 
 w 
 d 
  
  f! 
" 3# 
$ d% 
  
& '  	r  r  r  r  r   c                   K   |                                   d{V  |dz   }|                     |          }|d         |                     |d         |          ||d}	|dk    r|                     |d         |          |	d<   |                     |dd	          }
|                     |dd	g          }|
|
|	d	<   |                     |d
          }|r||	d<   |                     |d
          }|                     |                     |	|                     d{V }| 	                    |di           }| 
                    ||          S )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>`
        Nr  r]  r  )r!  r  r  r  r   rH  rL  rG  
reduceOnlyreduce_onlyr=  )ru  r3  amount_to_precisionprice_to_precisionsafe_string_2r  	safe_boolprivatePostOrdersr  rA  rT  )r   r  r  r  r  r   rC  	orderTyper3  r  rL  rV  rD  r=  s                 r  create_orderzdelta.create_order  s}      !!!!!!!!!8O	V$$ -,,VH-=vFF#

 

 7??%)%<%<VH=Mu%U%UGM"**6?DUVV6O5F#GHH$)6G%&^^FL99
 	5%/GM"YYv|44F//GV0L0LMMMMMMMMJ (B77///r  r1   c                   K   |                                   d{V  |                     |          }t          |          |d         d}	|&t          |                     ||                    |	d<   ||                     ||          |	d<   |                     |                     |	|                     d{V }
|                     |
d          }|                     ||          S )a  
        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>`
        Nr]  r1   r!  r  rH  r=  )	ru  r3  intrX  rY  privatePutOrdersr  rA  rT  )r   r1   r  r  r  r  r   rC  r3  r  rD  r=  s               r  
edit_orderzdelta.edit_order  s      !!!!!!!!!V$$b'' -
 
 !$":":66"J"JKKGFO%)%<%<VU%K%KGM"..t{{7F/K/KLLLLLLLL$ (33///r  c                 |  K   |t          | j        dz             |                                  d{V  |                     |          }t	          |          |d         d}|                     |                     ||                     d{V }|                     |d          }|                     ||          S )av  
        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>`
        Nz) cancelOrder() requires a symbol argumentr]  r`  r=  )	r$   r1   ru  r3  ra  privateDeleteOrdersr  rA  rT  )r   r1   r  rC  r3  r  rD  r=  s           r  cancel_orderzdelta.cancel_order  s       >#DG.Y$YZZZ!!!!!!!!!V$$b'' -
 
 11$++gv2N2NOOOOOOOOJ (33///r  c                 ,  K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|                     |                     ||                    }|                     d|i          gS )a|  
        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>`
        Nz- cancelAllOrders() requires a symbol argumentr!  r]  r'  )r$   r1   ru  r3  privateDeleteOrdersAllr  rR  )r   r  rC  r3  r  rD  s         r  cancel_all_orderszdelta.cancel_all_ordersL  s       >#DG.]$]^^^!!!!!!!!!V$$&-

 ..t{{7F/K/KLL OO  
 	
r  c                   K   |                                   d{V  d}||                     |          }|                     |g d          }|                     |g d          }i }d}|5||d<   |                     |                     ||                     d{V }n4||d<   |                     |                     ||                     d{V }|                     |di           }|                     ||          S )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)rL  
client_oid	clientOidrk  r  r=  )	ru  r3  safe_string_nr  &privateGetOrdersClientOrderIdClientOidr  privateGetOrdersOrderIdrA  rT  )	r   r1   r  rC  r3  rL  r  rD  r=  s	            r  fetch_orderzdelta.fetch_orderl  s9      !!!!!!!!![[((F**63_3_3_``6#O#O#OPP$$1GL!!HHU\^dIeIeffffffffHH"$GJ!99$++gv:V:VWWWWWWWWH2 (B77///r  c                 D   K   |                      d||||           d{V S )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>`
        privateGetOrdersNfetch_orders_with_methodr   r  r  r   rC  s        r  fetch_open_orderszdelta.fetch_open_orders  s9       223EvuV[]cdddddddddr  c                 D   K   |                      d||||           d{V S )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>`
        privateGetOrdersHistoryNrs  ru  s        r  fetch_closed_orderszdelta.fetch_closed_orders  s:       223LfV[]bdjkkkkkkkkkr  c                   K   |                                   d {V  i }d }| |                     |          }|d         |d<   |t          |          dz   |d<   |||d<   d }|dk    r0|                     |                     ||                     d {V }n5|dk    r/|                     |                     ||                     d {V }|                     |dg           }	|                     |	|||          S )	Nr]  product_ids000
start_time	page_sizerr  rx  r=  )ru  r3  strrr  r  rx  r`  parse_orders)
r   methodr  r  r   rC  r  r3  rD  r=  s
             r  rt  zdelta.fetch_orders_with_method  s?     !!!!!!!!!	
 [[((F%+K%8GM"$'JJ$6GL!#(GK '''!224;;w3O3OPPPPPPPPHH000!99$++gv:V:VWWWWWWWWH0 (B77  >>>r  c                 ~  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |t          |          dz   |d<   |||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )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=  )ru  r3  r  privateGetFillsr  r`  r  )	r   r  r  r   rC  r  r3  rD  r=  s	            r  fetch_my_tradeszdelta.fetch_my_trades  s       !!!!!!!!!
 [[((F%+K%8GM"$'JJ$6GL!#(GK --dkk'6.J.JKKKKKKKK\ (B77  >>>r  r^  c                 P  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )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-entry-structure>`
        Nr]  r  r~  r=  )ru  rk  privateGetWalletTransactionsr  r`  parse_ledger)	r   r^  r  r   rC  r  rk  rD  r=  s	            r  fetch_ledgerzdelta.fetch_ledger@	  s       !!!!!!!!!
 }}T**H"*;"7GJ#(GK ::4;;wPV;W;WXXXXXXXX, (B77  5%@@@r  c                 D    dddddddd}|                      |||          S )Npnltransactionr[  r  r   rebate)r  rZ  
withdrawalr  
conversionreferral_bonuscommission_rebaterC  )r   r  typess      r  parse_ledger_entry_typezdelta.parse_ledger_entry_types	  s?    $'! )!)
 
 tT222r  r~  rk  c                    |                      |d          }d }d }|                     |di           }|                      |d          }d }|                      |d          }	|	dk    s|	dk    s|	dk    s|	dk    s|	d	k    s|	d
k    rd}n|	dk    s|	dk    s|	dk    s|	dk    rd}|                     |	          }	|                      |d          }
|                     | j        d          }|                     ||
|          }|d n|d         }|                      |d          }|                     |                      |d                    }|                      |d          }t          j        dt          j        ||                    }d}| 	                    |||||||	|| 
                    |          | 
                    |          | 
                    |          |||                     |          d d|          S )Nuuidr  transaction_idtransaction_typerZ  r  r  r  withdrawal_cancellationpromo_creditinr  r  r  perpetual_futures_fundingoutr  rs  r^  r  r  r  r   rJ  )r'  r1   	directionr  referenceIdreferenceAccountr  rk  r  beforeafterrK  r0  r/  r[  )r*  rA  r  r   rQ  r,  r,   
string_max
string_subsafe_ledger_entryr   r  )r   r~  rk  r1   r  r  r  r  r  r  r  rs  r^  r  r0  r  r  rK  s                     r  parse_ledger_entryzdelta.parse_ledger_entry	  sc     dF++	>>$R88&&x1ABB&899I4+>#>#>DL\D\D\bfjobobouy  ~W  vW  vW  ]a  es  ]s  ]sIIl""(<(<$,BVBV\`d\\I++D11%%dJ77
 $t|=T U U??#8*hOO (ttx/?!!$11NN4#3#3D,#G#GHH	  y11#C);E6)J)JKK%%"& 0''//''//&&u--"Y//'
 '
  !  	r  c                   K   |                                   d{V  |                     |          }d|d         i}|                     |d          }|/|                     ||          |d<   |                     |d          }|                     |                     ||                     d{V }|                     |di           }|                     ||          S )aq  
        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>`
        Nasset_symbolr1   rS  r=  )	ru  rk  safe_string_uppernetwork_code_to_idr  privateGetDepositsAddressr  rA  parse_deposit_address)r   r^  rC  rk  r  rp  rD  r=  s           r  fetch_deposit_addresszdelta.fetch_deposit_address	  s       !!!!!!!!!==&&HTN
 ,,VY??"!%!8!8d!K!KGIYYvy11F77GV8T8TUUUUUUUU$ (B77))&(;;;r  c                 6   |                      |d          }|                      |d          }|                      |d          }|                     |           ||                     ||          |                     |          ||                      |d          dS )Naddressr  rS  memo)r'  rk  rS  r  tag)r*  check_addressrd  re  )r   depositAddressrk  r  r2  ro  s         r  r  zdelta.parse_deposit_address	  s     "">9==##NNCC$$^Y??	7###"//(CC..y99##NF;;
 
 	
r  c                 n  K   |                                   d{V  |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )ae  
        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>`
        Nr<   z0 fetchFundingRate() supports swap contracts onlyr  r1   r=  )ru  r3  r&   r1   r  r  rA  parse_funding_rater  s          r  fetch_funding_ratezdelta.fetch_funding_rate	  s       !!!!!!!!!V$$f~ 	ZDG&XXYYYfTl
 44T[[&5Q5QRRRRRRRR\ (B77&&vv666r  c                 $  K   |                                   d{V  |                     |          }ddi}|                     |                     ||                     d{V }|                     |dg           }|                     ||          S )a  
        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
        Ncontract_typesr  r=  )ru  r  r  r  r`  parse_funding_rates)r   r  rC  r  rD  ratess         r  fetch_funding_rateszdelta.fetch_funding_rates<
  s       !!!!!!!!!%%g..1
 ..t{{7F/K/KLLLLLLLL` x266''w777r  c                    |                      |dd          }|                     |d          }|                     |d          }t          j        |d          }i d|d|                     ||          d|                     |d          d	|                     |d
          dd dd d|d|                     |          d|                     |          dd dd dd dd dd dd dd dd dd iS )Nr0  r?  r  funding_rater   r'  r  r  r  r  interestRateestimatedSettlePricer/  fundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)rB  r*  r,   
string_divr  rf  r  r   )r   r  r3  r0  r2  fundingRateStringr  s          r  r  zdelta.parse_funding_rate~
  s   V --hUKK	##Hh77 ,,X~FF():EBB
H
d&&x88
 ))(LAA
 $**8\BB	

 D
 #D
 
 Y//
 4,,[99
 
 t
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 
 	
r  c                 B   K   |                      ||d|           d{V S )ar  
        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=margin-structure>`
        addNmodify_margin_helperr   r  r  rC  s       r  
add_marginzdelta.add_margin
  s4       ..vvufMMMMMMMMMr  c                 B   K   |                      ||d|           d{V S )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=margin-structure>`
        reduceNr  r  s       r  reduce_marginzdelta.reduce_margin
  s4       ..vvxPPPPPPPPPr  c                   K   |                                   d {V  |                     |          }t          |          }|dk    rt          j        |d          }|d         |d}|                     |                     ||                     d {V }|                     |di           }|                     ||          S )Nr  z-1r]  )r!  delta_marginr=  )	ru  r3  r  r,   
string_mul privatePostPositionsChangeMarginr  rA  parse_margin_modification)	r   r  r  r  rC  r3  r  rD  r=  s	            r  r  zdelta.modify_margin_helper
  s      !!!!!!!!!V$$V8'55F -"
 
 >>t{{7TZ?[?[\\\\\\\\0 (B77--ff===r  datac                     |                      |d          }|                     ||          }||d         d dd |                     |d          d d d d d
S )Nr,  r  isolatedr;   )
r'  r  r  r   r  r  r^  rK  r0  r/  )r*  r:  rf  )r   r  r3  r2  s       r  r  zdelta.parse_margin_modification  sq    * ##D*:;;!!(F33X&$%%dH55
 
 	
r  c                 n  K   |                                   d{V  |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )ae  
        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:
        Nr  z3 fetchOpenInterest() supports contract markets onlyr  r1   r=  )ru  r3  r%   r1   r  r  rA  parse_open_interestr  s          r  fetch_open_interestzdelta.fetch_open_interest%  s       !!!!!!!!!V$$j! 	^TW'\\]]]fTl
 44T[[&5Q5QRRRRRRRRj (B77''777r  c                    |                      |dd          }|                     |d          }|                     |                     ||          |                     |d          |                     |d          |                     |d          |                     |d          ||                     |          |d|          S )	Nr0  r?  r  oi_valueoi_value_usdoi_contractsoi)r  r  r  openInterestAmountopenInterestValuer0  r/  r'  )rB  r*  safe_open_interestr  rf  r  )r   interestr3  r0  r2  s        r  r  zdelta.parse_open_interestn  s    d --hUKK	##Hh77&&&&x88**8Z@@++HnEE"&"2"28^"L"L!%!1!1(D!A!A"Y//	(
 	(
 	 	 		r  c                 0  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )aR  
        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>`
        Nr!  r]  r=  )ru  r3  )privateGetProductsProductIdOrdersLeverager  rA  parse_leverager  s          r  fetch_leveragezdelta.fetch_leverage  s       !!!!!!!!!V$$&-
 GGT[]cHdHdeeeeeeee (B77""66222r  r   c                     |                      |d          }|                     |d          }||                     ||          |                     |d          ||dS )Nindex_symbolr   margin_mode)r'  r  r   longLeverageshortLeverage)r*  rc  r  safe_string_lower)r   r   r3  r2  leverageValues        r  r  zdelta.parse_leverage  sj    ##Hn==))(J??&&x8800=II)*
 
 	
r  c                 
  K   |t          | j        dz             |                                  d{V  |                     |          }|d         |d}|                     |                     ||                     d{V S )aa  
        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
        Nz) setLeverage() requires a symbol argumentr]  )r!  r   )r$   r1   ru  r3  *privatePostProductsProductIdOrdersLeverager  )r   r   r  rC  r3  r  s         r  set_leveragezdelta.set_leverage  s       >#DG.Y$YZZZ!!!!!!!!!V$$ - 
 
 DDT[[QXZ`EaEabbbbbbbbbr  c                   K   |                                   d{V  d}||                     |          }ddi}|||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||          }	|                     |	d          }
|                     |
|d         ||          S )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=  r0  r  )ru  r3  r  r  r`  parse_settlementssort_byfilter_by_symbol_since_limit)r   r  r  r   rC  r3  r  rD  r=  settlementssorteds              r  fetch_settlement_historyzdelta.fetch_settlement_history  s       !!!!!!!!![[((Fi
 #(GK //GV0L0LMMMMMMMMv (B77,,VV<<k;77009I5RWXXXr  c                     |                      |d          }|                      |d          }||                     ||          |                     |d          |                     |          |dS )Nr  r  settlement_price)r'  r  r   r0  r/  )r*  r  rf  r,  )r   
settlementr3  r/  r2  s        r  parse_settlementzdelta.parse_settlementM  s{    l ##J0ABB##J99&&x88%%j2DEE11 
 
 	
r  c                     g }t          dt          |                    D ]1}|                    |                     ||         |                     2|S )Nr   )ra  rb  r  r  )r   r  r3  r=  rj  s        r  r  zdelta.parse_settlements  sX    q#k**++ 	I 	IAMM$//AGGHHHHr  c                 0  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract

        https://docs.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>`
        Nr  r1   r=  )ru  r3  r  r  rA  parse_greeksr  s          r  fetch_greekszdelta.fetch_greeks  s       !!!!!!!!!V$$fTl
 44T[[&5Q5QRRRRRRRRj (B77  000r  greeksc                    |                      |dd          }|                     |d          }|                     ||          }|                     |di           }|                     |di           }i d|d|d|                     |          d|                     |d          d|                     |d          d	|                     |d	          d
|                     |d
          d|                     |d          d|                     |d          d|                     |d          d|                     |d          d|                     |d          d|                     |d          d|                     |d          d|                     |d          d|                     |d          dd |                     |d          |dS )Nr0  r?  r  r  r  r/  r.   gammathetavegarhobidSizer  askSizer  bidImpliedVolatilitybid_ivaskImpliedVolatilityask_ivmarkImpliedVolatilitymark_ivbidPricer  askPricer  r  r  	lastPricer  )underlyingPricer'  )rB  r*  r  rA  r  rf  )r   r  r3  r0  r2  r  r   r  s           r  r  zdelta.parse_greeks  sE   d --fk5II	##FH55!!(F33vx44"55
f

 Y//
 T%%eW55	

 T%%eW55
 T%%eW55
 D$$UF33
 4##E511
 t''
;;
 t''
;;
 #D$4$4VX$F$F
 #D$4$4VX$F$F
 $T%5%5fi%H%H
 ((<<
 ((<<
  ))&,??!
" #
$  $//EE'
 
 
 	
r  c                    K   |                                   d{V  ddd}|                     |                     ||                     d{V }|                     |                     |di                     }|gS )ag  
        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>`
        NT)close_all_portfolioclose_all_isolatedr=  )ru  privatePostPositionsCloseAllr  r#  rA  )r   rC  r  rD  r*  s        r  close_all_positionszdelta.close_all_positions'  s       !!!!!!!!!#'"&
 

 ::4;;wPV;W;WXXXXXXXX &&t~~h"'M'MNNzr  c                    K   |                                   d{V  d}||                     |          }|                     |           d{V }|                     |di           }|                     ||          S )ax  
        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=  )ru  r3  privateGetProfilerA  parse_margin_mode)r   r  rC  r3  rD  r=  s         r  fetch_margin_modezdelta.fetch_margin_mode>  s       !!!!!!!!![[((F//77777777@ (B77%%ff555r  r   c                 N    d }||d         }|||                      |d          dS )Nr  r  )r'  r  r   rC  )r   r   r3  r  s       r  r  zdelta.parse_margin_mode  s?    H%F**:}EE
 
 	
r  c                 2  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     |d|          S )a  
        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>`
        Nr  r1   r=  )ru  r3  r  r  rA  parse_optionr  s          r  fetch_optionzdelta.fetch_option  s       !!!!!!!!!V$$fTl
 44T[[&5Q5QRRRRRRRRj (B77  v666r  rn  c                    |                      |d          }|                     ||          }|                     |di           }|                     |dd          }i d|dd d|d         d|d|                     |          d|                     |d	          d
|                     |d          d|                     |d          d|                     |d          d|                     |d          d|                     |d          dd d|                     |d          dd dd d|                     |d          dd S )Nr  r  r0  r?  r'  rk  r/  impliedVolatilityr  openInterestr  r  r  r  r  midPriceimpact_mid_pricer  r  r  r  r  r  r   r  r  r  )r*  r:  rA  rB  r  rf  )r   rn  rk  r3  r2  r  r0  s          r  r#  zdelta.parse_option  s   d ##E844!!(F33x44--e[%HH	
E

 fX&
 	

 Y//
  !1!1&)!D!D
 D,,UD99
 ((<<
 ((<<
 ((1CDD
 ))%>>
 
 t//|DD
 d
 $
  $**5(;;!
" 4#
 	
r  c                    K   |                                   d{V  |                     |dddd          }|                     |           d{V }|                     |dg           }|                     ||          S )a  
        fetches the auto deleveraging rank and risk percentage for a list of symbols

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

        :param str[] [symbols]: a list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of `auto de leverage structures <https://docs.ccxt.com/?id=auto-de-leverage-structure>`
        NTr=  )ru  r  r&  r`  parse_adl_ranksr(  s        r  fetch_positions_adl_rankzdelta.fetch_positions_adl_rank*  s       !!!!!!!!!%%gtT4FF99&AAAAAAAAV (B77##FG444r  r'  c                     |                      |d          }|                      |d          }||                     ||d d          |                     |d          d d |                     |          |dS )Nr,  r  r  	adl_level)r'  r  rankratingr   r0  r/  )r*  r  rc  r,  )r   r'  r3  r2  r/  s        r  parse_adl_rankzdelta.parse_adl_rank  s    N ##D*:;;##D,77&&xzJJ%%dK8811 
 
 	
r  r   GETc                    d| j         z   dz   |                     ||          z   }| j        d         |         |z   }|                     ||                     |                    }	|dk    r|	r|d|                     |	          z   z  }n|dk    r|                                  t          |                                           }
| j	        |
d}||
z   |z   }|dk    r%|	r"d|                     |	          z   }||z  }||z  }n| 
                    |	          }||z  }d|d	<   |                     |                     |          |                     | j                  t          j                  }||d
<   ||||dS )Nr  r   r   ?r   )zapi-keyr0  r2  zapplication/jsonzContent-Type	signature)rN  r  bodyheaders)r6   implode_paramsr   r  extract_params	urlencodecheck_required_credentialsr  r
  r   jsonhmacencoder   hashlibsha256)r   pathr   r  rC  r7  r6  requestPathrN  queryr0  authqueryStringr5  s                 r  signz
delta.sign  s   DL(3.1D1DT61R1RRis#k1		&$"5"5d";";<<(?? 3sT^^E2222I++---DLLNN++I;& G I%3D '"%u(=(="=KK'D;&Cyy''*<'		$++d"3"3T[[5M5Mw~^^I#,GK fdwOOOr  reasonrN  r  r7  r6  c
                 ,   |d S |                      |di           }
|                     |
d          }|`| j        dz   |z   }|                     | j        d         ||           |                     | j        d         ||           t          |          d S )Nerrorr^   r   r   )rA  r*  r1   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr"   )r   r^  rG  rN  r  r7  r6  rD  requestHeadersrequestBodyrI  	errorCodefeedbacks                r  handle_errorszdelta.handle_errors  s    4 x"55$$UF33	 w}t+H001I9V^___001I9V^___)))tr  )NNNN)N)NN)f__name__
__module____qualname__r   r   r  r1  r   r   r    r:  r   rE  rQ  r   rq  ru  rv  r!   r  dictr   r  r  r   r   r  r   r  r   r  r  rz  r   r  r   r  r  r$  r   r)  r#  rE  r   rT  r   r   floatr   r^  rc  rf  ri  rp  rv  ry  rt  r  r   r  r  r	   r  r
   r  r  r   r  r   r  r  r   r  r  r  r  r  r  r   r  r  ra  r  r  r  r  r   r  r  r  r   r   r  r   r$  r#  r   r,  r1  rF  rQ  __classcell__)r  s   @r  r.   r.      s       D# D D D D D DL
A
3 A
 A
 A
 A
FW WC W WRU Wjm W  zI W W W W W W ') 	G 	GS 	G 	G 	G 	G )+ F
 F
 F
 F
P -/ p p: p p p pd ).b         *, l lV l l l l\	P P4 P P6 P P P Pd 68 M1 M1 M1F M1 M1 M1 M1^ 6:" UG UG7 UG UG UG UG UGn @DB &e &eS &e &eS\ &e &e &e &eP] ] ]v ] ] ] ] ]~ <@d[] "? "? "?S "? "?bfglbm "? "? "? "?H
 
 
4 
 
 
 
( ?CQUdhqs 5J 5J 5J 5J3 5J^a 5Jx|  ~B  yC 5J 5J 5J 5Jn) ) ) ) ) *,  ,  ,  ,  ,  ,  ,D 8: 3 33 3 3 3 3: 8<B "5 "5W "54PX> "5 "5 "5 "5HA At AV A A A AF: : : : :o o ov o o o o ob mqy{ M0 M0 M0I M0Y M0X] M0fi M0 M0 M0 M0^ fjx|  FH .0 .03 .0 .09 .0I .0_b .0ru .0 .0 .0 .0` 9=R 90 90S 90# 90 90 90 90v 59 
 
c 
 
 
 
@ 8<B 40 40C 40 405 40 40 40 40l 59tZ^gi e ec e eTW enrsxny e e e e 7;\`ik l l l3 lVY lptuzp{ l l l l DHVZimvx 1? 1?S 1?PS 1?cf 1? 1? 1? 1?f 37TX\eg M? M?C M?s M?RU M? M? M? M?^ .2SW`b 1A 1As 1A# 1AS 1Agklwgx 1A 1A 1A 1Af3 3 35 5t 5x 5; 5 5 5 5n =? $< $< $<> $< $< $< $<L
 
h 
R` 
 
 
 
6 <> @7 @7s @7+ @7 @7 @7 @7D <@ @8 @8 @8| @8 @8 @8 @8DB
 B
6 B
[ B
 B
 B
 B
H CE N Ns NE NI[ N N N N FH Q Q# Qu QL^ Q Q Q Q LN #> #> #>Rd #> #> #> #>J"
 "
d "
F "
N` "
 "
 "
 "
H =? G8 G8 G8 G8 G8 G8R= =F = = = =~ 8: 3 33 3h 3 3 3 3@	
 	
t 	
V 	
x 	
 	
 	
 	
 ?C2 c c3 c c c c c@ <@daenp SY SYS SY SY[^ SY SY SY SYj>
 >
 >
@   68 E1 E1 E1F E1 E1 E1 E1NK
 K
4 K
 K
6 K
 K
 K
 K
Z 02  d8n    . ;= O6 O6c O6 O6 O6 O6 O6b
 
D 
* 
 
 
 
 68 E7 E7 E7F E7 E7 E7 E7NH
 H
$ H
( H
6 H
]c H
 H
 H
 H
T AER x5 x5g x5TXY\T] x5 x5 x5 x5tq
 q
4 q
 q
3 q
 q
 q
 q
f &eBSW P P P P8# s  c TX `c        r  r.   )3 ccxt.async_support.base.exchanger   ccxt.abstract.deltar   r?  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   r    typingr!   ccxt.base.errorsr"   r#   r$   r%   r&   r'   r(   r)   r*   ccxt.base.decimal_to_precisionr+   ccxt.base.preciser,   r.    r  r  <module>r`     s   6 5 5 5 5 5 + + + + + +  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  r  r  r  r  r  r  r  r  r  r  r  r  r       * * * * * * 0 0 0 0 0 0 . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) * * * * * * 1 1 1 1 1 1 4 4 4 4 4 4 % % % % % %h> h> h> h> h>Hk h> h> h> h> h>r  