
    i7                         d dl Zd dlmZ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 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ArrayCacheByTimestamp)BalancesIntOrder	OrderBookStrTickerTrade)Client)List)AuthenticationErrorc            
       &    e Zd Z fdZi fdedefdZdefdZd,dZ	i fd	Z
i fd
Zi fdZi 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efdZdi fdededefdZdefdZd ZdefdZd Z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,defdZ d,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 Z%d,d!Z&d" Z'd# Z(i fde)fd$Z*defd%Z+i fd&Z,i fd'Z-defd(Z.defd)Z/defd*Z0d+ Z1 xZ2S )-mexcc                 8   |                      t          t          |                                           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ddddddddidddddiidddddddd d!d"d#d$
d%d&d'd d(| j        d)d*i d+          S ),NwsTcancelAllOrdersWsFcancelOrdersWscancelOrderWscreateOrderWseditOrderWsfetchBalanceWsfetchOpenOrdersWsfetchOrderWsfetchTradesWswatchBalancewatchMyTrades
watchOHLCVwatchOrderBookwatchOrderswatchTickerwatchTickerswatchTradesapizwss://wbs.mexc.com/wszwss://contract.mexc.com/ws)spotswapO Min1Min5Min15Min30Min60Hour4Hour8Day1Week1Month1)
1m5m15m30m1h4h8h1d1w1M      )snapshotDelaysnapshotMaxRetries)listenKeyRefreshRate
timeframesr    	listenKeyi'  )ping	keepAlive)hasurlsoptions	streaming
exceptions)deep_extendsuperr   describerD   )self	__class__s    S/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/pro/mexc.pyrM   zmexc.describe   s   dD 1 1 : : < <d#U !%  	
   u !% $U       d !$ t  t!" #$ t% *  7 <  )0 ! ""!!! !"  &(*+# # "' , 	" m8?
 8?
 8 8 8	    symbolreturnc                 .  K   |                                   d{V  |                     |          }d|d         z   }|d         r(d|d         z   }|                     |||           d{V S d}d|d         i}|                     ||||           d{V S )a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :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>`
        Nticker:rR   r&   zspot@public.bookTicker.v3.api@idz
sub.ticker)load_marketsmarketwatch_spot_publicwatch_swap_public)rN   rR   paramsrX   messageHashchannelrequestParamss          rP   watch_tickerzmexc.watch_tickerL   s       !!!!!!!!!V$$&"22&> 	]6EG//fMMMMMMMMM"G&,M //mU[\\\\\\\\\rQ   clientc                    |                      |dd          }|                     |dd          }|                     |d          }|                     |          }|d         }d }|d         r4|                     ||          }||d<   |                     |          |d<   n|                     ||          }|| j        |<   d	|z   }	|                    ||	           d S )
NddatasrR   tr&   	timestampdatetimerU   )	safe_value_2safe_string_2safe_integersafe_marketparse_ws_tickeriso8601parse_tickertickersresolve)
rN   r`   message	rawTickermarketIdrf   rX   rR   tickerr\   s
             rP   handle_tickerzmexc.handle_ticker`   s     %%gsF;;	%%gsH==%%gs33	!!(++!&> 	:)))V<<F"+F;!%i!8!8F:&&y&99F%V&(v{+++++rQ   Nc                 f   |                      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 dd dd dd d |d|          S )NrR   rf   rg   openhighlowclosebidb	bidVolumeBaska	askVolumeAvwappreviousClosechange
percentageaverage
baseVolume)quoteVolumeinfo)safe_tickersafe_symbolsafe_number)rN   rt   rX   s      rP   rl   zmexc.parse_ws_ticker~   sU     !
d&&tV44!
!
 !
 D	!

 D!
 4!
 T!
 4##FC00!
 ))&#66!
 4##FC00!
 ))&#66!
 D!
 T!
 d!
 $!
  t!!
" $#!
$  '!
 !
 !
( )  	rQ   c                    K   | j         d         d         d         }d|gd}|                     |||                     ||          |           d {V S )Nr%   r   r&   SUBSCRIPTIONmethodr[   )rG   watchextend)rN   r]   r\   r[   urlrequests         rP   rY   zmexc.watch_spot_public   sk      it$V,$i
 
 ZZ[$++gv2N2NPWXXXXXXXXXrQ   c                   K   |                                   |                     |           d {V }| j        d         d         d         dz   |z   }d|gd}|                     |||                     ||          |           d {V S )Nr%   r   r&   ?listenKey=r   r   )check_required_credentialsauthenticaterG   r   r   )rN   r]   r\   r[   rC   r   r   s          rP   watch_spot_privatezmexc.watch_spot_private   s      '')))++G44444444	it$V,}<yH$i
 
 ZZ[$++gv2N2NPWXXXXXXXXXrQ   c                    K   | j         d         d         d         }||d}|                     ||          }|                     ||||           d {V S )Nr%   r   r'   r   param)rG   r   r   )rN   r]   r\   r^   r[   r   r   rq   s           rP   rZ   zmexc.watch_swap_public   sm      it$V,"
 
 ++gv..ZZ[';GGGGGGGGGrQ   c                   K   |                                   d}| j        d         d         d         }t          |                                           }| j        |z   }|                     |                     |          |                     | j                  t          j	                  }|| j        ||dd}| 
                    ||          }	|                     |||	|           d {V S )Nloginr%   r   r'   )apiKey	signaturereqTimer   )r   rG   strmillisecondsr   hmacencodesecrethashlibsha256r   r   )
rN   r\   r[   r]   r   rf   payloadr   r   rq   s
             rP   watch_swap_privatezmexc.watch_swap_private   s      '')))it$V,))++,,	+	)IIdkk'22DKK4L4Lgn]]	+&$ 
 
 ++gv..ZZ['7CCCCCCCCCrQ   r3   sincelimitc                 "  K   |                                   d{V  |                     |          }|d         }|                     | j        di           }|                     ||          }d|z   dz   |z   }	d}
|d         r/d|d         z   d	z   |z   }|                     ||	|           d{V }
n+d
}|d         |d}|                     ||	||           d{V }
| j        r|
                    ||          }| 	                    |
||dd          S )a  
        :see: https://mxcdevelop.github.io/apidocs/spot_v3_en/#kline-streams
        watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        NrR   rB   candles::r&   zspot@public.kline.v3.api@rV   @z	sub.kline)rR   intervalr   T)
rW   rX   
safe_valuerH   safe_stringrY   rZ   
newUpdatesgetLimitfilter_by_since_limit)rN   rR   	timeframer   r   r[   rX   rB   timeframeIdr\   ohlcvr]   r^   s                rP   watch_ohlcvzmexc.watch_ohlcv   s^      !!!!!!!!!V$$!__T\<DD
&&z9== 6)C/);&> 		^1F4L@3FTG00+vNNNNNNNNEE!G ,' M 00+}V\]]]]]]]]E? 	2NN6511E))%q$GGGrQ   c                    |                      |ddi           }|                     |d|          }|                     |dd          }|                     | j        di           }|                     ||          }|                     |dd          }|                     |          }	|	d         }
d	|
z   d
z   |z   }|                     ||	          }|                     | j        |
i           | j        |
<   |                     | j        |
         |          }|;|                     | j        dd          }t          |          }|| j        |
         |<   |
                    |           |                    ||           d S )Nrb   rc   kir   rB   rd   rR   r   r   
OHLCVLimit  )rh   r   ri   rH   find_timeframerk   parse_ws_ohlcvohlcvsrj   r   appendrp   )rN   r`   rq   rb   rawOhlcvr   rB   r   rs   rX   rR   r\   parsedstoredr   s                  rP   handle_ohlcvzmexc.handle_ohlcv   ss   ^ gsFB77??1c1--((3
CC__T\<DD
''Z@@	%%gsH==!!(++! 6)C/);$$Xv66"oodk62FFFV!4i@@>%%dlL$GGE*511F-3DK	*fv{+++++rQ   c           
         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |dd          gS )Nre   ohlcvq)safe_timestampr   safe_number_2)rN   r   rX   s      rP   r   zmexc.parse_ws_ohlcv-  s    D s++UC((UC((UC((UC((uc3//
 	
rQ   c                 `  K   |                                   d{V  |                     |          }|d         }d|z   }d}|d         r)d|d         z   }|                     |||           d{V }n*d}d|d         i}|                     ||||           d{V }|                                S )aD  
        :see: https://mxcdevelop.github.io/apidocs/spot_v3_en/#diff-depth-stream
        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
        NrR   
orderbook:r&   z"spot@public.increase.depth.v3.api@rV   z	sub.depth)rW   rX   rY   rZ   r   )	rN   rR   r   r[   rX   r\   	orderbookr]   r^   s	            rP   watch_order_bookzmexc.watch_order_bookW  s       !!!!!!!!!V$$!"V+	&> 	b:VD\IG"44Wk6RRRRRRRRII!G&,M #44Wk=Z`aaaaaaaaI   rQ   c                     |                      |d          }|                    d          }|                      |d          }|                     |          }|                     i           | j        |<   d S )Nmsgr      )r   splitr   
order_book
orderbooks)rN   r`   rq   r   partsrs   rR   s          rP   handle_order_book_subscriptionz#mexc.handle_order_book_subscriptionp  sn     w..		###E1--!!(++"&//""5"5rQ   c                 N   |                      |d          }|                     |d          }|                     |dd          }||dz
  k     rdS t          dt	          |                    D ]+}||         }|                     |dd          }||k    r|c S ,t	          |          S )Nnoncer   rversion   )rj   r   safe_integer_2rangelen)	rN   r   cacher   
firstDeltafirstDeltaNoncer   delta
deltaNonces	            rP   get_cache_indexzmexc.get_cache_indexz  s    !!)W55__UA..
--j#yII?Q&&&2q#e**%% 	 	A!HE,,UCCCJU"" #5zzrQ   c                    |                      |dd          }|                     |dd          }|                     |          }d|z   }|                     |j        |          }|                     |d          }|du r'd|j        |<   |                     i           | j        |<   | j        |         }	|                     |	d	          }
|
lt          |	j	                  }| 
                    d
dd          }||k    r|                     | j        ||||i            |	j	                            |           d S 	 |                     |	|           |                     |dd          }||	d<   |                     |          |	d<   n5# t"          $ r(}|j        |= |                    ||           Y d }~nd }~ww xY w|                    |	|           d S )Nrb   rc   rd   rR   r   r   Tr   r   r    r?   r=   re   tsrf   rg   )rh   ri   r   r   subscriptionsrj   counted_order_bookr   r   r   handle_optionspawnload_order_bookr   handle_deltar   rm   	Exceptionrejectrp   )rN   r`   rq   rc   rs   rR   r\   subscriptionr   storedOrderBookr   cacheLengthr?   rf   es                  rP   handle_order_bookzmexc.handle_order_book  s   X   #v66%%gsH==!!(++"V+v';[II!!,884 12F -&*&=&=b&A&ADOF#/&1!!/7;;=o344K ../?RTUUMm++

4/feUWXXX!((...F	*ot444++GS$??I+4OK(*.,,y*A*AOJ'' 	* 	* 	*$[1MM![))))))))	* 	44444s   7A
F 
F4F//F4c                 0   t          dt          |                    D ]w}||         }t          |t                    r|                    |           5|                     |d          }|                     |d          }|                    ||           xd S )Nr   pr   )r   r   
isinstancelist
storeArray
safe_floatstore)rN   booksidebidasksr   bidaskpriceamounts          rP   handle_bookside_deltazmexc.handle_bookside_delta  s     q#g,,'' 	. 	.AQZF&$'' .##F++++4455uf----	. 	.rQ   c                 N   |                      |d          }|                     |dd          }||k     rd S ||d<   |                     |dg           }|                     |dg           }|d         }|d         }|                     ||           |                     ||           d S )Nr   r   r   asksbids)rj   r   r   r  )	rN   r   r   existingNoncer   r
  r  asksOrderSidebidsOrderSides	            rP   r   zmexc.handle_delta  s    )))W==((Y??
%% F'	'ufb11ufb11!&)!&)""=$777""=$77777rQ   c                   K   |                                   d{V  |                     |          }|d         }d|z   }d}|d         r)d|d         z   }|                     |||           d{V }n*d}d|d         i}	|                     |||	|           d{V }| j        r|                    ||          }|                     |||dd	          S )
a)  
        :see: https://mxcdevelop.github.io/apidocs/spot_v3_en/#trade-streams
        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>`
        NrR   trades:r&   zspot@public.deals.v3.api@rV   zsub.dealrf   T)rW   rX   rY   rZ   r   r   r   )
rN   rR   r   r   r[   rX   r\   tradesr]   r^   s
             rP   watch_tradeszmexc.watch_trades  s      !!!!!!!!!V$$!&(&> 	_1F4L@G11';OOOOOOOOFF G&,M  11';W]^^^^^^^^F? 	3OOFE22E))&%TRRRrQ   c                    |                      |dd          }|                     |          }|d         }d|z   }|                     | j        |          }|5|                     | j        dd          }t          |          }|| j        |<   |                     |dd          }	|                     |	d|	g          }
t          d	t          |
                    D ]Z}d }|d
         r| 
                    |
|         |          }n|                     |
|         |          }|                    |           [|                    ||           d S )Nrd   rR   r  tradesLimitr   rb   rc   dealsr   r&   )ri   rk   r   r  rj   rH   r   rh   r   r   parse_ws_tradeparse_trader   rp   )rN   r`   rq   rs   rX   rR   r\   r   r   rb   r  jparsedTrades                rP   handle_tradeszmexc.handle_trades  sQ   @ %%gsH==!!(++!&(f55>%%dlM4HHE&&F"(DKgsF33GaS11q#f++&& 	' 	'AKf~ B"11&)VDD"..vay&AAMM+&&&&v{+++++rQ   c                   K   |                                   d{V  d}d}|%|                     |          }|d         }|dz   |z   }d}|                     d||          \  }}d}|dk    r d}	|                     |	||           d{V }n|                     ||           d{V }| j        r|                    ||          }|                     ||||d          S )	aB  
        :see: https://mxcdevelop.github.io/apidocs/spot_v3_en/#spot-account-deals
        watches information on multiple trades made by the user
        :param str symbol: unified market symbol of the market trades were made in
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trade structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure
        NmyTradesrR   r   r   r&   zspot@private.deals.v3.apiT)rW   rX   handle_market_type_and_paramsr   r   r   r   filter_by_symbol_since_limit)
