
    E#i                         S SK rS SKJrJr  S SKrS SKJrJrJ	r	J
r
JrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr   " S S\R0                  R2                  5      rg)	    N)
ArrayCacheArrayCacheBySymbolById)AnyBalancesIntMarketOrder	OrderBookStrStringsTickerTickersTrade)Client)List)NotSupportedc            
          ^  \ rS rSrS\4U 4S jjrS r0 4S\4S jjrS\	4S jr
S rS	 r0 4S
\S\4S jjrS0 4S\S\4S jjrS\	4S jrSS0 4S
\S\S\S\\   4S jjrS\	4S jrSSS0 4S
\S\S\S\\   4S jjrS\	4S jrS0 4S
\S\S\4S jjrS\	4S jrS rS r SSS0 4S
\S\S\S\\!   4S jjr"S\	4S jr#S'S\$S\%S\!4S jjr&S'S\$S\%S\4S  jjr'S\	4S! jr(S\	4S" jr)S\	4S# jr*S\	4S$ jr+0 4S% jr,S&r-U =r.$ )(exmo   returnc                 x   > U R                  [        [        U ]  5       SSSSSSSSSS.	SSSSSS	.000 0 0 S
.5      $ )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/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/exmo.pyr,   exmo.describe   sv    dD : < $# $#!%#"&#
 "G F"O3?
  	    c                 |    U R                  U R                  U R                  SS5      S5      nXR                  S'   U$ )N	requestIdr      )sumsafe_integerr'   )r-   r3   s     r/   
