
    eiU                        d dl Zd dlmZmZmZm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 d dlmZ  G d d	ej        j                  ZdS )
    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)AnyBalancesIntOrder	OrderBookPositionStrStringsTickerTickersTrade)Client)List)ArgumentsRequired)Precisec            
       d    e Zd Zdef fdZdee         defdZi fdedefdZ	i fdedefdZ
di fd	edefd
Zdi fd	edefdZi fdedefdZi fdedefdZd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 Zdi fd	edefdZdi fd	edefdZdefdZdAdZddi fdedededee         fdZi fdedefdZddi fd	ee         dededee         fdZi fd	ee         defdZdefdZ dAdefdZ!di fdedede"fdZ#i fdedefd Z$di fd	ee         dede"fd!Z%i fd	ee         d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$i fdedefd&Z*ddi fd'eee                  dedefd(Z+i fd'eee                  defd)Z,defd*Z-dAde(fd+Z.d,i fd-Z/i fd.Z0dBd/Z1i fde2fd0Z3defd1Z4d2 Z5defd3Z6dddi fd	edededee7         fd4Z8defd5Z9d6 Z:d7 Z;dAd8Z<dddi fde=dededee>         fd9Z?dddi fde=dededee         fd:Z@defd;ZAdefd<ZBdefd=ZCdAd>ZDdefd?ZEdefd@ZF xZGS )Casterreturnc                 L   |                      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ddddddddd
dddddddddiid d dddddddddddddd d!i i d"          S )#NwsTwatchBalancewatchBidsAskswatchMarkPricewatchMarkPriceswatchTradeswatchTradesForSymbolswatchOrderswatchOrderBookwatchOrderBookForSymbols
watchOHLCVwatchOHLCVForSymbolswatchPositionswatchTickerwatchTickerswatchMyTradesunWatchTicker)
unWatchTickersunWatchMarkPriceunWatchMarkPricesunWatchBidsAsksunWatchTradesunWatchTradesForSymbolsunWatchOrderBookunWatchOrderBookForSymbolsunWatchOHLCVunWatchOHLCVForSymbolsapiz!wss://sstream.asterdex.com/streamz!wss://fstream.asterdex.com/stream)spotswapzwss://sstream.asterdex.com/wszwss://fstream.asterdex.com/ws)publicprivater   6 F)fetchBalanceSnapshotawaitBalanceSnapshotwb)fetchPositionsSnapshotawaitPositionsSnapshot)	listenKeylastAuthenticatedTimelistenKeyRefreshRater   walletr&   )hasurlsoptions	streaming
exceptions)deep_extendsuperr   describe)self	__class__s    L/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/pro/aster.pyrK   zaster.describe   s   eT 2 2 ; ; = =d   !$	
 "4 t ( t !$ +D d ' !$ t    !"  #$ #'$(%)#'!%+/$(.2 $*.7  < $G$G# #
 %D$C$ $	 	  !  
 * *
 $#) )
 -2,0! ! .2.2# #% . IE@
 E@
 E E E	    subscriptionsc                 z    d}t          dt          |                    D ]}||         }|dk    s|dk    r|} n|S )N r   r6   r7   )rangelen)rL   rP   accountTypeisubscriptions        rN   #get_account_type_from_subscriptionsz)aster.get_account_type_from_subscriptionsY   s_    q#m,,-- 	 	A(+L&&LF,B,B* -C rO   symbolc                    K   d|d<   |                                   d{V  |                     |          }|                     |g|           d{V }||         S )as  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#full-ticker-per-symbol
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#individual-symbol-ticker-streams

        :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>`
        r'   callerMethodNameN)load_marketssafe_symbolwatch_tickersrL   rY   paramstickerss       rN   watch_tickerzaster.watch_tickerb   s}       &3!"!!!!!!!!!!!&))**F8V<<<<<<<<vrO   c                 J   K   d|d<   |                      |g|           d{V S )a  
        unWatches a price ticker

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#full-ticker-per-symbol
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#individual-symbol-ticker-streams

        :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>`
        r*   r[   N)un_watch_tickersrL   rY   r`   s      rN   un_watch_tickerzaster.un_watch_tickers   s=       &5!"**F8V<<<<<<<<<rO   Nsymbolsc                   K   |                                   d{V  |                     |dddd          }|                     |          }|                     |dd          }t	          |          }d}|                     |dd          \  }}|                     |d          }|dk    rt          | j        dz   |z   d	z             | j	        d
         d         d         |         }g }g }	d|d}
t          dt	          |                    D ]i}||         }|                     |          }|                    |                     |d          dz              |	                    d|d         z              j|                     ||	|                     |
|          |g           d{V }| j        ri }|||d         <   |S |                     | 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://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#full-ticker-per-symbol
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#individual-symbol-ticker-streams

        :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>`
        NTtyper7   r[   r(   r    (() requires a non-empty array of symbolsr5   r   r8   	SUBSCRIBEmethodr`   id@tickerticker:rY   )r\   market_symbolsget_market_from_symbolssafe_stringrT   handle_param_stringomitr   ro   rE   rS   marketappendsafe_string_lowerwatch_multipleextend
newUpdatesfilter_by_arrayra   )rL   rg   r`   firstMarketri   symbolsLength
methodNameurlsubscriptionArgsmessageHashesrequestrV   rY   rw   	newTickerresults                   rN   r^   zaster.watch_tickers   s      !!!!!!!!!%%gtT4FF227;;VV<<G
!55f>PR`aa
F6#566A#DGcMJ$>Ak$klllit$X.t4!&
 
 q#g,,'' 	? 	?AQZF[[((F##D$:$:64$H$H9$TUUU  VH-=!=>>>>--c=$++gW]B^B^ae`fgggggggg	? 	F*3F9X&'M##DL(GDDDrO   c                 P  K   |                                   d{V  |                     |dddd          }|                     |          }|                     |dd          }t	          |          }d}|                     |dd          \  }}|                     |d          }|dk    rt          | j        dz   |z   d	z             | j	        d
         d         d         |         }g }g }	d|d}
t          dt	          |                    D ]i}||         }|                     |          }|                    |                     |d          dz              |	                    d|d         z              j|                     ||	|                     |
|          |g           d{V S )a  
        unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#full-ticker-per-symbol
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#individual-symbol-ticker-streams

        :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>`
        NTri   r7   r[   r+   r   rj   rk   r5   r   r8   UNSUBSCRIBErm   ro   rp   unsubscribe:ticker:rY   r\   rr   rs   rt   rT   ru   rv   r   ro   rE   rS   rw   rx   ry   rz   r{   rL   rg   r`   r~   ri   r   r   r   r   r   r   rV   rY   rw   s                 rN   rd   zaster.un_watch_tickers   s      !!!!!!!!!%%gtT4FF227;;VV<<G
