
    iU                         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 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)BalancesIntOrder	OrderBookStrTrade)Client)List)AuthenticationError)
BadRequest)	BadSymbolc            
       f    e Zd Z 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 ZdefdZdefdZdefdZ xZS )hollaexc                     |                      t          t          |                                           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watchTradesr   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    V/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/pro/hollaex.pyr'   zhollaex.describe   s    gt 4 4 = = ? ? $!&#"&#$ %#
 
 8 @	 ! 	  	 BK.8 ?'B
 'B
 ' ' '	    Nsymbollimitreturnc                    K   |                                   d{V  |                     |          }d|d         z   }|                     ||           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
        Nz
orderbook:id)load_marketsmarketwatch_publicr-   )r(   r,   r-   paramsr2   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 )Nr,   topicdata	timestamp:)	safe_stringsafe_market
safe_value	parse8601parse_order_book
orderbooks
order_bookresetresolve)r(   r8   messagemarketIdchannelr2   r,   r;   r<   timestampMssnapshotr6   r5   s                r*   handle_order_bookzhollaex.handle_order_bookK   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
        :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:r0   r<   T)r1   r2   r3   
newUpdatesgetLimitfilter_by_since_limit)r(   r,   rM   r-   r4   r2   r5   tradess           r*   watch_tradeszhollaex.watch_tradess   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:   r,   tradesLimit  r;   r   r=   )r>   r?   r@   rR   safe_integerr"   r   parse_tradesrangelenappendrF   )r(   r8   rG   rI   rH   r2   r,   storedr-   r;   parsedTradesjr5   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
        :param str symbol: unified market symbol of the market trades were made in
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trade structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure
        N	usertrader,   r=   r0   Tr1   r2   watch_privaterO   rP   filter_by_symbol_since_limit)r(   r,   rM   r-   r4   r5   r2   rR   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   rU   rV   r,   r0   Tr=   )r>   r@   rZ   myTradesrW   r"   r   rY   parse_trader[   r2   rF   listkeys)r(   r8   rG   subscriptionrI   	rawTrades
dataLengthr-   r\   	marketIdsitradeparsedr,   r2   rH   rj   r5   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
        :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=   r0   Trb   )r(   r,   rM   r-   r4   r5   r2   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   ordersLimitrV   r,   r0   Tr=   )r>   r@   rZ   ru   rW   r"   r   
isinstanceri   rY   parse_orderr[   r2   rF   rj   )r(   r8   rG   rk   rI   r;   rm   r-   r\   	rawOrdersrn   ro   rt   rq   r,   r2   rH   rj   r5   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
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        walletN)rc   )r(   r4   r5   s      r*   watch_balancezhollaex.watch_balance]  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)r>   r@   ri   rj   safe_timestampbalanceiso8601rY   rZ   splitsafe_currency_codeaccountsafe_balancerF   )r(   r8   rG   r5   r;   rj   r<   ro   keyparts
currencyIdcoder   secondfreeOrTotals                  r*   handle_balancezhollaex.handle_balancef  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(   r5   r4   urlrequestrG   s         r*   r3   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-expiresrV   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(   r5   r4   expiresr   r   auth	signature
authParams	signedUrlr   rG   s               r*   rc   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)rW   r0   jsonthrow_exactly_matched_exceptionr$   	Exceptionry   r   )r(   r8   rG   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 )NrG   pong)rp   r6   rt   r~   ra   r:   )	r   r>   handle_pongr_   rL   r|   r   rr   r@   )r(   r8   rG   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(   r8   s     r*   r   zhollaex.ping%  s    f~r+   c                 8    |                                  |_        |S N)millisecondslastPong)r(   r8   rG   s      r*   r   zhollaex.handle_pong)  s    ++--r+   c                 F    d | j         d<   |                     ||           d S Nr   )r"   on_errorr(   r8   r   s      r*   r   zhollaex.on_error-  (    %)\"fe$$$$$r+   c                 F    d | j         d<   |                     ||           d S r   )r"   on_closer   s      r*   r   zhollaex.on_close1  r   r+   r   ) __name__
__module____qualname__r'   r   r   r   r7   r   rL   r   r
   rS   r_   r	   re   rr   r   rv   r|   r   r   r   r3   rc   r   r   r   r   r   r   __classcell__)r)   s   @r*   r   r      s       ( ( ( ( (T @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*1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*X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    f$V f$ f$ f$ f$P  &    %v % % % %%v % % % % % % % %r+   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   ccxt.base.typesr   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  G G G G G G G G G G G G G G G G 4 4 4 4 4 4       0 0 0 0 0 0 ' ' ' ' ' ' & & & & & &b% b% b% b% b%d ( b% b% b% b% b%r+   