
    ir                    h   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 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lm*Z* d dlm+Z+ d dlm,Z, d dl-m.Z. d dl/m0Z0  G d dee          Z1dS )    )Exchange)ImplicitAPIN)AccountBalances
CurrenciesCurrencyGreeksIntMarketMarketInterfaceNumOptionOptionChainOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)NotSupported)DDoSProtection)ExchangeNotAvailable)OnMaintenance)	TICK_SIZE)Precisec                   \    e Zd Z fdZdefdZdZdedededed	ef
 fd
Z	i fdZ
i fd	efdZi fdZi fdZi fd	ee         fdZd[defdZi f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i fdefdZd[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ddi fdede de d	ee!         fdZ"d[ded	e#fd Z$ddi fdede de d	ee#         fd!Z%i fd	e&fd"Z'di fdede d	e(fd#Z)d$ Z*d% Z+d& Z,d[ded	e-fd'Z.di fd(edefd)Z/di fded*e0d+e1d,e2d-e3f
d.Z4ddi fd(eded*e0d+e1d,e3d-e3fd/Z5di fd(edefd0Z6di fdefd1Z7dddi fdede de d	ee-         fd2Z8dddi fdede de d	ee-         fd3Z9dddi fd(edede de fd4Z:dddi fdede de fd5Z;dddi fdede de d	ee<         fd6Z=dddi fdede de d	ee<         fd7Z>d8 Z?d[ded	e<fd9Z@d[defd:ZAi fdefd;ZBdi fdefd<ZCi fdefd=ZDd> ZEdddi fdede de fd?ZFi fded,e2d@edAed	eGf
dBZHd[defdCZIdD ZJdi fded,e2fdEZKd[defdFZLdi fdGefdHZMi fdefdIZNdddi fdede de fdJZOd[defdKZPddi fdede de fdLZQdM ZRdddi fdede de fdNZSd[defdOZTi fded	eUfdPZVd[defdQZWi fded	eXfdRZYi fded	eZfdSZ[d\dedefdTZ\dU Z]dVdWi ddfdXZ^dY Z_ xZ`S )]deribitc                    |                      t          t          |                                           dddg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 d*d	d+dd,d	d-dd.d	d/dd0d	d1dd2dd3dd4dd5dd6dd7dd8d	d9dd:di d;d	d<dd=d	d>dd?dd@ddAddBddCd	dDddEd	dFd	dGddHd	dIddJd	dKddddLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[id\dZd]id]d^d_gd`dadbdcdddei dfdgdhdgdidgdjdgdkdgdldgdmdgdndgdodgdpdgdqdgdrdgdsdgdtdgdudgdvdgdwdgi dxdgdydgdzdgd{dgd|dgd}dgd~dgddgddgddgddgddgddgddgddgddgddgdgdgdgdgdgdidei ddgddgddgddgdpdgdqdgdrdgddgddgddgddgddgddgddgddgddgddgi ddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgi ddgddgddgddgddddgddgddgddddddddddddddddddi ddddddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgdgdgdgdgdgdgdgdgdgdgdgdgdgdgd̜id͜i dt          dt
          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          d t          i dt          dt          dt          dt          dt          dt          dt          dt          d	t          d
t          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt
          dt          dt          dt
          dt
          dt
          dt
          d t          d!t
          d"t
          i d#t
          d$t          d%t
          d&t
          d't
          d(t
          d)t
          d*t          d+t
          d,t          d-t          d.t          d/t          d0t          d1t          d2t          d3t          t          t          t          t          t          t          t          t          t          t          d4
t           d5d6d5id6d5id7d8id9d:          S (;  Nr-   DeribitNLv22   TCORSspotFmarginswapfutureoptioncancelAllOrderscancelOrdercancelOrderscreateDepositAddresscreateOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrdercreateTrailingAmountOrder	editOrderfetchAccountsfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositsfetchDepositWithdrawFeesfetchFundingRatefetchFundingRateHistoryfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeverageTiersfetchLiquidationsfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchTransferfetchTransfersfetchUnderlyingAssetsfetchVolatilityHistoryfetchWithdrawalfetchWithdrawals)transferwithdraw135101530601201803607201D)1m3m5m10m15m30m1h2h3h6h12h1drestzhttps://test.deribit.comzchttps://user-images.githubusercontent.com/1294454/41933112-9e2dd65a-798b-11e8-8440-5bab2959fcb8.jpgzhttps://www.deribit.comzhttps://docs.deribit.com/v2zhttps://github.com/deribitz.https://www.deribit.com/pages/information/feesz%https://www.deribit.com/reg-1189.4038g?)urldiscount)testlogoapiwwwdocfeesreferralgetauth   exchange_token
fork_tokenset_heartbeatdisable_heartbeatget_timehellostatusr   	subscribeunsubscribeunsubscribe_allget_announcementsget_book_summary_by_currencyget_book_summary_by_instrumentget_contract_sizeget_currenciesget_delivery_pricesget_funding_chart_dataget_funding_rate_historyget_funding_rate_valueget_historical_volatility	get_indexget_index_priceget_index_price_namesget_instrumentget_instruments get_last_settlements_by_currency"get_last_settlements_by_instrumentget_last_trades_by_currency$get_last_trades_by_currency_and_timeget_last_trades_by_instrument&get_last_trades_by_instrument_and_timeget_mark_price_history)get_order_bookget_trade_volumesget_tradingview_chart_dataget_volatility_index_datatickerlogoutenable_cancel_on_disconnectdisable_cancel_on_disconnectget_cancel_on_disconnectchange_api_key_namechange_scope_in_api_keychange_subaccount_namecreate_api_keycreate_subaccountdisable_api_keydisable_tfa_for_subaccountenable_affiliate_programenable_api_keyget_access_logget_account_summaryget_affiliate_program_infoget_email_languageget_new_announcementsget_portfolio_marginsget_positionget_positionsget_subaccountsget_subaccounts_detailsget_transaction_loglist_api_keysremove_api_keyremove_subaccountreset_api_keyset_announcement_as_readset_api_key_as_defaultset_email_for_subaccountset_email_languageset_password_for_subaccount$toggle_notifications_from_subaccounttoggle_subaccount_loginexecute_block_trade   get_block_trade!get_last_block_trades_by_currency invalidate_block_trade_signatureverify_block_tradebuyselleditedit_by_labelcancel
cancel_allcancel_all_by_currencycancel_all_by_instrumentcancel_by_labelclose_positionget_marginsget_mmp_configget_open_orders_by_currencyget_open_orders_by_instrumentget_order_history_by_currencyget_order_history_by_instrumentget_order_margin_by_idsget_order_stateget_stop_order_historyget_trigger_order_historyget_user_trades_by_currency$get_user_trades_by_currency_and_timeget_user_trades_by_instrument&get_user_trades_by_instrument_and_timeget_user_trades_by_order)	reset_mmpset_mmp_config$get_settlement_history_by_instrument"get_settlement_history_by_currencycancel_transfer_by_idcancel_withdrawalcreate_deposit_addressget_current_deposit_addressget_depositsget_transfersget_withdrawalssubmit_transfer_to_subaccountsubmit_transfer_to_userrx   )publicprivate99991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610040100411004310044100451004610047100481100811029110301103111035110361103711038110391104111042110431104411045110461104711048110491105011051110521105311090110911109211093110941109511096120001200112002129981200312004120051210012999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017)
1301813019130201302113025z-32602z-32601z-32700z-3200011054BTCcodemethod$privateGetSubmitTransferToSubaccount)r  rD   rg   rw   )idname	countriesversion	userAgent	rateLimitprohas
timeframesurlsr   
exceptionsprecisionModeoptions)deep_extendsuperr-   describer   r   r   r$   r%   r"   r'   r&   r(   r)   r!   r#   r*   )self	__class__s    R/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/deribit.pyr  zderibit.describe   s   gt 4 4 = = ? ? GGG %G 	G
 $G $G "4G tG G 'G tG 'G (G "4G ,TG  T!G"  #G G$ %G& +E'G( )%)G* $T+G, '-G. (/G0 "41G2 3G4 &t5G6  7G8 +D9G: #D;G< *4=G> t?G@ "5AGB *5CGD +EEG G GF %eGGH $TIGJ "5KGL MGN !%OGP &tQGR +ESGT  UGV dWGX "4YGZ t[G\ #D]G^ d_G` !$aGb ucGd #DeGf  gG G Gh $UiGj !$kGl )%mGn toGp tqGr sGt TuGv twGx "5yGz #D{G| $U}G~  G@ !$AGB (CGD )$EGF "5GGH #DIG GJ ! MG G GR    6 ~5 110 IB #  *  .. )!. %a	. (. ,Q. #A.  . !!. . $Q. &q.  *1!.$ ,Q%.( 7).* 9!+., ,Q-.. )!/. .0 .q1.2 1!3.4 3A5.6 1!7.8 4Q9.: $Q;.< *1=.> 0?.@ )!A.B *1C.D ;AE.F =aG.H 6qI.J ?K.L 8M.N A!O.P 1!Q. .R +,-.6756"#[. . .0d  Z !Z 6q	Z
 7Z 3AZ $QZ &qZ *1Z .qZ 21Z 1!Z )!Z  ,Q!Z" *1#Z$ 5a%Z& 3A'Z( )!)Z* )!+Z Z, .q-Z. 5a/Z0 -a1Z2 03Z4 05Z6 '7Z8 (9Z: *1;Z< 21=Z> .q?Z@ (AZB )!CZD ,QEZF (GZH 3AIZJ 1!KZL 3AMZ Z ZN -aOZP 6qQZR ?SZT 21UZX .qYZZ *1[Z\ <Q]Z^ ;A_Z` -aaZd qeZf gZh iZj (kZl !!mZn %aoZp 1!qZr 3AsZ Z Zt *1uZv )!wZx &qyZz )!{Z| 6q}Z~ 8Z@ 8AZB :1CZD 21EZF *1GZH 1!IZJ 4QKZL 6qMZN ?OZP 8QZR A!SZT 3AUZ ZV &'*+@A>?12-.2378())*+,9:34$%sZ Z Z\eO O`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 1r2 3r4 5r6 7r8 9r: ;r< =r> ?r@ ArB CrD ErF Gr r rH IrJ KrL MrN OrP -QrR SrT UrV WrX YrZ [r\ ]r^ _r` arb crd erf grh ir r rj krl mrn orp qrr srt )urv wrx yrz {r| }r~ r@ ArB CrD ErF GrH IrJ Kr r rL MrN OrP QrR SrT UrV WrX YrZ ,[r\ ]r^ _r` ,arb ,crd ,erf ,grh irj ,krl ,mr r rn ,orp )qrr ,srt ,urv ,wrx ,yrz ,{r| }r~ ,r@ ArB CrD )ErF GrH IrJ KrL MrN Or rP '&&)&$$$$%cr r rf 'E! E# D oCB
 CB
 C C C	    symbolc                    d}d }|                     d          }|                     d          }d }d }|                    d          dk    rK|                     |d          }|                     |d          }|                    d          dk    r|dz   }n?|                     |d          }|                     |                     |d                    }|                    d          dk    rd}d}n|}|}|                    d	          dk    r+|                     d	          }	|                     |	d          }|                     |d
          }
