
    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 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)AnyBalancesIntOrder	OrderBookStrTickerTrade)Client)List)ExchangeError)AuthenticationError)ChecksumError)Precisec                   :    e Zd Zdef fdZi fdZi fdZd Zdddi fded	ed
e	de	de
e         f
dZdi fded	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i fd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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&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Z0S )+bitfinexreturnc                     |                      t          t          |                                           ddddd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watchTradesForSymbolswatchMyTradeswatchBalance
watchOHLCVwatchOrdersunWatchTickerunWatchTradesunWatchOHLCVunWatchOrderBookapir   zwss://api-pub.bitfinex.com/ws/2zwss://api.bitfinex.com/ws/2)publicprivateP0F0)precfreqchecksum  )r   ordersLimit)hasurlsoptions)deep_extendsuperr   describe)self	__class__s    O/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/pro/bitfinex.pyr5   zbitfinex.describe   s    h 5 5 > > @ @# %"&#).!% $"#!%!% $$( " "C#@  !  $# #
  $ 3!C
 !C
 ! ! !	    c                 ,  K   |                                   d {V  |                     |          }|d         }| j        d         d         d         }|                     |          }|dz   |z   }d||d}	|                     |||                     |	|          |dd	i           d {V }
|                     | j        dd
          }|rK|dk    rE|j        |         }|r6|d         s.d
|j        |         d<   |	                    ddd           d {V  |
S )Nidr&   r   r'   :	subscribe)eventchannelsymbolr-   FTbookconfi   )r>   flags)
load_marketsmarketr1   clientwatchr3   	safe_boolr2   subscriptionssend)r6   r?   r@   paramsrE   marketIdurlrF   messageHashrequestresultr-   subs                r8   r=   zbitfinex.subscribe8   sy     !!!!!!!!!V$$$<it$X.S!!mh. 
 

 zz#{D4D4DWf4U4UWbeoqvdwxxxxxxxx>>$,