!55f>PRbcc
F6#566A#DGcMJ$>Ak$klllit$X.t4#&
 
 q#g,,'' 	K 	KAQZF[[((F##D$:$:64$H$H9$TUUU  !69I!IJJJJ((mT[[RX=Y=Y\`[abbbbbbbbbrO   c                    K   d|d<   |                                   d{V  |                     |          }|                     |g|           d{V }||         S )a:  
        watches a mark price for a specific market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#mark-price-stream

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.use1sFreq]: *default is True* if set to True, the mark price will be updated every second, otherwise every 3 seconds
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r   r[   N)r\   r]   watch_mark_pricesr_   s       rN   watch_mark_pricezaster.watch_mark_price   s}       &6!"!!!!!!!!!!!&))..x@@@@@@@@vrO   c                 J   K   d|d<   |                      |g|           d{V S )a<  
        unWatches a mark price for a specific market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#mark-price-stream

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.use1sFreq]: *default is True* if set to True, the mark price will be updated every second, otherwise every 3 seconds
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r,   r[   N)un_watch_mark_pricesre   s      rN   un_watch_mark_pricezaster.un_watch_mark_price   s=       &8!"..x@@@@@@@@@rO   c                   K   |                                   d{V  |                     |dddd          }|                     |          }|                     |dd          }t	          |          }d}|                     |dd          \  }}|                     |d          }|dk    rt          | j        dz   |z   d	z             | j	        d
         d         d         |         }g }g }	d|d}
| 
                    |dd          }t          dt	          |                    D ]r}||         }|                     |          }|rdnd}|                    |                     |d          dz   |z              |	                    d|d         z              s|                     ||	|                     |
|          |g           d{V }| j        ri }|||d         <   |S |                     | j        d|          S )9  
        watches the mark price for all markets

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#mark-price-stream

        :param str[] symbols: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.use1sFreq]: *default is True* if set to True, the mark price will be updated every second, otherwise every 3 seconds
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        NTri   r7   r[   r   r   rj   rk   r5   r   r8   rl   rm   	use1sFreq@1srR   ro   
@markPricerq   rY   )r\   rr   rs   rt   rT   ru   rv   r   ro   rE   	safe_boolrS   rw   rx   ry   rz   r{   r|   r}   ra   )rL   rg   r`   r~   ri   r   r   r   r   r   r   r   rV   rY   rw   suffixr   r   s                     rN   r   zaster.watch_mark_prices   s>      !!!!!!!!!%%gtT4FF227;;VV<<G
!55f>PRcdd
F6#566A#DGcMJ$>Ak$klllit$X.t4!&
 
 NN6;==	q#g,,'' 	? 	?AQZF[[((F(1UUrF##D$:$:64$H$H<$WZ`$`aaa  VH-=!=>>>>--c=$++gW]B^B^ae`fgggggggg	? 	F*3F9X&'M##DL(GDDDrO   c                   K   |                                   d{V  |                     |dddd          }|                     |          }|                     |dd          }t	          |          }d}|                     |dd          \  }}|                     |d          }|dk    rt          | j        dz   |z   d	z             | j	        d
         d         d         |         }g }g }	d|d}
| 
                    |dd          }t          dt	          |                    D ]r}||         }|                     |          }|rdnd}|                    |                     |d          dz   |z              |	                    d|d         z              s|                     ||	|                     |
|          |g           d{V S )r   NTri   r7   r[   r-   r   rj   rk   r5   r   r8   r   rm   r   r   rR   ro   r   r   rY   )r\   rr   rs   rt   rT   ru   rv   r   ro   rE   r   rS   rw   rx   ry   rz   r{   )rL   rg   r`   r~   ri   r   r   r   r   r   r   r   rV   rY   rw   r   s                   rN   r   zaster.un_watch_mark_prices  s      !!!!!!!!!%%gtT4FF227;;VV<<G
!55f>PReff
F6#566A#DGcMJ$>Ak$klllit$X.t4#&
 
 NN6;==	q#g,,'' 	K 	KAQZF[[((F(1UUrF##D$:$:64$H$H<$WZ`$`aaa  !69I!IJJJJ((mT[[RX=Y=Y\`[abbbbbbbbbrO   clientc                 H   |j         }t          |                                          }|                     |          }|                     |d          }|                     ||          }|d         }d|z   }	|| j        |<   |                    | j        |         |	           d S )NdatarY   rq   )rP   listkeysrX   	safe_dictparse_ws_tickerra   resolve)
rL   r   messagerP   subscriptionsKeys
marketTypetickerparsedrY   messageHashs
             rN   handle_tickerzaster.handle_ticker:  s    N , !3!3!5!566==>OPP
00%%fj99!&(%Vt|F+[99999rO   c                    |                      |d          }|                    d          }|                      |d          }|                      |d          }|                     |d          }|                     |d d |          }|                      |d          }	|dk    r]|                     |d         ||                     |          ||                      |d	          |                      |d
          d          S |                     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#|          S )$Ne@   sEcmarkPriceUpdaterY   prV   )rY   	timestampdatetimeinfo	markPrice
indexPricer   r   highhlowlbid	bidVolumeask	askVolumevwapwopenocloselastpreviousClosechange
percentagePaveragevq)
baseVolumequoteVolumer   )rt   splitsafe_integersafe_marketsafe_tickeriso8601)
rL   r   r   eventpartchannelmarketIdr   rw   r   s
             rN   r   zaster.parse_ws_tickerk  s     #..{{3""4++##GS11%%gs33	!!(D$
CC--'''## *& LL33!--gs;;"..w<<% %     !
fX&!
!
 Y//!
 D$$Wc22	!

 4##GS11!
 4!
 !
 4!
 !
 D$$Wc22!
 D$$Wc22!
 T!
 D!
 T!
 d&&w44!
  $**7C88!!
" t#!
$ **7C88++GS99)!
 !
 !
* +  	rO   c                 D  K   |                                   d{V  |                     |dddd          }|                     |          }|                     |dd          }t	          |          }|dk    rt          | j        dz             | j        d         d         d	         |         }g }g }d
|d}	t          dt	          |                    D ]i}
||
         }| 	                    |          }|
                    |                     |d          dz              |
                    d|d         z              j|                     |||                     |	|          |g           d{V }| j        ri }|||d         <   |S |                     | j        d|          S )a.  
        watches best bid & ask for symbols

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#best-order-book-information-by-symbol
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#individual-symbol-book-ticker-streams

        :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>`
        NTri   r7   r   z6 watchBidsAsks() requires a non-empty array of symbolsr5   r   r8   rl   rm   ro   @bookTickerbidask:rY   )r\   rr   rs   rt   rT   r   ro   rE   rS   rw   rx   ry   rz   r{   r|   r}   bidsasks)rL   rg   r`   r~   ri   r   r   r   r   r   rV   rY   rw   r   r   s                  rN   watch_bids_askszaster.watch_bids_asks  s      !!!!!!!!!%%gtT4FF227;;VV<<GA#DG.f$fgggit$X.t4!&
 
 q#g,,'' 	? 	?AQZF[[((F##D$:$:64$H$H=$XYYY  VH-=!=>>>>--c=$++gW]B^B^ae`fgggggggg	? 	F*3F9X&'M##DM8WEEErO   c                   K   |                                   d{V  |                     |dddd          }|                     |          }|                     |dd          }t	          |          }|dk    rt          | j        dz             | j        d         d         d	         |         }g }g }d
