
    eiW                         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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)AnyBalancesBoolIntOrder	OrderBookStrTrade)Client)List)AuthenticationError)
BadRequest)	BadSymbolc            
       ~    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	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                     |                      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    N/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/pro/hollaex.pyr+   zhollaex.describe   s    gt 4 4 = = ? ? $!&#"&#$ %#).  8 @	 ! 	  	 BK.8 A(B
 (B
 ( ( (	    Nsymbollimitc                    K   |                                   d{V  |                     |          }d|d         z   }|                     ||           d{V }|                                S )a3  
        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_publicr1   )r,   r0   r1   paramsr5   messageHash	orderbooks          r.   watch_order_bookzhollaex.watch_order_book>   s       !!!!!!!!!V$$'&,6++K@@@@@@@@	   r/   clientc                    |                      |d          }|                      |d          }|                     |          }|d         }|                     |d          }|                      |d          }|                     |          }	|                     |||	          }
d }|| j        vr |                     |
          }|| j        |<   n"| j        |         }|                    |
           |dz   |z   }|                    ||           d S )Nr0   topicdata	timestamp:)	safe_stringsafe_market
safe_value	parse8601parse_order_book
orderbooks
order_bookresetresolve)r,   r;   messagemarketIdchannelr5   r0   r>   r?   timestampMssnapshotr9   r8   s                r.   handle_order_bookzhollaex.handle_order_bookO   s   , ##GX66""7G44!!(++!w//$$T;77	nnY//((v{CC	$/))11I&/DOF##/IOOH%%%mh.y+.....r/   sincec                 .  K   |                                   d{V  |                     |          }|d         }d|d         z   }|                     ||           d{V }| j        r|                    ||          }|                     |||dd          S )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>`
        Nr0   ztrade:r3   r?   T)r4   r5   r6   
newUpdatesgetLimitfilter_by_since_limit)r,   r0   rP   r1   r7   r5   r8   tradess           r.   watch_tradeszhollaex.watch_tradesw   s       !!!!!!!!!V$$!#fTl2((f========? 	3OOFE22E))&%TRRRr/   c                 t   |                      |d          }|                      |d          }|                     |          }|d         }|                     | j        |          }|5|                     | j        dd          }t          |          }|| j        |<   |                     |dg           }	|                     |	|          }
t          dt          |
                    D ]}|
                    |
|                    |dz   |z   }|                    ||           |                    ||           d S )Nr=   r0   tradesLimit  r>   r   r@   )rA   rB   rC   rU   safe_integerr&   r   parse_tradesrangelenappendrI   )r,   r;   rJ   rL   rK   r5   r0   storedr1   r>   parsedTradesjr8   s                r.   handle_tradeszhollaex.handle_trades   s7     ""7G44##GX66!!(++!f55>%%dlM4HHE&&F"(DKw33((v66q#l++,, 	+ 	+AMM,q/****mh.v{+++vw'''''r/   c                 @  K   |                                   d{V  d}d}|+|                     |          }|d         }|d|d         z   z  }|                     ||           d{V }| j        r|                    ||          }|                     ||||d          S )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	usertrader0   r@   r3   Tr4   r5   watch_privaterR   rS   filter_by_symbol_since_limit)r,   r0   rP   r1   r7   r8   r5   rU   s           r.   watch_my_tradeszhollaex.watch_my_trades   s       !!!!!!!!!![[((FH%F3--K))+v>>>>>>>>? 	3OOFE22E00tTTTr/   c                    |                      |d          }|                     |d          }t          |          }|dk    rd S | j        0|                     | j        dd          }t          |          | _        | j        }i }	t          dt          |                    D ]^}
||
         }|                     |          }|	                    |           |d         }| 
                    |          }|d         }d|	|<   _|                    | j        |           t          |	                                          }t          dt          |                    D ]-}
||
         }|d	z   |z   }|                    | j        |           .d S )