rN   rR   r   r   r[   r\   rX   typer  r]   s
             rP   watch_my_tradeszmexc.watch_my_tradesA  s%      !!!!!!!!! [[((FH%F%+f4K99/6SYZZf6>>1G227KPPPPPPPPFF22;GGGGGGGGF? 	3OOFE22E00tTTTrQ   c                 B   d}|                      |dd          }|                     |d          }|                     |d|          }|                     |          }|d         }	d }
|d         r|                     ||          }
n|                     ||          }
| j        }|2|                     | j        dd          }t          |          }|| _        |	                    |
           |
                    ||           |d	z   |	z   }|
                    ||           d S )
Nr  rb   rc   rR   rd   r&   r  r   r   )rh   r   rk   r  r  r  rj   rH   r   r   rp   )rN   r`   rq   r   r\   rc   futuresMarketIdrs   rX   rR   trader  r   symbolSpecificMessageHashs                 rP   handle_my_tradezmexc.handle_my_trade^  s0   & !  #v66**4::##GS/BB!!(++!&> 	3''f55EE$$T622E>%%dlM4HHE+E22F"DMev{+++$/#$5$>!v899999rQ   c                    |                      |d          }|                     |d          }||                      |d          }d }|                     |d          }|                     |d          }|                     |d          }|dk    rdnd}|                      |d	          }	|                     |||                     |d
          ||                     |          |                     d |          d ||	rdnd||d d d|          S )NTre   r   r   S1buysellmr   makertaker)r   rV   orderrf   rg   rR   r  sidetakerOrMakerr  r  costfee)rj   r   
safe_traderm   r   )
rN   r#  rX   rf   tradeIdpriceStringamountStringrawSider0  isMakers
             rP   r  zmexc.parse_ws_trade  s4   , %%eS11	""5#..))%55IG&&uc22''s33""5#.. Cuuf##E3//%%eS11"Y//&&tV44(/=GGg " 
  
   	rQ   c                   K   |                                   d{V  |                     |d          }d}d}|%|                     |          }|d         }|dz   |z   }d}|                     d||          \  }}d}|dk    r#|dz   }	|                     |	||           d{V }n|                     ||           d{V }| j        r|                    ||          }|                     ||||d	          S )
a  
        :see: https://mxcdevelop.github.io/apidocs/spot_v3_en/#spot-account-orders
        :see: https://mxcdevelop.github.io/apidocs/spot_v3_en/#margin-account-orders
        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
        :param str|None params['type']: the type of orders to retrieve, can be 'spot' or 'margin'
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  ordersrR   r   r!   r&   z@private.orders.v3.apiT)	rW   omitrX   r  r   r   r   r   r  )
rN   rR   r   r   r[   r\   rX   r  r;  r]   s
             rP   watch_orderszmexc.watch_orders  s>      !!!!!!!!!66**[[((FH%F%+f4K99-QWXXf6>>55G227KPPPPPPPPFF22;GGGGGGGGF? 	3OOFE22E00tTTTrQ   c                 B   d}|                      |dd          }|                     |d          }|                     |d|          }|                     |          }|d         }d }	|d         r|                     ||          }	n|                     ||          }	| j        }
|
2|                     | j        dd          }t          |          }
|
| _        |
	                    |	           |
                    |
|           |d	z   |z   }|
                    |
|           d S )
Nr;  rb   rc   rR   rd   r&   ordersLimitr   r   )rh   r   rk   parse_ws_orderparse_orderr;  rj   rH   r   r   rp   )rN   r`   rq   r\   rc   r"  rs   rX   rR   r   r;  r   r$  s                rP   handle_orderzmexc.handle_order  s1   D   #v66**4::##GS/BB!!(++!&> 	4((v66FF%%dF33F>%%dlM4HHE+E22F DKfv{+++$/#$5$>!v899999rQ   c                    |                      |d          }|                     |d          }|                     |d          }|                     |d          }d }|                     |d          }||d d}|                     i d|                     |d          d	|                     |d
          d|d|                     |          dd d|                     ||          d|                     d |          d|                     |          d|                     |          d|dk    rdndd|                     |d          dd d|                     |d          d|                     |d          d|                     |d          d|                     |d           d!|                     |d"          |                     |d#          |d |d$|          S )%NOr(  rd   r   N)currencyr2  rV   r   clientOrderIdr   rf   rg   lastTradeTimestampstatusrR   r  timeInForcer0  r)  r*  r+  r  r   	stopPricetriggerPricePr   apr  r   r2  r   filledcvV)	remainingr3  r  r   )	rj   r   
