
    ":h                         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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j0                  j2                        Zy)	    N)
ArrayCacheArrayCacheBySymbolById)AnyBalancesIntMarketOrder	OrderBookStrStringsTickerTickersTrade)Client)List)NotSupportedc            
           e Zd Zdef fdZd Zi fdefdZdefdZ	d Z
d Zi fd	edefd
Zd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i fd	ededefdZdefdZd Z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e#de$de fdZ%d%de#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d#Z*i fd$Z+ xZ,S )&exmoreturnc                 x    | j                  t        t        |          dddddddddd	dddddd	iii i i d
      S )NTF)	wswatchBalancewatchTickerwatchTickerswatchTradeswatchMyTradeswatchOrderswatchOrderBook
watchOHLCVapir   z#wss://ws-api.exmo.com:443/v1/publicz$wss://ws-api.exmo.com:443/v1/privatez+wss://ws-api.exmo.com:443/v1/margin/private)publicspotmargin)hasurlsoptions	streaming
exceptions)deep_extendsuperr   describe)self	__class__s    G/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/pro/exmo.pyr+   zexmo.describe   sv    dD : < $# $#!%#"&#
 "G F"O3?
  	    c                 ~    | j                  | j                  | j                  dd      d      }|| j                  d<   |S )N	requestIdr      )sumsafe_integerr&   )r,   r1   s     r.   
request_idzexmo.request_id/   s9    HHT..t||[!LaP	$-[!r/   c                 2  K   | j                  |       d{    | j                  dd|      \  }}d|z   }| j                  d   d   |   }d|dz   g| j                         d}| j	                  ||      }| j                  |||||       d{   S 7 {7 w)	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>`
        Nr   balance:r    r   	subscribez/walletmethodtopicsid)authenticatehandle_market_type_and_paramsr%   r5   r)   watch)r,   paramstypequerymessageHashurlr8   requests           r.   watch_balancezexmo.watch_balance4   s      '''88vVe 4'iit$T*!i'(//#
	
 ""9e4ZZ[';PPP 	( Qs"   BBA6BBBBclientc                 
   | j                  |d      }|j                  d      }| j                  |d      }|dk(  r| j                  |       n|dk(  r| j                  |       d|z   }|j	                  | j
                  |       y )Ntopic/r   r"   r#   r7   )safe_stringsplitparse_spot_balanceparse_margin_balanceresolvebalance)r,   rG   messagerI   partsrA   rC   s          r.   handle_balancezexmo.handle_balanceF   s~    h   '2C q)6>##G,X%%g. 4't||[1r/   c                    | j                  |d      }| j                  |d      }|| j                  d<   |dk(  r| j                  |di       }| j                  |di       }t        |j	                               }t        dt        |            D ]a  }||   }| j                  |      }	| j                         }
| j                  ||      |
d<   | j                  ||      |
d	<   |
| j                  |	<   c nq|d
k(  rl| j                  |d      }| j                  |      }	| j                         }
| j                  |d      |
d<   | j                  |d      |
d	<   |
| j                  |	<   | j                  | j                        | _        y )Neventdatainfosnapshotbalancesreservedr   freeusedupdatecurrencyrP   )
rK   
safe_valuerP   listkeysrangelensafe_currency_codeaccountsafe_balance)r,   rQ   rU   rV   rY   rZ   
currenciesi
currencyIdcodere   s              r.   rM   zexmo.parse_spot_balance   so      '2w/#VJtZ<HtZ<Hhmmo.J1c*o. -']
..z:,,."&"2"28Z"H"&"2"28Z"H%,T"- h))$
;J**:6DllnG"..tY?GFO"..tZ@GFO!(DLL((6r/   c                    | j                  |d      }|| j                  d<   t        |j                               }t	        dt        |            D ]  }||   }| j                  |      }| j                  ||      }| j                         }| j                  |d      |d<   | j                  |d      |d<   | j                  |d      |d<   || j                  |<   | j                  | j                        | _         y )NrV   rW   r   r[   r\   rP   total)
r_   rP   r`   ra   rb   rc   rd   re   rK   rf   )	r,   rQ   rV   rg   rh   ri   rj   walletre   s	            r.   rN   zexmo.parse_margin_balance   s     w/#V$))+&
q#j/* 		;A#AJ**:6D__T:6FllnG"..vv>GFO"..vv>GFO#//	BGG!(DLL,,T\\:DL		;r/   symbolc                 6  K   | j                          d{    | j                  |      }|d   }| j                  d   d   d   }d|z   }dd|d	   z   g| j                         d
}| j	                  ||      }| j                  |||||       d{   S 7 ~7 w)a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#fd8f47bc-8517-43c0-bb60-1d61a86d4471

        :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>`
        Nrn   r    r   r!   ticker:r8   spot/ticker:r<   r9   )load_marketsmarketr%   r5   r)   r?   )r,   rn   r@   rs   rD   rC   rQ   rE   s           r.   watch_tickerzexmo.watch_ticker   s      !!!V$!iit$X.&(!- //#
 ""7F3ZZ[';PPP 	" Qs"   BBA9BBBBNsymbolsc                   K   | j                          d{    | j                  |dd      }g }g }t        dt        |            D ]D  }| j	                  ||         }|j                  d|d   z          |j                  d|d   z          F | j                  d   d	   d
   }d|| j                         d}| j                  ||      }	| j                  |||	||	       d{    | j                  | j                  d|      S 7 7 #w)a
  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#fd8f47bc-8517-43c0-bb60-1d61a86d4471

        :param str[] [symbols]: 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>`
        NFr   rp   rn   rq   r<   r    r   r!   r8   r9   )rr   market_symbolsrb   rc   rs   appendr%   r5   r)   watch_multiplefilter_by_arraytickers)
