
    E#i&                         S SK rS SKJrJrJr  S SKrS SKJrJ	r	J
r
JrJrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr   " S
 S\R4                  R6                  5      rg)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)AnyBalancesIntOrder	OrderBookStrTickerTrade)Client)List)ExchangeError)AuthenticationError)ChecksumError)Precisec                   ~  ^  \ rS rSrS\4U 4S jjr0 4S jr0 4S jrS rSSS0 4S	\	S
\	S\
S\
S\\   4
S jjrS0 4S	\	S
\	4S jjrS\4S jrSS0 4S	\	S\
S\
S\\   4S jjr0 4S	\	4S jjrSSS0 4S	\S\
S\
S\\   4S jjr0 4S	\	S\4S jjr0 4S	\	4S jjr0 4S\4S jjrS\4S jrS,S jrS\4S jrS,S jrS0 4S	\	S\
S\4S jjrS\4S jr S\4S jr!0 4S\"4S jjr#S\4S jr$S  r%S\4S! jr&S\4S" jr'S\4S# jr(0 4S$ jr)S\4S% jr*SSS0 4S	\S\
S\
S\\+   4S& jjr,S\4S' jr-S( r.S,S) jr/S\4S* jr0S+r1U =r2$ )-bitfinex   returnc                    > U R                  [        [        U ]  5       SSSSSSSSSSSSSSS.SSSSS.00S	S
SS.SS.S.5      $ )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    K/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/bitfinex.pyr6   bitfinex.describe   s    h > @# %"&#).!% $"#!%!% $$(" "C#@ !  $#
  $3!C
 ! !	    c                 (  #    U R                  5       I S h  vN   U R                  U5      nUS   nU R                  S   S   S   nU R                  U5      nUS-   U-   nSUUS.n	U R	                  XhU R                  X5      USS	05      I S h  vN n
U R                  U R                  SS
5      nU(       aT  US:X  aN  UR                  U   nU(       a8  US   (       d.  S
UR                  U   S'   UR                  SSS.5      I S h  vN   U
$  N N N
7f)Nidr'   r   r(   :	subscribe)eventchannelsymbolr.   FTbookconfi   )r@   flags)
load_marketsmarketr2   clientwatchr4   	safe_boolr3   subscriptionssend)r7   rA   rB   paramsrG   marketIdurlrH   messageHashrequestresultr.   subs                r9   r?   bitfinex.subscribe8   s$    !!!V$$<iit$X.S!mh. 

 zz#D4D4DW4UWbeoqvdwxx>>$,,
DAF*&&{3C3z?@D$$[1*=kk###    + 	" ys5   DDA6DDA7DDDDDc                   #    U R                  5       I S h  vN   U R                  U5      nUS   nU R                  S   S   S   nU R                  U5      nUS-   U-   n	SU-   S-   U-   n
SU-   S-   U-   nU R	                  UR
                  U5      nSUS.nSU-   nXR
                  U'   U
/U	/US	U/S
.nU R                  XzU R                  X5      X5      I S h  vN $  N N7f)Nr=   r'   r   r(   r>   unsubscribe:unsubscriber@   chanIdTmessageHashessubMessageHashestopicrW   symbols)rF   rG   r2   rH   safe_stringrK   rI   r4   )r7   rA   r]   rB   rM   rG   rN   rO   rH   subMessageHashrP   
unSubTopic	channelIdrQ   unSubChanMsgsubscriptions                   r9   un_subscribebitfinex.un_subscribeP   s    !!!V$$<iit$X.S! 31$w.4x?(5036?
$$V%9%9:F	"
 &	1-;\*)]!/ 0x
 ZZ$2B2B72SU`ooo- 	", ps"   C"CCC"C C" C"c                    #    U R                  5       I S h  vN   U R                  5       I S h  vN   U R                  S   S   S   nU R                  X!S S5      I S h  vN $  NL N6 N7f)Nr'   r   r)      )rF   authenticater2   rI   )r7   rP   rO   s      r9   subscribe_privatebitfinex.subscribe_privatei   sb     !!!!!!iit$Y/ZZ$::: 	"!:s1   A)A#A)A%/A)A'A)%A)'A)1mNrB   	timeframesincelimitc                   #    U R                  5       I Sh  vN   U R                  U5      nUS   nU R                  U R                  X"5      nSnSU-   S-   US   -   n	US-   U-   S-   US   -   n
SUU	S.nU R                  S	   S
   S   nU R                  XU R                  X5      U
5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XUSS5      $  N N<7f)a  
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
NrB   candlestrade:r>   r=   r?   )r@   rA   keyr'   r   r(   r   T)
rF   rG   r_   
timeframesr2   rI   r4   
newUpdatesgetLimitfilter_by_since_limit)r7   rB   rm   rn   ro   rM   rG   intervalrA   rs   rP   rQ   rO   ohlcvs                 r9   watch_ohlcvbitfinex.watch_ohlcvo   s     !!!V$!##DOOYJ!C'&,6mh.4vd|C 

 iit$X.jj43C3CG3TVabb??NN61E))%q$GG# 	" cs"   C-C)BC-.C+/;C-+C-c                   #    U R                  5       I Sh  vN   U R                  U5      nUS   nU R                  U R                  X"5      nSnUS-   U-   S-   US   -   nSU-   nU R                  S   S   S	   n	U R                  U	5      n
S
U-   S-   US   -   nU R                  U
R                  U5      nSUS.nSU-   nXzR                  U'   U/U/SSU/S.nU R                  XU R                  X5      X5      I Sh  vN $  N N7f)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
NrB   rq   r>   r=   rV   r'   r   r(   zunsubscribe:trade:rW   rX   ry   TrZ   )	rF   rG   r_   rt   r2   rH   rK   rI   r4   )r7   rB   rm   rM   rG   rx   rA   r`   rP   rO   rH   subIdrb   rQ   rc   rd   s                   r9   un_watch_ohlcvbitfinex.un_watch_ohlcv   s;     !!!V$!##DOOYJ 31C7&,F$~5iit$X.S!$x/#5tD$$V%9%95A	"
 &	1-;\*)]!/ 0x
 ZZ$2B2B72SU`ooo1 	"0 ps"   DDC&D=D>DDrH   c                    U R                  US/ 5      nS nU R                  US5      n[        U[        5      (       a  UnOU/nU R                  US5      nU R                  US5      nUR	                  S5      n	U R                  U	S5      n
UnUR                  SS5      nUR                  U
S-   S5      nU R                  U5      nU R                  U
5      nUS   nUS-   U
-   S-   U-   nU R                  U R                  U0 5      U R                  U'   U R                  U R                  U   U5      nUc:  U R                  U R                  S	S
5      n[        U5      nUU R                  U   U'   [        U5      n[        SU5       H1  nUUU-
  S-
     nU R                  UU5      nUR                  U5        M3     UR!                  UU5        g )Nrh   r   rA   rs   r>   rr    rB   
OHLCVLimitr/   )
safe_value
isinstancelistr_   splitreplacesafe_marketfind_timeframeohlcvssafe_integerr3   r   lenrangeparse_ohlcvappendresolve)r7   rH   messagerd   datar   firstrA   rs   keyPartsrx   rN   rG   rm   rB   rP   storedro   ohlcvsLengthiry   parseds                         r9   handle_ohlcvbitfinex.handle_ohlcv   s   \ w2.a(eT""F VF//,	:|U399S>##Ha0##Hb1##HsNB7!!(+''1	!mh.4x?"oodkk62FFV!4i@>%%dllL$GE*51F-3DKK	*6{q,'A<!+a/0E%%eV4FMM&! ( 	v{+r;   c                    #    U R                  SX5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XRUSS5      $  N:7f)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?   ru   rv   rw   )r7   rB   rn   ro   rM   r   s         r9   watch_tradesbitfinex.watch_trades   sL      ~~h????OOF2E))&TRR @s   AA;Ac                 D   #    U R                  SSX5      I Sh  vN $  N7f)a-  
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re   r7   rB   rM   s      r9   un_watch_tradesbitfinex.un_watch_trades  "      &&x6JJJJ     c                    #    U R                  5       I Sh  vN   SnUb  U R                  U5      nUSUS   -   -  nU R                  U5      I Sh  vN nU R                  (       a  UR	                  X5      nU R                  XqX#S5      $  Ns N;7f)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rF   rG   rj   ru   rv   filter_by_symbol_since_limit)r7   rB   rn   ro   rM   rP   rG   r   s           r9   watch_my_tradesbitfinex.watch_my_trades  s      !!![[(F3--K--k::??OOF2E00tTT 	"
 ;!   BB
9BB:BBc                 B   #    U R                  SX5      I Sh  vN $  N7f)ah  
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      r9   watch_tickerbitfinex.watch_ticker'  s      ^^Hf====s   c                 D   #    U R                  SSX5      I Sh  vN $  N7f)aj  
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      r9   un_watch_tickerbitfinex.un_watch_ticker0  r   r   c                    SnU R                  US5      nU R                  U5      nUS   nU R                  U5      nUS-   US   -   n	U R                  c-  U R	                  U R
                  SS5      n
[        U
5      U l        U R                  nUR                  U5        Xl        UR                  X5        UR                  X5        g )Nr      rB   r>   r=   tradesLimitr/   )	r   parse_ws_traderG   myTradesr   r3   r   r   r   )r7   rH   r   rd   namer   traderB   rG   rP   ro   tradesArrays               r9   handle_my_tradebitfinex.handle_my_trade9  s    , w*##D)xV$Sj6$</== %%dllM4HE259DMmm5!#{){0r;   c                    U R                  US5      nU R                  US5      nU R                  U5      nUS-   U-   nU R                  U R                  SS5      nUS   n	U R                  U R
                  U	5      n
U
c  [        U5      n
XR
                  U	'   [        U5      nUS:X  a^  U R                  US/ 5      n[        U5      n[        SU5       H/  nX-
  S-
  nU R                  X   U5      nU
R                  U5        M1     OOU R                  US5      nUS	:X  a  g U R                  US/ 5      nU R                  UU5      nU
R                  U5        UR                  X5        g )
NrA   rB   r>   r   r/   r   rh   r   tu)r   r_   r   r   r3   r   r   r   	safe_listr   r   r   r   )r7   rH   r   rd   rA   rN   rG   rP   r   rB   r   messageLengthr   lengthr   indexr   typer   s                      r9   handle_tradesbitfinex.handle_trades`  sY   > //,	:##L(;!!(+mh.''mTJ!f5>,F"(KKGA^^GQ3F[F1f%
Q,,V]FCf% & ##GQ/Dt| OOGQ3E((7FMM&!v+r;   c                    [        U5      nUS:*  nU(       d  U R                  US5      OS nU R                  XR5      nU(       a  SOSnU(       a  SOSnU(       a  SOSnUS   nU R                  US5      n	U	b/  U	R                  S	5      S
:  a  Sn	OU	R                  S5      S
:  a  Sn	U(       d  U R                  US5      OS n
U R                  US5      nU R	                  X5      nU R                  X5      nU R                  X5      nU R                  [        R                  " U5      5      nS nUb   [        R                  " US5      (       a  SOSnU R                  XR5      nU R                  US5      nS nUb(  U R                  US5      nU R                  U5      nUUS.nU R	                  US5      nS nUb
  US
:X  a  SOSnU R                  UUU R                  U5      UUU
U	UUUUS US.U5      $ )N   rh   r            r=      LIMITro   MARKETrG   r   0buysell	   
   )costcurrencytakermaker)infor   datetimerB   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)r7   r   rG   	numFieldsisPublicrN   