safe_orderrm   parse_ws_order_statusr   parse_ws_order_typeparse_ws_time_in_forcer   )	rN   r/  rX   rf   r0  rI  r  r3  feeCurrencys	            rP   r@  zmexc.parse_ws_order-  sv   f %%eS11	s++!!%--s++&&uc22"' C   
$""5#.. 
T--eS99 
  
 Y//	 

 !$ 
 d00@@ 
 d&&tV44 
 D,,T22 
 466t<< 
 dckkEE 
 T%%eS11 
  
 D,,UC88 
 t''t44 
 d&&uc22 
  D$$UC00! 
" d&&ud33# 
$ ))%55+ 
  
  
, -  	rQ   c                 J    ddddddddddd
}|                      |||          S )Nrw   closedcanceledrejected)
r)  23456NEWCANCELEDEXECUTEDFAILEDr   )rN   rI  rX   statusess       rP   rT  zmexc.parse_ws_order_status  sF    "  
 
 &&999rQ   c                 @    dd d d ddd}|                      ||          S )Nr   rX   r)  r\  r]  r^  r_  100re  )rN   r  typess      rP   rU  zmexc.parse_ws_order_type  s8    
 
 t,,,rQ   c                 @    ddddddd}|                      ||          S )NGTCPOIOCFOKrh  re  )rN   rJ  timeInForceIdss      rP   rV  zmexc.parse_ws_time_in_force  s8    
 
 <<<rQ   c                    K   |                                   d{V  d}|                     dd|          \  }}d|z   }|dk    rd}|                     |||           d{V S |                     ||           d{V S )ap  
        :see: https://mxcdevelop.github.io/apidocs/spot_v3_en/#spot-account-upadte
        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&   zspot@private.account.v3.api)rW   r  r   r   )rN   r[   r  r\   r]   s        rP   watch_balancezmexc.watch_balance  s       !!!!!!!!!99.$PVWWf 4'6>>3G00+vNNNNNNNNN00fEEEEEEEEErQ   c                    |                      |d          }|dnd}d|z   }|                     |dd          }|                     |d          }|                     |d|          }|| j        vr