|d}	t          dt	          |                    D ]i}
||
         }| 	                    |          }|
                    |                     |d          dz              |
                    d|d         z              j|                     |||                     |	|          |g           d{V S )a0  
        unWatches best bid & ask for symbols

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#best-order-book-information-by-symbol
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#individual-symbol-book-ticker-streams

        :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>`
        NTri   r7   r   z8 unWatchBidsAsks() requires a non-empty array of symbolsr5   r   r8   r   rm   ro   r   zunsubscribe:bidask:rY   )r\   rr   rs   rt   rT   r   ro   rE   rS   rw   rx   ry   rz   r{   )rL   rg   r`   r~   ri   r   r   r   r   r   rV   rY   rw   s                rN   un_watch_bids_askszaster.un_watch_bids_asks  s      !!!!!!!!!%%gtT4FF227;;VV<<GA#DG.h$hiiiit$X.t4#&
 
 q#g,,'' 	K 	KAQZF[[((F##D$:$:64$H$H=$XYYY  !69I!IJJJJ((mT[[RX=Y=Y\`[abbbbbbbbbrO   c                    |j         }t          |                                          }|                     |          }|                     |di           }|                     |d          }|                     |d d |          }|                     ||          }	|	d         }
|	| j        |
<   d|
z   }|	                    |	|           d S )Nr   r   rY   r   )
rP   r   r   rX   r   rt   r   parse_ws_bid_askr   r   )rL   r   r   rP   r   r   r   r   rw   r   rY   r   s               rN   handle_bid_askzaster.handle_bid_ask  s    " , !3!3!5!566==>OPP
~~gvr22##D#..!!(D$
CC&&tV44! &f&(v{+++++rO   c                 >   |                      |d          }|                     |d         ||                     |          |                     |d          |                     |d          |                     |d          |                     |d          |d|          S )NTrY   aAbB)rY   r   r   r   r   r   r   r   )r   r   r   rt   )rL   r   rw   r   s       rN   r   zaster.parse_ws_bid_ask  s    %%gs33	X&"Y//##GS11))'377##GS11))'377	!
 	!
 	 	 		rO   sincelimitc                 N   K   d|d<   |                      |g|||           d{V S )a  
        watches information on multiple trades made in a market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#collection-transaction-flow
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#aggregate-trade-streams

        :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 <https://docs.ccxt.com/#/?id=trade-structure>`
        r   r[   N)watch_trades_for_symbols)rL   rY   r   r   r`   s        rN   watch_tradeszaster.watch_trades  sA       &3!"22F8UE6RRRRRRRRRrO   c                 J   K   d|d<   |                      |g|           d{V S )a   
        unsubscribe from the trades channel

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#collection-transaction-flow
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#aggregate-trade-streams

        :param str symbol: unified market symbol of the market trades were made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        r/   r[   N)un_watch_trades_for_symbolsre   s      rN   un_watch_tradeszaster.un_watch_trades  s=       &5!"55vhGGGGGGGGGrO   c                   K   |                                   d{V  |                     |dddd          }|                     |          }|                     |dd          }t	          |          }d}|                     |dd          \  }}|                     |d          }|dk    rt          | j        dz   |z   d	z             | j	        d
         d         d         |         }	g }
g }d|
d}t          dt	          |                    D ]i}||         }|                     |          }|
                    |                     |d          dz              |                    d|d         z              j|                     |	||                     ||          |g           d{V }| j        rB|                     |d          }|                     |d          }|                    ||          }|                     |||dd          S )a  
        get the list of most recent trades for a list of symbols

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#collection-transaction-flow
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#aggregate-trade-streams

        :param str[] symbols: 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>`
        NTri   r7   r[   r    r   rj   rk   r5   r   r8   rl   rm   ro   	@aggTradetrade:rY   r   )r\   rr   rs   rt   rT   ru   rv   r   ro   rE   rS   rw   rx   ry   rz   r{   r|   
safe_valuegetLimitfilter_by_since_limit)rL   rg   r   r   r`   r~   ri   r   r   r   r   r   r   rV   rY   rw   tradesfirsttradeSymbols                      rN   r   zaster.watch_trades_for_symbols   s9      !!!!!!!!!%%gtT4FF227;;VV<<G
!55f>PRijj
F6#566A#DGcMJ$>Ak$klllit$X.t4!&
 
 q#g,,'' 	> 	>AQZF[[((F##D$:$:64$H$H;$VWWW  F8,<!<====**3t{{7TZ?[?[^b]cdddddddd? 	8OOFA..E**5(;;KOOK77E))&%TRRRrO   c                 P  K   |                                   d{V  |                     |dddd          }|                     |          }|                     |dd          }t	          |          }d}|                     |dd          \  }}|                     |d          }|dk    rt          | j        dz   |z   d	z             | j	        d
         d         d         |         }g }g }	d|d}
t          dt	          |                    D ]i}||         }|                     |          }|                    |                     |d          dz              |	                    d|d         z              j|                     ||	|                     |
|          |g           d{V S )a  
        unsubscribe from the trades channel

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#collection-transaction-flow
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#aggregate-trade-streams

        :param str[] symbols: unified symbol of the market to fetch trades for
        :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>`
        NTri   r7   r[   r0   r   rj   rk   r5   r   r8   r   rm   ro   r   zunsubscribe:trade:rY   r   r   s                 rN   r   z!aster.un_watch_trades_for_symbolsJ  s      !!!!!!!!!%%gtT4FF227;;VV<<G
!55f>PRkll
F6#566A#DGcMJ$>Ak$klllit$X.t4#&
 
 q#g,,'' 	J 	JAQZF[[((F##D$:$:64$H$H;$VWWW  !5x8H!HIIII((mT[[RX=Y=Y\`[abbbbbbbbbrO   c                 H   |j         }t          |                                          }|                     |          }|                     |d          }|                     |d          }|                     |d d |          }|                     ||          }	|	d         }
|                     | j	        |
          }|5| 
                    | j        dd          }t          |          }|| j	        |
