
    ":hҳ                         d dl Zd dlmZmZ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 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  G d	 d
ej4                  j6                        Zy)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)
AnyBalancesIntOrder	OrderBookStrStringsTickerTickersTrade)Client)List)ExchangeError)ArgumentsRequired)NotSupportedc            
       f    e Zd Zdef fdZd Zi fdefdZ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efdZd	i fd
edefdZdefdZd+dZd	d	i fde
dededee   fdZd	d	i fd
ee
   dededee   fdZdefdZd	d	d	i fdedededee   fdZdefdZd	i fde
dedefdZd	i fd
ee
   dedefdZdefdZ d Z!d Z"d Z#d	d	d	i fdedededee$   fdZ%defdZ&dd	d	i fde
dededee'   fd Z(d	d	i fd!eee
      dedefd"Z)defd#Z*d+de'fd$Z+d	i fd%e
d&efd'Z,defd(Z-defd)Z.i fd*Z/ xZ0S ),deribitreturnc                     | j                  t        t        |          ddddddddddddddddiddidddd	d
ddddddddddiddddddg ddi i d      S )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/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/pro/deribit.pyrR   zderibit.describe   s    gt = ? $# $!%#)-!%#"&,0"(," < ;	 "!!##"###$"# #G.
 %,,1!%!'	1'4 <7:o9B
 9 9	    c                 ~    | j                  | j                  | j                  dd      d      }|| j                  d<   |S )N	requestIdr      )sumsafe_integerrM   )rS   rX   s     rU   
request_idzderibit.request_idO   s9    HHT..t||[!LaP	$-[!rV   c                   K   | j                  |       d{    d}| j                  d   d   }| j                  | j                  dg       }g }t	        dt        |            D ]  }||   }|j                  d|z           dd	d
|i| j                         d}| j                  ||      }	| j                  |||	||	       d{   S 7 7 w)aY  

        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   rJ   r   zuser.portfolio.2.0private/subscribechannelsjsonrpcmethodparamsid)
