
    E#i                         S SK rS SKJrJrJr  S SKrS SKJrJ	r	J
r
JrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr   " S	 S
\R4                  R6                  5      rg)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)
AnyBalancesIntOrder	OrderBookStrStringsTickerTickersTrade)Client)List)ExchangeError)ArgumentsRequired)NotSupportedc                     ^  \ rS rSrS\4U 4S jjrS r0 4S\4S jjrS\	4S jr
0 4S\S\4S	 jjrS
0 4S\S\4S jjrS\	4S jrS
0 4S\S\4S jjrS\	4S jrS.S jrS
S
0 4S\S\S\S\\   4S jjrS
S
0 4S\\   S\S\S\\   4S jjrS\	4S jrS
S
S
0 4S\S\S\S\\   4S jjrS\	4S jrS
0 4S\S\S\4S jjrS
0 4S\\   S\S\4S jjr S\	4S jr!S r"S r#S r$S
S
S
0 4S\S\S\S\\%   4S jjr&S\	4S jr'S S
S
0 4S\S!\S\S\S\\(   4
S" jjr)S
S
0 4S#\\\      S\S\4S$ jjr*S\	4S% jr+S.S\(4S& jjr,S
0 4S'\S(\4S) jjr-S\	4S* jr.S\	4S+ jr/0 4S, jr0S-r1U =r2$ )/deribit   returnc                    > U R                  [        [        U ]  5       SSSSSSSSSSSSSS.SS0SS0S.SSS	S
SSSSSSSS.SS0SSSSS.S./ SQS.0 0 S.5      $ )NT)wswatchBalancewatchTickerwatchTickerswatchBidsAskswatchTradeswatchTradesForSymbolswatchMyTradeswatchOrderswatchOrderBookwatchOrderBookForSymbols
watchOHLCVwatchOHLCVForSymbolsr   z wss://test.deribit.com/ws/api/v2zwss://www.deribit.com/ws/api/v2)testapi1351530601201803607201D)1m3m5m15m30m1h2h4h6h12h1dinterval100msF20none)r?   useDepthEndpointdepthgroup)
timeframesr    r$   )BTCETHSOLUSDC)r   
currencies)hasurlsoptions	streaming
exceptions)deep_extendsuperr   describe)self	__class__s    J/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/deribit.pyrS   deribit.describe   s    gt = ? $# $!%#)-!%#"&,0"(," < ;	 "!!##"###$"# #G.
 %,,1!%!'	1'4 <7:o9B
 9 9	    c                 |    U R                  U R                  U R                  SS5      S5      nXR                  S'   U$ )N	requestIdr      )sumsafe_integerrN   )rT   rZ   s     rV   