<   |                    |	           d|
z   }|                    ||           d S )Nr   r   rY   tradesLimit  r   )rP   r   r   rX   r   rt   r   parse_ws_trader   r   r   rF   r   rx   r   )rL   r   r   rP   r   r   trader   rw   r   rY   storedr   r   s                 rN   handle_tradezaster.handle_tradem  s   $ , !3!3!5!566==>OPP
w//##E3//!!(D$
CC$$UF33!f55>%%dlM4HHE&&F"(DKf#f,v{+++++rO   c                    |                      |d          }|dk    p|dk    }|                     |dd          }|                     |d          }|                     |dd          }d }|r|                      |d	          }n|                      |d
          }|                      |d          }	|	||t          j        ||          }	|                      |d          }
||                      | j        dd          n|d         }|                     |
|d |          }|                     |d          }d }|                      |d          }d|v r||d         rdnd}|d         rdnd}d }|                      |d          }|0|                      |d          }|                     |          }||d}|                     |d          }| 	                    ||| 
                    |          |||||||||	|d          S )Nr   r   aggTradetr   r   Lr   r   r   Yr   defaultTyper6   ri   SrV   msellbuymakertakernNcostcurrencyr   )r   r   r   rY   ro   orderri   takerOrMakersidepriceamountr  fee)rt   safe_string_2r   r   
string_mulrF   r]   ry   safe_currency_code
safe_trader   )rL   r   rw   r   isPublicTradero   r   r  r  r  r   r  rY   r  r  orderIdr  feeCostfeeCurrencyIdfeeCurrencyCoderi   s                        rN   r   zaster.parse_ws_trade  s^   R UC((g;1
?sC00%%eS11	""5#s33 	2%%eS11FF %%eS11Fs++<!(:)%88##E3//PVP^d&&t|]FKKKeklres!!(FD+FF%%eS11""5#..%<<|!&s6vv&+Cj=77gL""5#.. ,,UC88M"55mDDO+ C %%eS11"Y//( 
  
   	rO   c                 L   K   d|d<   |                      |g||           d{V S )a  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#limited-depth-information
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#partial-book-depth-streams

        :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
        r"   r[   N)watch_order_book_for_symbols)rL   rY   r   r`   s       rN   watch_order_bookzaster.watch_order_book,  s?       &6!"66xOOOOOOOOOrO   c                 J   K   d|d<   |                      |g|           d{V S )a  
        unsubscribe from the orderbook channel

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#limited-depth-information
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#partial-book-depth-streams

        :param str symbol: symbol of the market to unwatch the trades for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.limit]: orderbook limit, default is None
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        r1   r[   N)un_watch_order_book_for_symbolsre   s      rN   un_watch_order_bookzaster.un_watch_order_book;  s=       &8!"996(FKKKKKKKKKrO   c                   K   |                                   d{V  |                     |dddd          }|                     |          }|                     |dd          }t	          |          }d}|                     |dd          \  }}|                     |d          }|dk    rt          | j        dz   |z   d	z             | j	        d
         d         d         |         }g }	g }
d|	d}||dk    r|dk    r|dk    rd}t          dt	          |                    D ]y}||         }|                     |          }|	                    |                     |d          dz   t          |          z              |
                    d|d         z              z|                     ||
|                     ||          |g           d{V }|                                S )a  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#limited-depth-information
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#partial-book-depth-streams

        :param str[] symbols: unified array of symbols
        :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
        NTri   r7   r[   r#   r   rj   rk   r5   r   r8   rl   rm      
      ro   @depth
orderbook:rY   )r\   rr   rs   rt   rT   ru   rv   r   ro   rE   rS   rw   rx   ry   strrz   r{   r   )rL   rg   r   r`   r~   ri   r   r   r   r   r   r   rV   rY   rw   	orderbooks                   rN   r!  z"aster.watch_order_book_for_symbolsJ  s      !!!!!!!!!%%gtT4FF227;;VV<<G
!55f>PRlmm
F6#566A#DGcMJ$>Ak$klllit$X.t4!&
 
 =UaZZERKKERKKEq#g,,'' 	B 	BAQZF[[((F##D$:$:64$H$H8$SVYZ_V`V`$`aaa  x0@!@AAAA--c=$++gW]B^B^ae`fgggggggg	   rO   c                   K   |                                   d{V  |                     |dddd          }|                     |          }|                     |dd          }t	          |          }d}|                     |dd          \  }}|                     |d          }|dk    rt          | j        dz   |z   d	z             | j	        d
         d         d         |         }g }g }	d|d}
| 
                    |d          }|                     |d          }||dk    r|dk    r|dk    rd}t          dt	          |                    D ]l}||         }|                     |          }|                    |                     |d          dz   |z              |	                    d|d         z              m|                     ||	|                     |
|          |g           d{V S )a  
        unsubscribe from the orderbook channel

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#limited-depth-information
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#partial-book-depth-streams

        :param str[] symbols: unified symbol of the market to unwatch the trades for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.limit]: orderbook limit, default is None
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        NTri   r7   r[   r2   r   rj   rk   r5   r   r8   r   rm   r   r'  r(  r)  ro   r*  zunsubscribe:orderbook:rY   )r\   rr   rs   rt   rT   ru   rv   r   ro   rE   safe_numberrS   rw   rx   ry   rz   r{   )rL   rg   r`   r~   ri   r   r   r   r   r   r   r   rV   rY   rw   s                  rN   r$  z%aster.un_watch_order_book_for_symbolsq  s,      !!!!!!!!!%%gtT4FF227;;VV<<G
!55f>PRnoo
F6#566A#DGcMJ$>Ak$klllit$X.t4#&
 
   1167++=UaZZERKKERKKEq#g,,'' 	N 	NAQZF[[((F##D$:$:64$H$H8$SV[$[\\\  !9F8<L!LMMMM((mT[[RX=Y=Y\`[abbbbbbbbbrO   c                 N   |j         }t          |                                          }|                     |          }|                     |d          }|                     |d          }|                     |d          }|                     |d d |          }	|	d         }
|
| j        vr| 	                                | j        |
<   | j        |
         }| 
                    ||
|dd          }|                    |           d|
z   }|| j        |
<   |                    ||           d S )Nr   r   r   rY   r   r   r+  )rP   r   r   rX   r   rt   r   r   
orderbooks
order_bookparse_order_bookresetr   )rL   r   r   rP   r   r   r   r   r   rw   rY   r-  snapshotr   s                 rN   handle_order_bookzaster.handle_order_book  s&   6 , !3!3!5!566==>OPP
~~gv..##D#..%%dC00	!!(D$
CC!$/))&*oo&7&7DOF#OF+	((vy#sKK!!!'&0"+y+.....rO   1mc                    K   d|d<   |                                   d{V  |                     |          }|                     ||gg|||           d{V }||         |         S )a$  
        watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#k-line-streams
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#klinecandlestick-streams

        :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
        r$   r[   N)r\   r]   watch_ohlcv_for_symbols)rL   rY   	timeframer   r   r`   r   s          rN   watch_ohlcvzaster.watch_ohlcv  s       &2!"!!!!!!!!!!!&))33fi5H4I5RWY_````````f~i((rO   c                 N   K   d|d<   |                      ||gg|           d{V S )a  
        unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#k-line-streams
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#klinecandlestick-streams

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r3   r[   N)un_watch_ohlcv_for_symbols)rL   rY   r:  r`   s       rN   un_watch_ohlcvzaster.un_watch_ohlcv  sC       &4!"44vy6I5JFSSSSSSSSSrO   symbolsAndTimeframesc                   K   |                                   d{V  t          |          }d}|                     |dd          \  }}|                     |d          }|dk    rt	          | j        dz   |z   dz             |                     |d          }|                     |dddd          }|                     |d                   }	| 	                    |	d	d
          }