authenticaterL   
safe_valuerM   rangelenappendr\   rP   watch)
rS   re   messageHashurlrJ   ra   icurrencyCode	subscriberequests
             rU   watch_balancezderibit.watch_balanceT   s      '''iit$__T\\<D
q#j/* 	>A%a=LOO-<=	> )H //#
	 ""9f5ZZ[';PPP# 	(" Qs"   CCB+CC
C
Cclientc                 0   | j                  |di       }| j                  |di       }|| j                  d<   | j                  |d      }| j                  |      }| j	                  |      }|| j                  |<   d}|j                  | j                  |       y )Nre   datainfocurrencyr^   )rh   r^   safe_stringsafe_currency_codeparse_balanceresolve)	rS   rt   messagere   rv   
currencyIdrp   r^   rm   s	            rU   handle_balancezderibit.handle_balancep   s    X (B7vvr2#V%%dJ7
..z:$$T*%,\"t||[1rV   symbolc                   K   | j                          d{    | j                  |      }| j                  d   d   }| j                  |dd      }| j	                  |d      }| j                          d{    |dk(  r| j                          d{    d|d   z   d	z   |z   }d
ddd|d   z   d	z   |z   gi| j                         d}| j                  ||      }| j                  |||||       d{   S 7 7 7 i7 
w)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.rf   .r_   public/subscribera   rb   )	load_marketsmarketrL   ry   omitrg   r\   rP   rl   )	rS   r   re   r   rn   r>   channelr}   rr   s	            rU   watch_tickerzderibit.watch_ticker   s      !!!V$iit$##FJ@6:.!!!u##%%%fTl*S08;(Y5;hFG //#
 ""7F3ZZWgwHHH% 	"
 	"% IsG   DC9AD6C;7DC=A D4C?5D;D=D?DNsymbolsc                   K   | j                          d{    | j                  |dd      }| j                  d   d   }| j                  |dd      }| j	                  |d      }| j                          d{    |dk(  r| j                          d{    g }t        dt        |            D ]3  }| j                  ||         }|j                  d	|d
   z   dz   |z          5 ddd|i| j                         d}| j                  ||      }	| j                  |||	||	       d{   }
| j                  ri }|
||
d   <   |S | j                  | j                  d|      S 7 L7 7 7 @w)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   rf   r   r_   r   ra   rb   r   )r   market_symbolsrL   ry   r   rg   ri   rj   r   rk   r\   rP   watch_multiple
newUpdatesfilter_by_arraytickers)rS   r   re   rn   r>   ra   ro   r   r}   rr   
newTickersr   s               rU   watch_tickerszderibit.watch_tickers   s     !!!%%gtU;iit$##FJ@6:.!!!u##%%%q#g,' 	GA[[,FOOIt4s:XEF	G (H //#
 ""7F3..sHgxQXYY
??G,6GJx()N##DLL(GDD5 	"
 	"% ZsG   E+E"A!E+8E%9E+E'BE+(E)):E+%E+'E+)E+c                    | j                  |di       }| j                  |di       }| j                  |d      }| j                  |      }| j                  |      }| j                  |d      }|| j                  |<   |j                  ||       y )Nre   rv   instrument_namer   )rh   ry   safe_symbolparse_tickerr   r|   )	rS   rt   r}   re   rv   marketIdr   tickerrm   s	            rU   handle_tickerzderibit.handle_ticker   s    < (B7vvr2##D*;<!!(+""4(&&vy9%Vv{+rV   c                   K   | j                          d{    | j                  |dd      }| j                  d   d   }g }t        dt	        |            D ]-  }| j                  ||         }|j                  d|d   z          / dd	d
|i| j                         d}| j                  ||      }| j                  |||||       d{   }	| j                  ri }
|	|
|	d   <   |
S | j                  | j                  d|      S 7 7 ;w)as  

        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.rf   r_   r   ra   rb   r   )r   r   rL   ri   rj   r   rk   r\   rP   r   r   r   bidsasks)rS   r   re   rn   ra   ro   r   r}   rr   r   r   s              rU   watch_bids_askszderibit.watch_bids_asks  s!     !!!%%gtU;iit$q#g,' 	5A[[,FOOHvd|34	5 (H //#
 ""7F3..sHgxQXYY
??G,6GJx()N##DMM8WEE+ 	"  Zs"   DDB1DD	:DDc                     | j                  |di       }| j                  |di       }| j                  |      }|d   }|| j                  |<   | j                  |d      }|j	                  ||       y )Nre   rv   r   r   )	safe_dictparse_ws_bid_askr   ry   r|   )rS   rt   r}   re   rv   r   r   rm   s           rU   handle_bid_askzderibit.handle_bid_ask4  sp    $ 26~~ffb1&&t,! &f&&vy9v{+rV   c                 f   | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  ||| j	                  |      | j                  |d      | j                  |d      | j                  |d      | j                  |d      |d|      S )	Nr   r   	timestampbest_ask_pricebest_ask_amountbest_bid_pricebest_bid_amount)r   r   datetimeask	askVolumebid	bidVolumerw   )ry   safe_marketr[   safe_tickeriso8601)rS   r   r   r   r   r   s         rU   r   zderibit.parse_ws_bid_askN  s    ##F,=>!!(F3!!&(3%%fk:	"Y/##F,<=))&2CD##F,<=))&2CD	!
 	 		rV   sincelimitc                 R   K   d|d<   | j                  |g|||       d{   S 7 w)a  
        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)rS   r   r   r   re   s        rU   watch_tradeszderibit.watch_trades^  s2      &3!"22F8UE6RRRRs   '%'c                 d  K   d}| j                  |ddd      \  }}|dk(  r| j                          d{    | j                  d|||       d{   }| j                  r6| j	                  |d      }| j                  |d      }|j                  ||      }| j                  |||d	d
      S 7 w7 ]w)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_paramsrg   watch_multiple_wrapperr   r   ry   getLimitfilter_by_since_limit)	rS   r   r   r   re   r>   r   firsttradeSymbols	            rU   r   z deribit.watch_trades_for_symbolsn  s      88AXZdfmn&u##%%%228XwPVWW??NN61-E**5(;KOOK7E))&%TRR &Ws"   2B0B,B0B.AB0.B0c                    | j                  |di       }| j                  |dd      }|j                  d      }| j                  |d      }| j                  |d      }| j                  |      }| j	                  |      }	| j                  |dg       }
| j                  | j                  |      5| j                  | j                  dd	      }t        |      | j                  |<   | j                  |   }t        d
t        |
            D ]*  }|
|   }| j                  ||	      }|j                  |       , || j                  |<   d|z   dz   |z   }|j                  | j                  |   |       y )Nre   r    r   rY      rv   tradesLimit  r   ztrades||)r   ry   splitr   r   	safe_listrh   r   r[   rM   r   ri   rj   parse_traderk   r|   )rS   rt   r}   re   r   partsr   r>   r   r   r   r   storedro   tradeparsedrm   s                    rU   handle_tradeszderibit.handle_trades  sX   , 26""69b9c"##E1-##E1-!!(+!!(+3??4;;/7%%dllM4HE",U"3DKKV$q#f+& 	"A1IE%%eV4FMM&!	" %F&(3.9t{{6*K8rV   c                   K   | j                  |       d{    |)| j                          d{    | j                  |      }| j                  d   d   }| j	                  |dd      }| j                  |d      }d|z   }ddd	|gi| j                         d
}| j                  ||      }	| j                  |||	||	       d{   }
| j                  |
|||d      S 7 7 7 w)a  
        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.r_   r`   ra   rb   T)
rg   r   r   rL   ry   r   r\   rP   rl   filter_by_symbol_since_limit)rS   r   r   r   re   rn   r>   r   r}   rr   r   s              rU   watch_my_tradeszderibit.watch_my_trades  s      '''##%%%[[(Fiit$##FJ>6:.(83)WI //#
 ""7F3zz#w'JJ00tTT% 	(% Ks2   C%CC%C!BC%C#C%!C%#C%c                    | j                  |di       }| j                  |dd      }| j                  |dg       }| j                  }|(| j                  | j                  dd      }t        |      }| j                  |      }i }	t        dt        |            D ]"  }