createdKeypriceKey	amountKeyr   orderIdr=   r   r   amountStringr   r   rB   feeValuer   
currencyIdcoder   r   s                           r9   r   bitfinex.parse_ws_trade  s   V J	>6>4##E1-T!!(3"Q
 1a!Aq	$<q)yy!B&8$r)5=$""5!,DeQ'%%e8	  1''9""7#5#5l#CD#--lC@@5fD!!(3##E1-))%4J**:6D  C !!%+',{7L"Y/( 
  	r;   c                    U R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nU R	                  XF5      nSn	U	S-   U-   n
XR
                  U'   UR                  X5        g )Nrh   rB   r   r>   )r   r_   r   r   parse_ws_tickertickersr   )r7   rH   r   rd   r   rN   rG   rB   r   rA   rP   s              r9   handle_tickerbitfinex.handle_ticker  s    $ !,##L(;!!(+!!(+%%f5mh.%Vv+r;   c                    U R                  S U5      nUS   nU R                  US5      nU R                  US5      nU R                  0 SU_SS _SS _SU R                  US5      _SU R                  US	5      _S
U R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SS _SS _SU_SU_SS _SU_SU R                  US5      _SS _U R                  US5      S US.EU5      $ )NrB   r   r   r   r   highr   lowr   bidr   	bidVolumerh   askr   	askVolumer   vwapopencloselastpreviousClosechange
percentager   average   )
baseVolumequoteVolumer   )r   r_   safe_ticker)r7   r   rG   rB   r  r  s         r9   r   bitfinex.parse_ws_ticker  s    !!$/!*!!&!, !
f!
!
 !
 D$$VQ/	!

 4##FA.!
 4##FA.!
 ))&!4!
 4##FA.!
 ))&!4!
 D!
 D!
 T!
 D!
 T!
 f!
  $**615!!