| j
        d         d         d         |
         }g }g }d|d}t          dt          |                    D ]}||         }| 	                    |d          }|                     |          }|d         }| 	                    |d          }| 	                    | j        ||          }|                    |                     |d          dz   |z              |                    d|d         z   dz   |z              |                     |||                     ||          |
g           d{V \  }}}| j        r|                    ||          }|                     |||dd          }|                     |||          S )a:  
        watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#k-line-streams
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#klinecandlestick-streams

        :param str[][] symbolsAndTimeframes: array of arrays containing unified symbols and timeframes to fetch OHLCV data for, example [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]
        :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 dict: A list of candles ordered, open, high, low, close, volume
        Nr[   r%   r   rj   rk   FTri   r7   r5   r   r8   rl   rm   rY   r   ro   @kline_ohlcv::)r\   rT   ru   rv   r   ro   get_list_from_object_valuesrr   rw   rt   rE   rS   
timeframesrx   ry   rz   r{   r|   r   r   create_ohlcv_object)rL   r?  r   r   r`   r   r   rg   marketSymbolsr~   ri   r   r   r   r   rV   r   symbolStringrw   unfiedTimeframetimeframeIdrY   r:  r   filtereds                            rN   r9  zaster.watch_ohlcv_for_symbols  s      !!!!!!!!!011
!55f>PRhii
F6#566A#DGcMJ$>Ak$klll223GKK++GT5$MMkk-"233VV<<it$X.t4!&
 
 q#23344 	V 	VA'*D++D!44L[[..F!(+L"..tQ77O**4?O_]]K##D$:$:64$H$H9$TWb$bccc  F8,<!<s!B_!TUUUU*.*=*=c=RVR]R]^egmRnRnqupv*w*w$w$w$w$w$w$w!	6? 	3OOFE22E--feUAtLL''	8DDDrO   c                 :  K   |                                   d{V  t          |          }d}|                     |dd          \  }}|                     |d          }|dk    rt	          | j        dz   |z   dz             |                     |d          }|                     |dddd          }|                     |d                   }| 	                    |d	d
          }| j
        d         d         d         |         }	g }
g }d|
d}t          dt          |                    D ]}||         }| 	                    |d          }|                     |          }|d         }| 	                    |d          }| 	                    | j        ||          }|
                    |                     |d          dz   |z              |                    d|d         z   dz   |z              |                     |	||                     ||          |g           d{V S )a  
        unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#k-line-streams
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#klinecandlestick-streams

        :param str[][] symbolsAndTimeframes: array of arrays containing unified symbols and timeframes to fetch OHLCV data for, example [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr[   r4   r   rj   rk   FTri   r7   r5   r   r8   r   rm   rY   r   ro   rA  zunsubscribe:ohlcv:rC  )r\   rT   ru   rv   r   ro   rD  rr   rw   rt   rE   rS   rE  rx   ry   rz   r{   )rL   r?  r`   r   r   rg   rG  r~   ri   r   r   r   r   rV   r   rH  rw   rI  rJ  s                      rN   r=  z aster.un_watch_ohlcv_for_symbols  sZ      !!!!!!!!!011
!55f>PRjkk
F6#566A#DGcMJ$>Ak$klll223GKK++GT5$MMkk-"233VV<<it$X.t4#&
 
 q#23344 	b 	bA'*D++D!44L[[..F!(+L"..tQ77O**4?O_]]K##D$:$:64$H$H9$TWb$bccc  !5x8H!H3!NQ`!`aaaa((mT[[RX=Y=Y\`[abbbbbbbbbrO   c                 L   |j         }t          |                                          }|                     |          }|                     |d          }|                     |d          }|                     |d d |          }|d         }	|                     |d          }
|                     |
d          }|                     |          }|                     | j	        |	          }|
i | j	        |	<   |                     ||          9| 
                    | j        dd          }t          |          | j	        |	         |<   | j	        |	         |         }|                     |
          }|                    |           d|	z   d	z   |z   }|	||g}|                    ||           d S )
Nr   r   rY   krV   
OHLCVLimitr   rB  rC  )rP   r   r   rX   r   rt   r   find_timeframer   ohlcvsr   rF   r   parse_ws_ohlcvrx   r   )rL   r   r   rP   r   r   r   r   rw   rY   klinerJ  r:  ohlcvsByTimeframer   r   r   r   resolveDatas                      rN   handle_ohlcvzaster.handle_ohlcv>  s   < , !3!3!5!566==>OPP
~~gv..##D#..!!(D$
CC!tS))&&uc22''44	 OODK@@$"$DK??,i88@%%dlL$GGE-B5-I-IDK	*V$Y/$$U++f'#-	9y&1{K00000rO   c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr  r   r   r   r   r   )r   r/  )rL   ohlcvrw   s      rN   rR  zaster.parse_ws_ohlcvs  s~    eS))UC((UC((UC((UC((UC((
 	
rO   r6   c                 b  K   |                                  }|                     | j        di           }|                     ||d          }|                     | j        di           }|                     ||d          }||z
  |k    rd }|dk    r|                     |           d {V }n|                     |           d {V }|                     |d          | j        d         |<   || j        d         |<   |                     d|i|          }|                     || j	        |           d S d S )NrA   r   rB   r:   r6   r@   ri   )
millisecondsr   rF   r   sapiPrivatePostV1ListenKeyfapiPrivatePostV1ListenKeyrt   r{   delaykeep_alive_listen_key)	rL   ri   r`   timelastAuthenticatedTimeOptionsrA   listenKeyRefreshRateOptionsrB   responses	            rN   authenticatezaster.authenticate}  s^       ""'+~~dlD[]_'`'`$ $ 1 12NPTVW X X&*nnT\CY[]&^&^##001LdT[\\''*>>>Hv~~!%!@!@!H!HHHHHHH!%!@!@!H!HHHHHHH.2.>.>x.U.UDL%d+:>DL01$7[[&$88FJJ+T-GPPPPP ?>rO   c                 &  K   |                      |dd          }|                     | j        di           }|                      ||          }|d S 	 |                                  d {V  n# t          $ r}| j        d         d         d         |         dz   |z   }|                     |          }t          |j        	                                          }t          dt          |                    D ] }	||	         }
|                    ||
           !d | j        d         |<   d| j        d	         |<   Y d }~d S d }~ww xY w|                     | j        d