||
   }|j                  |       |d   }d	|	|<   $ |j                  ||       y )
Nre   r   r   rv   r   r   r   r   T)rh   ry   myTradesr[   rM   r   parse_tradesri   rj   rk   r|   )rS   rt   r}   re   r   r   cachedTradesr   r   	marketIdsro   r   r   s                rU   handle_my_tradeszderibit.handle_my_trades  s    B (B7""69b94}}%%dllM4HE1%8L""6*	q#f+& 	%A1IE&8_F $If		%
 	|W-rV   c                 P   K   d|d<   | j                  |g||       d{   S 7 w)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)rS   r   r   re   s       rU   watch_order_bookzderibit.watch_order_book  s0      &6!"66xOOOOs   &$&c                   K   d}| j                  |ddd      \  }}|dk(  r| j                          d{    d}d}| j                  |ddd      \  }}|rAd}| j                  |dd	d
      \  }}d}| j                  |ddd      \  }}|dz   |z   dz   |z   }n|}| j                  d|||       d{   }	|	j                         S 7 7 w)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   rB   FrC   r@   rD   rA   r   book)r   rg   r   r   )
rS   r   r   re   r>   
descriptorrB   rC   rD   	orderbooks
             rU   r   z$deribit.watch_order_book_for_symbols  s     88A[]gipq&u##%%%