request_idderibit.request_idO   s7    HHT..t||[!LaP	$-[!rX   c                   #    U R                  U5      I Sh  vN   SnU R                  S   S   nU R                  U R                  S/ 5      n/ n[	        S[        U5      5       H  nXF   nUR                  SU-   5        M     SS	S
U0U R                  5       S.nU R                  X5      n	U R                  X2XU	5      I Sh  vN $  N N7f)a1  

https://docs.deribit.com/#user-portfolio-currency

watch balance and get the amount of funds available for trading or funds locked in orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nbalancer(   r   rK   r   zuser.portfolio.2.0private/subscribechannelsjsonrpcmethodparamsid)
authenticaterM   
safe_valuerN   rangelenappendr^   rQ   watch)
rT   rh   messageHashurlrK   rd   icurrencyCode	subscriberequests
             rV   watch_balancederibit.watch_balanceT   s      '''iit$__T\\<D
q#j/*A%=LOO-<= + )H //#
	 ""95ZZ'PPP# 	(" Qs"   C
CB)C
CC
C
clientc                 ,   U R                  US0 5      nU R                  US0 5      nX@R                  S'   U R                  US5      nU R                  U5      nU R	                  U5      nXpR                  U'   SnUR                  U R                  U5        g )Nrh   datainfocurrencyra   )rk   ra   safe_stringsafe_currency_codeparse_balanceresolve)	rT   rx   messagerh   rz   
currencyIdrs   ra   rp   s	            rV   handle_balancederibit.handle_balancep   s    X (B7vvr2#V%%dJ7
..z:$$T*%,\"t||[1rX   symbolc                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  S   S   nU R                  USS5      nU R	                  US5      nU R                  5       I Sh  vN   US:X  a  U R                  5       I Sh  vN   SUS   -   S	-   U-   nS
SSSUS   -   S	-   U-   /0U R                  5       S.nU R                  Xr5      nU R                  XFXU5      I Sh  vN $  N N Nf N
7f)a  

https://docs.deribit.com/#ticker-instrument_name-interval

watches a price ticker, a statistical calculation with the information for a specific market.
:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.interval]: specify aggregation and frequency of notifications. Possible values: 100ms, raw
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr(   r   r?   r@   rawticker.ri   .rb   public/subscriberd   re   )	load_marketsmarketrM   r}   omitrj   r^   rQ   ro   )	rT   r   rh   r   rq   r?   channelr   ru   s	            rV   watch_tickerderibit.watch_ticker   s     !!!V$iit$##FJ@6:.!!!u##%%%fTl*S08;(Y5;hFG //#
 ""73ZZgHHH% 	"
 	"% IsG   C?C7AC?6C97C?C;AC?2C=3C?9C?;C?=C?Nsymbolsc                   #    U R                  5       I Sh  vN   U R                  USS5      nU R                  S   S   nU R                  USS5      nU R	                  US5      nU R                  5       I Sh  vN   US:X  a  U R                  5       I Sh  vN   / n[        S[        U5      5       H3  nU R                  X   5      nUR                  S	US
   -   S-   U-   5        M5     SSSU0U R                  5       S.nU R                  X5      n	U R                  X5XU	5      I Sh  vN n
U R                  (       a  0 nXU
S   '   U$ U R                  U R                  SU5      $  GNO N N ND7f)a$  

https://docs.deribit.com/#ticker-instrument_name-interval

watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
:param str[] [symbols]: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.interval]: specify aggregation and frequency of notifications. Possible values: 100ms, raw
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
NFr(   r   r?   r@   r   r   r   ri   r   rb   r   rd   re   r   )r   market_symbolsrM   r}   r   rj   rl   rm   r   rn   r^   rQ   watch_multiple
newUpdatesfilter_by_arraytickers)rT   r   rh   rq   r?   rd   rr   r   r   ru   
newTickersr   s               rV   watch_tickersderibit.watch_tickers   sr     !!!%%gtU;iit$##FJ@6:.!!!u##%%%q#g,'A[[,FOOIt4s:XEF ( (H //#
 ""73..sgQXYY
??G,6Jx()N##DLL(GDD5 	"
 	"% ZsG   E.E%A!E.8E(9E.E*BE.'E,(>E.(E.*E.,E.c                    U R                  US0 5      nU R                  US0 5      nU R                  US5      nU R                  U5      nU R                  U5      nU R                  US5      nXpR                  U'   UR                  Xx5        g )Nrh   rz   instrument_namer   )rk   r}   safe_symbolparse_tickerr   r   )	rT   rx   r   rh   rz   marketIdr   tickerrp   s	            rV   handle_tickerderibit.handle_ticker   s    < (B7vvr2##D*;<!!(+""4(&&vy9%Vv+rX   c                   #    U R                  5       I Sh  vN   U R                  USS5      nU R                  S   S   n/ n[        S[	        U5      5       H-  nU R                  X   5      nUR                  SUS   -   5        M/     SS	S
U0U R                  5       S.nU R                  Xr5      nU R                  X4XU5      I Sh  vN n	U R                  (       a  0 n
XU	S   '   U
$ U R                  U R                  SU5      $  N N?7f)aC  

https://docs.deribit.com/#quote-instrument_name

watches best bid & ask for symbols
:param str[] [symbols]: 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>`
NFr(   r   r   zquote.ri   rb   r   rd   re   r   )r   r   rM   rl   rm   r   rn   r^   rQ   r   r   r   bidsasks)rT   r   rh   rq   rd   rr   r   r   ru   r   r   s              rV   watch_bids_asksderibit.watch_bids_asks  s     !!!%%gtU;iit$q#g,'A[[,FOOHvd|34 ( (H //#
 ""73..sgQXYY
??G,6Jx()N##DMM8WEE+ 	"  Zs"   DDB/DD>DDc                     U R                  US0 5      nU R                  US0 5      nU R                  U5      nUS   nXPR                  U'   U R                  US5      nUR	                  XW5        g )Nrh   rz   r   r   )	safe_dictparse_ws_bid_askr   r}   r   )rT   rx   r   rh   rz   r   r   rp   s           rV   handle_bid_askderibit.handle_bid_ask4  sl    $ 26~~ffb1&&t,! &f&&vy9v+rX   c                 d   U R                  US5      nU R                  X25      nU R                  US5      nU R                  US5      nU R                  UUU R	                  U5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      US.U5      $ )	Nr   r   	timestampbest_ask_pricebest_ask_amountbest_bid_pricebest_bid_amount)r   r   datetimeask	askVolumebid	bidVolumer{   )r}   safe_marketr]   safe_tickeriso8601)rT   r   r   r   r   r   s         rV   r   deribit.parse_ws_bid_askN  s    ##F,=>!!(3!!&(3%%fk:	"Y/##F,<=))&2CD##F,<=))&2CD	!
 	 		rX   sincelimitc                 P   #    SUS'   U R                  U/X#U5      I Sh  vN $  N7f)aN  
get the list of most recent trades for a particular symbol

https://docs.deribit.com/#trades-instrument_name-interval

: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 str [params.interval]: specify aggregation and frequency of notifications. Possible values: 100ms, raw
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
r   callerMethodNameN)watch_trades_for_symbols)rT   r   r   r   rh   s        rV   watch_tradesderibit.watch_trades^  s/      &3!"22F8U6RRRRs   &$&c                 h  #    SnU R                  USSS5      u  pTUS:X  a  U R                  5       I Sh  vN   U R                  SXQU5      I Sh  vN nU R                  (       a5  U R	                  US5      nU R                  US5      nUR                  X5      nU R                  XbUS	S
5      $  Ny N`7f)a  
get the list of most recent trades for a list of symbols

https://docs.deribit.com/#trades-instrument_name-interval

:param str[] symbols: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
Nr    r?   r@   r   tradesr   r   r   T)handle_option_and_paramsrj   watch_multiple_wrapperr   r   r}   getLimitfilter_by_since_limit)	rT   r   r   r   rh   r?   r   firsttradeSymbols	            rV   r    deribit.watch_trades_for_symbolsn  s      88AXZdfmnu##%%%228XPVWW??NN61-E**5(;KOOK7E))&TRR &Ws"   2B2B.B2B0AB20B2c                    U R                  US0 5      nU R                  USS5      nUR                  S5      nU R                  US5      nU R                  US5      nU R                  U5      nU R	                  U5      n	U R                  US/ 5      n
U R                  U R                  U5      c5  U R                  U R                  SS	5      n[        U5      U R                  U'   U R                  U   n[        S
[        U
5      5       H)  nX   nU R                  X5      nUR                  U5        M+     XR                  U'   SU-   S-   U-   nUR                  U R                  U   U5        g )Nrh   r    r   r[      rz   tradesLimit  r   ztrades||)r   r}   splitr   r   	safe_listrk   r   r]   rN   r   rl   rm   parse_tradern   r   )rT   rx   r   rh   r   partsr   r?   r   r   r   r   storedrr   tradeparsedrp   s                    rV   handle_tradesderibit.handle_trades  sM   , 26""69b9c"##E1-##E1-!!(+!!(+3??4;;/7%%dllM4HE",U"3DKKV$q#f+&AIE%%e4FMM&! ' %F&(3.9t{{6*K8rX   c                   #    U R                  U5      I Sh  vN   Ub)  U R                  5       I Sh  vN   U R                  U5      nU R                  S   S   nU R	                  USS5      nU R                  US5      nSU-   nSSS	U/0U R                  5       S
.nU R                  X5      n	U R                  XWXU	5      I Sh  vN n
U R                  XX#S5      $  N N N7f)ag  
get the list of trades associated with the user

https://docs.deribit.com/#user-trades-instrument_name-interval

:param str symbol: unified symbol of the market to fetch trades for. Use 'any' to watch all trades
: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 str [params.interval]: specify aggregation and frequency of notifications. Possible values: 100ms, raw
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
Nr(   r   r?   r   zuser.trades.any.any.rb   rc   rd   re   T)
rj   r   r   rM   r}   r   r^   rQ   ro   filter_by_symbol_since_limit)rT   r   r   r   rh   rq   r?   r   r   ru   r   s              rV   watch_my_tradesderibit.watch_my_trades  s      '''##%%%[[(Fiit$##FJ>6:.(83)WI //#
 ""73zz#'JJ00tTT% 	(% Ks2   C!CC!CBC!CC!C!C!c                    U R                  US0 5      nU R                  USS5      nU R                  US/ 5      nU R                  nUc(  U R                  U R                  SS5      n[        U5      nU R                  U5      n0 n	[        S[        U5      5       H!  n