|                     |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USD-/r   r   USDC_USDC_      r  r  :basequotesettlebaseIdquoteIdsettleIdactiveFtyper8   linearinverser4   r6   r7   Tr5   Ccallputamountpriceminmax)r  r  cost)	contractcontractSizeexpiryexpiryDatetime
optionTypestrike	precisionlimitsinfo)splitfindsafe_stringconvert_market_id_expire_dateconvert_expire_date	parse8601%convert_expire_date_to_market_id_dateparse_number)r  r  r  r  optionParts
symbolBaser  r  	splitBasesplitSymbolr  r  datetime	timestamps                 r  create_expired_option_marketz$deribit.create_expired_option_market  sQ   ll3''\\#&&
;;sb  ##J22D%%k155F{{6""R''g~##K33D778H8HVW8X8XYYF;;v##EFFF	99S>>B**S//K((a88I!!+q11%%k155
++F33NN8,,	+
$*tII&QQQTWWZ``cffiss+
i#o-3f<sBVKcQTZZ]``cmm+
 D+
 U	+

 f+
 d+
 u+
 +
 e+
 H+
 d+
 t+
 E+
 E+
 e+
  d!+
" e#+
$  &%/3%6%6&&U''//    
   
     U+
 +
 +
 +	
r  NmarketIdmarket	delimiter
marketTypereturnc                     |d uo)|                     d          p|                     d          }|r|| j        vr|                     |          S t          t          |                               ||||          S )Nz-Cz-P)endswithmarkets_by_idr  r  r-   safe_market)r  r  r  r  r  isOptionr  s         r  r  zderibit.safe_market  s    D(f0A0A$0G0G/eXM^M^_cMdMd 	?X);;;44X>>>Wd##//&)ZXXXr  c                 X    |                      |          }|                     |d          S )aJ  
        fetches the current integer timestamp in milliseconds from the exchange server
        :see: https://docs.deribit.com/#public-get_time
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        result)publicGetGetTimesafe_integer)r  paramsresponses      r  
fetch_timezderibit.fetch_time  s/     ((00   8444r  c                    |                      |          }|                     |di           }i }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                     |d          }	||||	ddd|                     |d          |                     |                     |                     |d                              dddddddddd	dd
||<   |S )a  
        fetches all available currencies on an exchange
        :see: https://docs.deribit.com/#public-get_currencies
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r  r   currencycurrency_longNwithdrawal_feefee_precisionr  )r  rx   deposit)r  r  r  r  r  r  rx   feer  r  networks)	publicGetGetCurrencies
safe_valuerangelenr  safe_currency_codesafe_numberr  parse_precision)
r  r  r  datar  ir  
currencyIdr  r  s
             r  fetch_currencieszderibit.fetch_currencies	  sP    ..v66. x266q#d))$$ 	 	AAwH))(J??J**:66D##Ho>>D   ''2BCC!..t/C/CDDTDTU]_nDoDo/p/pqq  $# 
  $#! !
  $#     !1 F4LL4 r  c                     |                      | j        dd          }|                      | j        |i           }|                      |d|          }|                      |d|          S )Nr  r  )r  r  )r  
methodNamer  defaultCoder  r  s         r  code_from_optionszderibit.code_from_optionsJ  s[    oodlFEBB//$,
B??w<<vvt444r  c                     |                      |          }|                     |d          }|                     |d          }|                     |dd|                                           }|dk    rdnd|dd|d	S )
aE  
        the latest known information on the availability of the exchange API
        :see: https://docs.deribit.com/#public-status
        :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  lockedusIngMbP?falseokmaintenanceN)r   updatedetar   r  )publicGetStatusr  r  safe_integer_productmilliseconds)r  r  r  r  r  