#'#@#@Icewy~# &E 99&B\^egklME6E 99&B\^egmnME6u,s2X=J!J55fj'SYZZ	   & [s"   2C	CA;C	0C1C	C	c                    | j                  |di       }| j                  |di       }| j                  |d      }|j                  d      }d}t        |      }|dk(  }	|	rE| j                  |d      }
| j                  |d      }| j                  |d	      }|
dz   |z   dz   |z   }n| j                  |d      }|}| j                  |d
      }| j	                  |      }| j                  |d      }|| j                  vr| j                         | j                  |<   | j                  |   }| j                  |dg       }| j                  |dg       }| j                  |d   |       | j                  |d   |       ||d<   ||d<   | j                  |      |d<   ||d<   || j                  |<   d|z   dz   |z   }|j                  ||       y )Nre   rv   r   r   r      r         r   r   asksbidsnoncer   r   zbook|r   )rh   ry   r   rj   r   r[   
orderbookscounted_order_bookr   handle_deltasr   r|   )rS   rt   r}   re   rv   r   r   r   partsLength
isDetailedrD   rC   r>   r   r   r   storedOrderBookr   r   rm   s                       rU   handle_order_bookz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4rV   c                 R   | j                  |dg       }| j                  |dg       }g }t        dt        |            D ]!  }|j                  ||   d   ||   d   g       # g }t        dt        |            D ]!  }|j                  ||   d   ||   d   g       # ||d<   ||d<   |S )Nr   r   r   rY   r   )r   ri   rj   rk   )rS   rv   r   r   cleanedBidsro   cleanedAskss          rU   clean_order_bookzderibit.clean_order_book|  s    ~~dFB/~~dFB/q#d)$ 	9AQ
DGAJ78	9q#d)$ 	9AQ
DGAJ78	9"V"VrV   c                     |d   }|d   }|d   dk(  s|d   dk(  r|j                  ||dg       y |d   dk(  r|j                  ||dg       y y )NrY   r   r   newchangedelete)
storeArray)rS   booksidedeltapriceamounts        rU   handle_deltazderibit.handle_delta  sf    aq8uaH 4 231X! 23 "rV   c                 b    t        dt        |            D ]  }| j                  |||           y )Nr   )ri   rj   r   )rS   r   deltasro   s       rU   r   zderibit.handle_deltas  s0    q#f+& 	3Ahq	2	3rV   c                 v  K   | j                          d{    | j                  |       d{    || j                  |      }| j                  d   d   }| j	                  |dd      }| j	                  |dd      }| j	                  |dd      }| j                  |ddd      }d	|z   d
z   |z   d
z   |z   }	ddd|	gi| j                         d}
| j                  |
|      }| j                  ||	||	|       d{   }| j                  r|j                  ||      }| j                  ||||d      S 7 7 7 =w)a0  

        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   rx   anyr>   r   kindzuser.orders.r   r_   r`   ra   rb   T)r   rg   r   rL   ry   r   r\   rP   rl   r   r   r   )rS   r   r   r   re   rn   rx   r>   r   r   r}   rr   orderss                rU   watch_orderszderibit.watch_orders  sU     !!!'''[[(Fiit$##FJ>##FJ>66:z6B 4'#-83>I)WI //#
 ""7F3zz#w'JJ??OOFE2E00tTT- 	"'$ Ks2   D9D1D9D4C	D99D7:8D94D97D9c                    | j                   -| j                  | j                  dd      }t        |      | _         | j	                  |di       }| j                  |dd      }| j	                  |di       }g }t        |t              r| j                  |      }n| j                  |      }|g}| j                   }	t        dt        |            D ]  }
|	j                  ||
           |j                  | j                   |       y )NordersLimitr   re   r   r   rv   r   )r   r[   rM   r   rh   ry   
isinstancelistparse_ordersparse_orderri   rj   rk   r|   )rS   rt   r}   r   re   r   rv   r   ordercachedOrdersro   s              rU   handle_orderszderibit.handle_orders  s    F ;;%%dllM4HE07DK(B7""69b9vvr2dD!&&t,F$$T*EWF{{q#f+& 	+Aq	*	+t{{G,rV   r3   c                    K   | j                          d{    | j                  |      }| j                  ||gg|||       d{   }||   |   S 7 <7 w)a  

        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)rS   r   	timeframer   r   re   ohlcvss          rU   watch_ohlcvzderibit.watch_ohlcv  sc      !!!V$33fi5H4I5RWY_``f~i(( 	"`s!   AA/AAAAsymbolsAndTimeframesc                 P  K   t        |      }|dk(  st        |d   t              st        | j                  dz         | j                  dd||       d{   \  }}}| j                  r|j                  ||      }| j                  |||dd      }	| j                  |||	      S 7 Nw)a  
        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)
rj   r  r  r   rf   r   r   r   r   create_ohlcv_object)
rS   r  r   r   re   symbolsLengthr   r
  candlesfiltereds
             rU   r	  zderibit.watch_ohlcv_for_symbols  s      01AZ0DQ0G%N#DGG  /f  %f  g  g+/+F+F~W[]qsy+z%z"	7??$$VU3E--gueQM''	8DD	 &{s   AB&B$AB&c                 d   | j                  |di       }| j                  |dd      }|j                  d      }| j                  |d      }| j                  |d      }| j                  |      }|d   }	| j                  | j                  di       }
| j                  |
d	i       }| j                  ||      }| j                  | j                  |	i       | j                  |	<   | j                  | j                  |	   |      8| j                  | j                  d
d      }t        |      | j                  |	   |<   | j                  |	   |   }| j                  |di       }| j                  ||      }|j                  |       || j                  |	   |<   |	||g}d|	z   dz   |z   }|j                  ||       y )Nre   r   r   r   r   r   r   r   rE   
OHLCVLimitr   rv   zchart.trades|r   )r   ry   r   r   rM   find_timeframer  rh   r[   r   parse_ws_ohlcvrk   r|   )rS   rt   r}   re   r   r   r   rawTimeframer   r   	wsOptionsrE   unifiedTimeframer   r   ohlcvr   resolveDatarm   s                      rU   handle_ohlcvzderibit.handle_ohlcv  s   & 26""69b9c"##E1-''q1!!(+!NN4<<r:	^^I|R@
..|ZH"nnT[[&"EF??4;;v.0@AI%%dllL$GE4I%4PDKK 01V$%56vvr2$$UF3f06F,-/8%.4|C{K0rV   c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Ntickopenhighlowclosevolume)r[   safe_number)rS   r  r   s      rU   r  zderibit.parse_ws_ohlcv?  sn     eV,UF+UF+UE*UG,UH-
 	