X   nUR                  U5        US   nS	X'   M#     UR                  Xd5        g )
Nrh   r   r   rz   r   r   r   r   T)rk   r}   myTradesr]   rN   r   parse_tradesrl   rm   rn   r   )rT   rx   r   rh   r   r   cachedTradesr   r   	marketIdsrr   r   r   s                rV   handle_my_tradesderibit.handle_my_trades  s    B (B7""69b94}}%%dllM4HE1%8L""6*	q#f+&AIE&8_F $I	 '
 	|-rX   c                 N   #    SUS'   U R                  U/X#5      I Sh  vN $  N7f)a  

https://docs.deribit.com/#book-instrument_name-group-depth-interval

watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
: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
:param str [params.interval]: Frequency of notifications. Events will be aggregated over self interval. Possible values: 100ms, raw
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
r#   r   N)watch_order_book_for_symbols)rT   r   r   rh   s       rV   watch_order_bookderibit.watch_order_book  s-      &6!"66xOOOOs   %#%c                   #    SnU R                  USSS5      u  pCUS:X  a  U R                  5       I Sh  vN   SnSnU R                  USSS5      u  pcU(       a?  SnU R                  USS	S
5      u  psSnU R                  USSS5      u  pUS-   U-   S-   U-   nOUnU R                  SXQU5      I Sh  vN n	U	R                  5       $  N N7f)a  
watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://docs.deribit.com/#book-instrument_name-group-depth-interval

