
    ":h`Z                         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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TickerTrade)Client)List)ExchangeError)NotSupportedc            
           e Zd Zdef 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d Zi fde
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 )probitreturnc                     | j                  t        t        |          ddddddddddd
ddiddiddd	d
dii d      S )NTF)
wswatchBalancewatchTickerwatchTickerswatchTradeswatchTradesForSymbolswatchMyTradeswatchOrderswatchOrderBook
watchOHLCVr   z'wss://api.probit.com/api/exchange/v1/wsz,wss://demo-api.probit.com/api/exchange/v1/ws)apitestr   order_books_l2d   )filterinterval)hasurlsoptions	streaming)deep_extendsuperr   describe)self	__class__s    I/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/pro/probit.pyr+   zprobit.describe   s    fd < > $# %#).!%#"&# C H	 !. ##7A
  	    c                 ~   K   | j                  |       d{    d}| j                  |d|       d{   S 7 !7 w)aV  
        watch balance and get the amount of funds available for trading or funds locked in orders

        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balance)authenticatesubscribe_private)r,   paramsmessageHashs      r.   watch_balancezprobit.watch_balance1   sB      '''++KFKKK 	(Ks   =9=;==clientc                 b    d}| j                  |       |j                  | j                  |       y )Nr1   )parse_ws_balanceresolver1   )r,   r7   messager5   s       r.   handle_balancezprobit.handle_balance>   s)      g&t||[1r/   c                    | j                  |dd      }| j                  |di       }t        |j                               }|ri | _        t        dt        |            D ]f  }||   }||   }| j                  |      }| j                         }	| j                  |d      |	d<   | j                  |d      |	d<   |	| j                  |<   h | j                  | j                        | _        y )NresetFdatar   	availablefreetotal)	safe_bool
safe_valuelistkeysr1   rangelensafe_currency_codeaccountsafe_stringsafe_balance)
r,   r;   r>   r?   currencyIdsi
currencyIdentrycoderJ   s
             r.   r9   zprobit.parse_ws_balanceO   s     w7w3499;'DLq#k*+ 	)A$QJ$E**:6DllnG"..ukBGFO#//w?GG!(DLL	) ((6r/   symbolc                 L   K   d}| j                  d|d||       d{   S 7 w)a;  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        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>`
        tickerr   N)subscribe_public)r,   rR   r4   channels       r.   watch_tickerzprobit.watch_tickerk   s-      **=&(GU[\\\\s   $"$c                    | j                  |d      }| j                  |      }| j                  |di       }| j                  |      }| j	                  ||      }d|z   }|| j
                  |<   |j                  ||       y )N	market_idrT   zticker:)rK   safe_symbolrD   safe_marketparse_tickertickersr:   )	r,   r7   r;   marketIdrR   rT   marketparsedTickerr5   s	            r.   handle_tickerzprobit.handle_tickery   s    & ##G[9!!(+(B7!!(+((8&(+V|[1r/   Nsincelimitc                    K   d}| j                  |      }| j                  d|d||       d{   }| j                  r|j                  ||      }| j	                  ||||d      S 7 7w)a  
        get the list of most recent trades for a particular symbol

        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>`
        recent_tradesr   tradesNT)rZ   rU   
newUpdatesgetLimitfilter_by_symbol_since_limit)r,   rR   rb   rc   r4   rV   rf   s          r.   watch_tradeszprobit.watch_trades   so      "!!&),,]FHgW]^^??OOFE2E00tTT _s   ,A(A&8A(c                 N   | j                  |d      }| j                  |      }| j                  |      }| j                  |dg       }| j	                  |dd      ry d|z   }| j                  | j
                  |      }|7| j                  | j                  dd      }	t        |	      }|| j
                  |<   t        dt        |            D ]*  }
||
   }| j                  ||      }|j                  |       , || j
                  |<   |j                  | j
                  |   |       y )	NrY   re   r>   Fztrades:tradesLimit  r   )rK   rZ   r[   rD   rC   rf   safe_integerr'   r   rG   rH   parse_tradeappendr:   )r,   r7   r;   r^   rR   r_   rf   r5   storedrc   rN   tradeparseds                r.   handle_tradeszprobit.handle_trades   s   * ##G[9!!(+!!(+/2>>>'7E2&(f5>%%dllM4HE&F"(DKKq#f+& 	"A1IE%%eV4FMM&!	" %Ft{{6*K8r/   c                 N  K   | j                          d{    | j                  |       d{    d}|| j                  |      }|dz   |z   }| j                  |d|       d{   }| j                  r|j                  ||      }| j                  ||||d      S 7 7 q7 ;w)a  
        get the list of trades associated with the user

        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
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Nrf   :trade_historyT)load_marketsr2   rZ   r3   rg   rh   ri   )r,   rR   rb   rc   r4   r5   rf   s          r.   watch_my_tradeszprobit.watch_my_trades   s      !!!'''%%f-F%+f4K--k?FSS??OOFE2E00tTT 	"'
 Ts1   B%BB%B!7B%'B#(8B%!B%#B%c                    | j                  |dg       }t        |      }|dk(  ry | j                  |dd      ry d}| j                  }|/| j	                  | j
                  dd      }t        |      }|| _        | j                  |      }i }	t        dt        |            D ]9  }
