
    i                         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 d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ  G d
 dej        j                  ZdS )    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)BalancesIntOrder	OrderBookStrTickerTrade)Client)List)ExchangeError)AuthenticationError)InvalidNonce)Precisec            
           e Zd Z fdZi f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i fdededed	ee         fdZdddi fdededed	ee         fdZi fded	efdZi fdefdZdefdZd$dZdefdZd$dZdi fdeded	efdZdefdZdefdZi fd	efdZdefdZd ZdefdZ defdZ!i 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! Z'd$d"Z(defd#Z) xZ*S )%	bitfinex2c                     |                      t          t          |                                           dddddddddd	dddddiid	d
ddddd          S )NTF)	wswatchTickerwatchTickerswatchOrderBookwatchTradeswatchMyTradeswatchBalance
watchOHLCVwatchOrdersapir   zwss://api-pub.bitfinex.com/ws/2zwss://api.bitfinex.com/ws/2)publicprivateP0F0precfreq  )r   ordersLimitchecksum)hasurlsoptions)deep_extendsuperr   describe)self	__class__s    X/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/pro/bitfinex2.pyr/   zbitfinex2.describe   s    i 6 6 ? ? A A# %"&#!% $"#
 
 "C#@  ! # #  $  )D
 D
   	    c                 $  K   |                                   d {V  |                     |          }|d         }| j        d         d         d         }|                     |          }|dz   |z   }d||d}	|                     |||                     |	|          |dd	i           d {V }
|                     | j        dd
          }|rG|j        |         d         s4|dk    r.d
|j        |         d<   |	                    ddd           d {V  |
S )Nidr   r   r    :	subscribe)eventchannelsymbolr)   FTbookconfi   )r8   flags)
load_marketsmarketr+   clientwatchr-   	safe_boolr,   subscriptionssend)r0   r9   r:   paramsr?   marketIdurlr@   messageHashrequestresultr)   s               r2   r7   zbitfinex2.subscribe3   sn     !!!!!!!!!V$$$<it$X.S!!mh. 
 

 zz#{D4D4DWf4U4UWbeoqvdwxxxxxxxx>>$,