updateTimes         r  fetch_statuszderibit.fetch_statusP  s     ''// 844!!&(33..xHYHYH[H[\\
%00dd}!
 
 	
r  c                     |                                   |                     |          }|                     |dg           }|                     |          S )a_  
        fetch all the accounts associated with a profile
        :see: https://docs.deribit.com/#private-get_subaccounts
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
        r  )load_marketsprivateGetGetSubaccountsr  parse_accounts)r  r  r  r  s       r  fetch_accountszderibit.fetch_accountso  sU     	0088F 8R88""6***r  r  c                     ||                      |d          |                      |d          |                     d |          dS )Nr  r  )r  r  r  r  )r  r  )r  accountr  s      r  parse_accountzderibit.parse_account  sO      ""7D11$$Wf55++D(;;	
 
 	
r  c                    g }g }i }d}|                      |ddd          \  }}|r+|                     |          }|                    |           n|                     |          }|                     |dg           }t          dt          |                    D ]`}	|                     ||	         d          }
d|
i}|                     |                     ||                    }|                    |           at          dt          |                    D ]]}	|                     ||	         dg           }t          dt          |                    D ]}||         }|                     |d          }|d	k    }|                     |d
          }|                     |d          }|                     |d          }|                     |d          }| 	                    |          }| 	                    |          }| 	                    |          }|                     |d          }|dk    }| o|
                    d          dk    }|
                    d          dk    }|
                    d          dk    }|                     |d          }d}d}|} d}!|rd}!n	|rd}!n|rd	}!|r	|dz   |z   } n|s|dz   |z   dz   |z   } |s|ru| dz   |                     |d          z   } |rW|                     |d          }|                     |d          }|dk    rdnd}"| dz   |                     |          z   dz   |"z   } |                     ||           }#|#rd|| <   |                     |d          }$|                     |d          }%|                    i d |d!| d"|d#|d$|d%|d&|d'|d(|!d	|d)d*d|d|d|d+|                     |d,          d-| d.||k    ||k    |                     |d/          |                     |d0          |                     |d1          ||                     |          |||$|%d2ddd3|$dd3|%dd3ddd3d4|                     |d5          |d6            _|S )7aS  
        retrieves data on all markets for deribit
        :see: https://docs.deribit.com/#public-get_currencies
        :see: https://docs.deribit.com/#public-get_instruments
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        NrX   fetchAllMarketsTr  r   r  kindr4   instrument_namebase_currencycounter_currencysettlement_currencysettlement_period	perpetualr7   r8   comboexpiration_timestampr6   r  r  r   r  option_typer  r  Pmin_trade_amount	tick_sizer  r  r  r  r  r  r  r  r  r5   Fr  	is_activer  r  taker_commissionmaker_commissioncontract_sizer  r  )leverager  r  r  creation_timestamp)r  takermakerr  r  r  r  r  r  r  createdr  )handle_option_and_paramspublicGetGetInstrumentsappendr  r  r  r  r  extendr  r  r  yymmddr  number_to_stringiso8601)&r  r  instrumentsResponsesr  parsedMarketsr  instrumentsResponsecurrenciesResponsecurrenciesResultr  r  requestinstrumentsResultkr  r  isSpotr  r  r  r  r  r  r  settlementPeriodr6   r7   r8   isComboMarketr  r  r  r  r  letterparsedMarketValueminTradeAmounttickSizes&                                         r  fetch_marketszderibit.fetch_markets  s     ""&"?"?Xiko"p"p m	A"&">">v"F"F ''(;<<<<!%!<!<V!D!D2  $/A8RPP1c"23344 OA OA!--.>q.A:NN

 '+&B&B4;;wX^C_C_&`&`#T %++,?@@@@q#23344 `	 `	A $0DQ0GSU V V1c"34455 ^ ^*1-''77&.%%f.?@@))&/BB**63EFF++F4IJJ..v66//8800::#'??6;N#O#O (K7!@tyy':':a'?))H--2 $		' 2 2a 7**63IJJ!
 "#DD "#DD "!D 
a!CZ%/FF& a!CZ%/#5>F a a!'#FB0G0G!G! a%)%5%5fh%G%GF)-)9)9&-)P)PJ-76-A-ASSF%+c\D4I4I&4Q4Q%QTW%WZ`%`F$(OOM6$J$J!$ (,f%!%!1!1&:L!M!M++FK@@ 2"2f2 D2 U	2
 f2 f2 w2 2 D2 F2 e2 D2 f2 f2 doofkBB2  F
!2" v#2$ !'%!--f6HII!--f6HII$($4$4V_$M$M$&*ll6&:&:$","0!)" " $(#'% %
 $2#'# #
 $,#'" "
 $(#'! ! $  $009MNN"c2 2 2 2 2 2 2Y^~ r  c                 R   d|i}|                      |d          }|                     |          }|                                 }|                      |d          |d<   |                      |d          |d<   |                      |d          |d<   |||<   |                     |          S )	Nr  r  available_fundsfreemaintenance_marginusedequitytotal)r  r  r  safe_balance)r  balancer  r  currencyCoder  s         r  parse_balancezderibit.parse_balance  s    G
 %%gz::
..z::,,..**74EFF**74HII++GX>>&|  (((r  c                 >   |                                   |                     d|          }|                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     |          S )ae  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://docs.deribit.com/#private-get_account_summary
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        rD   r  r  r  )r  r  r  privateGetGetAccountSummaryr)  r  rG  )r  r  r  r  r2  r  r  s          r  fetch_balancezderibit.fetch_balance  s     	%%nf====&&
 33DKK4P4PQQV 8R88!!&)))r  r  c                 L   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     |d          }|                     |           ||d|dS )a  
        create a currency deposit address
        :see: https://docs.deribit.com/#private-create_deposit_address
        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r  r  r  addressN)r  rL  tagr  )r  r  privateGetCreateDepositAddressr)  r  r  check_addressr  r  r  r  r2  r  r  rL  s           r  r  zderibit.create_deposit_address  s     	==&&
 66t{{7F7S7STT 8R88""69557###	
 
 	
r  c                 N   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     |d          }|                     |           ||dd|dS )a  
        fetch the deposit address for a currency associated with self account
        :see: https://docs.deribit.com/#private-get_current_deposit_address
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r  r  r  rL  N)r  rL  rM  networkr  )r  r  "privateGetGetCurrentDepositAddressr)  r  r  rO  rP  s           r  fetch_deposit_addresszderibit.fetch_deposit_address  s     	==&&
 ::4;;wPV;W;WXX$ 8R88""69557###
 
 	
r  c           	         |                      |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 |                     |d          |d|          S ) Nr  r"  r  
last_pricelaststatsr  r  high	max_pricelow	min_pricebidbest_bid_price	bid_price	bidVolumebest_bid_amountaskbest_ask_price	ask_price	askVolumebest_ask_amountvwapopenclosepreviousClosechange
percentageaveragevolume)
baseVolumequoteVolumer  )safe_integer_2r  safe_symbolsafe_string_2r  safe_tickerr,  )r  r   r  r  r  r  rW  rX  s           r  parse_tickerzderibit.parse_ticker'  s    ^ ''=QRR	##F,=>>!!(F33!!&,??88 !
f!
!
 Y//!
 D&&ufkBB	!

 4%%eUK@@!
 4%%f.>LL!
 ))&2CDD!
 4%%f.>LL!
 ))&2CDD!
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ ++E8<<)!
 !
 !
* +  	r  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://docs.deribit.com/#public-ticker
        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r  r  r  )r  r  publicGetTickerr)  	safe_dictru  r  r  r  r  r2  r  r  s          r  fetch_tickerzderibit.fetch_tickerr  s     	V$$vd|
 ''GV(D(DEE: (33  000r  symbolsc                 b   |                                   |                     |          }|                     |dd          }|                     |dg          }|t	          | j        dz             |                     |          }d|d         i}|                     |                     ||                    }| 	                    |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
        :see: https://docs.deribit.com/#public-get_book_summary_by_currency
        :param str[] [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
        :param str [params.code]: *required* the currency code to fetch the tickers for, eg. 'BTC', 'ETH'
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        r  r  NzW fetchTickers requires a currency/code(eg: BTC/ETH/USDT) parameter to fetch tickers forr  r  r   r  )r  market_symbolsrs  omitr    r  r  !publicGetGetBookSummaryByCurrencyr)  	safe_listr  r  ru  filter_by_array_tickers)r  r{  r  r  r  r2  r  r  tickersr  r   r  s               r  fetch_tickerszderibit.fetch_tickers  sB    	%%g..!!&&*==6F8,,<#DG  /H  %H  I  I  I==&&
 99$++gv:V:VWW> (B77q#f++&& 	% 	%A&&vay11FH%F$GFOO++GXwGGGr  r   sincelimitc           
      j   |                                   d}|                     |dd          \  }}|r|                     d|||||d          S |                     |          }|d         |                     | j        ||          d}|                     |          }	|                                 }
||d}|
|d	z
  |	z  dz  z
  |d
<   |
|d<   n?t          |d	z
  d          }||d
<   ||
|d<   n| 	                    |||	z  dz            |d<   | 
                    |d          }||                     |d          }||d<   |                     |                     ||                    }|                     |di           }|                     |ddddddd          }|                     |||||          S )aJ  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: https://docs.deribit.com/#public-get_tradingview_chart_data
        :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 boolean [params.paginate]: whether to paginate the results, set to False by default
        :param int [params.until]: the latest time in ms to fetch ohlcv for
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Fr]   paginatei  r  )r  
resolutionN  r   start_timestampend_timestampr   untilr  ticksrh  rY  r[  ri  rn  T)r  r&  "fetch_paginated_call_deterministicr  r  r  parse_timeframer  r  sumr  r~   publicGetGetTradingviewChartDatar)  r  convert_trading_view_to_ohlcvparse_ohlcvs)r  r  	timeframer  r  r  r  r  r2  durationnowr  r  r  ohlcvss                  r  fetch_ohlcvzderibit.fetch_ohlcv  s    	88zZZ& 	x::<QVX]_hjprvwwwV$$%d|**4?IyQQ
 
 ''	22!!=}),	X/E/L)LG%&'*GO$$	1%%E).G%&}+.((+/88E58;Kd;R+S+S(!!&'22YYvw//F',GO$88Wf9U9UVV( 8R8833FGVVUZ\cemostt  E5IIIr  c                 `   |                      |d          }|                      |d          }|                     ||          }|                     |d          }|                      |d          }|                      |d          }|                     ||          }|                      |d          }	t	          j        |	|          }