Nr=   r>   r   rX   rY   r0   r3   Tr@   )rA   rC   r]   myTradesrZ   r&   r   r\   parse_trader^   r5   rI   listkeys)r,   r;   rJ   subscriptionrL   	rawTrades
dataLengthr1   r_   	marketIdsitradeparsedr0   r5   rK   rm   r8   s                     r.   handle_my_tradeszhollaex.handle_my_trades   s   . ""7G44OOGV44	 ^^
??F= %%dlM4HHE&u--DM	q#i..)) 	' 	'AaLE%%e,,FMM&!!!8_F[[((Fd|H"&Iht}g...INN$$%%q#d))$$ 	7 	7AAwH!C-(2KNN4=+6666	7 	7r/   c                 @  K   |                                   d{V  d}d}|+|                     |          }|d         }|d|d         z   z  }|                     ||           d{V }| j        r|                    ||          }|                     ||||d          S )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orderr0   r@   r3   Tre   )r,   r0   rP   r1   r7   r8   r5   orderss           r.   watch_orderszhollaex.watch_orders   s       !!!!!!!!![[((FH%F3--K))+v>>>>>>>>? 	3OOFE22E00tTTTr/   c                 N   |                      |d          }|                     |di           }t          |          }|dk    rd S | j        0|                     | j        dd          }t          |          | _        | j        }d }	t          |t                    s|g}	n|}	i }
t          dt          |	                    D ]^}|	|         }| 
                    |          }|                    |           |d         }|                     |          }|d         }d|
|<   _|                    | j        |           t          |
                                          }t          dt          |                    D ]-}||         }|d	z   |z   }|                    | j        |           .d S )
Nr=   r>   r   ordersLimitrY   r0   r3   Tr@   )rA   rC   r]   rx   rZ   r&   r   
isinstancerl   r\   parse_orderr^   r5   rI   rm   )r,   r;   rJ   rn   rL   r>   rp   r1   r_   	rawOrdersrq   rr   rw   rt   r0   r5   rK   rm   r8   s                      r.   handle_orderzhollaex.handle_order  s   t ""7G44w33YY
??F;%%dlM4HHE077DK	$%% 	III	q#i..)) 	' 	'AaLE%%e,,FMM&!!!8_F[[((Fd|H"&Iht{G,,,INN$$%%q#d))$$ 	5 	5AAwH!C-(2KNN4;4444	5 	5r/   c                 B   K   d}|                      ||           d{V S )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)rf   )r,   r7   r8   s      r.   watch_balancezhollaex.watch_balancej  s5       ''V<<<<<<<<<r/   c                 L   |                      |d          }|                     |d          }t          |                                          }|                     |d          }|| j        d<   || j        d<   |                     |          | j        d<   t          dt          |                    D ]}||         }|	                    d          }	|                      |	d          }
| 
                    |
          }|| j        v r| j        |         n|                                 }|                      |	d	          }|d
k    rdnd}|                      ||          ||<   || j        |<   |                     | j                  | _        |                    | j        |           d S )Nr=   r>   timeinfor?   datetimer   _   	availablefreetotal)rA   rC   rl   rm   safe_timestampbalanceiso8601r\   r]   splitsafe_currency_codeaccountsafe_balancerI   )r,   r;   rJ   r8   r>   rm   r?   rr   keyparts
currencyIdcoder   secondfreeOrTotals                  r.   handle_balancezhollaex.handle_balancev  s   " &&w88w//DIIKK  ''88	#V$-[!#'<<	#:#:Z q#d))$$ 		) 		)Aq'CIIcNNE))%33J**:66D-1T\-A-Adl4((G%%eQ//F%+{%:%:&&K#'#3#3D##>#>GK !(DL((66t|[11111r/   c                    K   | j         d         d         }d|gd}|                     ||          }|                     ||||           d {V S )Nr    r   	subscribeopargs)r%   extendwatch)r,   r8   r7   urlrequestrJ   s         r.   r6   zhollaex.watch_public  sj      it$ M
 
 ++gv..ZZ[';GGGGGGGGGr/   c                   K   |                                   |                     | j        d          }|et          | j        t          d          z            }|                     |                                 |          }t          |          }|| j        d<   | j        d         d         }d|z   }| 	                    | 
                    |          | 
                    | j                  t          j                  }| j        ||d}|dz   |                     |          z   }	d|gd	}