DAA 	F0=jI 	wZ`O`O`<@F -j9++           r3   c                    K   |                                   d {V  |                                  d {V  | j        d         d         d         }|                     ||d d           d {V S )Nr   r   r!      )r>   authenticater+   rA   )r0   rH   rG   s      r2   subscribe_privatezbitfinex2.subscribe_privateI   s      !!!!!!!!!!!!!!!!!!it$Y/ZZ[$:::::::::r3   1mNr:   sincelimitreturnc                   K   |                                   d{V  |                     |          }|d         }|                     | j        ||          }d}d|z   dz   |d         z   }	|dz   |z   dz   |d         z   }
d||	d}| j        d	         d
         d         }|                     ||
|                     ||          |
           d{V }| j        r|                    ||          }| 	                    |||dd          S )aQ  
        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
        Nr:   candlestrade:r6   r5   r7   )r8   r9   keyr   r   r    r   T)
r>   r?   safe_string
timeframesr+   rA   r-   
newUpdatesgetLimitfilter_by_since_limit)r0   r:   	timeframerP   rQ   rE   r?   intervalr9   rV   rH   rI   rG   ohlcvs                 r2   watch_ohlcvzbitfinex2.watch_ohlcvO   s9      !!!!!!!!!V$$!##DOY	JJ!C'&,6mh.4vd|C 
 

 it$X.jjk43C3CGV3T3TVabbbbbbbb? 	2NN6511E))%q$GGGr3   r@   c                    |                      |dg           }d }|                      |d          }t          |t                    r|}n|g}|                      |d          }|                     |d          }|                    d          }	|                     |	d          }
|}|                    dd          }|                    |
dz   d          }|                     |          }|                     |
          }|d         }|dz   |
z   dz   |z   }|                      | j        |i           | j        |<   |                      | j        |         |          }|;| 	                    | j
        d	d
          }t          |          }|| j        |         |<   t          |          }t          d|          D ];}|||z
  dz
           }|                     ||          }|                    |           <|                    ||           d S )NrL   r   r9   rV   r6   rU    r:   
OHLCVLimitr'   )
safe_value
isinstancelistrW   splitreplacesafe_marketfind_timeframeohlcvssafe_integerr,   r   lenrangeparse_ohlcvappendresolve)r0   r@   messagesubscriptiondatarj   firstr9   rV   keyPartsr]   rF   r?   r\   r:   rH   storedrQ   ohlcvsLengthir^   parseds                         r2   handle_ohlcvzbitfinex2.handle_ohlcvl   s   \ w2..a((eT"" 	FF VF//,	::|U3399S>>##Ha00##Hb11##HsNB77!!(++''11	!mh.4x?"oodk62FFFV!4i@@>%%dlL$GGE*511F-3DK	*6{{q,'' 	" 	"A<!+a/0E%%eV44FMM&!!!!v{+++++r3   c                    K   |                      d||           d{V }| j        r|                    ||          }|                     |||dd          S )a  
        get the list of most recent trades for a particular symbol
        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        tradesN	timestampT)r7   rY   rZ   r[   )r0   r:   rP   rQ   rE   r|   s         r2   watch_tradeszbitfinex2.watch_trades   sh       ~~h????????? 	3OOFE22E))&%TRRRr3   c                 *  K   |                                   d{V  d}|#|                     |          }|d|d         z   z  }|                     |           d{V }| j        r|                    ||          }|                     ||||d          S )a  
        watches information on multiple trades made by the user
        :param str symbol: unified market symbol of the market trades were made in
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trade structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure
        NmyTrader6   r5   Tr>   r?   rN   rY   rZ   filter_by_symbol_since_limit)r0   r:   rP   rQ   rE   rH   r?   r|   s           r2   watch_my_tradeszbitfinex2.watch_my_trades   s       !!!!!!!!![[((F3--K--k::::::::? 	3OOFE22E00tTTTr3   c                 @   K   |                      d||           d{V S )a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours 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
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        tickerN)r7   )r0   r:   rE   s      r2   watch_tickerzbitfinex2.watch_ticker   s0       ^^Hff=========r3   c                    d}|                      |d          }|                     |          }|d         }|                     |          }|dz   |d         z   }	| j        0|                     | j        dd          }
t          |
          | _        | j        }|                    |           || _        |                    ||           |                    ||	           d S )Nr      r:   r6   r5   tradesLimitr'   )	rc   parse_ws_trader?   myTradesrk   r,   r   ro   rp   )r0   r@   rq   rr   namers   trader:   r?   rH   rQ   tradesArrays               r2   handle_my_tradezbitfinex2.handle_my_trade   s    , w**##D))xV$$Sj6$</= %%dlM4HHE2599DMm5!!!#{D))){K00000r3   c                 H   |                      |d          }|                     |d          }|                     |          }|dz   |z   }|                     | j        dd          }|d         }	|                      | j        |	          }
|
t          |          }
|
| j        |	<   t          |          }|dk    rs|                     |dg           }t          |          }t          d|          D ];}||z
  dz
  }| 
                    ||         |          }|
                    |           <n`|                     |d          }|d	k    rd S |                      |dg           }| 
                    ||          }|
                    |           |                    |
|           d S )
Nr9   r:   r6   r   r'   r   rL   r   tu)rc   rW   rh   rk   r,   r|   r   rl   	safe_listrm   r   ro   rp   )r0   r@   rq   rr   r9   rF   r?   rH   r   r:   rv   messageLengthr|   lengthrx   indexry   typer   s                      r2   handle_tradeszbitfinex2.handle_trades  s   > //,	::##L(;;!!(++mh.''mTJJ!f55>,,F"(DKGA^^GQ33F[[F1f%% & &
Q,,VE]FCCf%%%%& ##GQ//Dt|| OOGQ33E((77FMM&!!!v{+++++r3   c                 @   t          |          }|dk    }|s|                     |d          nd }|                     ||          }|rdnd}|rdnd}|rdnd}|d         }|                     |d          }	|	7|	                    d	          d
k    rd}	n|	                    d          d
k    rd}	|s|                     |d          nd }
|                     |d          }|                     ||          }|                     ||          }|                     ||          }|                     t          j        |                    }d }|t          j        |d          rdnd}| 	                    ||          }|                     |d          }d }|0|                     |d          }| 
                    |          }||d}|                     |d          }d }|
