
    ":hW                         d dl Zd dl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  G d	 d
ej,                  j.                        Zy)    N)
ArrayCacheArrayCacheBySymbolById)AnyBalancesIntOrder	OrderBookStrTrade)Client)List)AuthenticationError)
BadRequest)	BadSymbolc            
       h    e Zd Zdef fdZdi fde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de	fdZdddi fded	ededee   fdZdde	fdZdddi fded	ededee   fdZdde	fdZi fdefdZde	fdZi fdZi fdZde	fdZde	fdZde	fdZde	fdZde	f fdZde	f fdZ xZ S )hollaexreturnc                     | j                  t        t        |          ddddddddddd
ddiddidi i dd	| j                  idd
t
        t        diid      S )NTF)
wswatchBalancewatchMyTrades
watchOHLCVwatchOrderBookwatchOrderswatchTickerwatchTickerswatchTradeswatchTradesForSymbolsr   zwss://api.hollaex.com/streamz$wss://api.sandbox.hollaex.com/stream)apitest)r   r   pingexact)z&Bearer or HMAC authentication requiredzError: wrong input)hasurlsoptions	streaming
exceptions)deep_extendsuperr   describer!   r   r   )self	__class__s    J/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/pro/hollaex.pyr*   zhollaex.describe   s    gt = ? $!&#"&#$ %#). 8 @	! 	 		 BK.8A(B
 ( (	    Nsymbollimitc                    K   | j                          d{    | j                  |      }d|d   z   }| j                  ||       d{   }|j                         S 7 G7 w)a5  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://apidocs.hollaex.com/#sending-receiving-messages

        :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
        Nz
orderbook:id)load_marketsmarketwatch_publicr0   )r+   r/   r0   paramsr4   messageHash	orderbooks          r-   watch_order_bookzhollaex.watch_order_book>   sd      !!!V$'&,6++K@@	  	 	" As!   A"A2A"	A 
A" A"clientc                    | j                  |d      }| j                  |d      }| j                  |      }|d   }| j                  |d      }| j                  |d      }| j                  |      }	| j	                  |||	      }
d }|| j
                  vr!| j                  |
      }|| j
                  |<   n | j
                  |   }|j                  |
       |dz   |z   }|j                  ||       y )Nr/   topicdata	timestamp:)	safe_stringsafe_market