i | j        |<   || j        |         d<   || j        |         d	<   |                     |          | j        |         d
<   |                     |dd          }	|                     |	          }
|                                 }|                     |dd          |d<   |                     |dd          |d<   || j        |         |
<   |                     | j        |                   | j        |<   |	                    | j        |         |           d S )Nr   r'   r&   rr  rb   rc   r   r   rf   rg   r   rF  favailableBalancefreer   frozenBalanceused)
r   rh   rj   balancerm   ri   safe_currency_codeaccountsafe_balancerp   )rN   r`   rq   r   r  r\   rc   futuresTimestamprf   
currencyIdcoder|  s               rP   handle_balancezmexc.handle_balance  s   @ Wc**)vv& 4'  #v66,,Wd;;%%dC1ABB	$$!#DL%)T6"*3T;')-i)@)@T:&''c:>>
&&z22,,..,,T38JKK,,T3HH#*T4 !..t|D/ABBTt|D);77777rQ   c                 0  K   |                      | j        d          }||S |                     |           d {V }|                      |d          }|| j        d<   |                     | j        dd          }|                     || j        ||           |S )NrC   rA   r(   )r   rH   spotPrivatePostUserDataStreamrj   delaykeep_alive_listen_key)rN   subscriptionHashr[   rC   responserA   s         rP   r   zmexc.authenticate  s      $$T\;??	 ;;FCCCCCCCC $$X{;;	$-[!#00?UW^__

')CYPVWWWrQ   c                   K   |d S d|i}	 |                      |                     ||                     d {V  |                     | j        dd          }|                     || j        ||           d S # t          $ rf}| j        d         d         d         dz   |z   }|                     |          }d | j        d<   |	                    |           | j
        |= Y d }~d S d }~ww xY w)NrC   rA   r(   r%   r   r&   r   )spotPrivatePutUserDataStreamr   rj   rH   r  r  r   rG   r`   r   clients)rN   rC   r[   r   rA   errorr   r`   s           rP   r  zmexc.keep_alive_listen_key  s     F
		"33DKK4P4PQQQQQQQQQ#'#4#4T\CY[b#c#c JJ+T-GTZ[[[[[ 	" 	" 	")E"4(0=@9LC[[%%F(,DL%MM%   S!!!!!!!	"s   A(A6 6
C& AC!!C&c                 8    |                                  |_        |S N)r   lastPong)rN   r`   rq   s      rP   handle_pongzmexc.handle_pong  s    ++--rQ   c                 X   |                      |d          }|dk    r|                     ||           d S |                    d          dk    rZ|                    d          }|                      |d          }d| j        i}|                     ||          }| |||           d S d S d S )Nr   PONGr   r   r   public.increase.depth.v3.api)r   r  findr   r   r   )rN   r`   rq   r   r   r]   methodsr   s           rP   handle_subscription_statuszmexc.handle_subscription_status  s     w..&==VW-----XXc]]RIIcNNE&&ua00G.0SG __Wg66F!vw'''''   "!rQ   c                 v   t          |t                    r4|dk    r,t          | j        dz             }|                    |           d S d|v r|                     ||           d S |                     |d          }d }||                     |d          }n+|                    d          }|                     |d          }| j        | j        | j	        | j	        | j
        | j
        | j        | j        | j        | j        | j        | j        | j        | j        | j        d}||v r||         } |||           d S d S )	NzInvalid listen keyz invalid listen keyr   r   r]   r   r   )zpublic.deals.v3.apiz	push.dealzpublic.kline.v3.apiz
push.klinezpublic.bookTicker.v3.apizpush.tickerr  z
push.depthzprivate.orders.v3.apizpush.personal.orderzprivate.account.v3.apizpush.personal.assetzprivate.deals.v3.apizpush.personal.order.dealpong)r   r   r   rV   r   r  r   r   r  r   ru   r   rB  r  r%  r  )	rN   r`   rq   r  r   r]   r   r  r   s	            rP   handle_messagezmexc.handle_message(  si   gs## 	...+DG6K,KLLe$$$FG++FG<<<FWc**9&&w	::GGGGCLLE&&ua00G#'#5+#'#4+(,(:-,0,B0%)%6#'#4&*&9#'#6$($8(,(<$
 
" gW%FF67##### rQ   c                 
    ddiS )Nr   rD    )rN   r`   s     rP   rD   z	mexc.pingM  s    &!!rQ   r  )3__name__
__module____qualname__rM   r   r   r_   r   ru   rl   rY   r   rZ   r   r   r   r   r   r   r   r	   r   r   r   r   r  r   r   r  r  r
   r   r%  r  r   r=  rB  r@  rT  rU  rV  r   rs  r  r   r  r  r  r  rD   __classcell__)rO   s   @rP   r   r      s       9 9 9 9 9v 68 ] ] ]F ] ] ] ](,F , , , ,<   @ DF Y Y Y Y EG Y Y Y Y SU H H H H <> D D D D$ 8<$]ajl H H HC HWZ Hquvzq{ H H H H@@,6 @, @, @, @,D(
 (
D (
 (
 (
 (
T @DB ! !S ! !S\ ! ! ! !26V 6 6 6 6  H5 H5 H5 H5 H5T. . . 8 8 8 <@d[] S S SS S Sbfglbm S S S S82,F 2, 2, 2, 2,h 37TX\eg U UC Us URU Ulpqvlw U U U U:&: &:f &: &: &: &:P. . . .` 04$UYbd U U UC Us Uimnsit U U U U@U:6 U: U: U: U:nT T T Tl: : : :	- 	- 	-	= 	= 	= *, F F F F F F"28V 28 28 28 28h ;=    " =? " " " ""&    ( ( ( ( (*#$V #$ #$ #$ #$J" " " " " " "rQ   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r   ccxt.base.typesr   r   r   r	   r
   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   async_supportr   r  rQ   rP   <module>r     s        f f f f f f f f f f  O O O O O O O O O O O O O O O O O O 4 4 4 4 4 4       0 0 0 0 0 0" " " " "4" " " " " "rQ   