
    eiʄ                         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j        j                  ZdS )	    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                     |                      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    K/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/pro/exmo.pyr+   zexmo.describe   s    dD 1 1 : : < < $# $#!%#"&#
 
 "G F"O 3?
 ?
   	    c                     |                                   |                     |                     | j        dd          d          }|| j        d<   |                                  |S )N	requestIdr      )lock_idsumsafe_integerr&   	unlock_id)r,   r1   s     r.   
request_idzexmo.request_id/   sX    HHT..t|[!LLaPP	$-[!r/   c                 N  K   |                      |           d{V  |                     dd|          \  }}d|z   }| j        d         d         |         }d|dz   g|                                 d}|                     ||          }|                     |||||           d{V S )	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%   r7   r)   watch)r,   paramstypequerymessageHashurlr:   requests           r.   watch_balancezexmo.watch_balance6   s       '''''''''88vVVe 4'it$T*!i'(//##
 
	
 ""9e44ZZ[';PPPPPPPPPr/   clientc                 6   |                      |d          }|                    d          }|                      |d          }|dk    r|                     |           n|dk    r|                     |           d|z   }|                    | j        |           d S )Ntopic/r   r"   r#   r9   )safe_stringsplitparse_spot_balanceparse_margin_balanceresolvebalance)r,   rI   messagerK   partsrC   rE   s          r.   handle_balancezexmo.handle_balanceH   s    h   '22C  q))6>>##G,,,,X%%g... 4't|[11111r/   c                 x   |                      |d          }|                     |d          }|| j        d<   |dk    r|                     |di           }|                     |di           }t          |                                          }t          dt          |                    D ]o}||         }|                     |          }	|                                 }
|                      ||          |
d<   |                      ||          |
d	<   |
| j        |	<   pn|d
k    r{|                      |d          }|                     |          }	|                                 }
|                      |d          |
d<   |                      |d          |
d	<   |
| j        |	<   | 	                    | j                  | _        d S )Neventdatainfosnapshotbalancesreservedr   freeusedupdatecurrencyrR   )
rM   
safe_valuerR   listkeysrangelensafe_currency_codeaccountsafe_balance)r,   rS   rW   rX   r[   r\   
currenciesi
currencyIdcoderg   s              r.   rO   zexmo.parse_spot_balance   s      '22w//#VJtZ<<HtZ<<Hhmmoo..J1c*oo.. - -']
..z::,,.."&"2"28Z"H"H"&"2"28Z"H"H%,T""- h))$
;;J**:66DllnnG"..tY??GFO"..tZ@@GFO!(DL((66r/   c                 >   |                      |d          }|| j        d<   t          |                                          }t	          dt          |                    D ]}||         }|                     |          }|                      ||          }|                                 }|                     |d          |d<   |                     |d          |d<   |                     |d          |d<   || j        |<   | 	                    | j                  | _        d S )NrX   rY   r   r]   r^   rR   total)
ra   rR   rb   rc   rd   re   rf   rg   rM   rh   )	r,   rS   rX   ri   rj   rk   rl   walletrg   s	            r.   rP   zexmo.parse_margin_balance   s    w//#V$))++&&
q#j//** 		; 		;A#AJ**:66D__T:66FllnnG"..vv>>GFO"..vv>>GFO#//	BBGG!(DL,,T\::DLL		; 		;r/   symbolc                 ^  K   |                                   d{V  |                     |          }|d         }| j        d         d         d         }d|z   }dd|d	         z   g|                                 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

        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>`
        Nrp   r    r   r!   ticker:r:   spot/ticker:r>   r;   )load_marketsmarketr%   r7   r)   rA   )r,   rp   rB   ru   rF   rE   rS   rG   s           r.   watch_tickerzexmo.watch_ticker   s       !!!!!!!!!V$$!it$X.&(!- //##
 
 ""7F33ZZ[';PPPPPPPPPr/   Nsymbolsc                 b  K   |                                   d{V  |                     |dd          }g }g }t          dt          |                    D ]Y}|                     ||                   }|                    d|d         z              |                    d|d         z              Z| j        d         d	         d
         }d||                                 d}|                     ||          }	| 	                    |||	||	           d{V  | 
                    | j        d|          S )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   rr   rp   rs   r>   r    r   r!   r:   r;   )rt   market_symbolsrd   re   ru   appendr%   r7   r)   watch_multiplefilter_by_arraytickers)
r,   rw   rB   messageHashesargsrj   ru   rF   rS   rG   s
             r.   watch_tickerszexmo.watch_tickers   sQ      !!!!!!!!!%%gtU;;q#g,,'' 	7 	7A[[,,F  VH-=!=>>>KK56666it$X.!//##
 

 ""7F33!!#}g}gVVVVVVVVV##DL(GDDDr/   c                    |                      |d          }|                    d          }|                      |d          }|                     |          }|                     |di           }|                     |          }|                     ||          }	d|z   }
|	| j        |<   |                    |	|
           d S )NrK   :r2   rX   rr   )rM   rN   safe_symbolra   safe_marketparse_tickerr}   rQ   )r,   rI   rS   rK   
topicPartsmarketIdrp   tickerru   parsedTickerrE   s              r.   handle_tickerzexmo.handle_ticker   s    (   '22[[%%
##J22!!(++&"55!!(++((88&(+V|[11111r/   sincelimitc                   K   |                                   d{V  |                     |          }|d         }| j        d         d         d         }d|z   }dd|d	         z   g|                                 d
}|                     ||          }	|                     |||	||	           d{V }
|                     |
||dd          S )a  
        get the list of most recent trades for a particular symbol
        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        Nrp   r    r   r!   trades:r:   zspot/trades:r>   r;   	timestampT)rt   ru   r%   r7   r)   rA   filter_by_since_limit)r,   rp   r   r   rB   ru   rF   rE   rS   rG   tradess              r.   watch_tradeszexmo.watch_trades  s       !!!!!!!!!V$$!it$X.&(!- //##
 
 ""7F33zz#{G['RRRRRRRR))&%TRRRr/   c                    |                      |d          }|                    d          }|                      |d          }|                     |          }|                     |          }|                     |dg           }d|z   }	|                     | j        |          }
|
5|                     | j        dd          }t          |          }
|
| j        |<   t          dt          |                    D ]5}||         }|                     ||          }|
                    |           6|
| j        |<   |                    | j        |         |	           d S )	NrK   r   r2   rX   r   tradesLimit  r   )rM   rN   r   r   ra   r   r5   r&   r   rd   re   parse_traderz   rQ   )r,   rI   rS   rK   rT   r   rp   ru   r   rE   storedr   rj   tradeparseds                  r.   handle_tradeszexmo.handle_trades6  sO       '22C  ##E1--!!(++!!(++&"55&(f55>%%dlM4HHE&&F"(DKq#f++&& 	" 	"A1IE%%eV44FMM&!!!!$Ft{6*K88888r/   c                   K   |                                   d{V  |                     |           d{V  |                     dd|          \  }}| j        d         d         |         }d}|d|z   }n(|                     |          }	|	d         }d|	d         z   }d|dz   g|                                 d	}
|                     |
|          }|                     |||||           d{V }|                     ||||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>`
        Nr   r    r   	myTrades:rp   r:   z/user_tradesr;   T	rt   r?   r@   r%   ru   r7   r)   rA   filter_by_symbol_since_limit)r,   rp   r   r   rB   rC   rD   rF   rE   ru   rS   rG   r   s                r.   watch_my_tradeszexmo.watch_my_tradesY  sM      !!!!!!!!!'''''''''88$PVWWeit$T*>%,KK[[((FH%F%x(88K!~% //##
 
 ""7E22zz#{G['RRRRRRRR00tTTTr/   c                 v   |                      |d          }|                    d          }|                      |d          }d|z   }|                      |d          }g }d }	| j        3|                     | j        dd          }
t          |
          }	|	| _        n| j        }	|dk    r|                     |d	g           }n |d
k    r|                     |d	i           }|g}|                     |          }i }t          dt          |                    D ]*}||         }|	
                    |           d||d         <   +t          |                                          }t          dt          |                    D ]%}||         }d|z   }|                    |	|           &|                    |	|           d S )NrK   rL   r   r   rW   r   r   rZ   rX   r_   Trp   )rM   rN   myTradesr5   r&   r   ra   parse_tradesrd   re   rz   rb   rc   rQ   )r,   rI   rS   rK   rT   rC   rE   rW   	rawTradesr   r   rawTrader   rw   jr   