i           }|                     |dd          }|                     || j        |           d S )Nri   r6   r@   r5   r   r9   /r   rA   listenKeyRefreshrB   r:   )rt   r   rF   sapiPrivatePutV1ListenKey	ExceptionrE   r   r   futuresr   rS   rT   rejectr   r]  r^  )rL   r`   ri   listenKeyOptionsr@   errorr   r   r   rV   r   listenKeyRefreshOptionsrB   s                rN   r^  zaster.keep_alive_listen_key  s     77>>$,RHH$$%5t<<	F	002222222222 		 		 		)E"4(3D9C?)KC[[%%F !4!4!6!677M1c-0011 2 2+A.e[1111.2DL%d+:;DL01$7FFFFF		 #'..?QSU"V"V#001HJ`bijj

')CVLLLLLs   A, ,
D?6B>D::D?c                     |                      | j        di           }|                     ||          }| j        d         d         d         |         dz   |z   }|S )Nr@   r5   r   r9   re  )r   rF   rt   rE   )rL   ri   rk  r@   r   s        rN   get_private_urlzaster.get_private_url  sZ    >>$,RHH$$%5t<<	it$Y/5;iG
rO   c                 L  K   |                                   d{V  d}|                     dd||          \  }}|                     ||           d{V  |                     |          }|                     |          }|                     ||           |                     | j        d          }|                     |dd          }|                     |dd          }|r |r|	                    |dz              d{V  |dz   }d}	| 
                    |||	|           d{V S )	aI  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#payload-account_update
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#event-balance-and-position-update

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: 'spot' or 'swap', default is 'spot'
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        Nr   r;   Fr<   T:fetchBalanceSnapshot:balance)r\   handle_market_type_and_paramsrc  ro  r   set_balance_cacher   rF   r   futurewatch)
rL   r`   ri   r   r   rF   r;   r<   r   r   s
             rN   watch_balancezaster.watch_balance  sj      !!!!!!!!!99.$PVX\]]ff---------""4((S!!vt,,,..~>>#~~g7MuUU#~~g7MtTT 	@$8 	@--'> >?????????Z'ZZ['4@@@@@@@@@rO   c                 2   ||j         v r|| j        v rd S |                     | j        d          }|                     |dd          }|rD|dz   }||j        vr4|                    |           |                     | j        |||           d S d S i | j        |<   d S )Nr   r;   Frq  )	rP   balancer   rF   r   ri  ru  spawnload_balance_snapshot)rL   r   ri   rF   r;   r   s         rN   rt  zaster.set_balance_cache  s    F(((tt|/C/CF//$,??#~~g7MuUU 	$!88K6>11k***

45v{DQQQQQ 21 "$DLrO   c                 X  K   d|i}|                      |           d {V }|                     ||                     | j        |i                     | j        |<   ||j        v rG|j        |         }|                                 |                    | j        |         |dz              d S d S )Nri   rr  )fetch_balancer{   r   ry  ri  r   )rL   r   r   ri   r`   rb  ru  s          rN   r{  zaster.load_balance_snapshot  s      D
 ++F33333333![[4??4<QUWY3Z3Z[[T&.((^K0FNNNN4<-tj/@AAAAA )(rO   c                    |j         }t          |                                          }|                     |          }|dz   }| j        |         
i | j        |<   || j        |         d<   |                     |d|          }|                     |dg           }|                     | j        dd          }t          dt          |                    D ]}	||	         }
|                     |
d          }|                     |          }|                                 }|                     |
d          |d	<   |                     |
d
          |d<   |                     |
|          |d<   || j        |         |<   |                     |d          }|| j        |         d<   |                     |          | j        |         d<   |                     | j        |                   | j        |<   |                    | j        |         |           d S )Nrr  r   r   r   rC   r=   r   ffreer   usedtotalr   r   r   )rP   r   r   rX   ry  r   	safe_listrt   rF   rS   rT   r  accountr   r   safe_balancer   )rL   r   r   rP   r   rU   r   r   rC   rV   entry
currencyIdcoder  r   s                  rN   handle_balancezaster.handle_balance  s   l , !3!3!5!566>>?PQQ!J.<$,(*DL%,3[!&)..#w77NN7C,,!!$,$??q#a&&!! 	6 	6AaDE))%55J**:66DllnnG"..uc::GFO"..uc::GFO#//v>>GG.5DL%d++%%gs33	1:[!+.04Y0G0G[!*-$($5$5dl;6O$P$P[!t|K0+>>>>>rO   c                 B  K   |                                   d{V  d}|                     ||           d{V  |                     |          }|                     |          }|                     |           g }d}	|                     |ddd          }||                    |	           nCt          dt          |                    D ]%}
||
         }|                    |	dz   |z              &| 	                    ddd          }| 	                    dd	d          }| j
        }|r8|r6|4|                    d           d{V }|                     ||||d          S |                     ||d|g           d{V }| j        r|S |                     ||||d          S )
a  
        watch all open positions

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#event-balance-and-position-update

        :param str[]|None symbols: list of unified market symbols
        :param number [since]: since timestamp
        :param number [limit]: limit
        :param dict params: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/en/latest/manual.html#position-structure>`
        Nr7   	positionsTr   ::r&   r>   r?   )r\   rc  ro  r   set_positions_cacherr   rx   rS   rT   handle_optionr  ru  filter_by_symbols_since_limitrz   r|   )rL   rg   r   r   r`   ri   r   r   r   r   rV   rY   r>   r?   cacher5  newPositionss                    rN   watch_positionszaster.watch_positions.  s
      !!!!!!!!!f---------""4((S!!  (((!%%gvtTBB?  ----1c'll++ B B $$[4%7&%@AAAA!%!3!34DF^`d!e!e!%!3!34DF^`d!e!e! 	]&< 	]#]]+CDDDDDDDDH55hPUW[\\\!00mTD6RRRRRRRR? 	 11%%PTUUUrO   c                     | j         d S |                     ddd          }|r@d}||j        vr3|                    |           |                     | j        ||           d S d S t                      | _         d S )Nr&   r>   F)r  r  ri  ru  rz  load_positions_snapshotr   )rL   r   r>   r   s       rN   r  zaster.set_positions_cacheT  s    >%F!%!3!34DF^`e!f!f! 	82K6>11k***

