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

        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      '''''''''it$__T\<DD
q#j//** 	> 	>A%a=LOO-<====)H //##
 
	 ""9f55ZZ[';PPPPPPPPPrV   clientc                 D   |                      |di           }|                      |di           }|| j        d<   |                     |d          }|                     |          }|                     |          }|| j        |<   d}|                    | j        |           d S )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7vvr22#V%%dJ77
..z::$$T**%,\"t|[11111rV   symbolc                 :  K   |                                   d{V  |                     |          }| j        d         d         }|                     |dd          }|                     |d          }|                                   d{V  |dk    r|                                  d{V  d|d         z   d	z   |z   }d
ddd|d         z   d	z   |z   gi|                                 d}|                     ||          }|                     |||||           d{V S )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   sg      !!!!!!!!!V$$it$##FJ@@6:..!!!!!!!!!u##%%%%%%%%%fTl*S08;(Y5;hFG //##
 
 ""7F33ZZWgwHHHHHHHHHrV   Nsymbolsc                 "  K   |                                   d{V  |                     |dd          }| j        d         d         }|                     |dd          }|                     |d          }|                                   d{V  |dk    r|                                  d{V  g }t          dt          |                    D ]A}|                     ||                   }|	                    d	|d
         z   dz   |z              Bddd|i| 
                                d}|                     ||          }	|                     |||	||	           d{V }
| j        ri }|
||
d         <   |S |                     | j        d|          S )aZ  

        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;;it$##FJ@@6:..!!!!!!!!!u##%%%%%%%%%q#g,,'' 	G 	GA[[,,FOOIt4s:XEFFFF(H //##
 
 ""7F33..sHgxQXYYYYYYYY
? 	G,6GJx()N##DL(GDDDrV   c                 N   |                      |di           }|                      |di           }|                     |d          }|                     |          }|                     |          }|                     |d          }|| j        |<   |                    ||           d S )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7vvr22##D*;<<!!(++""4((&&vy99%Vv{+++++rV   c                 H  K   |                                   d{V  |                     |dd          }| j        d         d         }g }t          dt	          |                    D ];}|                     ||                   }|                    d|d         z              <dd	d
|i|                                 d}|                     ||          }| 	                    |||||           d{V }	| j
        ri }
|	|
|	d         <   |
S |                     | j        d|          S )aq  

        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  sX      !!!!!!!!!%%gtU;;it$q#g,,'' 	5 	5A[[,,FOOHvd|34444(H //##
 
 ""7F33..sHgxQXYYYYYYYY
? 	G,6GJx()N##DM8WEEErV   c                    |                      |di           }|                      |di           }|                     |          }|d         }|| j        |<   |                     |d          }|                    ||           d S )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  s    $ 266~~ffb11&&t,,! &f&&vy99v{+++++rV   c                    |                      |d          }|                     ||          }|                      |d          }|                     |d          }|                     |||                     |          |                      |d          |                      |d          |                      |d          |                      |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!!&(33%%fk::	"Y//##F,<==))&2CDD##F,<==))&2CDD	!
 	!
 	 	 		rV   sincelimitc                 N   K   d|d<   |                      |g|||           d{V S )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^  sA       &3!"22F8UE6RRRRRRRRRrV   c                   K   d}|                      |ddd          \  }}|dk    r|                                  d{V  |                     d|||           d{V }| j        rB|                     |d          }|                     |d          }|                    ||          }|                     |||d	d
          S )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n&u##%%%%%%%%%228XwPVWWWWWWWW? 	8NN61--E**5(;;KOOK77E))&%TRRRrV   c                 .   |                      |di           }|                     |dd          }|                    d          }|                     |d          }|                     |d          }|                     |          }|                     |          }	|                     |dg           }
|                     | j        |          3|                     | j	        dd	          }t          |          | j        |<   | j        |         }t          d
t          |
                    D ]5}|
|         }|                     ||	          }|                    |           6|| j        |<   d|z   dz   |z   }|                    | j        |         |           d S )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  s   , 266""69b99c""##E1--##E1--!!(++!!(++33??4;//7%%dlM4HHE",U"3"3DKV$q#f++&& 	" 	"A1IE%%eV44FMM&!!!!$F&(3.9t{6*K88888rV   c                   K   |                      |           d{V  |/|                                  d{V  |                     |          }| j        d         d         }|                     |dd          }|                     |d          }d|z   }ddd	|gi|                                 d
}|                     ||          }	|                     |||	||	           d{V }
| 	                    |
|||d          S )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  s9      '''''''''##%%%%%%%%%[[((Fit$##FJ>>6:..(83)WI //##
 
 ""7F33zz#w'JJJJJJJJ00tTTTrV   c                    |                      |di           }|                     |dd          }|                      |dg           }| j        }|+|                     | j        dd          }t          |          }|                     |          }i }	t          dt          |                    D ],}