||
   }| j                  |d   d	      d
k(  r!d|	|d   <   |j                  |       ; t        |	j                               }t        |      }|dk(  ry t        dt        |            D ]!  }||   }|dz   |z   }|j                  ||       # |j                  ||       y )Nr?   r   r>   Frf   rl   rm   infostatusexecutedTrR   rv   )rD   rH   rC   myTradesrn   r'   r   parse_tradesrG   rK   rp   rE   rF   r:   )r,   r7   r;   	rawTradeslengthr5   rq   rc   rf   tradeSymbolsjrr   uniqueuniqueLengthrN   rR   symbolSpecificMessageHashs                    r.   handle_my_tradeszprobit.handle_my_trades   sa   ( OOGVR8	YQ;>>'7E2>%%dllM4HE+E2F"DM""9-q#f+& 	!A1IEfx8JF,0Lx)MM% 	! l'')*6{1q#f+& 	>AAYF(3c(9F(B%NN6#<=	> 	v{+r/   c                   K   | j                  |       d{    d}|| j                  |      }|dz   |z   }| j                  |d|       d{   }| j                  r|j	                  ||      }| j                  ||||d      S 7 o7 9w)ah  
        watches information on an order made by the user

        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>`
        Nordersrv   
open_orderT)r2   rZ   r3   rg   rh   ri   )r,   rR   rb   rc   r4   r5   r   s          r.   watch_orderszprobit.watch_orders  s      '''%%f-F%+f4K--k<PP??OOFE2E00tTT 	(
 Qs!   BB7BB	8B	Bc                 R   | j                  |dg       }t        |      }|dk(  ry d}| j                  |dd      }| j                  }||r/| j	                  | j
                  dd      }t        |      }|| _        i }	t        dt        |            D ]1  }
||
   }| j                  |      }d|	|d	   <   |j                  |       3 t        |	j                               }t        dt        |            D ]!  }
||
   }|d
z   |z   }|j                  ||       # |j                  ||       y )Nr?   r   r   r>   FordersLimitrm   TrR   rv   )rD   rH   rC   r   rn   r'   r   rG   parse_orderrp   rE   rF   r:   )r,   r7   r;   	rawOrdersr   r5   r>   rq   rc   orderSymbolsrN   rawOrderorderr   rR   r   s                   r.   handle_orderszprobit.handle_orders2  s2   2 OOGVR8	YQ;w7>U%%dllM4HE+E2F DKq#i.) 	!A |H$$X.E,0Lx)MM% 		!
 l'')*q#f+& 	>AAYF(3c(9F(B%NN6#<=	> 	v{+r/   c                    K   d}| j                  |ddd      \  }}| j                  d|d||       d{   }|j                         S 7 w)a-  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        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)handle_option_and_paramsrU   rc   )r,   rR   rc   r4   rV   r   s         r.   watch_order_bookzprobit.watch_order_bookc  s[      77@PRZ\ij//0@&+W^`fgg	   hs   2AA	Ac                    K   | j                   d   d   }d|d}| j                  ||      }|}| j                  ||||       d {   S 7 w)Nr   r   	subscribe)typerV   )r&   extendwatch)r,   r5   rV   r4   urlr   requestsubscribeHashs           r.   r3   zprobit.subscribe_privates  sX     iit$
	 ++i0#ZZ['=IIIIs   AAA
A
methodNamec                   K   | j                          d {    | j                  |      }|d   }| j                  d   d   }| j                  |      }d|z   }	|dz   |z   }
i }|	|j                  v r |j                  |	   }||vr|j                  |	= d||<   t        |j                               }d }| j                  ||dd      \  }}d	d
|d   ||d}| j                  ||      }| j                  ||
||	|       d {   S 7 7 w)NrR   r   r   zmarketdata:rv   Tr$   r"   r   
marketdataid)r   rV   rY   r#   r$   )
rx   r_   r&   r7   subscriptionsrE   rF   r   r   r   )r,   r   rR   dataTyper#   r4   r_   r   r7   r   r5   filtersrF   r$   r   s                  r.   rU   zprobit.subscribe_public}  s.    !!!V$!iit$S!%.nv-F000**=9Gg%((7GLLN#88ZY\]&# 
 ++gv.ZZ['='RRR5 	"4 Ss"   DDC&D=D>DDc           	         | j                  |d      }| j                  |      }| j                  |d      }d|z   }|| j                  vr| j	                  i       | j                  |<   | j                  |   }| j                  |dd      }	|	r)| j                  ||d dddd	      }
|j                  |
       n| j                  ||       |j                  ||       y )