|d         rt	          j        |	|          }
|                      |d          }d }|
|d	k    rd
nd}|                      |d          }d }|0|                      |d          }|                     |          }||d}|                     |||| 	                    |          ||                      |d          |                      |d          ||||	|
|d|          S )Ntrade_idr  r  	directionr  r  r  	liquidityMr$  r#  r  fee_currencyr  r  order_id
order_type)r  r  r  r  r  orderr  sidetakerOrMakerr  r  r  r  )
r  rr  r  r  r+   
string_mul
string_divr  
safe_trader,  )r  trader  r  r  r  r  r  priceStringr  r  r  r  feeCostStringr  feeCurrencyIdfeeCurrencyCodes                    r  parse_tradezderibit.parse_trade  s   V eZ00##E+<==!!(F33%%e[99	{33&&ug66!!(F33 !!%22!&+66) 	;%fk::D$$UK88	 '0C'7'777gL((66$ ,,UNCCM"55mDDO%+ C "Y//%%eZ88$$UL99(  
  
   	r  c                 N   |                                   |                     |          }|d         dd}|||d<   |t          |d          |d<   |                     |dd	          }||                     |dg          }||d	<   d}|.d	|vr*|                     |                     ||                    }n)|                     |                     ||                    }|                     |d
i           }	| 	                    |	dg           }
| 
                    |
|||          S )a  
        :see: https://docs.deribit.com/#public-get_last_trades_by_instrument
        :see: https://docs.deribit.com/#public-get_last_trades_by_instrument_and_time
        get the list of most recent trades for a particular symbol.
        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch trades for
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r  T)r  include_oldNr  r  countr  r  r  trades)r  r  r  rq  r~  "publicGetGetLastTradesByInstrumentr)  )publicGetGetLastTradesByInstrumentAndTimer  r  parse_trades)r  r  r  r  r  r  r2  r  r  r  r  s              r  fetch_tradeszderibit.fetch_tradesp  sG    	V$$%d|
 
 ).G%&"5$//GG##FG_EEYYvy11F',GO$MOw$>$>>>t{{7TZ?[?[\\HHEEdkkRY[aFbFbccH4 8R88"55  >>>r  c                    |                                   |                     d|          }|                     |          }|d         dd}|                     |                     ||                    }|                     |di           }|                     |dg           }i }i }	i }
t          dt          |                    D ]}||         }|                     |d          }|d	k    r/|| 	                    |d
          | 	                    |d          d}	U|dk    r/|| 	                    |d
          | 	                    |d          d}|dk    r.|| 	                    |d
          | 	                    |d          d}
i }t          dt          | j
                            D ]}| j
        |         }|                     |          }||dd|d         |d         d}|d         r|                     ||          }n=|d	         r|                     ||	          }n|d         r|                     ||
          }|||<   |S )aT  
        fetch the trading fees for multiple markets
        :see: https://docs.deribit.com/#private-get_account_summary
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        ro   r  T)r  extendedr  r   r   instrument_typer7   	maker_fee	taker_fee)r  r$  r#  r  r8   r$  r#  )r  r  rl  	tierBasedr$  r#  r6   )r  r  r  rI  r)  r  r  r  r  r  r{  r  )r  r  r  r  r2  r  r  r   perpetualFee	futureFee	optionFeer  r  instrumentType
parsedFeesr  r  s                    r  fetch_trading_feeszderibit.fetch_trading_fees  s    	%%&8&AA==&& 
 
 33DKK4P4PQQd 8R88vvr22		q#d))$$ 	 	Aq'C!--c3DEEN))!--c;??!--c;?? 		
  ;..!--c;??!--c;??   
  8++!--c;??!--c;?? 	
 
q#dl++,, 	% 	%A\!_F[[((F "! C f~ 2kk#|44! 2kk#y11! 2kk#y11!$Jvr  c                    |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |di           }|                     |d          }|                     |d          }	|                     ||d         |          }
|	|
d	<   |
S )
a1  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://docs.deribit.com/#public-get_order_book
        :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  r  Ndepthr  r  	change_idr  nonce)r  r  publicGetGetOrderBookr)  r  r  parse_order_book)r  r  r  r  r  r2  r  r  r  r  	orderbooks              r  fetch_order_bookzderibit.fetch_order_book  s     	V$$vd|
 $GG--dkk'6.J.JKKP 8R88%%fk::	!!&+66))&&2BINN	"	'r  c                 @    dddddd}|                      |||          S )Nrh  canceledclosedrejected)rh  	cancelledfilledr  untriggeredr  r  r   statusess      r  parse_order_statuszderibit.parse_order_statusZ  s7    #"!
 
 &&999r  c                 <    dddd}|                      |||          S )NGTCFOKIOC)good_til_cancelledfill_or_killimmediate_or_cancelr  )r  timeInForcetimeInForcess      r  parse_time_in_forcezderibit.parse_time_in_forced  s1    "'!#(
 

 k;GGGr  c                 >    ddddd}|                      |||          S )Nr  r  )
stop_limit
take_limitstop_markettake_marketr  )r  	orderType
orderTypess      r  parse_order_typezderibit.parse_order_typel  s4    !!##	
 

 
IyAAAr  c           	      8   |                      |d          }|                     ||          }|                     |d          }|                     |d          }|                      |d          }|                      |d          }|dk    rd }|                      |d          }|                      |d          }	|                      |d	          }
t          j        |	|          }|d
         r|dk    rt          j        |