r,   ru   r@   messageHashesargsrh   rs   rD   rQ   rE   s
             r.   watch_tickerszexmo.watch_tickers   s     !!!%%gtU;q#g,' 	7A[[,F  VH-=!=>KK56	7 iit$X.!//#

 ""7F3!!#}g}gVVV##DLL(GDD! 	" 	Ws"   DDC
D!D""DDc                 H   | j                  |d      }|j                  d      }| j                  |d      }| j                  |      }| j                  |di       }| j	                  |      }| j                  ||      }	d|z   }
|	| j                  |<   |j                  |	|
       y )NrI   :r2   rV   rp   )rK   rL   safe_symbolr_   safe_marketparse_tickerr{   rO   )r,   rG   rQ   rI   
topicPartsmarketIdrn   tickerrs   parsedTickerrC   s              r.   handle_tickerzexmo.handle_ticker   s    (   '2[[%
##J2!!(+&"5!!(+((8&(+V|[1r/   sincelimitc                 `  K   | j                          d{    | j                  |      }|d   }| j                  d   d   d   }d|z   }dd|d	   z   g| j                         d
}| j	                  ||      }	| j                  |||	||	       d{   }
| j                  |
||dd      S 7 7 w)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>`
        Nrn   r    r   r!   trades:r8   zspot/trades:r<   r9   	timestampT)rr   rs   r%   r5   r)   r?   filter_by_since_limit)r,   rn   r   r   r@   rs   rD   rC   rQ   rE   tradess              r.   watch_tradeszexmo.watch_trades  s      !!!V$!iit$X.&(!- //#
 ""7F3zz#{G['RR))&%TRR 	" Ss"   B.B*A9B.B,B.,B.c                 l   | j                  |d      }|j                  d      }| j                  |d      }| j                  |      }| j                  |      }| j	                  |dg       }d|z   }	| j	                  | j
                  |      }
|
7| j                  | j                  dd      }t        |      }
|
| j
                  |<   t        dt        |            D ]*  }||   }| j                  ||      }|
j                  |       , |
| j
                  |<   |j                  | j
                  |   |	       y )	NrI   r   r2   rV   r   tradesLimit  r   )rK   rL   r   r   r_   r   r4   r&   r   rb   rc   parse_traderx   rO   )r,   rG   rQ   rI   rR   r   rn   rs   r   rC   storedr   rh   tradeparseds                  r.   handle_tradeszexmo.handle_trades4  s#       '2C ##E1-!!(+!!(+&"5&(f5>%%dllM4HE&F"(DKKq#f+& 	"A1IE%%eV4FMM&!	" %Ft{{6*K8r/   c                   K   | j                          d{    | j                  |       d{    | j                  dd|      \  }}| j                  d   d   |   }d}|d|z   }n| j	                  |      }	|	d   }d|	d   z   }d|dz   g| j                         d	}
| j                  |
|      }| j                  |||||       d{   }| j                  ||||d
      S 7 7 7 w)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>`
        Nr   r    r   	myTrades:rn   r8   z/user_tradesr9   T	rr   r=   r>   r%   rs   r5   r)   r?   filter_by_symbol_since_limit)r,   rn   r   r   r@   rA   rB   rD   rC   rs   rQ   rE   r   s                r.   watch_my_tradeszexmo.watch_my_tradesW  s     !!!'''88$PVWeiit$T*>%,K[[(FH%F%x(88K!~% //#
 ""7E2zz#{G['RR00tTT) 	"'$ S2   C)C#C)C%BC)	C'
C)%C)'C)c                    | j                  |d      }|j                  d      }| j                  |d      }d|z   }| j                  |d      }g }d }	| j                  0| j                  | j                  dd      }
t        |
      }	|	| _        n| j                  }	|dk(  r| j                  |d	g       }n|d
k(  r| j                  |d	i       }|g}| j                  |      }i }t        dt        |            D ]   }||   }|	j                  |       d||d   <   " t        |j                               }t        dt        |            D ]  }||   }d|z   }|j                  |	|         |j                  |	|       y )NrI   rJ   r   r   rU   r   r   rX   rV   r]   Trn   )rK   rL   myTradesr4   r&   r   r_   parse_tradesrb   rc   rx   r`   ra   rO   )r,   rG   rQ   rI   rR   rA   rC   rU   	rawTradesr   r   rawTrader   ru   jr   
symbolKeysrh   rn   symbolSpecificMessageHashs                       r.   handle_my_tradeszexmo.handle_my_tradesv  s   t   '2C q)!D(  '2	== %%dllM4HE-e4H$DM}}HJ<Ihw;H!
I""9-q#f+& 	,A1IEOOE"'+GE(O$	, ',,.)
q#j/* 	@A]F(3f(<%NN8%>?	@ 	x-r/   c                 x  K   | j                          d{    | j                  |      }|d   }| j                  d   d   d   }d|z   }| j                  |d      }d| j	                         d	|d
   z   gd}| j                  ||      }| j                  ||||       d{   }	|	j                         S 7 7 w)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
        Nrn   r    r   r!   
orderbook:aggregationr8   zspot/order_book_updates:r<   )r:   r<   r;   )rr   rs   r%   omitr5   r)   r?   r   )
r,   rn   r   r@   rs   rD   rC   r8   rE   	orderbooks
             r.   watch_order_bookzexmo.watch_order_book  s      !!!V$!iit$X."V+6=1!//#*VD\9
	 ""9f5**S+wLL	   	" Ms"   B:B6B
B:!B8"B:8B:c                    | j                  |d      }|j                  d      }| j                  |d      }| j                  |      }| j                  |di       }d|z   }| j	                  |d      }	|| j
                  vr| j                  i       | j
                  |<   | j
                  |   }
| j                  |d      }|dk(  r'| j                  |||	d	d
      }|
j                  |       ni| j                  |d
g       }| j                  |d	g       }| j                  |
d   |       | j                  |
d   |       |	|
d<   | j                  |	      |
d<   |j                  |
|       y )NrI   r   r2   rV   r   tsrU   rX   bidaskasksbidsr   datetime)rK   rL   r   r_   r4   
orderbooks
order_bookparse_order_bookreset	safe_listhandle_deltasiso8601rO   )r,   rG   rQ   rI   rR   r   rn   	orderBookrC   r   r   rU   rX   r   r   s                  r.   handle_order_bookzexmo.handle_order_book  s^   D   '2C ##E1-!!(+OOGVR8	"V+%%gt4	$//)&*oob&9DOOF#OOF+	  '2J,,Y	5RWXHOOH%>>)UB7D>>)UB7Dy0$7y0$7%.Ik"$(LL$;Ij!y+.r/   c                 L    | j                  |dd      }|j                  |       y )Nr   r2   )parse_bid_ask
storeArray)r,   booksidedeltabidAsks       r.   handle_deltazexmo.handle_delta!  s$    ##E1a0F#r/   c                 b    t        dt        |            D ]  }| j                  |||           y )Nr   )rb   rc   r   )r,   r   deltasrh   s       r.   r   zexmo.handle_deltas%  s0    q#f+& 	3Ahq	2	3r/   c                   K   | j                          d{    | j                  |       d{    | j                  dd|      \  }}| j                  d   d   |   }d}|d|z   }n| j	                  |      }	|	d   }d|	d   z   }d|dz   g| j                         d	}
| j                  |
|      }| j                  |||||       d{   }| j                  ||||d
      S 7 7 7 w)a  

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#85f7bc03-b1c9-4cd2-bd22-8fd422272825
        https://documenter.getpostman.com/view/10287440/SzYXWKPi#95e4ed18-1791-4e6d-83ad-cbfe9be1051c

        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>`
        Nr   r    r   orders:rn   r8   z/ordersr9   Tr   )r,   rn   r   r   r@   rA   rB   rD   rC   rs   rQ   rE   orderss                r.   watch_orderszexmo.watch_orders)  s     !!!'''88fUeiit$T*>#d*K[[(FH%F#fX&66K!y  //#
 ""7E2zz#{G['RR00tTT) 	"'$ Sr   c                    | j                  |d      }|j                  d      }| j                  |d      }d|z   }| j                  |d      }| j                  -| j                  | j                  dd      }t        |      | _        | j                  }	g }