" t#!
$ **615)!
* + 	r;   c                 l  #    Ub$  US:w  a  US:w  a  [        U R                  S-   5      eU R                  U R                  S0 5      nU R	                  USS5      nU R	                  USS	5      nUUS
.nUb  X'S'   U R                  SXR                  Xs5      5      I Sh  vN nUR                  5       $  N7f)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   rC   )r   r=   r   r3   r_   r?   r4   ro   )	r7   rB   ro   rM   r3   r,   r-   rQ   	orderbooks	            r9   watch_order_bookbitfinex.watch_order_bookE  s      %3,#DGG.f$fgg//$,,0@"E66
 "EN..9I9I'9Z[[	   \s   BB4B2B4c                    U R                  US5      nU R                  U5      nSnUS-   U-   nU R                  USS5      nUS:H  n	XPR                  ;  Ga  U R                  US5      n
U	(       a   U R	                  0 U
5      U R                  U'   OU R                  0 U
5      U R                  U'   U R                  U   nU	(       a}  US   n[        S	[        U5      5       H^  nX   nUS
   nUS	:  a  U* OUnUS	:  a  SOSnUU   nU R                  US	5      nU R                  US5      nUR                  UUU/5        M`     OUS   n[        S	[        U5      5       Hk  nX   nU R                  US
5      nU R                  US5      nU R                  US	5      nUS	:  a  U* OUnUS	:  a  SOSnUU   nUR                  UUU/5        Mm     X[S'   UR                  X5        g U R                  U   nUS   nU R                  U   nU	(       a  U R                  US5      nUS
   nUS	:  a  U* OUnUS	:  a  SOSnUU   n[        R                  " US5      (       a  UOSnU R                  US	5      nUR                  U R                  U5      U R                  U5      U/5        OU R                  US
5      nU R                  US5      nU R                  US	5      n[        R                  " US5      (       a  [        R                   " U5      OUn[        R                  " US5      (       a  SOSnUU   nUR                  U R                  U5      U R                  U5      U R                  U5      /5        UR                  X5        g )NrB   rC   r>   r,   r*   R0r   rh   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)r7   rH   r   rd   rN   rB   rA   rP   r,   isRawro   r  deltasr   deltadelta2sizer   booksideidStringr   r   counterorderbookItemdeltas2s                            r9   handle_order_bookbitfinex.handle_order_book\  sy   6 ##L(;!!(+mh.fd;//)%%lE:E*.*A*A"e*L' +/*A*A"e*L'/I q#f+.A"IE"1XF'-zF7D&,qj6vD(H#//q9H OOE15E''h(?@ / !q#f+.A"IE!--eQ7F"..ua8G ,,UA6E'-zF7D&,qj6vD(H''g(>? / #)hNN92/IQZF OOF3M((3 )$+aKxg")A+vF(.!(!2!25#!>!>C++FA6##T%6%6u%=t?P?PQW?XZb$cd))&!4**615((35<5F5Fvs5S5Sw))&1Y_!(!2!263!?!?vV(.##T%6%6u%=t?P?PQU?VX\XiXijqXr$stNN92r;   c                    U R                  US5      nU R                  U5      nSnUS-   U-   nU R                  U R                  U5      nUc  g Sn	/ n
US   nUS   nU R                  USS5      nUS	:H  nU(       a  S
OSn[	        SU	5       H  nU R                  UU5      nU R                  UU5      nUbL  U
R                  U R                  UU   U   5      5        U
R                  U R                  UU   S   5      5        Uc  M{  U
R                  U R                  UU   U   5      5        UU   S   nU
R                  U R                  U* 5      5        M     SR                  U
5      nU R                  US5      nU R                  US
5      nUU:w  ar  UR                  U	 U R                  U	 U R                  SSS5      nU(       a=  [        U R                  S-   U R                  U5      -   5      nUR                  UU5        g g g )NrB   rC   r>   r  r  r  r,   r*   r  r   r   rh   Tr   r.    )r_   r   r   r  r   r   number_to_stringjoincrc32r   rK   handle_optionr   r=   orderbook_checksum_messagereject)r7   rH   r   rd   rN   rB   rA   rP   rC   depthstringArrayr  r  r,   r   	idToCheckr   r   r   aski1payloadlocalChecksumresponseChecksumr.   errors                            r9   handle_checksumbitfinex.handle_checksum  s    ##L(;!!(+mh.t7<F|F|fd;AA	q%A//$*C//$*C""4#8#8a9K#LM""4#8#8a#DE""4#8#8a9K#LMQ
""4#8#8%#@A ! ((;'

7D1,,Wa8},$$[1'))*:JMH%dggmd6U6UV\6]&]^e[1 	 -r;   c                    #    U R                  5       I Sh  vN   U R                  USS5      nU R                  US5      nSU-   nU R                  U5      I Sh  vN $  NG N7f)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:)rF   r_   omitrj   )r7   rM   balanceTyperP   s       r9   watch_balancebitfinex.watch_balance  se      !!!&&vxD68, ;.++K888	 	" 9s"   A"AAA"A A" A"c                    U R                  US5      nS nUS:X  a  U R                  US5      nOU R                  US5      /n0 n[        S[        U5      5       H  nXW   nU R                  US5      n	U R	                  U	5      n
U R                  U5      nU R                  US5      nU R                  U R                  U0 5      nXU
'   X-S'   U R                  U5      U R                  U'   SXl'   M     [        UR                  5       5      n[        S[        U5      5       H+  nX   nSU-   nUR                  U R                  U   U5        M-     g )Nrh   r   r   r   r   TrA  )r   r   r   r_   r   parse_ws_balancebalancesafe_balancer   keysr   )r7   rH   r   rd   
updateTyper   updatedTypesr   
rawBalancer   r   rH  rC  
oldBalanceupdatesKeysr   rP   s                    r9   handle_balancebitfinex.handle_balance  sD   ~ __Wa0
??7A.DOOGQ/0Dq#d)$AJ))*a8J**:6D++J7G**:q9K{BGJ&t!(v(,(9(9*(EDLL%(,L% % <,,./q#k*+A>D$t+KNN4<<-{; ,r;   c                     U R                  US5      nU R                  US5      nU R                  5       nUb  X4S'   X$S'   U$ )Nr   r   freetotal)r_   account)r7   rH  totalBalanceavailableBalancerU  s        r9   rG  bitfinex.parse_ws_balanceC  sN     ''3++GQ7,,.'.FO'r;   c                     U$ N )r7   rH   r   s      r9   handle_system_statusbitfinex.handle_system_statusW  s	     r;   c                    U R                  US5      nSU-   nU R                  UR                  U5      nU R                  UR                  SU-   5      nUR                  U	 U R                  US/ 5      nU R                  US/ 5      n[	        S[        U5      5       H  n	Xy   n
X   nU R                  XU
5        M     U R                  U5        g)NrY   rV   r[   r\   r   T)r_   rK   	safe_dictr   r   r   clean_unsubscriptionclean_cache)r7   rH   r   rb   unSubChannelr`   rd   r[   r\   r   rP   subHashs               r9   handle_unsubscription_status%bitfinex.handle_unsubscription_statusb  s     $$Wh7	%	1))&*>*>M~~f&:&:N^<[\  .|_bI>>,8JBOq#m,-A'*K&)G%%f{C . 	&r;   c                 n   U R                  US5      nX!R                  U'   SSSSS.nU R                  X@R                  US5      5      nSU;   a'  U R                  US5      nS	U-   nX1R                  U'   U$ U R                  US
5      nU R                  U5      n	Ub  S	U-   S-   U	-   n
X1R                  U
'   U$ )NrY   r  ry   r   r   )rC   rq   r   r   rA   rs   rV   rB   r>   )r_   rK   r   )r7   rH   r   rb   mappingsunifiedChannelrs   subKeyIdrN   rB   r}   s              r9   handle_subscription_status#bitfinex.handle_subscription_statusx  s    ( $$Wh7	*1Y'  	
 ))(4D4DWi4XYG""7E2C%+H-6  *  '':H%%h/F)&7#=F.7$$U+r;   c                   #    U R                   S   S   S   nU R                  U5      nSnUR                  U5      nU R                  UR                  U5      nUc  U R                  5       nS[        U5      -   nU R                  U R                  U5      U R                  U R                  5      [        R                  S5      n	Sn