|          }d }|	t          j        |	d          }|r|}|                     |                      |d                    }|                     |d          }|                      |d          }d }|t          j	        |          }||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%|          S )&Nr  r"  last_update_timestampr  r  market_priceaverage_pricefilled_amountr  r  0order_stater  
commissionr  r  r  r  time_in_force
stop_price	post_onlyr  r  clientOrderIdr  r  lastTradeTimestampr  r  r  postOnlyr  	stopPricetriggerPricer  rm  )r  	remainingr   r  r  )r  r  r  r+   r  r  	string_gtr  safe_string_lower
string_absr  r  r  
safe_orderr,  )r  r  r  r  r  
lastUpdater  r  averageStringfilledStringr  r  r  isFilledPositiver   r  r  r  rawTyper  r  r  r  r  s                           r  parse_orderzderibit.parse_orderu  s^   8 ##E+<==!!(F33%%e-ABB	&&u.EFF
eZ00&&ug66.((K((@@ ''??!!%22!,>>) 	A##)&-@@!#&0sCC 0%/"(()9)9%)O)OPP%%e[99((==$#.}==M%"6N C ""5,77$$W--11..t/?/?/W/WXXOOE<88	??5+66  
E 
" 
 T 
 	 

 Y// 
 !"4 
 fX& 
 D 
 ; 
  
 D 
 [ 
  
 I 
 f 
  D! 
" }# 
$ #- 
  
  
. /  	r  r  c                    |                                   d|i}d}||                     |          }|                     |                     ||                    }|                     |d          }|                     ||          S )a  
        fetches information on an order made by the user
        :see: https://docs.deribit.com/#private-get_order_state
        :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>`
        r  Nr  )r  r  privateGetGetOrderStater)  rx  r  )r  r  r  r  r2  r  r  r  s           r  fetch_orderzderibit.fetch_order  s     	
 [[((F//GV0L0LMM: (33///r  r  r  r  r  c                    |                                   |                     |          }|d         |                     ||          |d}|                     |dd          }	|                     |d          }
|                     |dd          }|                     |d          }|                     |d	          }|                     |d
d          }|du}|dk    }|dk    }|dk    }|dk    }|p|p|du}|p|p|du}|r|rt          | j	        dz             |p|}|dk    p|p|}|dk    p|p|}|                     |d          }| 
                    |||          }|rd|d<   |                     ||          |d<   nd|d<   |r#|	|d<   d|d<   |                     |          |d<   nC|rA||n|}|                     ||          |d<   |	|d<   |r|rd|d<   nd|d<   n|rd|d<   nd|d<   |rd|d<   |r
d|d<   d|d<   |
!|
dk    rd|d<   |
dk    rd|d<   |
d k    rd!|d<   |                     |g d"          }d}|                     |          d#k    r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |d$i           }|                     |d%          }|                     |d&g           }||d&<   |                     ||          S )'a.  
        create a trade order
        :see: https://docs.deribit.com/#private-buy
        :see: https://docs.deribit.com/#private-sell
        :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 you want to trade in units of the base currency. For inverse perpetual and futures the amount is in the quote currency USD. For options it is in the underlying assets base currency.
        :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.trigger]: the trigger type 'index_price', 'mark_price', or 'last_price', default is 'last_price'
        :param float [params.trailingAmount]: the quote amount to trail away from the current market price
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  )r  r  r  triggerrV  r  
reduceOnlyreduce_onlystopLossPricetakeProfitPricetrailingAmounttrigger_offsetNr  r  r  r  zR createOrder() only allows one of stopLossPrice or takeProfitPrice to be specifiedr  r  r  r  r  trailing_stoptrigger_priceTreject_post_onlyr  r  r  r  r  r  r  )r  r	  r
  r  r  r  Buyr  r  r  )r  r  amount_to_precisionr  safe_string_uppersafe_value_2r  rs  r$   r  is_post_onlyprice_to_precisionparse_to_numericr~  
capitalizeprivateGetBuyr)  privateGetSellr  ) r  r  r  r  r  r  r  r  r2  r  r  r  r	  r
  r  isTrailingAmountOrderisStopLimitisStopMarketisTakeLimitisTakeMarketisStopLossOrderisTakeProfitOrderisStopOrderisLimitOrderisMarketOrderexchangeSpecificPostOnlyr  r  r  r  r  r  s                                    r  create_orderzderibit.create_order   s    	V$$%d|..vv>>
 
 ""69lCC,,V]CC&&v|]KK
@@//&2CDD++F4DFVWW .d :l*},l*},%TT-t:S'X<XOSW<W 	0 	tw)}}~~~%:):FKF;)JlJl#'??6;#G#G $$]4LfUU 	'%GFO#66vuEEGG&GFO  	3!(GI-GFO(,(=(=n(M(MG$%% 	3-:-F==_L'+'>'>v|'T'TGO$!(GI 3  3&3GFOO '3GFOO  3&3GFOO '3GFO 	*%)GM" 	/#'GK *.G&'"e##+?(e##+@(e##+9(6  $C  $C  $C  D  D??4  E))))$++gv*F*FGGHH**4;;w+G+GHHHj 8R8800266 hv...r  c                 h   |t          | j        dz             |                                  ||                     ||          d}||                     ||          |d<   |                     |dd          }	|	du}
|
r.|                     |	          |d<   |                     |d          }|                     | 	                    ||                    }| 
                    |di           }| 
                    |d          }| 
                    |d	g           }||d	<   |                     |          S )
aN  
        edit a trade order
        :see: https://docs.deribit.com/#private-edit
        :param str id: edit order id
        :param str [symbol]: unified symbol of the market to edit an order in
        :param str [type]: 'market' or 'limit'
        :param str [side]: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency, inverse swap and future use the quote currency
        :param float [price]: the price at which the order is to be fullfilled, in units of the base currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.trailingAmount]: the quote amount to trail away from the current market price
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( editOrder() requires an amount argument)r  r  r  r  r  r  r  r  )r    r  r  r  r  rs  r  r~  privateGetEditr)  r  r  )r  r  r  r  r  r  r  r  r2  r  r  r  r  r  r  s                  r  
edit_orderzderibit.edit_order  sI    >#DG.X$XYYY..vv>>
 
 #66vuEEGG++F4DFVWW .d :  	9(,(=(=n(M(MG$%YYv'788F&&t{{7F'C'CDD8R8800266 h&&&r  c                     |                                   d|i}|                     |                     ||                    }|                     |di           }|                     |          S )aj  
        cancels an open order
        :see: https://docs.deribit.com/#private-cancel
        :param str id: order id
        :param str symbol: not used by deribit cancelOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  )r  privateGetCancelr)  rx  r  )r  r  r  r  r2  r  r  s          r  cancel_orderzderibit.cancel_order  sn     	
 ((Wf)E)EFF(B77'''r  c                     |                                   i }d}|*|                     |                     ||                    }nI|                     |          }|d         |d<   |                     |                     ||                    }|S )a  
        cancel all open orders
        :see: https://docs.deribit.com/#private-cancel_all
        :see: https://docs.deribit.com/#private-cancel_all_by_instrument
        :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
        :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>`
        Nr  r  )r  privateGetCancelAllr)  r  privateGetCancelAllByInstrument)r  r  r  r2  r  r  s         r  cancel_all_orderszderibit.cancel_all_orders  s     	>//GV0L0LMMHH[[((F)/G%&;;DKKQW<X<XYYHr  c                    |                                   i }d}d}|`|                     d|          }|                     |          }	|	d         |d<   |                     |                     ||                    }nI|                     |          }|d         |d<   |                     |                     ||                    }|                     |dg           }
|                     |
|||          S )ab  
        fetch all unfilled currently open orders
        :see: https://docs.deribit.com/#private-get_open_orders_by_currency
        :see: https://docs.deribit.com/#private-get_open_orders_by_instrument
        :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 orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr^   r  r  r  r  )	r  r  r  !privateGetGetOpenOrdersByCurrencyr)  r  #privateGetGetOpenOrdersByInstrumentr  parse_ordersr  r  r  r  r  r2  r  r  r  r  r  s              r  fetch_open_orderszderibit.fetch_open_orders  s     	>))*;VDDD}}T**H"*4.GJ==dkk'SY>Z>Z[[HH[[((F)/G%&??GU[@\@\]]H(B77  >>>r  c                    |                                   i }d}d}|`|                     d|          }|                     |          }	|	d         |d<   |                     |                     ||                    }nI|                     |          }|d         |d<   |                     |                     ||                    }|                     |dg           }
|                     |
|||          S )a  
        fetches information on multiple closed orders made by the user
        :see: https://docs.deribit.com/#private-get_order_history_by_currency
        :see: https://docs.deribit.com/#private-get_order_history_by_instrument
        :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>`
        NrG   r  r  r  r  )	r  r  r  #privateGetGetOrderHistoryByCurrencyr)  r  %privateGetGetOrderHistoryByInstrumentr  r3  r4  s              r  fetch_closed_orderszderibit.fetch_closed_orders  s     	>))*=vFFD}}T**H"*4.GJ??GU[@\@\]]HH[[((F)/G%&AA$++gW]B^B^__H(B77  >>>r  c                     |                                   d|i}|                     |                     ||                    }|                     |dg           }|                     |d||          S )a  
        fetch all the trades made from a single order
        :see: https://docs.deribit.com/#private-get_user_trades_by_order
        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        r  r  N)r  privateGetGetUserTradesByOrderr)  r  r  )	r  r  r  r  r  r  r2  r  r  s	            r  fetch_order_tradeszderibit.fetch_order_trades   sw     	
 66t{{7F7S7STTD (B77  ue<<<r  c                    |                                   ddi}d}|||d<   d}||                     d|          }|                     |          }	|	d         |d<   |*|                     |                     ||                    }n||d<   |                     |                     ||                    }nz|                     |          }|d         |d	<   |*|                     |                     ||                    }n.||d<   |                     |                     ||                    }| 	                    |d
i           }
| 
                    |
dg           }|                     ||||          S )a  
        fetch all trades made by the user
        :see: https://docs.deribit.com/#private-get_user_trades_by_currency
        :see: https://docs.deribit.com/#private-get_user_trades_by_currency_and_time
        :see: https://docs.deribit.com/#private-get_user_trades_by_instrument
        :see: https://docs.deribit.com/#private-get_user_trades_by_instrument_and_time
        :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>`
        r  TNr  r\   r  r  r  r  r  r  )r  r  r  !privateGetGetUserTradesByCurrencyr)  (privateGetGetUserTradesByCurrencyAndTimer  #privateGetGetUserTradesByInstrument*privateGetGetUserTradesByInstrumentAndTimer  r  r  )r  r  r  r  r  r2  r  r  r  r  r  r  s               r  fetch_my_tradeszderibit.fetch_my_tradesT  s    	4
 $GG>))/6BBD}}T**H"*4.GJ}AA$++gW]B^B^__-2)*HHU\^dIeIeff[[((F)/G%&}CCDKKPWY_D`D`aa-2)*JJ4;;W^`fKgKghhD 8R88"55  >>>r  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	||||          S )a  
        fetch all deposits made to an account
        :see: https://docs.deribit.com/#private-get_deposits
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nz2 fetchDeposits() requires a currency code argumentr  r  r  r  r  )	r    r  r  r  privateGetGetDepositsr)  r  r  parse_transactions
r  r  r  r  r  r  r2  r  r  r  s
             r  fetch_depositszderibit.fetch_deposits  s     <#DG.b$bccc==&&
 $GG--dkk'6.J.JKK* 8R88~~ffb11&&tXueVLLLr  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	||||          S )a  
        fetch all withdrawals made from an account
        :see: https://docs.deribit.com/#private-get_withdrawals
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nz5 fetchWithdrawals() requires a currency code argumentr  r  r  r  r  )	r    r  r  r  privateGetGetWithdrawalsr)  r  r  rE  rF  s
             r  fetch_withdrawalszderibit.fetch_withdrawals  s     <#DG.e$efff==&&
 $GG00Wf1M1MNN2 8R88~~ffb11&&tXueVLLLr  c                 :    ddd}|                      |||          S )Nr  pending)	completedunconfirmedr  r  s      r  parse_transaction_statusz deribit.parse_transaction_status  s.    $
 
 &&999r  c                    |                      |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S )Nr  created_timestampreceived_timestampupdated_timestampstaterL  r  r  