|                     |
|          }|                     |	|||           d {V S )
N
ws-expiresrY   r    r   zCONNECT/stream)zapi-keyzapi-signaturezapi-expires?r   r   )check_required_credentialsrA   r&   inttimeoutstrsumsecondsr%   hmacencodesecrethashlibsha256apiKey	urlencoder   r   )r,   r8   r7   expiresr   r   auth	signature
authParams	signedUrlr   rJ   s               r.   rf   zhollaex.watch_private  sT     '')))""4<>>?4<#d))355Ghht||~~w77G'llG *1DL&it$$w.IIdkk$//T[1I1I7>ZZ	{&"
 


 #Iz : ::	 M
 
 ++gv..ZZ	;MMMMMMMMMr/   c                 .   |                      |d          }	 |H| j        dz   |                     |          z   }|                     | j        d         d         ||           n2# t
          $ r%}t          |t                    rY d }~dS Y d }~nd }~ww xY w|S )Nerror r   r#   F)rZ   r3   jsonthrow_exactly_matched_exceptionr(   	Exceptionr|   r   )r,   r;   rJ   r   feedbackes         r.   handle_error_messagezhollaex.handle_error_message  s    
 !!'733	 7S=499W+=+==44T_T5J75SUZ\deee 	 	 	!011 uuuuu    	 s   A
A# #
B-BBc                 X   |                      ||          sd S |                     |d          }|dk    r|                     ||           d S | j        | j        | j        | j        | j        d}|                     |d          }|                     ||          }| |||           d S d S )NrJ   pong)rs   r9   rw   r   rd   r=   )	r   rA   handle_pongrb   rO   r   r   ru   rC   )r,   r;   rJ   contentmethodsr=   methods          r.   handle_messagezhollaex.handle_message  s    l ((99 	F""7I66fVW---F'/&).
 
 11%00F67##### r/   c                 
    ddiS )Nr   r"    )r,   r;   s     r.   r"   zhollaex.ping5  s    f~r/   c                 8    |                                  |_        |S N)millisecondslastPong)r,   r;   rJ   s      r.   r   zhollaex.handle_pong9  s    ++--r/   c                 n    d | j         d<   t          t          |                               ||           d S Nr   )r&   r*   r   on_errorr,   r;   r   r-   s      r.   r   zhollaex.on_error=  5    %)\"gt%%fe44444r/   c                 n    d | j         d<   t          t          |                               ||           d S r   )r&   r*   r   on_closer   s      r.   r   zhollaex.on_closeA  r   r/   r   )"__name__
__module____qualname__r   r+   r   r   r
   r:   r   rO   r   r   rV   rb   r   rh   ru   r	   ry   r   r   r   r   r6   rf   r   r   r   r"   r   r   r   __classcell__)r-   s   @r.   r   r      s0       )# ) ) ) ) ) )V @DB ! !S ! !S\ ! ! ! !"&/ &/ &/ &/ &/P <@d[] S S SS S Sbfglbm S S S S*(F ( ( ( (B 37TX\eg U UC Us URU Ulpqvlw U U U U017 17v 17 17 17 17f 04$UYbd U U UC Us Uimnsit U U U U0X5 X56 X5 X5 X5 X5t *, 
= 
= 
= 
= 
= 
=#2V #2 #2 #2 #2J 68 H H H H 79 N N N N46 t    f$V f$ f$ f$ f$P6    &    5v 5 5 5 5 5 55v 5 5 5 5 5 5 5 5 5 5r/   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   ccxt.base.typesr   r   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      s       O O O O O O O O  R R R R R R R R R R R R R R R R R R R R 4 4 4 4 4 4       0 0 0 0 0 0 ' ' ' ' ' ' & & & & & &r5 r5 r5 r5 r5d ( r5 r5 r5 r5 r5r/   