||
         }|	                    |           |d         }d	|	|<   -|
                    ||           d S )
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7""69b9944}%%dlM4HHE1%88L""6**	q#f++&& 	% 	%A1IE&&&8_F $If|W-----rV   c                 L   K   d|d<   |                      |g||           d{V S )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  s?       &6!"66xOOOOOOOOOrV   c                   K   d}|                      |ddd          \  }}|dk    r|                                  d{V  d}d}|                      |ddd          \  }}|rId}|                      |dd	d
          \  }}d}|                      |ddd          \  }}|dz   |z   dz   |z   }n|}|                     d|||           d{V }	|	                                S )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  s7      88A[]gipqq&u##%%%%%%%%%
#'#@#@Icewy~## & 	"E 99&B\^egkllME6E 99&B\^egmnnME6u,s2X=JJ!J55fj'SYZZZZZZZZ	   rV   c                    |                      |di           }|                      |di           }|                     |d          }|                    d          }d}t          |          }|dk    }	|	rQ|                     |d          }
|                     |d          }|                     |d	          }|
dz   |z   dz   |z   }n|                     |d          }|}|                     |d
          }|                     |          }|                     |d          }|| j        vr|                                 | j        |<   | j        |         }|                     |dg           }|                     |dg           }| 	                    |d         |           | 	                    |d         |           ||d<   ||d<   | 
                    |          |d<   ||d<   || j        |<   d|z   dz   |z   }|                    ||           d S )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7vvr22""6955c""
%jj A%
 	"$$UA..E$$UA..E''q11Hu,s2X=JJ''q11H!J##D*;<<!!(++%%dK88	$/))&*&=&=&?&?DOF#/&1~~dFB//~~dFB//?62D999?62D999#, '0$&*ll9&=&=