withdrawalr  r  r  txidtransaction_idr  r  	addressToaddressFromrM  tagTotagFromr  r  r   r  rR  )internalcommentr  )r  r  rq  r  rO  r  r,  )r  transactionr  r  r  r  r  r   rL  feeCostr  r  s               r  parse_transactionzderibit.parse_transaction	  s   < %%k:>>
&&z8<<''5HJ^__	##K1DEE..t/?/?W/U/UVV"";	::"";66D  C
K
$"";55
 D$$[2BCC
 	

 Y//
 w
 
 4
 4
 T
 t
 D
 d&&{H==
 
 f
  w!
" t#
$ )
 
 
 	
r  c                    |                      |d          }|                     ||          }|                      |d          }|dk    rdnd}|                      |d          }|                      |d          }|                      |d          }|                      |d	          }|                                 }	|                     i d
|dd d|                      |d          d|	d|                     |	          dd d|                     |          d|                     t          j        t          j        ||          d                    d|                     |          d|                     t          j        t          j        ||          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  r   longshortfloating_profit_lossinitial_marginsize_currencyr@  r  r  r  r  r  lastUpdateTimestampinitialMargininitialMarginPercentage100maintenanceMarginmaintenanceMarginPercentage
entryPricer  notionalr!  unrealizedPnl	contractsr  marginRatioestimated_liquidation_price
mark_price)
liquidationPrice	markPrice	lastPrice
collateral
marginModer  rl  hedgedr	  r
  )r  r  r  safe_positionr,  r  r+   r  r  r  r  )
r  positionr  r  r  ro  initialMarginStringnotionalStringmaintenanceMarginStringcurrentTimes
             r  parse_positionzderibit.parse_positionF	  s	   6 ##H.?@@!!(F33+66%--vvg((3IJJ"..x9IJJ))(ODD"&"2"28=Q"R"R''))!! #
H#
$#
 d&&vx88#
 	#

 [11#
 "4#
 T../BCC#
 &t'8'89KGL^_r  uC  MD  MD  FK  :L  :L  (M  (M#
  !2!23J!K!K#
 *4+<+<W=OPWPbcz  }K  QL  QL  NS  >T  >T  ,U  ,U#
 $**8_EE#
 )).99#
 ))(J??#
 T..}==#
 #
  D,,V^DD!#
" 4##
$ !% 0 0;X Y Y))(LAA!#7#
 #
 #
   	r  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     |          S )a  
        fetch data on a single open contract trade position
        :see: https://docs.deribit.com/#private-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>`
        r  r  r  )r  r  privateGetGetPositionr)  rx  r  ry  s          r  fetch_positionzderibit.fetch_position	  s     	V$$vd|
 --dkk'6.J.JKK6 (33""6***r  c                    |                                   |                     |d          }d}||                     d|          }nt          |t                    r|}d}n~t          |t
                    rit          |          }|dk    rt          | j        dz             | 	                    |d                   }|d         }||n|d         }|d	         d         }| 
                    |          }d
|d         i}	|||	d<   |                     |                     |	|                    }
|                     |
d          }|                     ||          S )a  
        fetch all open positions
        :see: https://docs.deribit.com/#private-get_positions
        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.kind]: market type filter for positions 'future', 'option', 'spot', 'future_combo' or 'option_combo'
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        r  Nrg   r   zD fetchPositions() symbols argument cannot contain more than 1 symbolr   r  r  r  r  r  r  )r  r  r  
isinstancestrlistr  r!   r  r  r  privateGetGetPositionsr)  r  parse_positions)r  r{  r  r  r  lengthr  r  r  r2  r  r  s               r  fetch_positionszderibit.fetch_positions	  sd    	//?))*:FCCDD%% 	.DGG'4(( .WQ;;$TW/u%uvvvWQZ00)"("4vv6&>f~f-==&&
 "GFO..t{{7F/K/KLL< (33##FG444r  c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |          S )a  
        fetch the historical volatility of an option market based on an underlying asset
        :see: https://docs.deribit.com/#public-get_historical_volatility
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `volatility history objects <https://docs.ccxt.com/#/?id=volatility-structure>`
        r  r  )r  r   publicGetGetHistoricalVolatilityr)  parse_volatility_history)r  r  r  r  r2  r  s         r  fetch_volatility_historyz deribit.fetch_volatility_history	  sp     	==&&
 88Wf9U9UVV ,,X666r  c                 B   |                      |dg           }g }t          dt          |                    D ]g}|                     ||         d          }|                     ||         d          }|                    |||                     |          |d           h|S )Nr  r   r   )r  r  r  
volatility)r  r  r  r  r  r(  r,  )r  r  volatilityResultr  r  r  volatilityObjs          r  r  z deribit.parse_volatility_history
  s      ??:xDDq#.//00 	 	A))*:1*=qAAI ,,-=a-@!DDMMM%& LL33+	      r  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	||||          S )a1  
        fetch a history of internal transfers made on an account
        :see: https://docs.deribit.com/#private-get_transfers
        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of  transfers structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
        Nz3 fetchTransfers() requires a currency code argumentr  r  r  r  r  )	r    r  r  r  privateGetGetTransfersr)  r  r  parse_transfers)