request_idexmo.request_id/   s7    HHT..t||[!LaP	$-[!r1   c                 *  #    U R                  U5      I Sh  vN   U R                  SSU5      u  p#SU-   nU R                  S   S   U   nSUS-   /U R                  5       S.nU R	                  Xc5      nU R                  XTXtU5      I Sh  vN $  Nw N7f)	z
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&   r7   r*   watch)r-   paramstypequerymessageHashurlr;   requests           r/   watch_balanceexmo.watch_balance4   s      '''88vV 4'iit$T*!i'(//#
	
 ""94ZZ'PPP 	( Qs"   BBA2B
BBBclientc                    U R                  US5      nUR                  S5      nU R                  US5      nUS:X  a  U R                  U5        OUS:X  a  U R                  U5        SU-   nUR	                  U R
                  U5        g )Ntopic/r   r#   r$   r:   )safe_stringsplitparse_spot_balanceparse_margin_balanceresolvebalance)r-   rK   messagerM   partsrD   rF   s          r/   handle_balanceexmo.handle_balanceF   s~    h   '2C q)6>##G,X%%g. 4't||[1r1   c                    U R                  US5      nU R                  US5      nX0R                  S'   US:X  a  U R                  US0 5      nU R                  US0 5      n[        UR	                  5       5      n[        S[        U5      5       H^  nXg   nU R                  U5      n	U R                  5       n
U R                  XH5      U
S'   U R                  XX5      U
S	'   XR                  U	'   M`     OqUS
:X  ak  U R                  US5      nU R                  U5      n	U R                  5       n
U R                  US5      U
S'   U R                  US5      U
S	'   XR                  U	'   U R                  U R                  5      U l        g )Neventdatainfosnapshotbalancesreservedr   freeusedupdatecurrencyrT   )
rO   
safe_valuerT   listkeysrangelensafe_currency_codeaccountsafe_balance)r-   rU   rZ   r[   r^   r_   
currenciesi
currencyIdcoderj   s              r/   rQ   exmo.parse_spot_balance   s^      '2w/#VJtZ<HtZ<Hhmmo.J1c*o.']
..z:,,."&"2"28"H"&"2"28"H%,T" / h))$
;J**:6DllnG"..tY?GFO"..tZ@GFO!(LL((6r1   c                    U R                  US5      nX R                  S'   [        UR                  5       5      n[	        S[        U5      5       H  nX4   nU R                  U5      nU R                  X%5      nU R                  5       nU R                  US5      US'   U R                  US5      US'   U R                  US5      US'   XR                  U'   U R                  U R                  5      U l        M     g )Nr[   r\   r   r`   ra   rT   total)
rd   rT   re   rf   rg   rh   ri   rj   rO   rk   )	r-   rU   r[   rl   rm   rn   ro   walletrj   s	            r/   rR   exmo.parse_margin_balance   s     w/#V$))+&
q#j/*A#J**:6D__T6FllnG"..vv>GFO"..vv>GFO#//	BGG!(LL,,T\\:DL +r1   symbolc                 0  #    U R                  5       I Sh  vN   U R                  U5      nUS   nU R                  S   S   S   nSU-   nSSUS	   -   /U R                  5       S
.nU R	                  Xb5      nU R                  XEXuU5      I Sh  vN $  N{ N7f)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>`
Nru   r!   r   r"   ticker:r;   spot/ticker:r?   r<   )load_marketsmarketr&   r7   r*   rB   )r-   ru   rC   rz   rG   rF   rU   rH   s           r/   watch_tickerexmo.watch_ticker   s      !!!V$!iit$X.&(!- //#
 ""73ZZ'PPP 	" Qs"   BBA6BBBBNsymbolsc                   #    U R                  5       I Sh  vN   U R                  USS5      n/ n/ n[        S[        U5      5       HD  nU R	                  X   5      nUR                  SUS   -   5        UR                  SUS   -   5        MF     U R                  S   S	   S
   nSUU R                  5       S.nU R                  X5      n	U R                  XsXU	5      I Sh  vN   U R                  U R                  SU5      $  N N#7f)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   rw   ru   rx   r?   r!   r   r"   r;   r<   )ry   market_symbolsrg   rh   rz   appendr&   r7   r*   watch_multiplefilter_by_arraytickers)
r-   r}   rC   messageHashesargsrm   rz   rG   rU   rH   s
             r/   watch_tickersexmo.watch_tickers   s     !!!%%gtU;q#g,'A[[,F  VH-=!=>KK56 ( iit$X.!//#

 ""73!!#ggVVV##DLL(GDD! 	" 	Ws"   DDCDD "DDc                 B   U R                  US5      nUR                  S5      nU R                  US5      nU R                  U5      nU R                  US0 5      nU R	                  U5      nU R                  Xx5      n	SU-   n
XR                  U'   UR                  X5        g )NrM   :r4   r[   rw   )rO   rP   safe_symbolrd   safe_marketparse_tickerr   rS   )r-   rK   rU   rM   
topicPartsmarketIdru   tickerrz   parsedTickerrF   s              r/   handle_tickerexmo.handle_ticker   s    (   '2[[%
##J2!!(+&"5!!(+((8&(+V|1r1   sincelimitc                 X  #    U R                  5       I Sh  vN   U R                  U5      nUS   nU R                  S   S   S   nSU-   nSSUS	   -   /U R                  5       S
.nU R	                  X5      n	U R                  XgXU	5      I Sh  vN n
U R                  XUSS5      $  N N7f)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>`
Nru   r!   r   r"   trades:r;   zspot/trades:r?   r<   	timestampT)ry   rz   r&   r7   r*   rB   filter_by_since_limit)r-   ru   r   r   rC   rz   rG   rF   rU   rH   tradess              r/   watch_tradesexmo.watch_trades  s      !!!V$!iit$X.&(!- //#
 ""73zz#G'RR))&TRR 	" Ss"   B*B&A6B*B(B*(B*c                 j   U R                  US5      nUR                  S5      nU R                  US5      nU R                  U5      nU R                  U5      nU R	                  US/ 5      nSU-   n	U R	                  U R
                  U5      n
U
c6  U R                  U R                  SS5      n[        U5      n
XR
                  U'   [        S[        U5      5       H)  nX   nU R                  X5      nU
R                  U5        M+     XR
                  U'   UR                  U R
                  U   U	5        g )	NrM   r   r4   r[   r   tradesLimit  r   )rO   rP   r   r   rd   r   r6   r'   r   rg   rh   parse_trader   rS   )r-   rK   rU   rM   rV   r   ru   rz   r   rF   storedr   rm   tradeparseds                  r/   handle_tradesexmo.handle_trades4  s       '2C ##E1-!!(+!!(+&"5&(f5>%%dllM4HE&F"(KKq#f+&AIE%%e4FMM&! ' %Ft{{6*K8r1   c                   #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN   U R                  SSU5      u  pVU R                  S   S   U   nSnUc  SU-   nOU R	                  U5      n	U	S   nSU	S   -   nSUS-   /U R                  5       S	.n
U R                  X5      nU R                  XxXU5      I Sh  vN nU R                  XX#S
5      $  N N N7f)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:ru   r;   z/user_tradesr<   T	ry   r@   rA   r&   rz   r7   r*   rB   filter_by_symbol_since_limit)r-   ru   r   r   rC   rD   rE   rG   rF   rz   rU   rH   r   s                r/   watch_my_tradesexmo.watch_my_tradesW  s     !!!'''88$PVWiit$T*>%,K[[(FH%F%x(88K!~% //#
 ""72zz#G'RR00tTT) 	"'$ S2   C$CC$C BC$C"C$ C$"C$c                    U R                  US5      nUR                  S5      nU R                  US5      nSU-   nU R                  US5      n/ nS n	U R                  c/  U R                  U R                  SS5      n
[        U
5      n	Xl        OU R                  n	US:X  a  U R                  US	/ 5      nOUS
:X  a  U R                  US	0 5      nU/nU R                  U5      n0 n[        S[        U5      5       H  nX   nU	R                  U5        SXS   '   M!     [        UR                  5       5      n[        S[        U5      5       H  nUU   nSU-   nUR                  U	U5        M!     UR                  X5        g )NrM   rN   r   r   rZ   r   r   r]   r[   rb   Tru   )rO   rP   myTradesr6   r'   r   rd   parse_tradesrg   rh   r   re   rf   rS   )r-   rK   rU   rM   rV   rD   rF   rZ   	rawTradesr   r   rawTrader   r}   jr   
symbolKeysrm   ru   symbolSpecificMessageHashs                       r/   handle_my_tradesexmo.handle_my_tradesv  ss   t   '2C q)!D(  '2	== %%dllM4HE-e4H$M}}HJ<Ihw;H!
I""9-q#f+&AIEOOE"'+G(O$ ' ',,.)
q#j/*A]F(3f(<%NN8%>? + 	x-r1   c                 r  #    U R                  5       I Sh  vN   U R                  U5      nUS   nU R                  S   S   S   nSU-   nU R                  US5      nSU R	                  5       S	US
   -   /S.nU R                  Xs5      nU R                  XVX5      I Sh  vN n	U	R                  5       $  N N7f)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
Nru   r!   r   r"   
orderbook:aggregationr;   zspot/order_book_updates:r?   )r=   r?   r>   )ry   rz   r&   omitr7   r*   rB   r   )
r-   ru   r   rC   rz   rG   rF   r;   rH   	orderbooks
             r/   watch_order_bookexmo.watch_order_book  s      !!!V$!iit$X."V+6=1!//#*VD\9
	 ""95**SwLL	   	" Ms"   B7B3BB7B5B75B7c                    U R                  US5      nUR                  S5      nU R                  US5      nU R                  U5      nU R                  US0 5      nSU-   nU R	                  US5      n	X`R
                  ;  a  U R                  0 5      U R
                  U'   U R
                  U   n
U R                  US5      nUS:X  a&  U R                  XvU	S	S
5      nU
R                  U5        OhU R                  US
/ 5      nU R                  US	/ 5      nU R                  U
S   U5        U R                  U
S   U5        XS'   U R                  U	5      U
S'   UR                  X5        g )NrM   r   r4   r[   r   tsrZ   r]   bidaskasksbidsr   datetime)rO   rP   r   rd   r6   
orderbooks
order_bookparse_order_bookreset	safe_listhandle_deltasiso8601rS   )r-   rK   rU   rM   rV   r   ru   	orderBookrF   r   r   rZ   r]   r   r   s                  r/   handle_order_bookexmo.handle_order_book  sV   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%.k"$(LL$;Ij!y.r1   c                 L    U R                  USS5      nUR                  U5        g )Nr   r4   )parse_bid_ask
storeArray)r-   booksidedeltabidAsks       r/   handle_deltaexmo.handle_delta!  s$    ##E1a0F#r1   c                 d    [        S[        U5      5       H  nU R                  XU   5        M     g )Nr   )rg   rh   r   )r-   r   deltasrm   s       r/   r   exmo.handle_deltas%  s)    q#f+&Ahq	2 'r1   c                   #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN   U R                  SSU5      u  pVU R                  S   S   U   nSnUc  SU-   nOU R	                  U5      n	U	S   nSU	S   -   nSUS-   /U R                  5       S	.n
U R                  X5      nU R                  XxXU5      I Sh  vN nU R                  XX#S
5      $  N N N7f)ar  

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:ru   r;   z/ordersr<   Tr   )r-   ru   r   r   rC   rD   rE   rG   rF   rz   rU   rH   orderss                r/   watch_ordersexmo.watch_orders)  s     !!!'''88fUiit$T*>#d*K[[(FH%F#fX&66K!y  //#
 ""72zz#G'RR00tTT) 	"'$ Sr   c                 
   U R                  US5      nUR                  S5      nU R                  US5      nSU-   nU R                  US5      nU R                  c-  U R                  U R                  SS5      n[        U5      U l        U R                  n	/ n
US:X  a  U R                  US	/ 5      n
O*US
:X  a$  U R                  US	0 5      nU
R                  U5        0 n[        S[        U
5      5       H.  nU R                  X   5      nU	R                  U5        SXS   '   M0     [        UR                  5       5      n[        S[        U5      5       H  nUU   nSU-   nUR                  U	U5        M!     UR                  X5        g )NrM   rN   r   r   rZ   ordersLimitr   r]   r[   rb   Tru   )rO   rP   r   r6   r'   r   rd   	safe_dictr   rg   rh   parse_ws_orderre   rf   rS   )r-   rK   rU   rM   rV   rD   rF   rZ   r   cachedOrders	rawOrdersrawOrderr}   r   orderr   rm   ru   r   s                      r/   handle_ordersexmo.handle_ordersL  so   p   '2C q)$&  '2;;%%dllM4HE07DK{{	J<Ih~~gvr:HX&q#i.)A''	5E&'+G(O$ * ',,.)
q#j/*A]F(1F(:%NN<)BC + 	|1r1   r   rz   c           
      v   U R                  US5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  US5      nU R                  Xr5      nUS   nU R                  US5      n	U	c  US:X  a  SOS	n
U R                  X5      n	U R                  US
5      nU R	                  U R                  US5      5      nU R	                  U R                  US5      5      nS nUS:w  a  US:w  a  UnS nSU;   a  U R                  X5      nU/nU R                  0 SU_SU_SU R                  U5      _SU_SS _SU R                  U R                  US5      5      _SU_SU_SS _SS _SU_S
U_SU_SU_SS _SU R                  US5      _SS _U R                  US5      S US US.EU5      $ )Norder_idcreatedrD   pairru   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   feer\   )	rO   safe_timestamp	parseSider   	omit_zeroparse_ws_trade
safe_orderr   parseStatus)r-   r   rz   r?   r   	orderTyper   r   ru   r   amountFieldr   r   r   rD   r   r   s                    r/   r   exmo.parse_ws_order  sb     eZ0''y9	$$UF3	~~i(##E62!!(3!!!%4>*.%-+lK%%e9F  0t'7'7{'KL~~d&6&6ul&KLY&%8De#''6EWF  
" 
] 
 Y/ 
 	 

 !$ 
 d&&t'7'7x'HI 
 f 
 D 
 4 
  
 D 
 U 
  
 L 
 D 
  d&&u.AB! 
" d# 
$ ))%<- 
. / 	r1   r   c                 t   U R                  US5      nU R                  US5      nU R                  U5      nU R                  US5      nU R                  Xb5      nUS   nS nUS:w  a  US:w  a  UnU R                  U R                  US5      UUUUU R                  US5      U R                  US	5      S S S
.	U5      $ )Nr   rD   r   ru   r   r   r   last_trade_pricelast_trade_quantity)	r?   ru   r   rD   r   r   r   r   r  )rO   r  r   
safe_trade)	r-   r   rz   r?   r
  r   r   ru   rD   s	            r/   r  exmo.parse_ws_trade  s    eZ0$$UF3	~~i(##E62!!(3!Y&%8D""5/:%%e-?@&&u.CD
 
 
 
	r1   c                    U R                  US5      nU R                  U R                  U R                  S.nU R	                  XC5      nUb	  U" X5        g US:X  d  US:X  a  U R                  US5      nUb  UR                  S5      nU R                  US5      nU R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S.n	U R	                  X5      n
U
b	  U
" X5        g [        U R                  S	-   U R                  U5      -   5      e)
NrZ   )	logged_inr\   
subscribedrb   r]   rM   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: )rO   handle_authentication_messagehandle_infohandle_subscribedrd   rP   r   rW   r   r   r   r   r   r?   json)r-   rK   rU   rZ   eventseventHandlerrM   rV   channelhandlershandlers              r/   handle_messageexmo.handle_message  sO       '2;;$$00

 v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(,(=(=*.*?*?" //(<&F,477%IIDIIV]L^^__r1   c                     U$ N r-   rK   rU   s      r/   r  exmo.handle_subscribed%  s	     r1   c                     U$ r!  r"  r#  s      r/   r  exmo.handle_info/  s	     r1   c                 *    SnUR                  X#5        g )Nauthenticated)rS   )r-   rK   rU   rF   s       r/   r  "exmo.handle_authentication_message;  s     &w,r1   c                   #    SnU R                  SS U5      u  p4U R                  S   S   U   nU R                  U5      nU R                  UR                  U5      nUc  U R                  5       nU R                  5         U R                  5       n	U R                  [        U5      -   n
U R                  U R                  U
5      U R                  U R                  5      [        R                  S5      nSU	U R                  UUS.nU R                  X5      nU R!                  XRX5      I S h  vN nXvR                  U'   U$  N7f)Nr(  r@   r!   r   base64login)r=   r?   api_keysignnonce)rA   r&   rK   rd   subscriptionsmillisecondscheck_required_credentialsr7   apiKeystrhmacencodesecrethashlibsha512extendrB   )r-   rC   rF   rD   rE   rG   rK   futuretimer3   signDatar.  rH   rU   s                 r/   r@   exmo.authenticateH  s    %88vViit$T*S!!5!5{C>$$&D++-)I{{SY.H99T[[2DKK4Lgnn^fgD!;;G kk'1G::cMMF06  - Ns   D'E )D>*E )rT   r   r   r!  )/__name__
__module____qualname____firstlineno__r   r,   r7   r   rI   r   rW   rQ   rR   r4  r   r{   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@   __static_attributes____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 - )+  r1   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r8  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"  r1   r/   <module>rN     s?     O  n n n n 4  )O4"" Or1   