:param str[] symbols: unified array of symbols
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
Nr$   r?   r@   r   r   rC   FrD   rA   rE   rB   r   book)r   rj   r   r   )
rT   r   r   rh   r?   
descriptorrC   rD   rE   	orderbooks
             rV   r   $deribit.watch_order_book_for_symbols  s      88A[]gipqu##%%%
#'#@#@Icewy~# E 99&B\^egklMEE 99&B\^egmnMEu,s2X=J!J55fjSYZZ	   & [s"   2C
CA<C
1C2C
C
c                    U R                  US0 5      nU R                  US0 5      nU R                  US5      nUR                  S5      nSn[        U5      nUS:H  n	U	(       aE  U R                  US5      n
U R                  US5      nU R                  US	5      nU
S-   U-   S-   U-   nOU R                  US5      nUnU R                  US
5      nU R	                  U5      nU R                  US5      nXR                  ;  a  U R                  5       U R                  U'   U R                  U   nU R                  US/ 5      nU R                  US/ 5      nU R                  US   U5        U R                  US   U5        UUS'   UUS'   U R                  U5      US'   UUS'   UU R                  U'   SU-   S-   U-   nUR                  UU5        g )Nrh   rz   r   r   r      r         r   r   asksbidsnoncer   r   zbook|r   )rk   r}   r   rm   r   r]   
orderbookscounted_order_bookr   handle_deltasr   r   )rT   rx   r   rh   rz   r   r   r   partsLength
isDetailedrE   rD   r?   r   r   r   storedOrderBookr   r   rp   s                       rV   handle_order_bookderibit.handle_order_book-  s   \ (B7vvr2""695c"
%j A%
$$UA.E$$UA.E''q1Hu,s2X=J''q1H!J##D*;<!!(+%%dK8	//)&*&=&=&?DOOF#//&1~~dFB/~~dFB/?62D9?62D9#, '0$&*ll9&=
#$*!"1&,z94rX   c                 N   U R                  US/ 5      nU R                  US/ 5      n/ n[        S[        U5      5       H   nUR                  X%   S   X%   S   /5        M"     / n[        S[        U5      5       H   nUR                  X5   S   X5   S   /5        M"     XAS'   XaS'   U$ )Nr   r   r   r[   r   )r   rl   rm   rn   )rT   rz   r   r   cleanedBidsrr   cleanedAskss          rV   clean_order_bookderibit.clean_order_book|  s    ~~dFB/~~dFB/q#d)$A
DGAJ78 %q#d)$A
DGAJ78 %"V"VrX   c                     US   nUS   nUS   S:X  d	  US   S:X  a  UR                  X4S/5        g US   S:X  a  UR                  X4S/5        g g )Nr[   r   r   newchangedelete)
storeArray)rT   booksidedeltapriceamounts        rV   handle_deltaderibit.handle_delta  sb    aq8uaH 4 231X! 23 "rX   c                 d    [        S[        U5      5       H  nU R                  XU   5        M     g )Nr   )rl   rm   r  )rT   r  deltasrr   s       rV   r   deribit.handle_deltas  s)    q#f+&Ahq	2 'rX   c                 v  #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN   Ub  U R                  U5      nU R                  S   S   nU R	                  USS5      nU R	                  USS5      nU R	                  USS5      nU R                  USSS5      nS	U-   S
-   U-   S
-   U-   n	SSSU	/0U R                  5       S.n
U R                  X5      nU R                  XYXU5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XX#S5      $  GN GN N?7f)a  