r  r  r  r  r  r  r2  r  r  	transferss
             r  fetch_transferszderibit.fetch_transfers.
  s     <#DG.c$cddd==&&
 $GG..t{{7F/K/KLLD 8R88NN66266	##IxvNNNr  fromAccount	toAccountc                 >   |                                   |                     |          }||d         |d}|                     |d          }|                     |d          }|3|                     | j        di           }	|                     |	dd          }d}
|dk    r*|                     |                     ||                    }
n)|                     |                     ||                    }
| 	                    |
di           }| 
                    ||          S )	ai  
        transfer currency internally between wallets on the same account
        :see: https://docs.deribit.com/#private-submit_transfer_to_user
        :see: https://docs.deribit.com/#private-submit_transfer_to_subaccount
        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        r  )r  r  destinationr  Nrw   r  privateGetSubmitTransferToUserr  )r  r  r  r~  r  r  r  r)  r  rx  parse_transfer)r  r  r  r  r  r  r  r2  r  transferOptionsr  r  s               r  rw   zderibit.transferg
  s"    	==&& $
 

 !!&(3368,,>"oodlJKKO%%oxAghhF555::4;;wPV;W;WXXHH@@WV\A]A]^^H$ (B77""68444r  c                    |                      |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }||                     |d          |                     |          |                     |d          |                     ||          ||k    ||k    ||                     |          d		S )
NrQ  rT  
other_sider  r  r  r  payment)	r  r  r   r  r  r  r  r  r  )safe_timestampr  parse_transfer_statusr  r  r,  )r  rw   r  r  r   r  r  r  s           r  r  zderibit.parse_transfer
  s     ''2EFF	!!(G44""8\::$$X{;;	%%h
;;
""8T220088&&x::++JAA$/"g-"Y//

 

 
	
r  c                 >    ddddd}|                      |||          S )NrL  r  r  )prepared	confirmedr  waiting_for_adminr  r  s      r  r  zderibit.parse_transfer_status
  s4    !$!*	
 
 &&999r  c                    |                      ||          \  }}|                     |           |                                  |                     |          }|d         ||d}| j        |                     | j                  |d<   |                     |                     ||                    }|                     ||          S )a  
        make a withdrawal
        :see: https://docs.deribit.com/#private-withdraw
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r  )r  rL  r  Ntfa)	handle_withdraw_tag_and_paramsrO  r  r  twofatotpprivateGetWithdrawr)  r`  )	r  r  r  rL  rM  r  r  r2  r  s	            r  rx   zderibit.withdraw
  s     99#vFFV7###==&& 
 
 :!!YYtz22GEN**4;;w+G+GHH%%h999r  c                 D    ||                      |d          ddd d di dS )Nr  F)r  rl  )r  rx   r  r  )r  )r  r  r  s      r  parse_deposit_withdraw_feez"deribit.parse_deposit_withdraw_fee
  sN     ''-=>># 
 "  
 
 	
r  codesc                     |                                   |                     |          }|                     |dg           }|                     ||d          S )ab  
        fetch deposit and withdraw fees
        :see: https://docs.deribit.com/#public-get_currencies
        :param str[]|None codes: list of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
        r  r  )r  r  r  parse_deposit_withdraw_fees)r  r  r  r  r  s        r  fetch_deposit_withdraw_feesz#deribit.fetch_deposit_withdraw_fees
  sX     	..v66. ~~h"55//eZHHHr  c                    |                                   |                     |          }|                                 }|d         |dz
  |d}|                     |                     ||                    }|                     ||          S )a  
        fetch the current funding rate
        :see: https://docs.deribit.com/#public-get_funding_rate_value
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.start_timestamp]: fetch funding rate starting from self timestamp
        :param int [params.end_timestamp]: fetch funding rate ending at self timestamp
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        r  i tr  r  r  )r  r  r  publicGetGetFundingRateValuer)  parse_funding_rate)r  r  r  r  timer2  r  s          r  fetch_funding_ratezderibit.fetch_funding_rate  s     	V$$  ""%d|#'9:!
 

 44T[[&5Q5QRR &&x888r  c           	      x   |                                   |                     |          }d}|                     |dd          \  }}|r|                     d|||d|d          S |                                 }d}|||z
  }|d         |d	z
  |d
}	|                     |                     |	|                    }
g }|                     |
dg           }t          dt          |                    D ]5}||         }| 
                    ||          }|                    |           6|                     ||||          S )a  
        fetch the current funding rate
        :see: https://docs.deribit.com/#public-get_funding_rate_history
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.end_timestamp]: fetch funding rate ending at self timestamp
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        FrP   r  8hi  l    H4 Nr  r   r  r  r   )r  r  r&  r  r  publicGetGetFundingRateHistoryr)  r  r  r  r  r(  filter_by_symbol_since_limit)r  r  r  r  r  r  r  r  monthr2  r  ratesr  r  frrates                   r  fetch_funding_rate_historyz"deribit.fetch_funding_rate_history7  sf    	V$$88AZ\fgg& 	::;TV\^cejlprxz}~~~  ""(=5LE%d|$qy!
 

 66t{{7F7S7STT  8R88q#f++&& 	 	AB**2v66DLL00uMMMr  c                 @   |                      |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 S )Nr  r  interest_8hr  r  ru  
indexPriceindex_priceinterestRateestimatedSettlePricer  fundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetime)r  r,  safe_number_2rr  r  )r  r  r  r  r  r  s         r  r  zderibit.parse_funding_rateh  s3   & %%h<<	<<	**##HhFF
H
d&&tV44
 
 $**8]CC	

 D
 #D
 
 
 6
 
 t
 t
 #D
 "4
 "4
  '!
" &t#
 	
r  c           
         |                                   d}|                     |dd          \  }}|r|                     d||||ddd          S |                     |          }|d         r#t	          | j        dz   |d         z   d	z             |d
         dd}|||d<   |||d<   |                     |                     ||                    }|                     |di           }	| 	                    |	d          }
|                     |	dg           }| 
                    |
|          }|                     ||||          S )a(  
        retrieves the public liquidations of a trading pair
        :see: https://docs.deribit.com/#public-get_last_settlements_by_currency
        :param str symbol: unified CCXT market symbol
        :param int [since]: the earliest time in ms to fetch liquidations for
        :param int [limit]: the maximum number of liquidation structures to retrieve
        :param dict [params]: exchange specific parameters for the deribit api endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
        FrV   r  continuationNr4   z& fetchLiquidations() does not support r   marketsr  
bankruptcyr  r  search_start_timestampr  r  settlements)r  r&  fetch_paginated_call_cursorr  r&   r  'publicGetGetLastSettlementsByInstrumentr)  r  r  add_pagination_cursor_to_resultparse_liquidations)r  r  r  r  r  r  r  r2  r  r  cursorr  settlementsWithCursors                r  fetch_liquidationszderibit.fetch_liquidations  s    	88ATV`aa& 	M334GQVX]_egu  xF  HL  M  M  MV$$&> 	qtw)QQTZ[aTbbeooppp%d| 
 
 05G,-$GG??GU[@\@\]]2 8R88!!&.99oofmR@@ $ D DV[ Y Y&&'<feUSSSr  c                     |?t          |          }|dk    r*|d         }||dz
           }||d<   ||d<   ||d<   |||dz
  <   |S )Nr   r   r  )r  )r  r  r  
dataLengthfirstrW  s         r  r  z'deribit.add_pagination_cursor_to_result  sc    TJA~~QJN+(.n%'-^$Q'+Z!^$r  c                    |t          | j        dz             |                                  |                     |          }|d         r#t	          | j        dz   |d         z   dz             |d         dd	}|||d
<   |||d<   |                     |                     ||                    }|                     |di           }|                     |dg           }	| 	                    |	|||          S )a0  
        retrieves the users liquidated positions
        :see: https://docs.deribit.com/#private-get_settlement_history_by_instrument
        :param str symbol: unified CCXT market symbol
        :param int [since]: the earliest time in ms to fetch liquidations for
        :param int [limit]: the maximum number of liquidation structures to retrieve
        :param dict [params]: exchange specific parameters for the deribit api endpoint
        :returns dict: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
        Nz1 fetchMyLiquidations() requires a symbol argumentr4   z( fetchMyLiquidations() does not support r  r  r  r  r  r  r  r  r  )
r    r  r  r  r&   *privateGetGetSettlementHistoryByInstrumentr)  r  r  r  )
r  r  r  r  r  r  r2  r  r  r  s
             r  fetch_my_liquidationszderibit.fetch_my_liquidations  s    >#DG.a$abbbV$$&> 	stw)SSV\]cVddgqqrrr%d| 
 
 05G,-$GGBB4;;wX^C_C_``2 8R88nnV]B??&&{FE5IIIr  c                 
   |                      |d          }|                     ||                     d |          d |                     |d          d |                     |d          d ||                     |          d	          S )Nr  r  session_bankrupcy)	r  r  rp  r  r  	baseValue
quoteValuer  r  )r  safe_liquidationrr  r  r,  )r  liquidationr  r  s       r  parse_liquidationzderibit.parse_liquidation  s     %%k;??	$$&&tV44 ,,V^DD))+7JKK"Y//
&
 