47MMMMM 21 677DNNNrO   c                   K   |                                   d {V }t                      | _        | j        }t          dt	          |                    D ]<}||         }|                     |dd          }|dk    r|                    |           =||j        v r:|j        |         }|                    |           |                    |d           d S d S )Nr   	contractsr  )	fetch_positionsr   r  rS   rT   r/  rx   ri  r   )	rL   r   r   r  r  rV   positionr  ru  s	            rN   r  zaster.load_positions_snapshot`  s      ..00000000	133q#i..)) 	' 	'A |H((;BBI1}}X&&&&.((^K0FNN5!!!NN5+..... )(rO   c                    d}| j         t                      | _         | j         }|                     |di           }|                     |dg           }g }t	          dt          |                    D ]|}||         }	|                     |	          }
|                     |d          }||
d<   |                     |          |
d<   |	                    |
           |	                    |
           }| 
                    ||          }|                     |          sft	          dt          |                    D ]0}||         }
|
d         }|d	z   |z   }|                    |
|           1|                    |d           d S d S )
Nr  r   r   r   r   r   r   rY   r  )r  r   r   r  rS   rT   parse_ws_positionr   r   rx   find_message_hashesis_emptyr   )rL   r   r   r   r  r   rawPositionsr  rV   rawPositionr  r   r   rY   symbolMessageHashs                  rN   handle_positionszaster.handle_positionso  s   @ ">!577DN~~gsB//~~dC44q#l++,, 	# 	#A&q/K--k::H))'377I$-H[!#'<<	#:#:HZ )))LL""""00EE}}]++ 	61c,//00 < <'?!(+$/$$6$?!x):;;;;NN<55555	6 	6rO   c           
         |                      |d          }|                      |d          }t          j        |                      |d                    }|                     |d          }d}|dk    r1d}t          j        |d          st          j        |d          rd}nd	}|                     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 d d d          S ) Nr   papsTbothF0shortlongr   ro   rY   r7   notional
marginModemtliquidationPrice
entryPriceepunrealizedPnlupr   r  contractSizer   r  hedgedr   r   maintenanceMargin)maintenanceMarginPercentage
collateralinitialMargininitialMarginPercentageleveragemarginRatio)
rt   r   
string_absry   	string_eq	string_ltsafe_positionr]   r/  parse_number)rL   r  rw   r   r  contractsAbspositionSider  s           rN   r  zaster.parse_ws_position  s    ##Hc22$$Xt44	)$*:*:8T*J*JKK--h==6!!F$Y44 *$Y44 *#*LL#)L!! #
H#
$#
 d&&xtVDD#
 	#

 $**8T::#
 #
 $**8T::#
 T--h==#
 $#
 **<88#
 D#
 #
 L#
 f#
 #
  !#
"  ##
$ ,0!'+/#
 #
 #
   	rO   c                 2  K   |                                   d{V  d}||                     |          }|d         }d}d}|                     d|||          \  }}|                     ||           d{V  ||d|z   z  }|                     |          }|                     |          }	|                     |	|           |                     ||gd|g           d{V }
| j        r|
	                    ||          }| 
                    |
|||d          S )a  
        watches information on multiple orders made by the user

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#payload-order-update
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#event-order-update

        :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 [params.type]: 'spot' or 'swap', default is 'spot' if symbol is not provided
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        NrY   ordersr!   r  Tr\   rw   rs  rc  ro  r   rt  rz   r|   r   filter_by_symbol_since_limit)rL   rY   r   r   r`   rw   r   ri   r   r   r  s              rN   watch_orderszaster.watch_orders  sY      !!!!!!!!![[((FH%F99-QWY]^^ff---------4&=(K""4((S!!vt,,,**3tdVLLLLLLLL? 	3OOFE22E00tTTTrO   c                 2  K   |                                   d{V  d}||                     |          }|d         }d}d}|                     d|||          \  }}|                     ||           d{V  ||d|z   z  }|                     |          }|                     |          }	|                     |	|           |                     ||gd|g           d{V }
| j        r|
	                    ||          }| 
                    |
|||d          S )a  
        watches information on multiple trades made by the user

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#payload-order-update
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#event-order-update

        :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 [params.type]: 'spot' or 'swap', default is 'spot' if symbol is not provided
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        NrY   myTradesr!   r  Tr  )rL   rY   r   r   r`   rw   r   ri   r   r   r   s              rN   watch_my_tradeszaster.watch_my_trades  sY      !!!!!!!!![[((FH%F 99-QWY]^^ff---------4&=(K""4((S!!vt,,,**3tdVLLLLLLLL? 	3OOFE22E00tTTTrO   c                     |                      |d|          }|                     |d          }|dk    s|dk    r|                      |d|          }|                     ||           |                     ||           d S )Nr   r   ORDER_TRADE_UPDATEALGO_UPDATE)r   rt   handle_orderhandle_my_trade)rL   r   r   rawOrderr   s        rN   handle_order_updatezaster.handle_order_update  s    >>'388Wc**%%%1+=+=nnWc7;;G&(+++VW-----rO   c                    d}|                      |d          }|dk    r8|j                            d          dk    }|rdnd}|                     d|i          }|                     ||          }|                      |d	          }	|                     |d
i           }
|                     i |
          }
|                      |d          }|	|
|| j        }||                     |j	        |i           }|                     ||	          }||                     |d          }|                     |d
          }| 
                    |          sd}t          dt          |                    D ]z}||         }|d         |
d         k    r^|                     |
d         |d                   }t          |                     |
d         |                    |d         |         d<   d} n{|r|d                             |
           n||d         |
d         k    rU|                     |d         |
d                   }t          |                     |
d         |                    |d
         d<   n |d         |
|d
<   n||
g|d<   d |d
<   n|
|d
<   |                     |dg           }|                    |           ||d<   | j        0|                     | j        dd          }t+          |          | _        | j        }|                    |           |                    | j        |           |dz   |z   }|                    | j        |           d S d S )Nr  xTRADEfstreamr   r7   r6   ri   r  r  rY   feesTr  r  Fr   r   r   r  )rt   r   findsafe_market_structurer   r   r{   r  r   hashmapr  rS   rT   sumfloatcurrency_to_precisionrx   r  r  r   rF   r   r   )rL   r   r   r   executionTypeisSwapri   
fakeMarketr   r  tradeFeerY   cachedOrdersr  r  r  r  insertNewFeeCurrencyrV   orderFeer  orderTradesr   r  messageHashSymbols                            rN   r  zaster.handle_my_trade$  s    ((#66G##Z__Y//14F#/66D33VTNCCJ''<<E&&ug66G~~eUB77H{{2x00H%%eX66F"x';@R#{+!__\-A62NNF OOFG<<E(#uf=="ooeU;;#}}T22 4370%*1c$ii%8%8 * *+/7#+J#78J;O#O#O.2hhx7GRXIY.Z.ZG?DTE_E_`his`tv}E~E~??E&M!$4V$<;@$8$)E	 $P
  4 ? %f 4 4X > > > _":(:2FFF*.((3v;@P*Q*Q7<T=W=WX`akXlnu=v=v7w7weV 4 4!$Z!8/7e14hf/3e+3E%L&*nnUHb&I&I#**5111*5h }$))$,tLL 6u = =}HOOE"""NN4=+666 +d 2V ;NN4=*;<<<<<k $#rO   c                    d}|                      ||          }| j        0|                     | j        dd          }t	          |          | _        | j        }|                     ||          }|d         }|                    |           |                     ||          }	|                     |	          s6|dz   |z   }