DAA 	F**&{3C 3z? @D$[1*=kk### #          r9   c                   K   |                                   d {V  |                     |          }|d         }| j        d         d         d         }|                     |          }|dz   |z   }	d|z   dz   |z   }
d|z   dz   |z   }|                     |j        |          }d|d}d|z   }|	|j        |<   |
g|	g|d	|gd
}|                     ||
|                     ||          |
|           d {V S )Nr;   r&   r   r'   r<   unsubscribe:unsubscriber>   chanIdTmessageHashessubMessageHashestopicrT   symbols)rD   rE   r1   rF   safe_stringrI   rG   r3   )r6   r?   rZ   r@   rK   rE   rL   rM   rF   subMessageHashrN   
unSubTopic	channelIdrO   unSubChanMsgsubscriptions                   r8   un_subscribezbitfinex.un_subscribeP   sF     !!!!!!!!!V$$$<it$X.S!! 31$w.4x?(5036?
$$V%9:FF	"
 
 &	1-;\*)]!/ 0x
 
 ZZ[$2B2B7F2S2SU`bnooooooooor9   c                    K   |                                   d {V  |                                  d {V  | j        d         d         d         }|                     ||d d           d {V S )Nr&   r   r(      )rD   authenticater1   rG   )r6   rN   rM   s      r8   subscribe_privatezbitfinex.subscribe_privatei   s      !!!!!!!!!!!!!!!!!!it$Y/ZZ[$:::::::::r9   1mNr@   	timeframesincelimitc                   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:r<   r;   r=   )r>   r?   keyr&   r   r'   r   T)
rD   rE   r\   
timeframesr1   rG   r3   
newUpdatesgetLimitfilter_by_since_limit)r6   r@   rh   ri   rj   rK   rE   intervalr?   rn   rN   rO   rM   ohlcvs                 r8   watch_ohlcvzbitfinex.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Gr9   c                 :  K   |                                   d{V  |                     |          }|d         }|                     | j        ||          }d}|dz   |z   dz   |d         z   }d|z   }| j        d         d         d	         }	|                     |	          }
d
|z   dz   |d         z   }|                     |
j        |          }d|d}d|z   }||
j        |<   |g|gdd|gd}|                     |	||                     ||          ||           d{V S )a  
        unWatches 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 dict [params]: extra parameters specific to the exchange API endpoint
        :returns bool: True if successfully unsubscribed, False otherwise
        Nr@   rl   r<   r;   rS   r&   r   r'   zunsubscribe:trade:rT   rU   rt   TrW   )	rD   rE   r\   ro   r1   rF   rI   rG   r3   )r6   r@   rh   rK   rE   rs   r?   r]   rN   rM   rF   subIdr_   rO   r`   ra   s                   r8   un_watch_ohlcvzbitfinex.un_watch_ohlcv   so      !!!!!!!!!V$$!##DOY	JJ 31C7&,F$~5it$X.S!!$x/#5tD$$V%95AA	"
 
 &	1-;\*)]!/ 0x
 
 ZZ[$2B2B7F2S2SU`bnooooooooor9   rF   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 )Nrd   r   r?   rn   r<   rm    r@   
OHLCVLimitr.   )
safe_value
isinstancelistr\   splitreplacesafe_marketfind_timeframeohlcvssafe_integerr2   r   lenrangeparse_ohlcvappendresolve)r6   rF   messagera   datar   firstr?   rn   keyPartsrs   rL   rE   rh   r@   rN   storedrj   ohlcvsLengthirt   parseds                         r8   handle_ohlcvzbitfinex.handle_ohlcv   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{+++++r9   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)r=   rp   rq   rr   )r6   r@   ri   rj   rK   r   s         r8   watch_tradeszbitfinex.watch_trades   sh       ~~h????????? 	3OOFE22E))&%TRRRr9   c                 B   K   |                      dd||           d{V S )aS  
        unWatches the list of most recent trades for a particular symbol
        :param str symbol: unified symbol of the market to fetch trades for
        :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>`
        r   Nrb   r6   r@   rK   s      r8   un_watch_tradeszbitfinex.un_watch_trades  4       &&x66JJJJJJJJJr9   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 <https://docs.ccxt.com/?id=trade-structure>`
        NmyTrader<   r;   TrD   rE   rf   rp   rq   filter_by_symbol_since_limit)r6   r@   ri   rj   rK   rN   rE   r   s           r8   watch_my_tradeszbitfinex.watch_my_trades  s       !!!!!!!!![[((F3--K--k::::::::? 	3OOFE22E00tTTTr9   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)r=   r   s      r8   watch_tickerzbitfinex.watch_ticker'  s0       ^^Hff=========r9   c                 B   K   |                      dd||           d{V S )a  
        unWatches 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>`
        r   Nr   r   s      r8   un_watch_tickerzbitfinex.un_watch_ticker0  r   r9   c                    d}|                      |d          }|                     |          }|d         }|                     |          }|dz   |d         z   }	| j        0|                     | j        dd          }
t          |
          | _        | j        }|                    |           || _        |                    ||           |                    ||	           d S )Nr      r@   r<   r;   tradesLimitr.   )	r|   parse_ws_traderE   myTradesr   r2   r   r   r   )r6   rF   r   ra   namer   trader@   rE   rN   rj   tradesArrays               r8   handle_my_tradezbitfinex.handle_my_trade9  s    , w**##D))xV$$Sj6$</= %%dlM4HHE2599DMm5!!!#{D))){K00000r9   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 )
Nr?   r@   r<   r   r.   r   rd   r   tu)r|   r\   r   r   r2   r   r   r   	safe_listr   r   r   r   )r6   rF   r   ra   r?   rL   rE   rN   r   r@   r   messageLengthr   lengthr   indexr   typer   s                      r8   handle_tradeszbitfinex.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{+++++r9   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   rd   r            r;      LIMITrj   MARKETrE   r   0buysell	   
   )costcurrencytakermaker)infor   datetimer@   r;   orderr   takerOrMakersidepriceamountr   fee)r   r\   r   findr   parse_numberr   
string_abs	string_gtsafe_symbolsafe_currency_code
safe_tradeiso8601)r6   r   rE   	numFieldsisPublicrL   
createdKeypriceKey	amountKeyr   orderIdr;   r   r   amountStringr   r   r@   feeValuer   
currencyIdcoder   r   s                           r8   r   zbitfinex.parse_ws_trade  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//( 
  
   	r9   c                 2   |                      |d          }|                     |d          }|                     |          }|                     |          }|                     ||          }d}	|	dz   |z   }
|| j        |<   |                    ||
           d S )Nrd   r@   r   r<   )r|   r\   r   r   parse_ws_tickertickersr   )r6   rF   r   ra   r   rL   rE   r@   r   r?   rN   s              r8   handle_tickerzbitfinex.handle_ticker  s    $ !,,##L(;;!!(++!!(++%%ff55mh.%Vv{+++++r9   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   	bidVolumerd   askr   	askVolumer   vwapopencloselastpreviousClosechange
percentager   average   )
baseVolumequoteVolumer   )r   r\   safe_ticker)r6   r   rE   r@   r   r   s         r8   r   zbitfinex.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)!
 !
 !
* +  	r9   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+   r,   r   rA   )r   r;   r|   r2   r\   r=   r3   rj   )	r6   r@   rj   rK   r2   r+   r,   rO   	orderbooks	            r8   watch_order_bookzbitfinex.watch_order_bookE  s       %3,,#DG.f$fggg//$,0@"EE6666
 
 "GEN..9I9I'SY9Z9Z[[[[[[[[	   r9   c                    |                      |d          }|                     |          }d}|dz   |z   }|                      |dd          }|dk    }	|| j        vr|                     |d          }
|	r|                     i |
          | j        |<   n|                     i |
          | j        |<   | j        |         }|	r|d         }t          d	t          |                    D ]s}||         }|d
         }|d	k     r| n|}|d	k     rdnd}||         }|                      |d	          }|                     |d          }|	                    |||g           tn|d         }t          d	t          |                    D ]}||         }| 
                    |d
          }| 
                    |d          }| 
                    |d	          }|d	k     r| n|}|d	k     rdnd}||         }|	                    |||g           ||d<   |                    ||           d S | j        |         }|d         }| j        |         }|	r|                      |d          }|d
         }|d	k     r| n|}|d	k     rdnd}||         }t          j        |d          r|nd}|                      |d	          }|	                    |                     |          |                     |          |g           n|                      |d
          }|                      |d          }|                      |d	          }t          j        |d          rt          j        |          n|}t          j        |d          rdnd}||         }|	                    |                     |          |                     |          |                     |          g           |                    ||           d S )Nr@   rA   r<   r+   r)   R0r   rd   r   r   asksbidsr   )r\   r   
orderbooksr   indexed_order_bookcounted_order_bookr   r   
safe_float
storeArraysafe_numberr   r   r   r   	string_lt
string_neg)r6   rF   r   ra   rL   r@   r?   rN   r+   isRawrj   r   deltasr   deltadelta2sizer   booksideidStringr   r   counterorderbookItemdeltas2s                            r8   handle_order_bookzbitfinex.handle_order_book\  sD   6 ##L(;;!!(++mh.fd;;$/))%%lE::E M*.*A*A"e*L*L'' +/*A*A"e*L*L'/I @ q#f++.. A AA"1IE"1XF'-zzF77D&,qjj66vD(H#//q99H OOE155E''h(?@@@@A !q#f++.. @ @A"1IE!--eQ77F"..ua88G ,,UA66E'-zzF77D&,qjj66vD(H''g(>????"(IhNN9k22222/IQZF OF3M u((33 )$+aKKxxg")A++vvF(.!(!25#!>!>GC++FA66##T%6%6u%=%=t?P?PQW?X?XZb$cdddd))&!44**6155((335<5Fvs5S5S_w)&111Y_!(!263!?!?KvvV(.##T%6%6u%=%=t?P?PQU?V?VX\XiXijqXrXr$stttNN9k22222r9   c                    |                      |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    rn|j
        |= | j        |= |                     ddd          }|rGt          | j        dz   |                     |          z             }|                    ||           d S d S d S )Nr@   rA   r<   r   r  r  r+   r)   r   r   r   rd   Tr   r-    )r\   r   r|   r  r   r   number_to_stringjoincrc32r   rI   handle_optionr   r;   orderbook_checksum_messagereject)r6   rF   r   ra   rL   r@   r?   rN   rA   depthstringArrayr  r  r+   r  	idToCheckr   r   r   aski1payloadlocalChecksumresponseChecksumr-   errors                            r8   handle_checksumzbitfinex.handle_checksum  sp    ##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},,$[1'))*:JMMH 2%dgmd6U6UV\6]6]&]^^e[11111 -,2 2r9   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:)rD   r\   omitrf   )r6   rK   balanceTyperN   s       r8   watch_balancezbitfinex.watch_balance  s       !!!!!!!!!&&vxDD68,, ;.++K888888888r9   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 )Nrd   r   r   r   r   Tr*  )r|   r   r   r\   r   parse_ws_balancebalancesafe_balancer~   keysr   )r6   rF   r   ra   
updateTyper   updatedTypesr   
rawBalancer   r   r0  r,  
oldBalanceupdatesKeysr   rN   s                    r8   handle_balancezbitfinex.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<-{;;;;	< 	<r9   c                     |                      |d          }|                      |d          }|                                 }|||d<   ||d<   |S )Nr   r   freetotal)r\   account)r6   r0  totalBalanceavailableBalancer<  s        r8   r/  zbitfinex.parse_ws_balanceC  sZ     ''33++GQ77,,..'.GFO'r9   c                     |S N )r6   rF   r   s      r8   handle_system_statuszbitfinex.handle_system_statusW  s	     r9   c                    |                      |d          }d|z   }|                      |j        |          }|                     |j        d|z             }|j        |= |                     |dg           }|                     |dg           }t	          dt          |                    D ])}	||	         }
||	         }|                     |||
           *|                     |           dS )NrV   rS   rX   rY   r   T)r\   rI   	safe_dictr   r   r   clean_unsubscriptionclean_cache)r6   rF   r   r_   unSubChannelr]   ra   rX   rY   r   rN   subHashs               r8   handle_unsubscription_statusz%bitfinex.handle_unsubscription_statusb  s     $$Wh77	%	1))&*>MM~~f&:N^<[\\ .|_bII>>,8JBOOq#m,,-- 	D 	DA'*K&q)G%%fg{CCCC&&&tr9   c                    |                      |d          }||j        |<   ddddd}|                      ||                      |d                    }d|v r&|                      |d          }d	|z   }||j        |<   nB|                      |d
          }|                     |          }	|d	|z   dz   |	z   }
||j        |
<   |S )NrV   r   rt   r   r   )rA   rl   r   r   r?   rn   rS   r@   r<   )r\   rI   r   )r6   rF   r   r_   mappingsunifiedChannelrn   subKeyIdrL   r@   rw   s              r8   handle_subscription_statusz#bitfinex.handle_subscription_statusx  s    ( $$Wh77	*1Y'  	
 
 ))(D4D4DWi4X4XYYG""7E22C%+H-6F **''::H%%h//F)&7#=F.7$U+r9   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authPayloadr>   )r1   rF   reusableFuturer|   rI   millisecondsstrhmacencodesecrethashlibsha384rT  extendrG   )r6   rK   rM   rF   rN   futurerP  noncer"  	signaturer>   rO   r   s                r8   re   zbitfinex.authenticate  s     it$Y/S!!%&&{33(<kJJ %%''Es5zz)G		$++g"6"6DK8P8PRYR`bghhIE+$"& G kk'622GJJsK+>>>||||||r9   c                 <   d}|                      |d          }|dk    r2|                     |j        |          }|                    d           d S t	          |                     |                    }|                    ||           ||j        v r
|j        |= d S d S )NrP  statusOKT)r\   r|   futuresr   r   jsonr  rI   )r6   rF   r   rN   re  ra  r%  s          r8   handle_authentication_messagez&bitfinex.handle_authentication_message  s    %!!'844T>>__V^[AAFNN4     '		'(:(:;;EMM%---f222(555 32r9   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 <https://docs.ccxt.com/?id=order-structure>`
        Nordersr<   r;   Tr   )r6   r@   ri   rj   rK   rN   rE   rk  s           r8   watch_orderszbitfinex.watch_orders  s       !!!!!!!!![[((F3--K--k::::::::? 	3OOFE22E00tTTTr9   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   rd   r/   r.   osr   r@   Trk  r<   r;   )r|   r\   rk  r   r2   r   r   r   parse_ws_orderr   r   r~   r2  rE   )r6   rF   r   ra   r   messageTyperj   rk  	symbolIdssnapshotLengthr   valuer   r@   r   r2  rE   rN   s                     r8   handle_orderszbitfinex.handle_orders  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 	5r9   c                 >    ddddd}|                      |||          S )Nr   canceledclosed)ACTIVECANCELEDEXECUTED	PARTIALLY)r\   )r6   re  statusess      r8   parse_ws_order_statuszbitfinex.parse_ws_order_status"  s4    " 	
 
 &&999r9   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   rd   r   r   r   r   r   r   r   r   r   rj   r   rE      r     r   r         r   r;   clientOrderIdr   r   lastTradeTimestampr@   r   r   r   	stopPricetriggerPricer   r   	remainingfilledre  )r   r   r   )r\   r   r   r   r	  r   r   r   r}  safe_integer_2	omit_zero