NrY   sidez
orderbook:r>   Fbuysellpricequantity)
rK   rZ   group_by
orderbooks
order_bookrC   parse_order_bookr>   handle_deltar:   )r,   r7   r;   	orderBookr^   rR   
dataBySider5   r   r>   snapshots              r.   handle_order_bookzprobit.handle_order_book  s     ##G[9!!(+]]9f5
"V+$//)&*oob&9DOOF#OOF+	w7,,ZufV]_ijHOOH%i4y+.r/   c                     t        dt        |            D ]+  }||   }| j                  |dd      }|j                  |       - y )Nr   r   r   )rG   rH   parse_bid_ask
storeArray)r,   bookSidebidAsksrN   bidAskrs   s         r.   handle_bid_askszprobit.handle_bid_asks  sG    q#g,' 	(AQZF''DF'	(r/   c                     |d   }|d   }| j                  |dg       }| j                  |dg       }| j                  ||       | j                  ||       y )Nbidsasksr   r   )rD   r   )r,   r   delta
storedBids
storedAsksr   r   s          r.   r   zprobit.handle_delta  sZ    v&
v&
ufb1ueR0Z.Z.r/   c                    | j                  |d      }| j                  |dd      }| j                  |d      }| j                  dz   |z   dz   |z   dz   | j                  |      z   }d| j                  v r | j                  | j                  d   ||       d| j                  v r | j                  | j                  d   ||       t        |      )N	errorCoder;    details exactbroad)rK   rD   r   json
exceptionsthrow_exactly_matched_exceptionthrow_broadly_matched_exceptionr   )r,   r7   r;   rQ   
errMessager   feedbacks          r.   handle_error_messagezprobit.handle_error_message  s     5%%gy"=
//'9577S=4'#-
:S@499WCUUdoo%001I4QYZdoo%001I:W_`H%%r/   c                     | j                  |d      }|j                  d   }|dk(  rd}|j                  ||       y |j                  |       |j                  d= y )Nresultauthenticatedok)rK   r   r:   reject)r,   r7   r;   r   futurer5   s         r.   handle_authenticatezprobit.handle_authenticate  sZ     !!'84%%o6T>)KNN7K0MM'"$$_5r/   c                     | j                  |d      }|| j                  ||       | j                  |dg       }t        |      }|r| j                  ||       | j	                  |g dg       }t        |      }|r| j                  |||       y y )NrT   re   )r   order_books_l1r!   order_books_l3order_books_l4)rD   ra   rH   rt   safe_value_nr   )r,   r7   r;   rT   rf   tradesLengthr   orderBookLengths           r.   handle_market_datazprobit.handle_market_data  s    (3vw//2>6{vw/%%g  0G  IK  L	i.""67I> r/   c                    | j                  |d      }|| j                  ||       y | j                  |d      }|dk(  r| j                  ||       y | j                  | j                  | j
                  | j                  | j                  d}| j                  |d      }| j                  ||      }|
 |||       y t        | j                  dz   | j                  |      z         }|j                  |       y )Nr   r   authorization)r   r1   rw   r   order_historyrV   z! handleMessage: unknown message: )rK   r   r   r   r<   r   r   rD   r   r   r   r   )	r,   r7   r;   r   r   handlersrV   handlererrors	            r.   handle_messagezprobit.handle_message  s     $$Wk:	 %%fg60?"$$VW511**!22,,!//
 ""7I6//(G4FG$TWW'JJTYYW^M__`er/   c                   K   | j                   d   d   }| j                  |      }d}| j                  | j                  dd      }| j	                  |j
                  |      }|| j                         |kD  rj| j                          d {   }| j                  |d      }d|d}	| j                  ||| j                  |	|      |       d {   }||j
                  |<   |S 7 X7 w)	Nr   r   r   expiresr   access_tokenr   )r   token)r&   r7   rn   r'   rD   r   millisecondssign_inrK   r   r   )
r,   r4   r   r7   r5   r   r   responseaccessTokenr   s
             r.   r2   zprobit.authenticate  s     iit$S!%##DLL)Q?!5!5{CN 1 1 3g =!\\^+H **8^DK'$G  ::c;GV8TVabbF06F  - , cs%   BC&	C"
AC&C$C&$C&)&__name__
__module____qualname__r   r+   r   r6   r   r<   r9   strr   rW   ra   r   r   r   rj   rt   r
   ry   r   r   r   r   r	   r   r3   rU   r   r   r   r   r   r   r   r2   __classcell__)r-   s   @r.   r   r      s   # @ *, L L2V 2"78 68 ] ]F ]2F 28 <@d[] U US U Ubfglbm U(&9F &9P 37TX\eg UC Us URU Ulpqvlw U.1,v 1,f 04$UYbd U UC Us Uimnsit U./,F /,b @DB !S ! !S\ ! J ]_ S Sc S:/ /<(/&6 &(6& 6? ?"V "H )+ r/   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   ccxt.base.typesr   r   r   r   r	   r
   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   async_supportr    r/   r.   <module>r      s<     O T T T 4  * )_T&& _r/   