|	                    ||
           |	                    ||           d S d S )Nr  ordersLimitr   rY   r  )
get_market_from_orderr  r   rF   r   parse_ws_orderrx   r  r  r   )rL   r   r   r   rw   r   r  r   rY   r   r  s              rN   r  zaster.handle_order^  s    V ++FG<<;%%dlM4HHE077DK$$Wf55!V00EE}}]++ 	/ +d 2V ;NN5"3444NN5+.....	/ 	/rO   c                    |                      |d          }|                      |d          }|                     ||          }|                     |d          }|                     |d          }d }|dk    s|dk    s|dk    r||}n|dk    r|}|}d }	|                      |d	          }
|
Et          j        |
d
          r0|                      |d          }|                     |          }|
|d}	|                      |d          }|                     |          }|                     |dd          }|t          |          dk    r|                      |d          }| 	                    |g d          }|                      |d          }|dk    rd}| 
                    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/          |                      |d0          d ||	d d1          S )2Nr  r   Or   NEW	AMENDMENTCANCELEDr  r  r  r  r  XCcaidr   r   )r   sptpr  GTXPOr   rY   ro   rV   aidclientOrderIdr   r   lastTradeTimestamplastUpdateTimestampri   r   timeInForcepostOnly
reduceOnlyRr  r  r  r   	stopPricetriggerPricer  r   Zapz)r  r   filled	remainingstatusr  r   )rt   r   r   r   	string_gtr  parse_order_statusr  rT   safe_string_n
safe_orderr   parseOrderTypery   r   )rL   r  rw   r  r   r   r   r  r  r  r  r  feeCurrency	rawStatusr  r  r  r  s                     rN   r  zaster.parse_ws_order  s   ((44##E3//!!(F33%%eS11	eS))!E!!]k%A%A]V`E`E` 	g%%!"""5#..g&7&E&E ,,UC88M11-@@K' C $$UC00	((33**5#v>>!s='9'9Q'>'> ,,UC88M&&u.?.?.?@@	&&uc22%K  
E 
fX& 
 $$$UC77 
 ]	 

  
 Y// 
 !"4 
 "#6 
 D''(>(>uc(J(JKK 
 ; 
  
 $..44 
 D**5#66 
 T%%eS11 
  
  I! 
" d&&uc22# 
$ $$UC00''t44&&uc221 
  
  
   	rO   c                     |                      |d          }|j        }t          |                                          }|                     |          }|                     |d d |          S )Nr   )rt   rP   r   r   rX   r   )rL   r   r  r   rP   r   r   s          rN   r  zaster.get_market_from_order  sg    ##E3//, !3!3!5!566==>OPP
$jAAArO   c           	         |                      |d          }||                    d          }|                      |dd          }|                    d          }|                      |dd          }| j        | j        | j        | j        | j        | j        | j        | j        d}|                     ||          }| |||           d S d S |                      |d          }	|	d	k    r|                     ||           d S |	d
k    r.|                     ||           | 	                    ||           d S |	dk    s|	dk    r| 
                    ||           d S d S )Nstreamr   r   rR   _r   )r   r  depth5depth10depth20rS  r   
bookTickerr   outboundAccountPositionACCOUNT_UPDATEr  executionReport)rt   r   r   r   r6  rV  r   r   r  r  r  )
rL   r   r   r  r   topicpart2methodsrn   r   s
             rN   handle_messagezaster.handle_message  s   !!'844<<$$D$$T1b11EKK$$E$$UAr22E, -011*!/"1	 	G __We44F!vw''''' "! $$Wc22E111##FG44444***##FG444%%fg66666///U>O5O5O((99999 6P5OrO   )N)r6   )H__name__
__module____qualname__r   rK   r   r,  rX   r   rb   rf   r   r   r^   rd   r   r   r   r   r   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   r   r"  r%  r!  r$  r6  r   r;  r>  r9  r=  rV  rR  rc  r^  ro  r   rw  rt  r{  r  r   r  r  r  r  r  r   r
   r  r  r  r  r  r  r  r  __classcell__)rM   s   @rN   r   r      s6	       F# F F F F F FPc s     68   F    " 9; = =C =s = = = = 6:" &E &E7 &E &E &E &E &EP 9=R !c !cg !cC !c !c !c !cF :<  S     " =? A A A3 A A A A :>b (E (Ew (EW (E (E (E (ET =A #c #c' #cPS #c #c #c #cJ/:F /: /: /: /:b& & &P 8<B #F #FW #F7 #F #F #F #FJ ;?r c c cc c c c c@,V , , , ,:    <@d[] S S SS S Sbfglbm S S S S  9; H HC Hs H H H H OSaenp (S (Sd3i (S (S[^ (Suyz  vA (S (S (S (ST LN !c !cc !cRU !c !c !c !cF!,6 !, !, !, !,FZ ZE Z Z Z Zx @DB P PS P PS\ P P P P =? L L L3 L L L L SW_a %! %!$s) %!C %!fo %! %! %! %!N PR &c &cT#Y &cVY &c &c &c &cP*/ */ */ */ */X 8<$]ajl ) ) )C )WZ )quvzq{ ) ) ) )( ;?r T T3 Tc T T T T aesw  AC ,E ,E$tCy/ ,EZ] ,Emp ,E ,E ,E ,E\ ^` &c &cT$s)_ &cdg &c &c &c &cP316 31 31 31 31j
 
D 
 
 
 
 '-R Q Q Q Q" 24 M M M M.    *, A A A A A A6$ $ $ $ $
B 
B 
BM?V M? M? M? M?^ 8<$]ajl $V $VW $VC $VWZ $Vquv~q $V $V $V $VL
8& 
8 
8 
8 
8/ / /66 66 66p1 1 1 1f 04$UYbd U U UC Us Uimnsit U U U UB 37TX\eg U UC Us URU Ulpqvlw U U U UB.& . . . .8=f 8= 8= 8= 8=tX/6 X/ X/ X/ X/t9 9 9 9vBF B B B B:V : : : : : : : :rO   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   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   ccxt.base.preciser   async_supportr    rO   rN   <module>r'     s5       A  A  A  A  A  A  A  A  A  A  A  A p p p p p p p p p p p p p p p p p p p p p p p p p p 4 4 4 4 4 4       . . . . . . % % % % % %H: H: H: H: H:D$ H: H: H: H: H:rO   