
    eie[                         d dl Zd dlmZm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  G d dej        j                  ZdS )	    N)
ArrayCacheArrayCacheByTimestamp)AnyBoolInt	OrderBookTickerTrade)Client)List)ExchangeErrorc                   n    e Zd Zdef fdZd Z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de	fdZdddi fdeded	ed
edee         f
dZde	fdZdi fded
edefdZde	fdZd Zd Z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dZde	fdZd Zde	fdZ de	de!fdZ"de	fdZ# xZ$S ) bittradereturnc                     |                      t          t          |                                           dddddddddddddddiiid	d	dd
didd          S )NTF)wswatchOrderBookwatchTickerswatchTickerwatchTradeswatchTradesForSymbolswatchBalance
watchOHLCVapir   zwss://{hostname}/wszwss://{hostname}/ws/v2)publicprivate  gunzip)tradesLimit
OHLCVLimitr   r   )hasurlsoptions)deep_extendsuperr   describe)self	__class__s    O/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/pro/bittrade.pyr&   zbittrade.describe   s    h 5 5 > > @ @"& %##). %"	 	 &;'?   	  $"d	 +C
 C
   	    c                     |                                   |                     |                     | j        dd          d          }|| j        d<   |                                  t          |          S )N	requestIdr      )lock_idsumsafe_integerr#   	unlock_idstr)r'   r,   s     r)   
request_idzbittrade.request_id0   s^    HHT..t|[!LLaPP	$-[!9~~r*   symbolc                   K   |                                   d{V  |                     |          }|d         }d|d         z   dz   }|                     | j        dd          }d| j        i}|                     | j        d         d         |         d	         |          }|                                 }||d
}	||||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>`
        Nr4   market.idz.detailr   hostnamer   r   subr7   r7   messageHashr4   params)
load_marketsmarketsafe_stringr#   r8   implode_paramsr"   r3   watchextend)r'   r4   r=   r?   r<   r   r8   urlr,   requestsubscriptions              r)   watch_tickerzbittrade.watch_ticker7   s#      !!!!!!!!!V$$!&,.:t|UE::$dm4!!$)E"24"8"=h"GRROO%%	
 

 &	
 
 ZZ[$++gv2N2NP[]ijjjjjjjjjr*   clientc                    |                      |di           }|                     |d          }|                    d          }|                     |d          }|                     |          }|                     ||          }|                      |d          }	|	|d<   |                     |	          |d<   |d         }
|| j        |
<   |                    ||           |S )	Ntickch.r-   ts	timestampdatetimer4   )
safe_valuer@   splitsafe_marketparse_tickeriso8601tickersresolve)r'   rH   messagerJ   rK   partsmarketIdr?   tickerrN   r4   s              r)   handle_tickerzbittrade.handle_tickerS   s    $ w33gt,,##E1--!!(++""400OOGT22	'{!\\)44z!%Vvr"""r*   Nsincelimitc                 R  K   |                                   d{V  |                     |          }|d         }d|d         z   dz   }|                     | j        dd          }d| j        i}|                     | j        d         d         |         d	         |          }	|                                 }
||
d
}|
|||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>`
        Nr4   r6   r7   z.trade.detailr   r8   r   r   r9   r;   rN   T)r>   r?   r@   r#   r8   rA   r"   r3   rB   rC   
newUpdatesgetLimitfilter_by_since_limit)r'   r4   r\   r]   r=   r?   r<   r   r8   rD   r,   rE   rF   tradess                 r)   watch_tradeszbittrade.watch_tradess   s[      !!!!!!!!!V$$!&,.@t|UE::$dm4!!$)E"24"8"=h"GRROO%%	
 

 &	
 
 zz#{DKK4P4PR]_kllllllll? 	3OOFE22E))&%TRRRr*   c                    |                      |di           }|                      |di           }|                     |d          }|                    d          }|                     |d          }|                     |          }|d         }	|                      | j        |	          }
|
5|                     | j        dd          }t          |          }
|
| j        |	<   t          d	t          |                    D ]3}| 
                    ||         |          }|
                    |           4|                    |
|           |S )
NrJ   datarK   rL   r-   r4   r   r   r   )rP   r@   rQ   rR   rb   r0   r#   r   rangelenparse_tradeappendrV   )r'   rH   rW   rJ   re   rK   rX   rY   r?   r4   tradesCacher]   itrades                 r)   handle_tradeszbittrade.handle_trades   s9   * w33tVR00gt,,##E1--!!(++!oodk6::%%dlM4HHE$U++K"-DKq#d))$$ 	& 	&A$$T!Wf55Eu%%%%{B'''r*   1m	timeframec                   K   |                                   d{V  |                     |          }|d         }|                     | j        ||          }d|d         z   dz   |z   }|                     | j        dd          }	d| j        i}
|                     | j        d         d         |	         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
        Nr4   r6   r7   z.kline.r   r8   r   r   r9   )r7   r<   r4   ro   r=   r   T)r>   r?   r@   