safe_value	parse8601parse_order_book
orderbooks
order_bookresetresolve)r+   r:   messagemarketIdchannelr4   r/   r=   r>   timestampMssnapshotr8   r7   s                r-   handle_order_bookzhollaex.handle_order_bookO   s    , ##GX6""7G4!!(+!w/$$T;7	nnY/((v{C	$//)1I&/DOOF#/IOOH%mh.y+.r.   sincec                   K   | j                          d{    | j                  |      }|d   }d|d   z   }| j                  ||       d{   }| j                  r|j	                  ||      }| j                  |||dd      S 7 o7 9w)a  
        get the list of most recent trades for a particular symbol

        https://apidocs.hollaex.com/#sending-receiving-messages

        :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>`
        Nr/   ztrade:r2   r>   T)r3   r4   r5   
newUpdatesgetLimitfilter_by_since_limit)r+   r/   rO   r0   r6   r4   r7   tradess           r-   watch_tradeszhollaex.watch_tradesw   s      !!!V$!#fTl2((f==??OOFE2E))&%TRR 	" >s!   B
B7B
B8B
B
c                     | j                  |d      }| j                  |d      }| j                  |      }|d   }| j                  | j                  |      }|7| j	                  | j
                  dd      }t        |      }|| j                  |<   | j                  |dg       }	| j                  |	|      }
t        dt        |
            D ]  }|j                  |
|           |dz   |z   }|j                  ||       |j                  ||       y )Nr<   r/   tradesLimit  r=   r   r?   )r@   rA   rB   rT   safe_integerr%   r   parse_tradesrangelenappendrH   )r+   r:   rI   rK   rJ   r4   r/   storedr0   r=   parsedTradesjr7   s                r-   handle_tradeszhollaex.handle_trades   s     ""7G4##GX6!!(+!f5>%%dllM4HE&F"(DKKw3((v6q#l+, 	+AMM,q/*	+mh.v{+vw'r.   c                 *  K   | j                          d{    d}d}|!| j                  |      }|d   }|d|d   z   z  }| j                  ||       d{   }| j                  r|j	                  ||      }| j                  ||||d      S 7 x7 9w)a.  
        watches information on multiple trades made by the user

        https://apidocs.hollaex.com/#sending-receiving-messages

        :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	usertrader/   r?   r2   Tr3   r4   watch_privaterQ   rR   filter_by_symbol_since_limit)r+   r/   rO   r0   r6   r7   r4   rT   s           r-   watch_my_tradeszhollaex.watch_my_trades   s      !!!![[(FH%F3--K))+v>>??OOFE2E00tTT 	" ?"   BBA BB8BBc                    | j                  |d      }| j                  |d      }t        |      }|dk(  ry | j                  -| j	                  | j
                  dd      }t        |      | _        | j                  }i }	t        dt        |            D ]I  }
||
   }| j                  |      }|j                  |       |d   }| j                  |      }|d   }d|	|<   K |j                  | j                  |       t        |	j                               }t        dt        |            D ]+  }
||
   }|d	z   |z   }|j                  | j                  |       - y )
Nr<   r=   r   rW   rX   r/   r2   Tr?   )r@   rB   r\   myTradesrY   r%   r   r[   parse_trader]   r4   rH   listkeys)r+   r:   rI   subscriptionrK   	rawTrades
dataLengthr0   r^   	marketIdsitradeparsedr/   r4   rJ   rm   r7   s                     r-   handle_my_tradeszhollaex.handle_my_trades   sH   . ""7G4OOGV4	 ^
?== %%dllM4HE&u-DM	q#i.) 	'AaLE%%e,FMM&!8_F[[(Fd|H"&Ih	' 	t}}g.INN$%q#d)$ 	7AAwH!C-(2KNN4==+6	7r.   c                 *  K   | j                          d{    d}d}|!| j                  |      }|d   }|d|d   z   z  }| j                  ||       d{   }| j                  r|j	                  ||      }| j                  ||||d      S 7 x7 9w)a.  
        watches information on multiple orders made by the user

        https://apidocs.hollaex.com/#sending-receiving-messages

        :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orderr/   r?   r2   Trd   )r+   r/   rO   r0   r6   r7   r4   orderss           r-   watch_orderszhollaex.watch_orders   s      !!![[(FH%F3--K))+v>>??OOFE2E00tTT 	" ?rh   c                    | j                  |d      }| j                  |di       }t        |      }|dk(  ry | j                  -| j	                  | j
                  dd      }t        |      | _        | j                  }d }	t        |t              s|g}	n|}	i }
t        dt        |	            D ]I  }|	|   }| j                  |      }|j                  |       |d   }| j                  |      }|d   }d|
|<   K |j                  | j                  |       t        |
j                               }t        dt        |            D ]+  }||   }|d	z   |z   }|j                  | j                  |       - y )
Nr<   r=   r   ordersLimitrX   r/   r2   Tr?   )r@   rB   r\   rx   rY   r%   r   
isinstancerl   r[   parse_orderr]   r4   rH   rm   )r+   r:   rI   rn   rK   r=   rp   r0   r^   	rawOrdersrq   rr   rw   rt   r/   r4   rJ   rm   r7   s                      r-   handle_orderzhollaex.handle_order  sd   t ""7G4w3Y
?;;%%dllM4HE07DK	$%II	q#i.) 	'AaLE%%e,FMM&!8_F[[(Fd|H"&Ih	' 	t{{G,INN$%q#d)$ 	5AAwH!C-(2KNN4;;4	5r.   c                 F   K   d}| j                  ||       d{   S 7 w)a_  
        watch balance and get the amount of funds available for trading or funds locked in orders

        https://apidocs.hollaex.com/#sending-receiving-messages

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        walletN)re   )r+   r6   r7   s      r-   watch_balancezhollaex.watch_balancej  s&      ''V<<<<s   !!c                    | j                  |d      }| j                  |d      }t        |j                               }| j	                  |d      }|| j
                  d<   || j
                  d<   | j                  |      | j
                  d<   t        dt        |            D ]  }||   }|j                  d      }	| j                  |	d      }
| j                  |
      }|| j
                  v r| j
                  |   n| j                         }| j                  |	d	      }|d
k(  rdnd}| j                  ||      ||<   || j
                  |<    | j                  | j
                        | _        |j                  | j
                  |       y )Nr<   r=   timeinfor>   datetimer   _   	availablefreetotal)r@   rB   rl   rm   safe_timestampbalanceiso8601r[   r\   splitsafe_currency_codeaccountsafe_balancerH   )r+   r:   rI   r7   r=   rm   r>   rr   keyparts
currencyIdcoder   secondfreeOrTotals                  r-   handle_balancezhollaex.handle_balancev  s]   " &&w8w/DIIK ''8	#V$-[!#'<<	#:Z q#d)$ 		)Aq'CIIcNE))%3J**:6D-1T\\-Adll4(G%%eQ/F%+{%:&K#'#3#3D##>GK !(DLL		) ((6t||[1r.   c                    K   | j                   d   d   }d|gd}| j                  ||      }| j                  ||||       d {   S 7 w)Nr   r   	subscribeopargs)r$   extendwatch)r+   r7   r6   urlrequestrI   s         r-   r5   zhollaex.watch_public  sU     iit$ M
 ++gv.ZZ[';GGGGs   AAA	Ac                   K   | j                          | j                  | j                  d      }|[t        | j                  t        d      z        }| j                  | j                         |      }t        |      }|| j                  d<   | j                  d   d   }d|z   }| j                  | j                  |      | j                  | j                        t        j                        }| j                  ||d}|dz   | j                  |      z   }	d|gd	}
| j!                  |
|      }| j#                  |	|||       d {   S 7 w)
N
ws-expiresrX   r   r   zCONNECT/stream)zapi-keyzapi-signaturezapi-expires?r   r   )check_required_credentialsr@   r%   inttimeoutstrsumsecondsr$   hmacencodesecrethashlibsha256apiKey	urlencoder   r   )r+   r7   r6   expiresr   r   auth	signature
authParams	signedUrlr   rI   s               r-   re   zhollaex.watch_private  s%    '')""4<<>?4<<#d)35Ghht||~w7G'lG *1DLL&iit$$w.IIdkk$/T[[1I7>>Z	{{&"


 #Iz ::	 M
 ++gv.ZZ	;MMMMs   E E	EE	c                    | j                  |d      }	 |D| j                  dz   | j                  |      z   }| j                  | j                  d   d   ||       |S # t
        $ r }t        |t              rY d }~yY d }~|S d }~ww xY w)Nerror r   r"   F)rY   r2   jsonthrow_exactly_matched_exceptionr'   	Exceptionr|   r   )r+   r:   rI   r   feedbackes         r-   handle_error_messagezhollaex.handle_error_message  s    
 !!'73	 77S=499W+==44T__T5J75SUZ\de   	!01 2	s   AA 	B%B  Bc                 R   | j                  ||      sy | j                  |d      }|dk(  r| j                  ||       y | j                  | j                  | j
                  | j                  | j                  d}| j                  |d      }| j                  ||      }|
 |||       y y )NrI   pong)rs   r8   rw   r   rc   r<   )	r   r@   handle_pongra   rN   r   r   ru   rB   )r+   r:   rI   contentmethodsr<   methods          r-   handle_messagezhollaex.handle_message  s    l ((9""7I6fVW-''//&&))..
 1%067# r.   c                 
    ddiS )Nr   r!    )r+   r:   s     r-   r!   zhollaex.ping5  s    f~r.   c                 0    | j                         |_        |S N)millisecondslastPong)r+   r:   rI   s      r-   r   zhollaex.handle_pong9  s    ++-r.   c                 L    d | j                   d<   t        t        |   ||       y Nr   )r%   r)   r   on_errorr+   r:   r   r,   s      r-   r   zhollaex.on_error=  "    %)\"gt%fe4r.   c                 L    d | j                   d<   t        t        |   ||       y r   )r%   r)   r   on_closer   s      r-   r   zhollaex.on_closeA  r   r.   r   )!__name__
__module____qualname__r   r*   r   r   r	   r9   r   rN   r   r   rU   ra   r
   rg   ru   r   ry   r   r   r   r   r5   re   r   r   r!   r   r   r   __classcell__)r,   s   @r-   r   r      s   )# )V @DB !S ! !S\ !"&/ &/P <@d[] S SS S Sbfglbm S*(F (B 37TX\eg UC Us URU Ulpqvlw U017v 17f 04$UYbd U UC Us Uimnsit U0X56 X5t *, 
= 
=#2V #2J 68 H 79 N46 f$V f$P6 & 5v 55v 5 5r.   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   ccxt.base.typesr   r   r   r   r	   r
   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   async_supportr   r   r.   r-   <module>r      sB     O  L L L 4  0 ' &r5d  (( r5r.   