rV   channelNamechannelDescriptorc                 &  K   | j                          d {    | j                  d   d   }g }g }|dk(  }|r| j                  |d      n|}	| j                  |	d d       t	        dt        |            D ]  }
||
   }d }|r9| j                  |d         }|d   }| j                  | j                  ||      }|}n| j                  |      }|dz   |d   z   dz   |z   }|j                  |       |j                  |d	z   |d
   z   d	z   |z           ddd|i| j                         d}| j                  ||      }d}| j                  |      }t        |      |k\  rt        | j                  dz         | j                  ||||       d {   S 7 v7 w)Nr'   r   r  r   FrY   r   rf   r   r   r_   r   ra   rb   i  zG requested subscription length over limit, try to reduce symbols amount)r   rL   get_list_from_object_valuesr   ri   rj   r   ry   rE   rk   r\   rP   jsonr   rf   r   )rS   r&  r'  symbolsArrayre   rn   rawSubscriptionsmessageHashesisOHLCVr   ro   currentr   	unifiedTfrawTfr}   rr   extendedRequestmaxMessageByteLimit
jsonedTexts                       rU   r   zderibit.watch_multiple_wrapperT  s    !!!iit$.0GN$22<CT`GT51q#l+, 	aA"1oGFWQZ0#AJ	(()YO$)!W-!C'&,6<?PPG##G,  s!2VH5E!E!KN_!_`	a (, //#
 **7F;'YY/
z?11*s stt((m_N^___C 	"B `s"   FFE0FFFFc                    | j                  |d      }|*t        | j                  dz   | j                  |      z         | j                  |d      }| j	                  |d      }||j                  d      }| j	                  |d      }| j                  | j                  | j                  d}| j                  | j                  | j                  | j                  | j                  | j                  || j	                  |d            d	}	| j                  |	|      }
|

 |
||       y t        | j                  d
z   | j                  |      z         | j                  |di       }| j	                  |d      }|| j                  ||       y y )Nerror re   r   r   r   )r   	portfolior   rY   )r   quoter   r   chartuserz# no handler found for self message resultaccess_token)rh   r   rf   r*  ry   r   r   r   r  r   r   r   r   r  r   handle_authentication_message)rS   rt   r}   r6  re   r   r   	channelIduserHandlershandlershandlerr<  accessTokens                rU   handle_messagezderibit.handle_messagex  s   x 1#		%0@ @AA(3""695MM#&E((2I//!00,,"L ,,,,..,,**d6F6Fua6PQH ooh	:G"(tww)NNQUQZQZ[bQccdd(B7&&v~>"..vw? #rV   c                 .    d}|j                  ||       |S )Nauthenticated)r|   )rS   rt   r}   rm   s       rU   r>  z%deribit.handle_authentication_message  s    $ &w,rV   c           
      h  K   | j                   d   d   }| j                  |      }| j                         }| j                  |      }|}d}| j	                  |j
                  |      }|| j                          | j                         }	| j                  | j                  |dz   |z   dz         | j                  | j                        t        j                        }
d|	dd| j                  ||
|dd	d
}| j                  ||| j                  ||      |       d {   }||j
                  |<   |S 7 w)Nr'   r   rF  
r_   zpublic/authclient_signaturer   )
grant_type	client_idr   	signaturer   rv   )rc   rf   rd   re   )rL   rt   millisecondsnumber_to_stringrh   subscriptionscheck_required_credentialsr\   hmacencodesecrethashlibsha256apiKeyrl   extend)rS   re   rn   rt   time
timeStringr   rm   futurerX   rL  rr   s               rU   rg   zderibit.authenticate  s1    iit$S!  "**40
%!5!5{C>++-)I		$++j4.?%.G$.N"OQUQ\Q\]a]h]hQikrkykyzI '"4!%!%!*"	G  ::c;GV8TVabbF06F  - cs   DD2D0D2)N)1__name__
__module____qualname__r   rR   r\   r   rs   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	  r  r  r   rD  r>  rg   __classcell__)rT   s   @rU   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 8<$]ajl ) )C )WZ )quvzq{ )$ 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 , )+ rV   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   rT  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    rV   rU   <module>ri     sE     f f  f f f 4  * . )sd  (( srV   