#$*!"1&,z944444rV   c                    |                      |dg           }|                      |dg           }g }t          dt          |                    D ]1}|                    ||         d         ||         d         g           2g }t          dt          |                    D ]1}|                    ||         d         ||         d         g           2||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))$$ 	9 	9AQ
DGAJ78888q#d))$$ 	9 	9AQ
DGAJ78888"V"VrV   c                     |d         }|d         }|d         dk    s|d         dk    r|                     ||dg           d S |d         dk    r|                     ||dg           d S d S )NrY   r   r   newchangedelete)
storeArray)rS   booksidedeltapriceamounts        rU   handle_deltazderibit.handle_delta  s    aq8uaH 4 4 2333331X!! 233333 "!rV   c                 ~    t          dt          |                    D ]}|                     |||                    d S )Nr   )ri   rj   r   )rS   r   deltasro   s       rU   r   zderibit.handle_deltas  sH    q#f++&& 	3 	3Ahq	2222	3 	3rV   c                   K   |                                   d{V  |                     |           d{V  ||                     |          }| j        d         d         }|                     |dd          }|                     |dd          }|                     |dd          }|                     |ddd          }d	|z   d
z   |z   d
z   |z   }	ddd|	gi|                                 d}
|                     |
|          }|                     ||	||	|           d{V }| j	        r|
                    ||          }|                     ||||d          S )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   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  s      !!!!!!!!!'''''''''[[((Fit$##FJ>>##FJ>>666:z6BB 4'#-83>I)WI //##
 
 ""7F33zz#w'JJJJJJJJ? 	3OOFE22E00tTTTrV   c                 B   | j         0|                     | j        dd          }t          |          | _         |                     |di           }|                     |dd          }|                     |di           }g }t          |t                    r|                     |          }n| 	                    |          }|g}| j         }	t          dt          |                    D ]}
|	                    ||
                    |                    | j         |           d S )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 ;%%dlM4HHE077DK(B77""69b99vvr22dD!! 	&&t,,FF$$T**EWF{q#f++&& 	+ 	+Aq	****t{G,,,,,rV   r3   	timeframec                    K   |                                   d{V  |                     |          }|                     ||gg|||           d{V }||         |         S )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   r  r   r   re   ohlcvss          rU   watch_ohlcvzderibit.watch_ohlcv  s       !!!!!!!!!V$$33fi5H4I5RWY_````````f~i((rV   symbolsAndTimeframesc                 r  K   t          |          }|dk    st          |d         t                    st          | j        dz             |                     dd||           d{V \  }}}| j        r|                    ||          }|                     |||dd          }	| 	                    |||	          S )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1AZ0DQ0G%N%N#DG  /f  %f  g  g  g+/+F+F~W[]qsy+z+z%z%z%z%z%z%z"	7? 	4$$VU33E--gueQMM''	8DDDrV   c                    |                      |di           }|                     |dd          }|                    d          }|                     |d          }|                     |d          }|                     |          }|d         }	|                      | j        di           }
|                      |
d	i           }|                     ||          }|                      | j        |	i           | j        |	<   |                     | j        |	         |          9|                     | j        d
d          }t          |          | j        |	         |<   | j        |	         |         }|                      |di           }| 
                    ||          }|                    |           || j        |	         |<   |	||g}d|	z   dz   |z   }|                    ||           d S )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6""69b99c""##E1--''q11!!(++!NN4<r::	^^I|R@@
..|ZHH"nnT[&"EEF??4;v.0@AAI%%dlL$GGE4I%4P4PDK 01V$%56vvr22$$UF33f06F,-/8%.4|C{K00000rV   c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Ntickopenhighlowclosevolume)r[   safe_number)rS   r  r   s      rU   r  zderibit.parse_ws_ohlcv?  s     eV,,UF++UF++UE**UG,,UH--
 	
rV   channelNamechannelDescriptorc                   K   |                                   d {V  | j        d         d         }g }g }|dk    }|r|                     |d          n|}	|                     |	d d           t	          dt          |                    D ]}
||
         }d }|rB|                     |d                   }|d         }|                     | j        ||          }|}n|                     |          }|dz   |d         z   dz   |z   }|	                    |           |	                    |d	z   |d
         z   d	z   |z              ddd|i| 
                                d}|                     ||          }d}|                     |          }t          |          |k    rt          | j        dz             |                     ||||           d {V S )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$     !!!!!!!!!it$.0GN`$22<CCCT`GT5111q#l++,, 	a 	aA"1oGF .WQZ00#AJ	(()YOO$)!!W--!C'&,6<?PPG##G,,,  s!2VH5E!E!KN_!_````(, //##
 
 **7F;;'YY//
z??111*s sttt((m_N^_________rV   c                 4   |                      |d          }|-t          | j        dz   |                     |          z             |                      |d          }|                     |d          }||                    d          }|                     |d          }| j        | j        | j        d}| j	        | j
        | j        | j        | j        |                      ||                     |d                    d	}	|                      |	|          }
|
 |
||           d S t          | j        d
z   |                     |          z             |                      |di           }|                     |d          }||                     ||           d S d S )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1#		%0@0@ @AAA(33""6955MM#&&E((22I/!0," "L ,,.,*d6F6Fua6P6PQQ H ooh	::G"(((tw)NNQUQZQZ[bQcQccddd(B77&&v~>>"..vw????? #"rV   c                 6    d}|                     ||           |S )Nauthenticated)r|   )rS   rt   r}   rm   s       rU   r>  z%deribit.handle_authentication_message  s"    $ &w,,,rV   c           
        K   | j         d         d         }|                     |          }|                                 }|                     |          }|}d}|                     |j        |          }||                                  |                                 }	d}
|                     | 	                    ||
z   |z   |
z             | 	                    | j
                  t          j                  }d|	dd| j        |||dd	d
}|                     |||                     ||          |           d {V }||j        |<   |S )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   	lineBreakrL  rr   s                rU   rg   zderibit.authenticate  sg     it$S!!  ""**400
%!5{CC>++---))II		$++j9.Du.Ly.X"Y"Y[_[f[fgkgr[s[su|  vD  E  EI '"4!%!%!*" 	 G  ::c;GV8T8TVabbbbbbbbF06F -rV   )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      sr       :# : : : : : :x  
 *, Q Q Q Q Q Q842V 42 42 42 42l 68 I I IF I I I I> 6:" %E %E7 %E %E %E %E %EN%,F %, %, %, %,N 8<B F FW F7 F F F FB,V , , , ,4     <@d[] S S SS S Sbfglbm S S S S  OSaenp S Sd3i S S[^ Suyz  vA S S S S.(9F (9 (9 (9 (9T 37TX\eg U UC Us URU Ulpqvlw U U U UB/.v /. /. /. /.b @DB P PS P PS\ P P P P SW_a ! !$s) !C !fo ! ! ! !:M5 M5 M5 M5 M5^  4 4 43 3 3 04$UYbd "U "U "UC "Us "Uimnsit "U "U "U "UH2-F 2- 2- 2- 2-h ?CQUdhqs ) ) ) )3 )^a )x|  ~B  yC ) ) ) )$ aesw  AC E E$tCy/ EZ] Emp E E E E*)16 )1 )1 )1 )1V
 
D 
 
 
 
* cgoq "` "` "`PS "` "` "` "`HY@V Y@ Y@ Y@ 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>rj     s        f f f f f f f f f f  f f f f f f f f f f f f f f f f f f f f f f f f 4 4 4 4 4 4       * * * * * * . . . . . . ) ) ) ) ) )t t t t td ( t t t t trV   