
    i&Y                         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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TickerTrade)Client)List)ExchangeError)NotSupportedc            
           e Zd Z fdZi fdefdZde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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efdZd
i fde	dedefdZi fde	fdZdef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!i fdZ" xZ#S )probitc                     |                      t          t          |                                           dddddddddd	ddiddiddd	d
ddiddiddidi i d          S )NTF)	wswatchBalancewatchTickerwatchTickerswatchTradeswatchMyTradeswatchOrderswatchOrderBook
watchOHLCVr   z'wss://api.probit.com/api/exchange/v1/wsz,wss://demo-api.probit.com/api/exchange/v1/ws)apitestorder_books_l2d   )filterintervalr    recent_tradestickerchannel
open_order)r   r   r   r   )hasurlsoptions	streaming
exceptions)deep_extendsuperr   describe)self	__class__s    U/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/pro/probit.pyr-   zprobit.describe   s    fd 3 3 < < > > $# %#!%#"&#
 
 C H	  / ## #
 o  h  |  K'A
 'A
 ' ' '	    returnc                    K   |                      |           d{V  d}| j        d         d         }ddd}|                     ||          }|                     ||||           d{V S )aZ  
        watch balance and get the amount of funds available for trading or funds locked in orders
        :see: https://docs-en.probit.com/reference/balance-1
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nbalancer   r   	subscribetyper$   )authenticater'   extendwatch)r.   paramsmessageHashurlr5   requests         r0   watch_balancezprobit.watch_balance;   s       '''''''''it$ 
 
	 ++i00ZZ[';GGGGGGGGGr1   clientc                 j    d}|                      |           |                    | j        |           d S )Nr4   )parse_ws_balanceresolver4   )r.   r@   messager<   s       r0   handle_balancezprobit.handle_balanceL   s9      g&&&t|[11111r1   c                    |                      |dd          }|                     |di           }t          |                                          }|ri | _        t          dt          |                    D ]w}||         }||         }|                     |          }|                                 }	| 	                    |d          |	d<   | 	                    |d          |	d<   |	| j        |<   x| 
                    | j                  | _        d S )NresetFdatar   	availablefreetotal)	safe_bool