&
 
 
 
	r  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract
        :see: https://docs.deribit.com/#public-ticker
        :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  r  r  )r  r  rw  r)  r  parse_greeksry  s          r  fetch_greekszderibit.fetch_greeks'  s     	V$$vd|
 ''GV(D(DEE^ 8R88  000r  c                    |                      |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S )Nr  r  greeksr  r  deltagammathetavegarhobidSizera  askSizerf  bidImpliedVolatilitybid_ivaskImpliedVolatilityask_ivmarkImpliedVolatilitymark_ivbidPricer^  askPricerc  ru  rs  rv  rV  underlying_price)underlyingPricer  )r  r  rr  r  r,  r  )r  r  r  r  r  r  rX  s          r  r  zderibit.parse_greeksf  sD   P %%fk::	##F,=>>!!(F33"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''0ABB
 t''0ABB
 #D$4$4VX$F$F
 #D$4$4VX$F$F
 $T%5%5fi%H%H
 ((1ABB
 ((1ABB
  ))&,??!
" ))&,??#
$  $//8JKK'
 
 
 	
r  c                 D   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     |di           }|                     |d|          S )a  
        fetches option data that is commonly found in an option chain
        :see: https://docs.deribit.com/#public-get_book_summary_by_instrument
        :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  r  r  r   N)r  r  #publicGetGetBookSummaryByInstrumentr)  r  rx  parse_option)r  r  r  r  r2  r  r  chains           r  fetch_optionzderibit.fetch_option  s     	V$$vd|
 ;;DKKQW<X<XYYB (B77vq"--  f555r  c                    |                                   |                     |          }|d         dd}|                     |                     ||                    }|                     |dg           }|                     |dd          S )a  
        fetches data for an underlying asset that is commonly found in an option chain
        :see: https://docs.deribit.com/#public-get_book_summary_by_currency
        :param str currency: base currency to fetch an option chain for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `option chain structures <https://docs.ccxt.com/#/?id=option-chain-structure>`
        r  r8   )r  r  r  r  r  )r  r  r  r)  r  parse_option_chain)r  r  r  r  r2  r  r  s          r  fetch_option_chainzderibit.fetch_option_chain  s     	==&& 
 
 99$++gv:V:VWWB (B77&&v@QRRRr  c                 
   |                      |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          S )Nr  r  r  r  r  r  r  impliedVolatilityopenInterestopen_interestr  r_  r  rd  midPrice	mid_priceru  rs  rv  rW  r  r  rk  rl  price_changero  rn  rp  
volume_usd)r  r  r  r  r,  r  )r  r  r  r  r  r  r  r  s           r  r  zderibit.parse_option  s   0 ##E+<==!!(F33%%e_==
&&z8<<%%e[99	
E

 fX&
 	

 Y//
  
 D,,UODD
 ((<<
 ((<<
 ((<<
 ))%>>
 ))%88
 t//7IJJ
 d
 $**5.AA
  $**5(;;!
" 4++E<@@#
 	
r  c                 *    |                                  S N)r  )r  s    r  r  zderibit.nonce=  s      """r  r  GETc                    d| j         z   dz   |z   dz   |z   }|dk    r|r|d|                     |          z   z  }|dk    r|                                  t          |                                           }t          |                                           }	d}
|r|d|                     |          z   z  }|dz   |z   dz   |
z   dz   }|	dz   |z   dz   |z   }|                     |                     |          |                     | j                  t          j
                  }dd	| j        z   d
z   |	z   dz   |z   dz   dz   |z   i}| j        d         d         |z   }||||dS )Nz/api/r  r  ?r  r  
Authorizationzderi-hmac-sha256 id=z,ts=z,sig=,znonce=r   r   )r   r  bodyheaders)r  	urlencodecheck_required_credentialsr  r  r  hmacencodesecrethashlibsha256apiKeyr  )r  pathr   r  r  r  r  r2  r  r  requestBodyrequestDatar   	signaturer   s                  r  signzderibit.sign@  s   -3c9C?$F(?? 83!7!777)++---

%%ED--//00IK 83!7!777 4-'1D8;FMKt#e+d2[@D		$++d"3"3T[[5M5Mw~^^I!7$+!E!NQZ!Z]d!dgp!psv!v  zB  "B  EJ  "JG iv&0fdwOOOr  c
                     |sd S |                      |d          }
|
N|                     |
d          }| j        dz   |z   }|                     | j        ||           t          |          d S )Nerrorr   )r  r  r  throw_exactly_matched_exceptionr  r   )r  httpCodereasonr   r  r  r  r  requestHeadersr(  r-  	errorCodefeedbacks                r  handle_errorszderibit.handle_errorsU  s|     	4 '22((77Iw}t+H00)XVVV)))tr  )NNNNr  )NN)a__name__
__module____qualname__r  r  r  r   r   r   r  r  r   r  r  r  r   r   r	  r   r  r<  r   rG  rJ  r  rT  r   ru  rz  r   r   r  r
   r  r  r   r  r  r   r  r   r  r  r  r  r   r  r  r   r   floatr   r%  r(  r+  r/  r5  r9  r<  rB  r   rG  rJ  rO  r`  r  r  r  r  r  r  r   rw   r  r  rx   r  r  r  r  r  r  r  r  r  r	   r  r  r   r	  r   r  r  r  r+  r5  __classcell__)r  s   @r  r-   r-      s       D D D D DLH
3 H
 H
 H
 H
TY YC Y YRU Yjm Y  zI Y Y Y Y Y Y !# 5 5 5 5( ') ? ?Z ? ? ? ?B 46 5 5 5 5 #% 
 
 
 
> %' ,+ ,+4= ,+ ,+ ,+ ,+\
 
x 
 
 
 
, $& \ \$v, \ \ \ \|) ) ) ) ) $& 9* 9*( 9* 9* 9* 9*v 8: "
 "
3 "
 "
 "
 "
H 79 (
 (
# (
 (
 (
 (
TI I6 IV I I I IV 02 +1 +13 +1f +1 +1 +1 +1Z 04B 8H 8HW 8H7 8H 8H 8H 8Ht 26DW[df ?J ?J# ?Jc ?JQT ?Jkoptku ?J ?J ?J ?JBT T T5 T T T Tl 6:UW :? :?3 :?s :?# :?\`af\g :? :? :? :?x )+ m m{ m m m m^ :>b = =s =3 =Y = = = =~: : :H H HB B BZ Z Z5 Z Z Z Zx 26b -0 -0c -03 -0 -0 -0 -0^ gksu [/ [/3 [/i [/y [/RW [/`c [/ [/ [/ [/z `drv  @B &' &'S &'# &'Y &'i &'Y\ &'lo &' &' &' &'P 37r ( (s (C ( ( ( (" /32      ( /3TXac ? ? ?3 ?c ?hlmrhs ? ? ? ?6 154VZce ? ?# ?S ?PS ?jnotju ? ? ? ?6 9=4^bkm 2= 2=S 2=# 2=S 2=X[ 2= 2= 2= 2=h -1tRV_a I? I?c I? I?C I? I? I? I?V *.Dt\^ *M *M3 *Mc *M *Mcghsct *M *M *M *MX -1tRV_a .M .Mc .M .MC .Mfjkvfw .M .M .M .M`: : :B
 B
x B
; B
 B
 B
 B
H@ @v @ @ @ @D 24 )+ )+S )+ )+ )+ )+V 26b ?5 ?5w ?5 ?5 ?5 ?5B :< 7 7S 7 7 7 7<  8 +/TPT]_ 7O 7OC 7Os 7O# 7O 7O 7O 7Or [] /5 /5S /5% /5c /5c /5an /5 /5 /5 /5b
 
 
 
 
 
>: : : ?C2 : :S :% : : : :6
 
 
 
 
 
4 <@ !I !I !I !I !I !IF 68 9 9 9 9 9 9> 8<$]ajl /N /N /NC /NWZ /N /N /N /Nb(
 (
6 (
 (
 (
 (
T <@d[] 8T 8T 8TS 8T 8T 8T 8T 8Tt
 
 
 37TX\eg 3J 3JC 3Js 3JRU 3J 3J 3J 3Jj V    4 02 =1 =13 =1f =1 =1 =1 =1~@
 @
6 @
 @
 @
 @
D 02 06 063 06f 06 06 06 06d 46 0S 0Ss 0S+ 0S 0S 0S 0Sd/
 /
H /
V /
 /
 /
 /
b# # # &eBSW P P P P*      r  r-   )2ccxt.base.exchanger   ccxt.abstract.deribitr   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   typingr   ccxt.base.errorsr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   ccxt.base.decimal_to_precisionr*   ccxt.base.preciser+   r-    r  r  <module>rC     s   ( ' ' ' ' ' - - - - - -  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {  {       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' . . . . . . + + + + + + ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) + + + + + + 1 1 1 1 1 1 * * * * * * 4 4 4 4 4 4 % % % % % %P5 P5 P5 P5 P5h P5 P5 P5 P5 P5r  