|d
k    rdnd}|                     |||                     |          |||
|	||||d |d|          S )N   rL   r            r5      LIMITrQ   MARKETr?   r   0buysell	   
   )costcurrencytakermaker)infor}   datetimer:   r5   orderr   takerOrMakersidepriceamountr   fee)rl   rW   rh   findrk   parse_numberr   
string_abs	string_gtsafe_symbolsafe_currency_code
safe_tradeiso8601)r0   r   r?   	numFieldsisPublicrF   
createdKeypriceKey	amountKeyr   orderIdr5   r}   r   amountStringr   r   r:   feeValuer   
currencyIdcoder   r   s                           r2   r   zbitfinex2.parse_ws_tradeK  s   V JJ	>6>I4##E1---T!!(F33")QQ
 '11a!(AAq	$<q))yy!!B&&8$$r))5=H$""5!,,,DeQ''%%eZ88	  11''y99""7#5l#C#CDD#-lC@@L55fD!!(F33##E1--))%44J**:66D   C !!%++',{{77L"Y//( 
  
   	r3   c                 2   |                      |d          }|                     |d          }|                     |          }|                     |          }|                     ||          }d}	|	dz   |z   }
|| j        |<   |                    ||
           d S )NrL   r:   r   r6   )rc   rW   rh   r   parse_ws_tickertickersrp   )r0   r@   rq   rr   r   rF   r?   r:   ry   r9   rH   s              r2   handle_tickerzbitfinex2.handle_ticker  s    $ !,,##L(;;!!(++!!(++%%ff55mh.%Vv{+++++r3   c                 t   |                      d |          }|d         }|                     |d          }|                     |d          }|                     i d|dd dd d|                     |d          d|                     |d	          d
|                     |d          d|                     |d          d|                     |d          d|                     |d          dd dd d|d|dd d|d|                     |d          dd |                     |d          d |d|          S )Nr:   r   r   r}   r   highr   lowr   bidr   	bidVolumerL   askr   	askVolumer   vwapopencloselastpreviousClosechange
percentager   average   )
baseVolumequoteVolumer   )rh   rW   safe_ticker)r0   r   r?   r:   r   r   s         r2   r   zbitfinex2.parse_ws_ticker  s    !!$//!**!!&!,, !
f!
!
 !
 D$$VQ//	!

 4##FA..!
 4##FA..!
 ))&!44!
 4##FA..!
 ))&!44!
 D!
 D!
 T!
 D!
 T!
 f!
  $**6155!!
" t#!
$ **6155)!
 !
 !
* +  	r3   c                   K   |#|dk    r|dk    rt          | j        dz             |                     | j        di           }|                     |dd          }|                     |dd	          }||d
}|||d<   |                     d||                     ||                     d{V }|                                S )a  
        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
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        N   d   z6 watchOrderBook limit argument must be None, 25 or 100r   r%   r"   r&   r#   r$   rl   r;   )r   r5   rc   r,   rW   r7   r-   rQ   )	r0   r:   rQ   rE   r,   r%   r&   rI   	orderbooks	            r2   watch_order_bookzbitfinex2.watch_order_book  s       %3,,#DG.f$fggg//$,0@"EE6666
 
 "GEN..9I9I'SY9Z9Z[[[[[[[[	   r3   c                    |                      |d          }|                     |          }d}|dz   |z   }|                      |dd          }|dk    }	|                     | j        |          }
|
|                     |d          }|	r|                     i |          | j        |<   n|                     i |          | j        |<   | j        |         }
|	r|d         }t          d	t          |                    D ]r}||         }|d
         }|d	k     r| n|}|d	k     rdnd}|
|         }|                      |d	          }| 	                    |d          }|
                    |||           sn|d         }t          d	t          |                    D ]}||         }|                     |d
          }|                     |d          }|                     |d	          }|d	k     r| n|}|d	k     rdnd}|
|         }|
                    |||           ||
d<   |                    |
|           d S |d         }| j        |         }|	r|                      |d          }|d
         }|d	k     r| n|}|d	k     rdnd}||         }t          j        |d          r|nd}|                      |d	          }|
                    |                     |          |                     |          |           n|                      |d
          }|                      |d          }|                      |d	          }t          j        |d          rt          j        |          n|}t          j        |d          rdnd}||         }|
                    |                     |          |                     |          |                     |                     |                    |