safe_orderr   )r6   r   rE   r;   r  rL   r@   r   r   r  r   rawState
statePartstrimmedStatusre  r   r   r   r  s                      r8   ro  zbitfinex.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# 
$ ) 
  
  
* +  	r9   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          }
|
A| j        | j        | j        | j        d	}|                     ||
          }	|	 |	||           d S d S d S )
Nr   rd   hbr?   )rA   csrl   r   r   )rn  ouonocwur   r   r   r>   )r   
subscribedunsubscribedrS  )r\   r}   r~   r|   rI   r  r&  r   r   r   rt  r8  r   safe_value_2rB  rN  rI  ri  )r6   rF   r   r_   ra   r?   r   publicMethodsprivateMethodsmethodr>   methodss               r8   handle_messagezbitfinex.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$($E >	! ! %88%F67+++++ !  &%r9   r@  )1__name__
__module____qualname__r   r5   r=   rb   rf   rZ  r   r   r~   ru   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r   r  r&  r   r-  r8  r/  rB  rI  rN  re   ri  r	   rl  rt  r}  ro  r  __classcell__)r7   s   @r8   r   r      s       "# " " " " " "H 79    0 AC p p p p2; ; ; ?CQUdhqs H H H H3 H^a Hx|  ~B  yC H H H H: BFb  p  p3  p3  p  p  p  pDM,6 M, M, M, M,^ <@d[] S S SS S Sbfglbm S S S S 9; K KC K K K K 37TX\eg U UC Us URU Ulpqvlw U U U U& 68 > > >F > > > > 9; K KC K K K K 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&2f &2 &2 &2 &2P *, 9 9 9 9 9 9U<V U< U< U< U<n  (	6 	 	 	 	6    ,) ) ) ) )V )+    ,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C,V C, C, C, C, C, C, C, C,r9   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r^  ccxt.base.typesr   r   r   r	   r
   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   ccxt.base.preciser   async_supportr   rA  r9   r8   <module>r     s&       f f f f f f f f f f  T T T T T T T T T T T T T T T T T T T T 4 4 4 4 4 4       * * * * * * 0 0 0 0 0 0 * * * * * * % % % % % %p, p, p, p, p,t!* p, p, p, p, p,r9   