safe_valuelistkeysr4   rangelensafe_currency_codeaccountsafe_stringsafe_balance)
r.   rD   rG   rH   currencyIdsi
currencyIdentrycoderS   s
             r0   rB   zprobit.parse_ws_balance]   s    w77w33499;;'' 	DLq#k**++ 	) 	)A$QJ$E**:66DllnnG"..ukBBGFO#//w??GG!(DL((66r1   symbolc                 |   K   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
        :see: https://docs-en.probit.com/reference/marketdata
        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.interval]: Unit time to synchronize market information(ms). Available units: 100, 500
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr   r    r#   )handle_option_and_paramssubscribe_order_book)r.   r[   r;   r    s       r0   watch_tickerzprobit.watch_tickery   sW       66v}hX`aa..vxPPPPPPPPPr1   c                 *   |                      |d          }|                     |          }|                     |di           }|                     |          }|                     ||          }d|z   }|| j        |<   |                    ||           d S )N	market_idr#   zticker:)rT   safe_symbolrM   safe_marketparse_tickertickersrC   )	r.   r@   rD   marketIdr[   r#   marketparsedTickerr<   s	            r0   handle_tickerzprobit.handle_ticker   s    & ##G[99!!(++(B77!!(++((88&(+V|[11111r1   Nsincelimitc                    K   d}|                      |ddd          \  }}|                     |d||           d{V }| j        r|                    ||          }|                     ||||d          S )a  
        get the list of most recent trades for a particular symbol
        :see: https://docs-en.probit.com/reference/trade_history
        :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
        :param int [params.interval]: Unit time to synchronize market information(ms). Available units: 100, 500
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Nr   r    r"   tradesT)r]   r^   
newUpdatesgetLimitfilter_by_symbol_since_limit)r.   r[   rj   rk   r;   r    rm   s          r0   watch_tradeszprobit.watch_trades   s       66v}hXghh0066RRRRRRRR? 	3OOFE22E00tTTTr1   c                    |                      |d          }|                     |          }|                     |          }|                     |dg           }|                     |dd          }d|z   }|                     | j        |          }	|	|r5|                     | j        dd          }
t          |
          }	|	| j        |<   t          dt          |                    D ]5}||         }|                     ||          }|	                    |           6|	| j        |<   |                    | j        |         |           d S )	Nra   r"   rG   Fztrades:tradesLimit  r   )rT   rb   rc   rM   rL   rm   safe_integerr(   r   rP   rQ   parse_tradeappendrC   )r.   r@   rD   rf   r[   rg   rm   rG   r<   storedrk   rW   tradeparseds                 r0   handle_tradeszprobit.handle_trades   sB   * ##G[99!!(++!!(++/2>>w77&(f55>U>%%dlM4HHE&&F"(DKq#f++&& 	" 	"A1IE%%eV44FMM&!!!!$Ft{6*K88888r1   c                   K   |                                   d{V  |                     |           d{V  d}|%|                     |          }|d         }|dz   |z   }| j        d         d         }d}d|d	}	|                     |	|          }
|                     |||
|           d{V }| j        r|                    ||          }|                     ||||d
          S )a  
        get the list of trades associated with the user
        :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>`
        NmyTradesr[   :r   r   trade_historyr5   r6   T)	load_marketsr8   rg   r'   r9   r:   rn   ro   rp   )r.   r[   rj   rk   r;   r<   rg   r=   r$   rD   r>   rm   s               r0   watch_my_tradeszprobit.watch_my_trades   s&      !!!!!!!!!''''''''' [[((FH%F%+f4Kit$!
 
 ++gv..zz#{GWEEEEEEEE? 	3OOFE22E00tTTTr1   c                    |                      |dg           }t          |          }|dk    rd S |                     |dd          }d}| j        }||r2|                     | j        dd          }t          |          }|| _        |                     |          }	i }
t          dt          |	                    D ]*}|	|         }d|
|d	         <   |	                    |           +t          |
                                          }t          dt          |                    D ](}||         }|d
z   |z   }|                    ||           )|                    ||           d S )NrH   r   rG   Fr}   rs   rt   Tr[   r~   )rM   rQ   rL   r}   ru   r(   r   parse_tradesrP   rw   rN   rO   rC   )r.   r@   rD   	rawTradeslengthrG   r<   rx   rk   rm   tradeSymbolsjry   uniquerW   r[   symbolSpecificMessageHashs                    r0   handle_my_tradeszprobit.handle_my_trades   so   ( OOGVR88	YQ;;Fw77 NuN%%dlM4HHE+E22F"DM""9--q#f++&& 	! 	!A1IE,0Lx)MM%    l''))**q#f++&& 	> 	>AAYF(3c(9F(B%NN6#<====v{+++++r1   c                   K   |                      |           d{V  | j        d         d         }d}|%|                     |          }|d         }|dz   |z   }d}|                     |ddd	          \  }}d
|d}	|                     |	|          }
|                     |||
|           d{V }| j        r|                    ||          }|                     ||||d          S )al  
        watches information on an order made by the user
        :see: https://docs-en.probit.com/reference/open_order
        :param str symbol: unified symbol of the market the order was made in
        :param int [since]: timestamp in ms of the earliest order to watch
        :param int [limit]: the maximum amount of orders to watch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.channel]: choose what channel to use. Can open_order or order_history.
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r   ordersr[   r~   r   r$   r%   r5   r6   T)	r8   r'   rg   r]   r9   r:   rn   ro   rp   )r.   r[   rj   rk   r;   r=   r<   rg   r$   r5   r>   r   s               r0   watch_orderszprobit.watch_orders#  s       '''''''''it$[[((FH%F%+f4K77yZfgg
 
	 ++i00zz#{GWEEEEEEEE? 	3OOFE22E00tTTTr1   c                    |                      |dg           }t          |          }|dk    rd S d}|                     |dd          }| j        }||r2|                     | j        dd          }t          |          }|| _        i }	t          dt          |                    D ]?}
||
         }|                     |          }d|	|d	         <   |	                    |           @t          |	                                          }t          dt          |                    D ](}
||
         }|d
z   |z   }|                    ||           )|                    ||           d S )NrH   r   r   rG   FordersLimitrt   Tr[   r~   )rM   rQ   rL   r   ru   r(   r   rP   parse_orderrw   rN   rO   rC   )r.   r@   rD   	rawOrdersr   r<   rG   rx   rk   orderSymbolsrW   rawOrderorderr   r[   r   s                   r0   handle_orderszprobit.handle_ordersA  so   2 OOGVR88	YQ;;Fw77>U>%%dlM4HHE+E22F DKq#i..)) 	! 	!A |H$$X..E,0Lx)MM%    l''))**q#f++&& 	> 	>AAYF(3c(9F(B%NN6#<====v{+++++r1   c                    K   d}|                      |ddd          \  }}|                     |d||           d{V }|                                S )a1  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://docs-en.probit.com/reference/marketdata
        :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
        Nr   r    order_books	orderbook)r]   r^   rk   )r.   r[   rk   r;   r    r   s         r0   watch_order_bookzprobit.watch_order_bookr  si       66v?OQY[hii33FKQWXXXXXXXX	   r1   c                 2  K   |                                   d {V  |                     |          }|d         }| j        d         d         }|                     |          }d }|                     |ddd          \  }}d|z   }	|dz   |z   }i }
|	|j        v r|j        |	         }
||
vr|j        |	= d	|
|<   t          |
                                          }d
||d         d|d}|                     ||          }| 	                    |||||
           d {V S )Nr[   r   r   r   r!   r   zmarketdata:r~   T
marketdataidr5   )r$   r!   ra   r7   r    )
r   rg   r'   r@   r]   subscriptionsrN   rO   r9   r:   )r.   r[   r<   r    r;   rg   r=   r@   r!   subscriptionHashfiltersrO   rD   r>   s                 r0   r^   zprobit.subscribe_order_book  s]     !!!!!!!!!V$$!it$S!!88AQS]_bcc&(61!C'&0v333*+;<Gg%%()9:GLLNN### 
 
 ++gv..ZZ[';PPPPPPPPPr1   c           	         |                      |d          }|                     |          }|                     |d          }d|z   }|                     | j        |          }||                     i           }|| j        |<   |                     |dd          }	|	r1|                     ||d dddd	          }
|                    |
           n| 	                    ||           |
                    ||           d S )
Nra   sidez
orderbook:rG   Fbuysellpricequantity)rT   rb   group_byrM   
orderbooks
order_bookrL   parse_order_bookrG   handle_deltarC   )r.   r@   rD   	orderBookrf   r[   
dataBySider<   r   rG   snapshots              r0   handle_order_bookzprobit.handle_order_book  s    ##G[99!!(++]]9f55
"V+OODOV<<	++I&/DOF#w77 	5,,ZufV]_ijjHOOH%%%%i444y+.....r1   c                     t          dt          |                    D ]6}||         }|                     |dd          }|                    |           7d S )Nr   r   r   )rP   rQ   parse_bid_ask
storeArray)r.   bookSidebidAsksrW   bidAskrz   s         r0   handle_bid_askszprobit.handle_bid_asks  sb    q#g,,'' 	( 	(AQZF''DDF''''	( 	(r1   c                     |d         }|d         }|                      |dg           }|                      |dg           }|                     ||           |                     ||           d S )Nbidsasksr   r   )rM   r   )r.   r   delta
storedBids
storedAsksr   r   s          r0   r   zprobit.handle_delta  sr    v&
v&
ufb11ueR00Z...Z.....r1   c                     |                      |d          }|                      |dd          }|                     |d          }t          | j        dz   |z   dz   |z   dz   |                     |          z             )N	errorCoderD    details )rT   rM   r   r   json)r.   r@   rD   rZ   
errMessager   s         r0   handle_error_messagezprobit.handle_error_message  s}     55%%gy"==
//'955DGcMD036CcIDIIV]L^L^^___r1   c                     |                      |d          }|j        d         }|dk    r|                    d           d S |                    |           |j        d= d S )NresultauthenticatedokT)rT   r   rC   reject)r.   r@   rD   r   futures        r0   handle_authenticatezprobit.handle_authenticate  sj     !!'844%o6T>>NN4     MM'"""$_555r1   c                 \   |                      |d          }||                     ||           |                      |dg           }t          |          r|                     ||           |                     |g dg           }t          |          r|                     |||           d S d S )Nr#   r"   )r   order_books_l1r   order_books_l3order_books_l4)rM   ri   rQ   r{   safe_value_nr   )r.   r@   rD   r#   rm   r   s         r0   handle_market_datazprobit.handle_market_data  s    (33vw////2>>v;; 	0vw///%%g  0G  0G  0G  IK  L  L	y>> 	?""67I>>>>>	? 	?r1   c                    |                      |d          }||                     ||           d S |                      |d          }|dk    r|                     ||           d S | j        | j        | j        | j        | j        d}|                      |d          }|                     ||          }| |||           d S t          | j	        dz   | 
                    |          z             }|                    |           d S )Nr   r7   authorization)r   r4   r   r%   order_historyr$   z! handleMessage: unknown message: )rT   r   r   r   rE   r   r   rM   r   r   r   r   )	r.   r@   rD   r   r7   handlersr$   handlererrors	            r0   handle_messagezprobit.handle_message  s%    $$Wk::	 %%fg666F00?""$$VW555F1*!2,!/
 
 ""7I66//(G44GFG$$$FTW'JJTYYW^M_M__``er1   c                   K   | j         d         d         }|                     |          }d}|                     | j        dd          }|                     |j        |          }||                                 |k    rq|                                  d {V }|                     |d          }d|d}	| 	                    ||| 
                    |	|          |           d {V }||j        |<   |S )	Nr   r   r   expiresr   access_tokenr   )r7   token)r'   r@   ru   r(   rM   r   millisecondssign_inrT   r:   r9   )
r.   r;   r=   r@   r<   r   r   responseaccessTokenr>   s
             r0   r8   zprobit.authenticate  s     it$S!!%##DL)Q??!5{CCN 1 1 3 3g = =!\\^^++++++H **8^DDK'$ G  ::c;GV8T8TVabbbbbbbbF06F -r1   )$__name__
__module____qualname__r-   r   r?   r   rE   rB   strr
   r_   ri   r   r   r   rq   r{   r	   r   r   r   r   r   r   r   r^   r   r   r   r   r   r   r   r8   __classcell__)r/   s   @r0   r   r      sN       ( ( ( ( (T *, H H H H H H"2V 2 2 2 2"7 7 78 68 Q Q QF Q Q Q Q2F 2 2 2 28 <@d[] U U US U Ubfglbm U U U U$%9F %9 %9 %9 %9N 37TX\eg U UC Us URU Ulpqvlw U U U U8*,v *, *, *, *,X 04$UYbd U U UC Us Uimnsit U U U U</,F /, /, /, /,b @DB ! !S ! !S\ ! ! ! ! SU Q Q Q Q Q Q:/ / / / /<( ( (/ / /`6 ` ` ` ` 
6& 
6 
6 
6 
6	? 	? 	? 	? 	?V    B )+        r1   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   ccxt.base.typesr   r   r   r   r	   r
   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   async_supportr    r1   r0   <module>r      s        O O O O O O O O O O O O O O O O O O O O O O O O O O 4 4 4 4 4 4       * * * * * * ) ) ) ) ) )X X X X XT& X X X X Xr1   