timeframesr#   r8   rA   r"   r3   rB   rC   r_   r`   ra   )r'   r4   ro   r\   r]   r=   r?   intervalr<   r   r8   rD   r,   rE   rF   ohlcvs                   r)   watch_ohlcvzbittrade.watch_ohlcv   s|      !!!!!!!!!V$$!##DOY	JJ&,.:XEt|UE::$dm4!!$)E"24"8"=h"GRROO%%	
 

 &"
 
 jjk4;;w3O3OQ\^jkkkkkkkk? 	2NN6511E))%q$GGGr*   c                    |                      |d          }|                    d          }|                      |d          }|                     |          }|d         }|                      |d          }|                     |          }	|                     | j        |i           | j        |<   |                     | j        |         |	          }
|
;|                     | j        dd          }t          |          }
|
| j        |         |	<   |                     |d          }| 	                    ||          }|

                    |           |                    |
|           d S )	NrK   rL   r-   r4      r    r   rJ   )r@   rQ   rR   find_timeframerP   ohlcvsr0   r#   r   parse_ohlcvri   rV   )r'   rH   rW   rK   rX   rY   r?   r4   rr   ro   storedr]   rJ   parseds                 r)   handle_ohlcvzbittrade.handle_ohlcv   sJ   " gt,,##E1--!!(++!##E1--''11	"oodk62FFFV!4i@@>%%dlL$GGE*511F-3DK	*w//!!$//fvr"""""r*   c                   K   ||dk    rt          | j        dz             |                                  d{V  |                     |          }|d         }|dn|}d|d         z   dz   t	          |          z   }|                     | j        dd          }d	| j        i}|                     | j	        d         d
         |         d         |          }| 
                                }	||	d}