symbolKeysrj   rp   symbolSpecificMessageHashs                       r.   handle_my_tradeszexmo.handle_my_tradesx  s   t   '22C  q))!D(  '22	= %%dlM4HHE-e44H$DMM}HJ<<IIhw;;H!
I""9--q#f++&& 	, 	,A1IEOOE"""'+GE(O$$',,..))
q#j//** 	@ 	@A]F(3f(<%NN8%>????x-----r/   c                   K   |                                   d{V  |                     |          }|d         }| j        d         d         d         }d|z   }|                     |d          }d|                                 d	|d
         z   gd}|                     ||          }|                     ||||           d{V }	|	                                S )a  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/?id=order-book-structure>` indexed by market symbols
        Nrp   r    r   r!   
orderbook:aggregationr:   zspot/order_book_updates:r>   )r<   r>   r=   )rt   ru   r%   omitr7   r)   rA   r   )
r,   rp   r   rB   ru   rF   rE   r:   rG   	orderbooks
             r.   watch_order_bookzexmo.watch_order_book  s       !!!!!!!!!V$$!it$X."V+6=11!//##*VD\9
 
	 ""9f55**S+wLLLLLLLL	   r/   c                 D   |                      |d          }|                    d          }|                      |d          }|                     |          }|                     |di           }d|z   }|                     |d          }	|| j        vr|                     i           | j        |<   | j        |         }
|                      |d          }|dk    r/|                     |||	d	d
          }|
                    |           n| 	                    |d
g           }| 	                    |d	g           }| 
                    |
d         |           | 
                    |
d         |           |	|
d<   |                     |	          |
d<   |                    |
|           d S )NrK   r   r2   rX   r   tsrW   rZ   bidaskasksbidsr   datetime)rM   rN   r   ra   r5   
orderbooks
order_bookparse_order_bookreset	safe_listhandle_deltasiso8601rQ   )r,   rI   rS   rK   rT   r   rp   	orderBookrE   r   r   rW   rZ   r   r   s                  r.   handle_order_bookzexmo.handle_order_book  s   D   '22C  ##E1--!!(++OOGVR88	"V+%%gt44	$/))&*oob&9&9DOF#OF+	  '22J,,Y	5RWXXHOOH%%%%>>)UB77D>>)UB77Dy0$777y0$777%.Ik"$(LL$;$;Ij!y+.....r/   c                 ^    |                      |dd          }|                    |           d S )Nr   r2   )parse_bid_ask
storeArray)r,   booksidedeltabidAsks       r.   handle_deltazexmo.handle_delta#  s3    ##E1a00F#####r/   c                 ~    t          dt          |                    D ]}|                     |||                    d S )Nr   )rd   re   r   )r,   r   deltasrj   s       r.   r   zexmo.handle_deltas'  sH    q#f++&& 	3 	3Ahq	2222	3 	3r/   c                   K   |                                   d{V  |                     |           d{V  |                     dd|          \  }}| j        d         d         |         }d}|d|z   }n(|                     |          }	|	d         }d|	d         z   }d|dz   g|                                 d	}
|                     |
|          }|                     |||||           d{V }|                     ||||d
          S )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:rp   r:   z/ordersr;   Tr   )r,   rp   r   r   rB   rC   rD   rF   rE   ru   rS   rG   orderss                r.   watch_orderszexmo.watch_orders+  sL      !!!!!!!!!'''''''''88fUUeit$T*>#d*KK[[((FH%F#fX&66K!y  //##
 
 ""7E22zz#{G['RRRRRRRR00tTTTr/   c                    |                      |d          }|                    d          }|                      |d          }d|z   }|                      |d          }| j        0|                     | j        dd          }t          |          | _        | j        }	g }
|dk    r|                     |d	g           }
n2|d
k    r,|                     |d	i           }|
                    |           i }t          dt          |
                    D ]=}|                     |
|                   }|	                    |           d||d         <   >t          |                                          }t          dt          |                    D ]%}||         }d|z   }|                    |	|           &|                    |	|           d S )NrK   rL   r   r   rW   ordersLimitr   rZ   rX   r_   Trp   )rM   rN   r   r5   r&   r   ra   	safe_dictrz   rd   re   parse_ws_orderrb   rc   rQ   )r,   rI   rS   rK   rT   rC   rE   rW   r   cachedOrders	rawOrdersrawOrderrw   r   orderr   rj   rp   r   s                      r.   handle_orderszexmo.handle_ordersN  s   p   '22C  q))$&  '22;%%dlM4HHE077DK{	J<<IIh~~gvr::HX&&&q#i..)) 	, 	,A''	!55E&&&'+GE(O$$',,..))
q#j//** 	D 	DA]F(1F(:%NN<)BCCCC|[11111r/   r   ru   c           
         |                      |d          }|                     |d          }|                      |d          }|                     |          }|                      |d          }|                     ||          }|d         }|                      |d          }	|	 |dk    rdnd	}
|                      ||
          }	|                      |d
          }|                     |                      |d                    }|                     |                      |d                    }d }|dk    r|dk    r|}d }d|v r|                     ||          }|g}|                     i d|d|d|                     |          d|dd d|                     |                      |d                    d|d|dd dd d|d
|d|d|dd d|                      |d          dd |                      |d          d |d |d|          S )Norder_idcreatedrC   pairrp   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   feerY   )	rM   safe_timestamp	parseSider   	omit_zeroparse_ws_trade
safe_orderr   parseStatus)r,   r   ru   r>   r   	orderTyper   r   rp   r   amountFieldr   r   r   rC   r   r   s                    r.   r   zexmo.parse_ws_order  s     eZ00''y99	$$UF33	~~i((##E622!!(F33!!!%44>*.%--++lK%%e[99F  00t'7'7{'K'KLL~~d&6&6ul&K&KLLY&%8%8De##''v66EWF  
" 
] 
 Y// 
 	 

 !$ 
 d&&t'7'7x'H'HII 
 f 
 D 
 4 
  
 D 
 U 
  
 L 
 D 
  d&&u.ABB! 
" d# 
$ ))%<<- 
  
  
. /  	r/   r   c                    |                      |d          }|                      |d          }|                     |          }|                      |d          }|                     ||          }|d         }d }|dk    r|dk    r|}|                     |                      |d          |||||                      |d          |                      |d	          d d d
	|          S )Nr   rC   r   rp   r   r   r   last_trade_pricelast_trade_quantity)	r>   rp   r   rC   r   r   r   r   r   )rM   r   r   
safe_trade)	r,   r   ru   r>   r   r   r   rp   rC   s	            r.   r   zexmo.parse_ws_trade  s   eZ00$$UF33	~~i((##E622!!(F33!Y&%8%8D""5/::%%e-?@@&&u.CDD
 
 
 
 
 
 
	r/   c                 r   |                      |d          }| j        | j        | j        d}|                     ||          }| |||           d S |dk    s|dk    r|                      |d          }||                    d          }|                      |d          }| j        | j        | j        | j        | j        | j        | j	        | j
        | j
        | j        | j        d}	|                     |	|          }
|
 |
||           d S t          | j        d	z   |                     |          z             )
NrW   )	logged_inrY   
subscribedr_   rZ   rK   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: )rM   handle_authentication_messagehandle_infohandle_subscribedra   rN   r   rU   r   r   r   r   r   r>   json)r,   rI   rS   rW   eventseventHandlerrK   rT   channelhandlershandlers              r.   handle_messagezexmo.handle_message  sg       '22;$0
 

 vu55#L)))FX5J#6#6$$Wg66E C((**5!44#'#5#'#6%)%8&*&9#'#5%)%7/3/E#'#5%)%7(,(=*.*?" " //(G<<&GFG,,,F47%IIDIIV]L^L^^___r/   c                     |S N r,   rI   rS   s      r.   r  zexmo.handle_subscribed'  s	     r/   c                     |S r  r  r  s      r.   r  zexmo.handle_info1  s	     r/   c                 6    d}|                     ||           d S )Nauthenticated)rQ   )r,   rI   rS   rE   s       r.   r   z"exmo.handle_authentication_message=  s#     &w,,,,,r/   c                   K   d}|                      dd |          \  }}| j        d         d         |         }|                     |          }|                     |j        |          }||                                 }|                                  |                                 }	| j        t          |          z   }
| 
                    |                     |
          |                     | j                  t          j        d          }d|	| j        ||d}|                     ||          }|                     ||||           d {V }||j        |<   |S )Nr  r?   r    r   base64login)r<   r>   api_keysignnonce)r@   r%   rI   ra   subscriptionsmillisecondscheck_required_credentialsr7   apiKeystrhmacencodesecrethashlibsha512extendrA   )r,   rB   rE   rC   rD   rF   rI   futuretimer1   signDatar  rG   rS   s                 r.   r?   zexmo.authenticateJ  sM     %88vVVeit$T*S!!!5{CC>$$&&D++---))I{SYY.H99T[[22DKK4L4Lgn^fggD!; G kk'511G::c;MMMMMMMMF06F -r/   r  )-__name__
__module____qualname__r   r+   r7   r   rH   r   rU   rO   rP   r  r   rv   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 Q Q Q Q$<2V <2 <2 <2 <2|$7 $7 $7L; ; ;: 68 Q Q QF Q Q Q Q2 6:" E E7 E E E E E82F 2 2 2 2> <@d[] S S SS S Sbfglbm S S S S2!9F !9 !9 !9 !9F 37TX\eg U UC Us URU Ulpqvlw U U U U>W.v W. W. W. W.r @DB ! !S ! !S\ ! ! ! !27/ 7/ 7/ 7/ 7/r$ $ $3 3 3 04$UYbd !U !U !UC !Us !Uimnsit !U !U !U !UFQ2F Q2 Q2 Q2 Q2f< <D <& <E < < < <| D & E    ,0`V 0` 0` 0` 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>r2     s        O O O O O O O O  n n n n n n n n n n n n n n n n n n n n n n n n n n 4 4 4 4 4 4       ) ) ) ) ) )Q Q Q Q Q4" Q Q Q Q Qr/   