U R                  U	UUU
S.nU R                  X5      nU R                  X$X5        UI S h  vN $  N7f)	Nr'   r   r)   authenticatedAUTHhexauth)apiKeyauthSig	authNonceauthPayloadr@   )r2   rH   reusableFuturer   rK   millisecondsstrhmacencodesecrethashlibsha384rq  extendrI   )r7   rM   rO   rH   rP   futurerm  noncer8  	signaturer@   rQ   r   s                r9   ri   bitfinex.authenticate  s     iit$Y/S!%&&{3(<(<kJ %%'Es5z)G		$++g"6DKK8PRYR`R`bghIE++$"&G kk'2GJJs>||s   C=D?D Dc                 $   SnU R                  US5      nUS:X  a.  U R                  UR                  U5      nUR                  S5        g [	        U R                  U5      5      nUR                  Xc5        X1R                  ;   a  UR                  U	 g g )Nrm  statusOKT)r_   r   futuresr   r   jsonr3  rK   )r7   rH   r   rP   r  r~  r;  s          r9   handle_authentication_message&bitfinex.handle_authentication_message  s~    %!!'84T>__V^^[AFNN4 '		'(:;EMM%-222((5 3r;   c                    #    U R                  5       I Sh  vN   SnUb  U R                  U5      nUSUS   -   -  nU R                  U5      I Sh  vN nU R                  (       a  UR	                  X5      nU R                  XqX#S5      $  Ns N;7f)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   )r7   rB   rn   ro   rM   rP   rG   r  s           r9   watch_ordersbitfinex.watch_orders  s      !!![[(F3--K--k::??OOF2E00tTT 	"
 ;r   c                    U R                  US/ 5      nU R                  US5      nU R                  c-  U R                  U R                  SS5      n[        U5      U l        U R                  n0 nUS:X  a^  [        U5      n	U	S:X  a  g [        S[        U5      5       H2  n
XJ   nU R                  U5      nUS   nSX'   UR                  U5        M4     O+U R                  U5      nUR                  U5        US   nSX'   S	nUR                  U R                  U5        [        UR                  5       5      n[        S[        U5      5       H?  n
X   nU R                  U5      nUS
-   US   -   nUR                  U R                  U5        MA     g )Nr   rh   r0   r/   osr   rB   Tr  r>   r=   )r   r_   r  r   r3   r   r   r   parse_ws_orderr   r   r   rJ  rG   )r7   rH   r   rd   r   messageTypero   r  	symbolIdssnapshotLengthr   valuer   rB   r   rJ  rG   rP   s                     r9   handle_ordersbitfinex.handle_orders  sq   R w2.&&w2;;%%dllM4HE07DK	$ YN"1c$i(,,U3)$(	!f% ) ((.FMM&!H%F $It{{D)INN$%q#d)$AWF[[(F*vd|3KNN4;;4	 %r;   c                 4    SSSSS.nU R                  X!U5      $ )Nr  canceledclosed)ACTIVECANCELEDEXECUTED	PARTIALLY)r_   )r7   r  statusess      r9   parse_ws_order_statusbitfinex.parse_ws_order_status"  s*    " 	
 &99r;   c                     U R                  US5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nU R                  US5      nSn[        R                  " US5      (       a  [        R
                  " U5      nSn[        R
                  " U R                  US5      5      n	U R                  US	5      n
U
R                  S
5      S:  a  Sn
OU
R                  S5      S:  a  Sn
U R                  US5      nUR                  S5      nU R                  US5      nU R                  U5      nU R                  US5      nU R                  USS5      nU R                  US5      nU R                  U R                  US5      5      nU R                  0 SU_SU_SU_SU_SU R                  U5      _SS _SU_SU
_SU_SU_S U_S!U_S"U_S#U_S$U	_S%S _S&U_S S S S'.EU5      $ )(Nr   rh   r   r	  r   r   r   r   r   r   r   ro   r   rG      r-     r   r      r   r   r=   clientOrderIdr   r   lastTradeTimestamprB   r   r   r   	stopPricetriggerPricer  r   	remainingfilledr  )r   r   r   )r_   r   r   r   r  r   r   r   r  safe_integer_2	omit_zero
safe_orderr   )r7   r   rG   r=   r  rN   rB   r   r   r  r   rawState
statePartstrimmedStatusr  r   r   r  r  s                      r9   r  bitfinex.parse_ws_order+  s   J eQ'((2##E1-!!(+!!&)!!%+VS))''/FD&&t'7'7q'AB	q)99W"DYYx 2%D##E2.^^C(
((Q7++M:  +''q!4	""5"-NN4#3#3E2#>?	  
E 
" 
 ] 
 	 

 Y/ 
 !$ 
 f 
 D 
 D 
 U 
  
 I 
 w 
 f 
  
  d! 
" f# 
$ ) 
* + 	r;   c                 6   U R                  US5      n[        U[        5      (       Ga  US   S:X  a  g U R                  UR                  U0 5      nU R                  US5      nU R                  US5      nU R
                  U R                  U R                  U R                  U R                  S.nU R                  U R                  U R                  U R                  U R                  U R                  U R                  S.nS n	US:X  a  U R                  X5      n	OU R                  XvU5      n	U	b
  U	" XU5        g g U R                  US5      n
U
bM  U R                  U R                  U R                   U R"                  S	.nU R                  X5      n	U	b	  U	" X5        g g g )
Nr   rh   hbrA   )rC   csrq   r   r   )r  ouonocwur   r   r   r@   )r   
subscribedunsubscribedrp  )r_   r   r   r   rK   r*  r<  r   r   r   r  rP  r   safe_value_2r\  rj  rd  r  )r7   rH   r   rb   rd   rA   r   publicMethodsprivateMethodsmethodr@   methodss               r9   handle_messagebitfinex.handle_message  s   $$Wa0	4 gt$$qzT!??6+?+?BOL&&|Y?G##GQ/D..**,,,,,,#M (((((((())))**$N FC>**=H!v5 " $$Wg6E  55"&"A"A$($E$E >>	! 8%6+ & !r;   )r   r  rZ  )3__name__
__module____qualname____firstlineno__r   r6   r?   re   rj   rw  r   r   r   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r  r*  r<  r   rD  rP  rG  r\  rd  rj  ri   r  r	   r  r  r  r  r  __static_attributes____classcell__)r8   s   @r9   r   r      s   "# "H 79 0 AC p2; ?CQUdhqs H H H3 H^a Hx|  ~B  yC H: BFb  p3  p3  pDM,6 M,^ <@d[] S SS S Sbfglbm S 9; KC K 37TX\eg UC Us URU Ulpqvlw U& 68 > >F > 9; KC K EG %1f %1N=,F =,~^@,F ,8(T @DB !S ! !S\ !.Y3 Y3v&2f &2P *, 9 9U<V U<n(	6 	6 ,) )V )+ ,6F 6 04$UYbd U UC Us Uimnsit U&F5F F5P:RhC,V C, C,r;   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   r[  r;   r9   <module>r     sH     f f  T T T 4  * 0 * %p,t!!** p,r;   