https://docs.deribit.com/#user-orders-instrument_name-raw

watches information on multiple orders made by the user
: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 dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr(   r   r|   anyr?   r   kindzuser.orders.r   rb   rc   rd   re   T)r   rj   r   rM   r}   r   r^   rQ   ro   r   r   r   )rT   r   r   r   rh   rq   r|   r?   r  r   r   ru   orderss                rV   watch_ordersderibit.watch_orders  sF     !!!'''[[(Fiit$##FJ>##FJ>66:z6B 4'#-83>I)WI //#
 ""73zz#'JJ??OOF2E00tTT- 	"'$ Ks2   D9D1D9D4CD97D78:D94D97D9c                    U R                   c-  U R                  U R                  SS5      n[        U5      U l         U R	                  US0 5      nU R                  USS5      nU R	                  US0 5      n/ n[        U[        5      (       a  U R                  U5      nOU R                  U5      nU/nU R                   n	[        S[        U5      5       H  n
U	R                  Xz   5        M     UR                  U R                   U5        g )NordersLimitr   rh   r   r   rz   r   )r  r]   rN   r   rk   r}   
isinstancelistparse_ordersparse_orderrl   rm   rn   r   )rT   rx   r   r   rh   r   rz   r  ordercachedOrdersrr   s              rV   handle_ordersderibit.handle_orders  s    F ;;%%dllM4HE07DK(B7""69b9vvr2dD!!&&t,F$$T*EWF{{q#f+&A	* 't{{G,rX   r4   	timeframec                    #    U R                  5       I Sh  vN   U R                  U5      nU R                  X//X4U5      I Sh  vN nXa   U   $  N9 N7f)aU  

https://docs.deribit.com/#chart-trades-instrument_name-resolution

watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
: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
:returns int[][]: A list of candles ordered, open, high, low, close, volume
N)r   r   watch_ohlcv_for_symbols)rT   r   r   r   r   rh   ohlcvss          rV   watch_ohlcvderibit.watch_ohlcv  sZ      !!!V$33f5H4I5Y_``~i(( 	"`s!   AA-AAAAsymbolsAndTimeframesc                 \  #    [        U5      nUS:X  d  [        US   [        5      (       d  [        U R                  S-   5      eU R                  SSX5      I Sh  vN u  pgnU R                  (       a  UR                  Xc5      nU R                  XUSS5      n	U R                  XgU	5      $  NO7f)av  
watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://docs.deribit.com/#chart-trades-instrument_name-resolution

:param str[][] symbolsAndTimeframes: array of arrays containing unified symbols and timeframes to fetch OHLCV data for, example [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]
: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
:returns int[][]: A list of candles ordered, open, high, low, close, volume
r   zu watchOHLCVForSymbols() requires a an array of symbols and timeframes, like  [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]chart.tradesNT)
rm   r  r  r   ri   r   r   r   r   create_ohlcv_object)
rT   r&  r   r   rh   symbolsLengthr   r   candlesfiltereds
             rV   r"  deribit.watch_ohlcv_for_symbols  s      01AZ0DQ0G%N%N#DGG  /f  %f  g  g+/+F+F~W[]q+z%z"7??$$V3E--geQM''8DD	 &{s   AB,B*AB,c                 ^   U R                  US0 5      nU R                  USS5      nUR                  S5      nU R                  US5      nU R                  US5      nU R                  U5      nUS   n	U R                  U R                  S0 5      n
U R                  U
S	0 5      nU R                  X{5      nU R                  U R                  U	0 5      U R                  U	'   U R                  U R                  U	   U5      c8  U R                  U R                  S
S5      n[        U5      U R                  U	   U'   U R                  U	   U   nU R                  US0 5      nU R                  X5      nUR                  U5        XR                  U	   U'   XU/nSU	-   S-   U-   nUR                  UU5        g )Nrh   r   r   r   r   r   r   r   rF   
OHLCVLimitr   rz   zchart.trades|r   )r   r}   r   r   rN   find_timeframer#  rk   r]   r   parse_ws_ohlcvrn   r   )rT   rx   r   rh   r   r   r   rawTimeframer   r   	wsOptionsrF   unifiedTimeframer   r   ohlcvr   resolveDatarp   s                      rV   handle_ohlcvderibit.handle_ohlcv  s   & 26""69b9c"##E1-''q1!!(+!NN4<<r:	^^I|R@
..|H"nnT[[&"EF??4;;v.0@AI%%dllL$GE4I%4PDKK 01V$%56vvr2$$U3f06F,-8%.4|C{K0rX   c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Ntickopenhighlowclosevolume)r]   safe_number)rT   r5  r   s      rV   r1  deribit.parse_ws_ohlcv?  sn     eV,UF+UF+UE*UG,UH-
 	
rX   channelNamechannelDescriptorc                 :  #    U R                  5       I S h  vN   U R                  S   S   n/ n/ nUS:H  nU(       a  U R                  US5      OUn	U R                  U	S S5        [	        S[        U5      5       H  n
X:   nS nU(       a8  U R                  US   5      nUS   nU R                  U R                  X5      nUnOU R                  U5      nUS-   US   -   S-   U-   nUR                  U5        UR                  US	-   US
   -   S	-   U-   5        M     SSSU0U R                  5       S.nU R                  UU5      nSnU R                  U5      n[        U5      U:  a  [        U R                  S-   5      eU R                  XWUU5      I S h  vN $  GN N7f)Nr(   r   r(  r   Fr[   r   ri   r   r   rb   r   rd   re   i  zG requested subscription length over limit, try to reduce symbols amount)r   rM   get_list_from_object_valuesr   rl   rm   r   r}   rF   rn   r^   rQ   jsonr   ri   r   )rT   rB  rC  symbolsArrayrh   rq   rawSubscriptionsmessageHashesisOHLCVr   rr   currentr   	unifiedTfrawTfr   ru   extendedRequestmaxMessageByteLimit
jsonedTexts                       rV   r   deribit.watch_multiple_wrapperT  s    !!!iit$.0GN$22<CT`GT51q#l+,A"oGFWQZ0#AJ	(()O$)!W-!C'&,6<?PPG##G,  s!2VH5E!E!KN_!_` - (, //#
 **7F;'YY/
z?11*s stt((_N^___C 	"B `s"   FFE:FFFFc                    U R                  US5      nUb*  [        U R                  S-   U R                  U5      -   5      eU R                  US5      nU R	                  US5      nUb  UR                  S5      nU R	                  US5      nU R                  U R                  U R                  S.nU R                  U R                  U R                  U R                  U R                  U R                  XR	                  US5      5      S	.n	U R                  X5      n
U
b	  U
" X5        g [        U R                  S
-   U R                  U5      -   5      eU R                  US0 5      nU R	                  US5      nUb  U R                  X5        g g )Nerror rh   r   r   r   )r   	portfolior  r[   )r   quoter   r   chartuserz# no handler found for self message resultaccess_token)rk   r   ri   rF  r}   r   r   r   r  r   r   r   r   r7  r   handle_authentication_message)rT   rx   r   rS  rh   r   r   	channelIduserHandlershandlershandlerrY  accessTokens                rV   handle_messagederibit.handle_messagex  sz   x 1#		%0@ @AA(3""695MM#&E((2I//!00,,"L ,,,,..,,**6F6Fua6PQH ooh:G"(tww)NNQUQZQZ[bQccdd(B7&&v~>"..v? #rX   c                 ,    SnUR                  X#5        U$ )Nauthenticated)r   )rT   rx   r   rp   s       rV   r[  %deribit.handle_authentication_message  s    $ &w,rX   c           
      f  #    U R                   S   S   nU R                  U5      nU R                  5       nU R                  U5      nUnSnU R	                  UR
                  U5      nUc  U R                  5         U R                  5       n	Sn
U R                  U R                  XZ-   U-   U
-   5      U R                  U R                  5      [        R                  5      nSU	SSU R                  UUUSS	.S
.nU R                  X'U R                  X5      U5      I S h  vN nXR
                  U'   U$  N7f)Nr(   r   rd  
rb   zpublic/authclient_signaturer   )
grant_type	client_idr   	signaturer   rz   )rf   ri   rg   rh   )rM   rx   millisecondsnumber_to_stringrk   subscriptionscheck_required_credentialsr^   hmacencodesecrethashlibsha256apiKeyro   extend)rT   rh   rq   rx   time
timeStringr   rp   futurerZ   	lineBreakrk  ru   s                rV   rj   deribit.authenticate  s8    iit$S!  "**40
%!5!5{C>++-)II		$++j.Du.Ly.X"Y[_[f[fgkgrgr[su|  vD  vD  EI '"4!%!%!*"	G  ::cG8TVabbF06  - cs   DD1D/D1)r  )N)3__name__
__module____qualname____firstlineno__r   rS   r^   r   rv   r   r   strr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r   r   r   r   r  r   r	   r  r  r  r$  r"  r7  r1  r   ra  r[  rj   __static_attributes____classcell__)rU   s   @rV   r   r      s   :# :x
 *, Q Q842V 42l 68 I IF I> 6:" %E7 %E %EN%,F %,N 8<B FW F7 FB,V ,4  <@d[] S SS S Sbfglbm S  OSaenp Sd3i S S[^ Suyz  vA S.(9F (9T 37TX\eg UC Us URU Ulpqvlw UB/.v /.b @DB PS P PS\ P SW_a !$s) !C !fo !:M5 M5^43 04$UYbd "U "UC "Us "Uimnsit "UH2-F 2-h ?CQUdhqs ) ) )3 )^a )x|  ~B  yC )$ aesw  AC E$tCy/ EZ] Emp E*)16 )1V
D 
* cgoq "` "`PS "`HY@V Y@vF , )+  rX   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   rs  ccxt.base.typesr   r   r   r	   r
   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   async_supportr    rX   rV   <module>r     sE     f f  f f f 4  * . )td  (( trX   