|           d S )Nr:   r;   r6   r%   r"   R0rl   rL   r   r   asksbidsr   )rW   r   rc   
orderbooksrk   indexed_order_bookcounted_order_bookrm   rl   
safe_floatstoresafe_numberrp   r   r   r   	string_lt
string_neg)r0   r@   rq   rr   rF   r:   r9   rH   r%   isRawr   rQ   deltasrx   deltadelta2sizer   booksideidStringr   r   counterorderbookItemdeltas2s                            r2   handle_order_bookzbitfinex2.handle_order_book  s*   6 ##L(;;!!(++mh.fd;;OODOV<<	%%lE::E M*.*A*A"e*L*L'' +/*A*A"e*L*L'/I 9 q#f++.. : :A"1IE"1XF'-zzF77D&,qjj66vD(H#//q99H OOE155ENN5$9999: !q#f++.. 9 9A"1IE!--eQ77F"..ua88G ,,UA66E'-zzF77D&,qjj66vD(HNN5$8888"(IhNN9k22222QZF OF3M n((33 )$+aKKxxg")A++vvF(.!(!25#!>!>GC++FA66t00779J9J69R9RT\]]]]))&!44**6155((335<5Fvs5S5S_w)&111Y_!(!263!?!?KvvV(.t00779J9J49P9PRVRcRcdkRlRlmmmNN9k22222r3   c                 8   |                      |d          }|                     |          }d}|dz   |z   }|                     | j        |          }|d S d}	g }
|d         }|d         }|                      |dd          }|d	k    }|rd
nd}t	          d|	          D ]}|                     ||          }|                     ||          }|h|
                    |                     ||         |                              |
                    |                     ||         d                              |k|
                    |                     ||         |                              ||         d         }|
                    |                     |                      d                    |
          }|                     |d          }| 	                    |d
          }||k    r/t          | j        dz             }|                    ||           d S d S )Nr:   r;   r6   r   r   r   r%   r"   r   r   r   rL   Tz invalid checksum)rW   r   rc   r   rm   ro   number_to_stringjoincrc32rk   r   r5   reject)r0   r@   rq   rr   rF   r:   r9   rH   r;   depthstringArrayr   r   r%   r   	idToCheckrx   r   r   aski1payloadlocalChecksumresponseChecksumerrors                           r2   handle_checksumzbitfinex2.handle_checksumc  s    ##L(;;!!(++mh.t77<FF|F|fd;;%AAA	q% 		B 		BA//$**C//$**C""4#8#8a9K#L#LMMM""4#8#8a#D#DEEE""4#8#8a9K#L#LMMMQ
""4#8#8%#@#@AAA((;''

7D11,,Wa88},, +>!>??EMM%----- -,r3   c                    K   |                                   d{V  |                     |dd          }|                     |d          }d|z   }|                     |           d{V S )a  
        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
        :param str [params.type]: spot or contract if not provided self.options['defaultType'] is used
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nwalletexchangebalance:)r>   rW   omitrN   )r0   rE   balanceTyperH   s       r2   watch_balancezbitfinex2.watch_balance  s       !!!!!!!!!&&vxDD68,, ;.++K888888888r3   c                    |                      |d          }d }|dk    r|                      |d          }n|                      |d          g}i }t          dt          |                    D ]}||         }|                     |d          }	|                     |	          }
|                     |          }|                     |d          }|                      | j        |i           }|||
<   ||d<   |                     |          | j        |<   d||<   t          |	                                          }t          dt          |                    D ]0}||         }d|z   }|
                    | j        |         |           1d S )NrL   r   r   r   r   Tr  )rc   rm   rl   rW   r   parse_ws_balancebalancesafe_balancere   keysrp   )r0   r@   rq   rr   
updateTypers   updatedTypesrx   
rawBalancer   r   r  r
  