|	||||| j        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   z( watchOrderBook accepts limit = 150 onlyr4   r6   r7   z.mbp.r   r8   r   r   r9   r7   r<   r4   r]   r=   method)r   r7   r>   r?   r2   r@   r#   r8   rA   r"   r3   handle_order_book_subscriptionrB   rC   r]   )r'   r4   r]   r=   r?   r<   r   r8   rD   r,   rE   rF   	orderbooks                r)   watch_order_bookzbittrade.watch_order_book  sw      ESLL*T TUUU!!!!!!!!!V$$!E&,.83u::Et|UE::$dm4!!$)E"24"8"=h"GRROO%%	
 

 &9
 
 **S+t{{7F7S7SU`bnoooooooo	   r*   c                    |                      |d          }|                      |d          }| j        |         }|                     |d          }|                     ||          }|                     |d          |d<   |                    |           |j        }	t          dt          |	                    D ]}
| 	                    ||	|
         |            || j        |<   |
                    ||           d S )Nr4   r<   re   seqNumnoncer   )r@   
orderbooksrP   parse_order_bookr0   resetcacherf   rg   handle_order_book_messagerV   )r'   rH   rW   rF   r4   r<   r   re   snapshotmessagesrk   s              r)   handle_order_book_snapshotz#bittrade.handle_order_book_snapshot$  s    * !!,99&&|]CCOF+	w//((v66 --dH==!!!?q#h--(( 	K 	KA**68A;	JJJJ"+y+.....r*   c                   K   |                      |d          }	 |                      |d          }|                     |d          }|                     |d          }|                      | j        dd          }d| j        i}	|                     | j        d         d         |         d         |	          }
|                                 }||d	}|||||| j        d
}| 	                    |
||||           d {V }|
                                S # t          $ r(}|j        |= |                    ||           Y d }~nd }~ww xY wd S )Nr<   r4   r]   r=   r   r8   r   r   )reqr7   r   )r@   r0   rP   r#   r8   rA   r"   r3   r   rB   r]   	Exceptionsubscriptionsreject)r'   rH   rW   rF   r<   r4   r]   r=   r   r8   rD   r,   rE   snapshotSubscriptionr   es                   r)   watch_order_book_snapshotz"bittrade.watch_order_book_snapshotG  s     &&|]CC	*%%lH==F%%lG<<E__\8<<F""4<>>C($-8H%%di&6t&<S&A(&KXVVC))I" G  *  9* *  #jji)MabbbbbbbbI??$$$ 	* 	* 	*$[1MM![))))))))	* ts   C3D 
E D;;E c                     |                      |d          }|                      |d          }|                    ||           d S )Nr   r-   )
safe_floatstore)r'   booksidedeltapriceamounts        r)   handle_deltazbittrade.handle_deltaf  sB    q))**uf%%%%%r*   c                 ~    t          dt          |                    D ]}|                     |||                    d S )Nr   )rf   rg   r   )r'   r   deltasrk   s       r)   handle_deltaszbittrade.handle_deltask  sH    q#f++&& 	3 	3Ahq	2222	3 	3r*   c                    |                      |di           }|                     |d          }|                     |d          }||d         k    r||d         k    r|                      |dg           }|                      |dg           }|                     |d         |           |                     |d         |           ||d<   |                     |d          }	|	|d<   |                     |	          |d	<   |S )
NrJ   r   
prevSeqNumr   asksbidsrM   rN   rO   )rP   r0   r   rT   )
r'   rH   rW   r   rJ   r   r   r   r   rN   s
             r)   r   z"bittrade.handle_order_book_messageo  s   * w33""422&&t\::
)G,,,6Ig<N3N3N??444D??444Dy0$777y0$777!'Ig))'488I%.Ik"$(LL$;$;Ij!r*   c                    |                      |d          }|                     |d          }|                    d          }|                      |d          }|                     |          }| j        |         }|d         |j                            |           d S |                     |||           |                    ||           d S )NrK   rL   r-   r   )	r@   rP   rQ   safe_symbolr   r   ri   r   rV   )	r'   rH   rW   r<   rK   rX   rY   r4   r   s	            r)   handle_order_bookzbittrade.handle_order_book  s    . &&w55__Wd++##E1--!!(++OF+	W%O""7+++++**67IFFFNN9k22222r*   c                     |                      |d          }|                     |d          }|| j        v r| j        |= |                     i |          | j        |<   |                     | j        |||           d S )Nr4   r]   )r@   r0   r   
order_bookspawnr   )r'   rH   rW   rF   r4   r]   s         r)   r   z'bittrade.handle_order_book_subscription  s~    !!,99!!,88T_$$'"&//"e"<"<

4167LQQQQQr*   c                    |                      |d          }|                     |j        d          }|                     ||          }|6|                     |d          }| ||||          S ||j        v r|j        |= |S )Nr7   r   )r@   index_byr   rP   )r'   rH   rW   r7   subscriptionsByIdrF   r   s          r)   handle_subscription_statusz#bittrade.handle_subscription_status  s     gt,, MM&*>EE'8"==#__\8<<F!vfg|<<<V)))(,r*   c                     |S N r'   rH   rW   s      r)   handle_system_statuszbittrade.handle_system_status  s	     r*   c                 F   |                      |d          }|                    d          }|                     |d          }|dk    rW|                     |d          }| j        | j        | j        | j        d}|                      ||          }| |||           d S d S d S )NrK   rL   r   r?      )mbpdetailrl   kline)rP   rQ   r@   r   r[   rm   r|   )	r'   rH   rW   rK   rX   type
methodNamemethodsr   s	            r)   handle_subjectzbittrade.handle_subject  s    * __Wd++q))8))%33J-,+*	 G __Wj99F!vw'''''  "!r*   c                 l   K   |                     d|                     |d          i           d {V  d S )Npongping)sendr0   r   s      r)   r   zbittrade.pong  sG       kk64#4#4Wf#E#EFGGGGGGGGGGGr*   c                 >    |                      | j        ||           d S r   )r   r   r   s      r)   handle_pingzbittrade.handle_ping  s     

49fg.....r*   c                 D   |                      |d          }|dk    r|                      |d          }|                     |j        d          }|                     ||          }||                      |d          }	 |                     | j        d         ||                     |                     nj# t          $ r]}|                      |d          }	|                    ||	           |                    ||           ||j        v r|j        |= Y d }~nd }~ww xY wdS |S )Nstatuserrorr7   zerr-codeexactr<   F)	r@   r   r   rP   throw_exactly_matched_exception
exceptionsjsonr   r   )
r'   rH   rW   r   r7   r   rF   	errorCoder   r<   s
             r)   handle_error_messagezbittrade.handle_error_message  s=    !!'844W!!'400B $f.BD I I??+<bAAL' ,,WjAA	5889QS\^b^g^gho^p^pqqqq  5 5 5"&"2"2<"O"OKMM![111MM!R(((V111"045 5s   >5B4 4
D>ADDc                 J   |                      ||          r|                     |d          |                     ||           d S |                     |d          |                     ||           d S |                     |d          |                     ||           d S d S d S )Nr7   rK   r   )r   r@   r   r   r   r   s      r)   handle_messagezbittrade.handle_message*  s    $$VW55 	2 ..://@@@@@!!'400<##FG44444!!'622>  11111%	2 	2" ?>r*   )%__name__
__module____qualname__r   r&   r3   r2   r	   rG   r   r[   r   r   r
   rc   rm   listrt   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r(   s   @r)   r   r      s(       #      @   68 k k kF k k k k8F    @ <@d[] S S SS S Sbfglbm S S S SB%F % % % %N ?CQUdhqs !H !H !H !H3 !H^a !Hx|  ~B  yC !H !H !H !HF!#6 !# !# !# !#F @DB !! !!S !! !!S\ !! !! !! !!F!/ !/ !/ !/ !/F  >& & &
3 3 3! ! ! ! !F!3 !3 !3 !3 !3FRV R R R R    *6    #(V #( #( #( #(JH H H/& / / / /6 t    82V 2 2 2 2 2 2 2 2r*   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   ccxt.base.typesr   r   r   r   r	   r
   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   async_supportr   r   r*   r)   <module>r      s        N N N N N N N N D D D D D D D D D D D D D D D D 4 4 4 4 4 4       * * * * * *o2 o2 o2 o2 o2t!* o2 o2 o2 o2 o2r*   