|dk(  r| j                  |d	g       }
n)|d
k(  r$| j                  |d	i       }|
j                  |       i }t        dt        |
            D ]/  }| j                  |
|         }|	j                  |       d||d   <   1 t        |j                               }t        dt        |            D ]  }||   }d|z   }|j                  |	|         |j                  |	|       y )NrI   rJ   r   r   rU   ordersLimitr   rX   rV   r]   Trn   )rK   rL   r   r4   r&   r   r_   	safe_dictrx   rb   rc   parse_ws_orderr`   ra   rO   )r,   rG   rQ   rI   rR   rA   rC   rU   r   cachedOrders	rawOrdersrawOrderru   r   orderr   rh   rn   r   s                      r.   handle_orderszexmo.handle_ordersL  s   p   '2C q)$&  '2;;%%dllM4HE07DK{{	J<Ih~~gvr:HX&q#i.) 	,A''	!5E&'+GE(O$	, ',,.)
q#j/* 	DA]F(1F(:%NN<)BC	D 	|[1r/   r   rs   c           
      p   | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |d      }| j                  ||      }|d   }| j                  |d      }	|	|dk(  rdnd	}
| j                  ||
      }	| j                  |d
      }| j	                  | j                  |d            }| j	                  | j                  |d            }d }|dk7  r|dk7  r|}d }d|v r| j                  ||      }|g}| j                  i d|d|d| j                  |      d|dd d| j                  | j                  |d            d|d|dd dd d|d
|d|d|dd d| j                  |d      dd | j                  |d      d |d |d|      S )Norder_idcreatedrA   pairrn   quantitybuy	in_amount
out_amountprice	client_id
stop_priceselllast_trade_idr<   clientOrderIdr   r   lastTradeTimestampstatustimeInForcepostOnlyside	stopPricetriggerPricecostamountoriginal_quantityfilled)	remainingaverager   feerW   )	rK   safe_timestamp	parseSider   	omit_zeroparse_ws_trade
safe_orderr   parseStatus)r,   r   rs   r<   r   	orderTyper   r   rn   r   amountFieldr   r   r   rA   r   r   s                    r.   r   zexmo.parse_ws_order  sh     eZ0''y9	$$UF3	~~i(##E62!!(F3!!!%4>*.%-+lK%%e[9F  0t'7'7{'KL~~d&6&6ul&KLY&%8De#''v6EWF  
" 
] 
 Y/ 
 	 

 !$ 
 d&&t'7'7x'HI 
 f 
 D 
 4 
  
 D 
 U 
  
 L 
 D 
  d&&u.AB! 
" d# 
$ ))%<- 
. / 	r/   r   c                 r   | j                  |d      }| j                  |d      }| j                  |      }| j                  |d      }| j                  ||      }|d   }d }|dk7  r|dk7  r|}| j                  | j                  |d      ||||| j                  |d      | j                  |d	      d d d
	|      S )Nr   rA   r   rn   r   r   r   last_trade_pricelast_trade_quantity)	r<   rn   r   rA   r   r   r   r   r   )rK   r   r   
safe_trade)	r,   r   rs   r<   r   r   r   rn   rA   s	            r.   r   zexmo.parse_ws_trade  s    eZ0$$UF3	~~i(##E62!!(F3!Y&%8D""5/:%%e-?@&&u.CD
 
 
 
	r/   c                    | j                  |d      }| j                  | j                  | j                  d}| j	                  ||      }|
 |||       y |dk(  s|dk(  r| j                  |d      }||j                  d      }| j                  |d      }| j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  d}	| j	                  |	|      }
|

 |
||       y t        | j                  d	z   | j                  |      z         )
NrU   )	logged_inrW   
subscribedr]   rX   rI   r   r   )zspot/tickerzspot/walletzmargin/walletzmargin/walletszspot/tradeszmargin/tradeszspot/order_book_updateszspot/orderszmargin/orderszspot/user_tradeszmargin/user_tradesz" received an unsupported message: )rK   handle_authentication_messagehandle_infohandle_subscribedr_   rL   r   rS   r   r   r   r   r   r<   json)r,   rG   rQ   rU   eventseventHandlerrI   rR   channelhandlershandlers              r.   handle_messagezexmo.handle_message  sW       '2;;$$00

 vu5#)X5J#6$$Wg6E C(**5!4#'#5#5#'#6#6%)%8%8&*&9&9#'#5#5%)%7%7/3/E/E#'#5#5%)%7%7(,(=(=*.*?*?" //(G<&FG,477%IIDIIV]L^^__r/   c                     |S N r,   rG   rQ   s      r.   r  zexmo.handle_subscribed%  s	     r/   c                     |S r
  r  r  s      r.   r   zexmo.handle_info/  s	     r/   c                 ,    d}|j                  ||       y )Nauthenticated)rO   )r,   rG   rQ   rC   s       r.   r   z"exmo.handle_authentication_message;  s     &w,r/   c                   K   d}| j                  dd |      \  }}| j                  d   d   |   }| j                  |      }| j                  |j                  |      }|| j                         }| j                          | j                         }	| j                  t        |      z   }
| j                  | j                  |
      | j                  | j                        t        j                  d      }d|	| j                  ||d}| j                  ||      }| j!                  ||||       d {   }||j                  |<   |S 7 w)Nr  r=   r    r   base64login)r:   r<   api_keysignnonce)r>   r%   rG   r_   subscriptionsmillisecondscheck_required_credentialsr5   apiKeystrhmacencodesecrethashlibsha512extendr?   )r,   r@   rC   rA   rB   rD   rG   futuretimer1   signDatar  rE   rQ   s                 r.   r=   zexmo.authenticateH  s)    %88vVeiit$T*S!!5!5{C>$$&D++-)I{{SY.H99T[[2DKK4Lgnn^fgD!;;G kk'51G::c;MMF06F  - Ns   D*E,E-Er
  )-__name__
__module____qualname__r   r+   r5   r   rF   r   rS   rM   rN   r  r   rt   r   r   r~   r   r   r   r   r   r   r   r   r   r
   r   r   r   r   r	   r   r   dictr   r   r   r  r  r   r   r=   __classcell__)r-   s   @r.   r   r      s	   # <
 *, Q Q$<2V <2|$7L;: 68 Q QF Q2 6:" E7 E E82F 2> <@d[] S SS S Sbfglbm S2!9F !9F 37TX\eg UC Us URU Ulpqvlw U>W.v W.r @DB !S ! !S\ !27/ 7/r$3 04$UYbd !U !UC !Us !Uimnsit !UFQ2F Q2f<D <& <E <|D & E ,0`V 0`d 
& 
-F - )+ r/   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   async_supportr   r  r/   r.   <module>r1     s?     O  n n n n 4  )O4"" Or/   