oldBalanceupdatesKeysr   rH   s                    r2   handle_balancezbitfinex2.handle_balance  s   ~ __Wa00
??7A..DDOOGQ//0Dq#d))$$ 
	- 
	-AaJ))*a88J**:66D++J77G**:q99K{BGGJ&Jt!(Jv(,(9(9*(E(EDL%(,L%%<,,..//q#k**++ 	< 	<Aq>D$t+KNN4<-{;;;;	< 	<r3   c                     |                      |d          }|                      |d          }|                                 }|||d<   ||d<   |S )Nr   r   freetotal)rW   account)r0   r  totalBalanceavailableBalancer  s        r2   r  zbitfinex2.parse_ws_balance  sZ     ''33++GQ77,,..'.GFO'r3   c                     |S N )r0   r@   rq   s      r2   handle_system_statuszbitfinex2.handle_system_status  s	     r3   c                 F    |                      |d          }||j        |<   |S )NchanId)rW   rC   )r0   r@   rq   	channelIds       r2   handle_subscription_statusz$bitfinex2.handle_subscription_status
  s+     $$Wh77	*1Y'r3   c                 :  K   | j         d         d         d         }|                     |          }d}|                    |          }|                     |j        |          }||                                 }dt          |          z   }|                     |                     |          |                     | j	                  t          j        d          }	d}
| j        |	|||
d}|                     ||          }|                     ||||           | d {V S )	Nr   r   r!   authenticatedAUTHhexauth)apiKeyauthSig	authNonceauthPayloadr8   )r+   r@   futurerc   rC   millisecondsstrhmacencodesecrethashlibsha384r*  extendrA   )r0   rE   rG   r@   rH   r.  r&  noncer   	signaturer8   rI   rq   s                r2   rM   zbitfinex2.authenticate  s     it$Y/S!!%{++(<kJJ %%''Es5zz)G		$++g"6"6DK8P8PRYR`bghhIE+$"& G kk'622GJJsK+>>>||||||r3   c                 <   d}|                      |d          }|dk    r2|                     |j        |          }|                    d           d S t	          |                     |                    }|                    ||           ||j        v r
|j        |= d S d S )Nr&  statusOKT)rW   rc   futuresrp   r   jsonr   rC   )r0   r@   rq   rH   r:  r.  r  s          r2   handle_authentication_messagez'bitfinex2.handle_authentication_message1  s    %!!'844T>>__V^[AAFNN4     '		'(:(:;;EMM%---f222(555 32r3   c                 *  K   |                                   d{V  d}|#|                     |          }|d|d         z   z  }|                     |           d{V }| j        r|                    ||          }|                     ||||d          S )a  
        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]{@link https://docs.ccxt.com/#/?id=order-structure
        Nordersr6   r5   Tr   )r0   r:   rP   rQ   rE   rH   r?   r@  s           r2   watch_orderszbitfinex2.watch_orders?  s       !!!!!!!!![[((F3--K--k::::::::? 	3OOFE22E00tTTTr3   c                    |                      |dg           }|                     |d          }| j        0|                     | j        dd          }t          |          | _        | j        }i }|dk    rwt          |          }	|	dk    rd S t          dt          |                    D ]A}
||
         }|                     |          }|d         }d||<   |	                    |           Bn7|                     |          }|	                    |           |d         }d||<   d	}|
                    | j        |           t          |                                          }t          dt          |                    D ]H}
||
         }|                     |          }|d
z   |d         z   }|
                    | j        |           Id S )Nr   rL   r(   r'   osr   r:   Tr@  r6   r5   )rc   rW   r@  rk   r,   r   rl   rm   parse_ws_orderro   rp   re   r  r?   )r0   r@   rq   rr   rs   messageTyperQ   r@  	symbolIdssnapshotLengthrx   valuery   r:   r   r  r?   rH   s                     r2   handle_orderszbitfinex2.handle_ordersR  s   R w2..&&w22;%%dlM4HHE077DK	$ YYN""1c$ii(( & &Q,,U33)$(	&!f%%%%& ((..FMM&!!!H%F $Ift{D)))INN$$%%q#d))$$ 	5 	5A!WF[[((F*vd|3KNN4;4444		5 	5r3   c                 >    ddddd}|                      |||          S )Nr   canceledclosed)ACTIVECANCELEDEXECUTED	PARTIALLY)rW   )r0   r:  statusess      r2   parse_ws_order_statuszbitfinex2.parse_ws_order_status  s4    " 	
 
 &&999r3   c                    |                      |d          }|                      |d          }|                      |d          }|                     |          }|                     |          }|                      |d          }d}t          j        |d          rt          j        |          }d}t          j        |                      |d                    }	|                      |d	          }
|
                    d
          dk    rd}
n|
                    d          dk    rd}
|                      |d          }|                    d          }|                      |d          }|                     |          }|                      |d          }| 	                    |dd          }|                      |d          }| 
                    |                      |d                    }|                     i d|d|d|d|d|                     |          dd d|d|
d|d|d |d!|d"|d#|d$|	d%d d&|d d d d'|          S )(Nr   rL   r   r   r   r   r   r   r   r   r   rQ   r   r?          r   r         r   r5   clientOrderIdr}   r   lastTradeTimestampr:   r   r   r   	stopPricetriggerPricer   r   	remainingfilledr:  )r   r   r|   )rW   r   rh   r   r   r   r   rf   rR  safe_integer_2	omit_zero
safe_orderr   )r0   r   r?   r5   rY  rF   r:   r   r   r]  r   rawState
statePartstrimmedStatusr:  r   r}   r   r[  s                      r2   rD  zbitfinex2.parse_ws_order  s   J eQ''((22##E1--!!(++!!&))!!%++VS)) 	'//FD&t'7'7q'A'ABB	q))99W""DDYYx  2%%D##E2..^^C((
((Q77++M::  ++''q!44	""5"--NN4#3#3E2#>#>??	  
E 
" 
 ] 
 	 

 Y// 
 !$ 
 f 
 D 
 D 
 U 
  
 I 
 w 
 f 
  
  d! 
" f# 
$ ) 
  
  
* +  	r3   c                    |                      |d          }t          |t                    r|d         dk    rd S |                     |j        |i           }|                      |d          }|                      |d          }| j        | j        | j        | j        | j	        d}| j
        | j
        | j
        | j
        | j        | j        | j        d}d }	|dk    r|                     ||          }	n|                     |||          }	|	 |	|||           d S d S |                      |d          }
|
;| j        | j        | j        d	}|                     ||
          }	|	 |	||           d S d S d S )
Nr   rL   hbr9   )r;   csrT   r   r|   )rC  ouonocwur   r   r   r8   )r   
subscribedr)  )rW   rd   re   rc   rC   r   r  rz   r   r   rI  r  r   safe_value_2r   r$  r>  )r0   r@   rq   r#  rr   r9   r   publicMethodsprivateMethodsmethodr8   methodss               r2   handle_messagezbitfinex2.handle_message  s   $$Wa00	4 gt$$ '	,qzT!!??6+?BOOL&&|Y??G##GQ//D.*,,, M (((())* N FC>>**=$HH!vw55555 "! $$Wg66E  5"&"A > 
 %88%F67+++++ !  &%r3   r  )+__name__
__module____qualname__r/   r7   rN   r0  r   r   re   r_   r   rz   r   r~   r
   r   r   r   r   r   r   r   r   r	   r   r   r  r   r  r  r  r   r$  rM   r>  r   rA  rI  rR  rD  rr  __classcell__)r1   s   @r2   r   r      s#           > 79    ,; ; ; 8<$]ajl H H HC HWZ Hquvzq{ H H H H:M,6 M, M, M, M,^ <@d[] S S SS S Sbfglbm S S S S 37TX\eg U UC Us URU Ulpqvlw U U U U& 68 > > >F > > > > EG %1 %1f %1 %1 %1 %1N=,F =, =, =, =,~^ ^ ^ ^@,F , , , ,8( ( ( (T @DB ! !S ! !S\ ! ! ! !.Y3 Y3 Y3 Y3 Y3v".f ". ". ". ".H *, 9 9 9 9 9 9U<V U< U< U< U<n  (	6 	 	 	 	    " )+    ,6F 6 6 6 6 04$UYbd U U UC Us Uimnsit U U U U&F5F F5 F5 F5 F5P: : :R R R RhB,V B, B, B, B, B, B, B, B,r3   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r4  ccxt.base.typesr   r   r   r	   r
   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   ccxt.base.preciser   async_supportr   r  r3   r2   <module>r     s        f f f f f f f f f f  O O O O O O O O O O O O O O O O O O 4 4 4 4 4 4       * * * * * * 0 0 0 0 0 0 ) ) ) ) ) ) % % % % % %g, g, g, g, g,", g, g, g, g, g,r3   