
    i                         d dl Zd dlmZ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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 d dlmZ  G d	 d
ej        j                  ZdS )    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)BalancesIntNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTrade)Client)List)AuthenticationError)NetworkError)InvalidNoncec                       e Zd Z fdZd Zdi fdededefdZdi fde	e         dedefd	Z
d
 Zd ZdefdZddi fdededede	e         fdZddi fde	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i fd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efdZdddi fdededede	e         fdZd4defdZdddi fdededede	e         fdZ d4dedefdZ!d Z"d Z#i fde$fdZ%defdZ&di fded e'd!e(d"e)d#e*defd$Z+defd%Z,di fd&ededefd'Z-di fdefd(Z.defd)Z/i fd*Z0i fd+Z1i fd,Z2i fd-Z3defd.Z4defd/Z5defd0Z6i fd1Z7defd2Z8defd3Z9 xZ:S )5	cryptocomc                     |                      t          t          |                                           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dddii d          S )NTF)wswatchBalancewatchTickerwatchTickerswatchMyTradeswatchTradeswatchTradesForSymbolswatchOrderBookwatchOrderBookForSymbolswatchOrders
watchOHLCVwatchPositionscreateOrderWscancelOrderWscancelAllOrdersr   z*wss://stream.crypto.com/exchange/v1/marketz(wss://stream.crypto.com/exchange/v1/user)publicprivatez+wss://uat-stream.3ona.co/exchange/v1/marketz)wss://uat-stream.3ona.co/exchange/v1/user)apitestr&   )fetchPositionsSnapshotawaitPositionsSnapshot)hasurlsoptions	streaming)deep_extendsuperr   describe)self	__class__s    X/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/pro/cryptocom.pyr6   zcryptocom.describe   s    i 6 6 ? ? A A $# %!%#)-"&,0#""&!%!%#' & "N#M  LJ   !.2.2# #I&D
 &D
 & & &	    c                 $  K   	 |                     |                     |d          dd           d {V  d S # t          $ rM}t          | j        dz   |                     |          z             }|                    |           Y d }~d S d }~ww xY w)Nidzpublic/respond-heartbeat)r<   methodz pong failed with error )sendsafe_integer	Exceptionr   r<   jsonreset)r7   clientmessageeerrors        r9   pongzcryptocom.pong<   s      	 ++T%6%6w%E%EQkllmmmmmmmmmmm 	  	  	  +E!E		RS!TUUELL	 s   28 
BAB

BNsymbollimitreturnc                 B   K   |                      |g||           d{V S )a  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#book-instrument_name
        :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
        :param str [params.bookSubscriptionType]: The subscription type. Allowed values: SNAPSHOT full snapshot. This is the default if not specified. SNAPSHOT_AND_UPDATE delta updates
        :param int [params.bookUpdateFrequency]: Book update interval in ms. Allowed values: 100 for snapshot subscription 10 for delta subscription
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        N)watch_order_book_for_symbols)r7   rH   rI   paramss       r9   watch_order_bookzcryptocom.watch_order_bookH   s4       66xOOOOOOOOOr:   symbolsc                   K   |                                   d{V  |                     |          }g }g }|sd}|                     |d          }|i |d<   d}|                     |dddd          \  }}|||d         d<   d}|                     |ddd          \  }}|||d         d<   t	          d	t          |                    D ]r}	||	         }
|                     |
          }d
|d         z   dz   t          |          z   }d|d         z   }|                    |           |                    |           s| 	                    |||           d{V }|
                                S )a  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#book-instrument_name
        :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
        :param str [params.bookSubscriptionType]: The subscription type. Allowed values: SNAPSHOT full snapshot. This is the default if not specified. SNAPSHOT_AND_UPDATE delta updates
        :param int [params.bookUpdateFrequency]: Book update interval in ms. Allowed values: 100 for snapshot subscription 10 for delta subscription
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        N2   rM   r"   r#   bookSubscriptionTypeSNAPSHOT_AND_UPDATEbookUpdateFrequencyr   zbook.r<   .
orderbook:rH   )load_marketsmarket_symbols
safe_valuehandle_option_and_params_2rangelenmarketstrappendwatch_public_multiplerI   )r7   rO   rI   rM   topicsmessageHashestopicParamsrR   rT   irH   r]   currentTopicmessageHash	orderbooks                  r9   rL   z&cryptocom.watch_order_book_for_symbolsU   s      !!!!!!!!!%%g.. 	Eoofh77!F8#'+'F'FvO_a{  ~T  Vk  (l  (l$f+7KF834"&*&E&EfN^`z  }R  'S  'S#V*7KF834q#g,,'' 	( 	(AQZF[[((F'&,6<s5zzIL&)99K  ---MM,''''44]FFSSSSSSSS	   r:   c                     |                      |d          }|                      |d          }|                     |d          }|                    |||           d S )Nr         )
safe_floatr?   store)r7   booksidedeltapriceamountcounts         r9   handle_deltazcryptocom.handle_delta{   sY    q))**!!%++ufe,,,,,r:   c                 ~    t          dt          |                    D ]}|                     |||                    d S )Nr   )r[   r\   rr   )r7   rm   deltasrd   s       r9   handle_deltaszcryptocom.handle_deltas   sH    q#f++&& 	3 	3Ahq	2222	3 	3r:   rC   c                 @   |                      |d          }|                     |          }|d         }|                     |d          }|                     |d          }|                     |d          }|                     | j        |          }|,|                     |d          }	|                     i |	          }|                      |d          }
|                     |dd	          }|}|
d
k    r=|                    i            ||d<   ||d<   |                     |          |d<   ||d<   na|                     |di           }|                     |d          }|d         }||k    r&t          | j
        dz   |z   dz   |z   dz   |z             |                     |d         |                     |dg                      |                     |d         |                     |dg                      ||d<   || j        |<   d|z   }|                    ||           d S )Ninstrument_namerH   datar   tdepthchannelusbook	timestampdatetimenonceupdatepuz watchOrderBook()  z != asksbidsrV   )safe_stringsafe_marketrY   r?   
orderbookscounted_order_booksafe_integer_2rB   iso8601r   r<   ru   resolve)r7   rC   rD   marketIdr]   rH   rx   r   rg   rI   r{   r   bookspreviousNoncecurrentNoncerf   s                   r9   handle_order_bookzcryptocom.handle_order_book   s>   p ##G->??!!(++!w//tQ''%%dC00	OODOV<<	%%gw77E//E::I""7I66##D#s33fOOB"(Ih%.Ik"$(LL$;$;Ij!!&IgOOD(B77E --dD99M$W-L},,"47-A#AF#JS#PS`#`ci#ilq#qrrr9V,dooeVR.P.PQQQ9V,dooeVR.P.PQQQ"	'"+"V+y+.....r:   sincec                 D   K   |                      |g|||           d{V S )@  
        get the list of most recent trades for a particular symbol
        :see: https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#trade-instrument_name
        :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>`
        N)watch_trades_for_symbols)r7   rH   r   rI   rM   s        r9   watch_tradeszcryptocom.watch_trades   s6       22F8UE6RRRRRRRRRr:   c                    K   |                                   d{V  |                     |          }g }t          dt          |                    D ]?}||         }|                     |          }d|d         z   }	|                    |	           @|                     |||           d{V }
| j        rB|                     |
d          }| 	                    |d          }|

                    ||          }|                     |
||dd          S )r   Nr   ztrade.r<   rH   r   T)rW   rX   r[   r\   r]   r_   r`   
newUpdatesrY   r   getLimitfilter_by_since_limit)r7   rO   r   rI   rM   ra   rd   rH   r]   re   tradesfirsttradeSymbols                r9   r   z"cryptocom.watch_trades_for_symbols   s*      !!!!!!!!!%%g..q#g,,'' 	( 	(AQZF[[((F(6$<7LMM,''''11&&&IIIIIIII? 	8OOFA..E**5(;;KOOK77E))&%TRRRr:   c                    |                      |d          }|                      |d          }|                      |d          }|                     |          }|d         }|                     | j        |          }|5|                     | j        dd          }	t          |	          }|| j        |<   |                     |dg           }
t          |
          }|dk    rd S |                     |
|          }t          dt          |                    D ]}|
                    ||                    |                    d	|z   d
          }|                    ||           |                    ||           d S )Nr{   rw   subscriptionrH   tradesLimit  rx   r   rU    )r   r   rY   r   r?   r2   r   r\   parse_tradesr[   r_   replacer   )r7   rC   rD   r{   r   symbolSpecificMessageHashr]   rH   storedrI   rx   
dataLengthparsedTradesjchannelReplaceds                  r9   handle_tradeszcryptocom.handle_trades  sq   . ""7I66##G->??$($4$4Wn$M$M!!!(++!f55>%%dlM4HHE&&F"(DKw33YY
??F((v66q#l++,, 	+ 	+AMM,q/****!//#."==v8999v/////r:   c                 H  K   |                                   d{V  d}||                     |          }|d         }d}||dz   |d         z   n|}|                     ||           d{V }| j        r|                    ||          }|                     ||||d          S )aY  
        watches information on multiple trades made by the user
        :see: https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#user-trade-instrument_name
        :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
        NrH   
user.traderU   r<   TrW   r]   watch_private_subscriber   r   filter_by_symbol_since_limit)r7   rH   r   rI   rM   r]   rf   r   s           r9   watch_my_tradeszcryptocom.watch_my_trades.         !!!!!!!!![[((FH%F"=C=O{S(6$<77Va33KHHHHHHHH? 	3OOFE22E00tTTTr:   c                    K   |                                   d{V  |                     |          }d|d         z   }|                     ||           d{V S )a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#ticker-instrument_name
        :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>`
        Nzticker.r<   )rW   r]   watch_public)r7   rH   rM   r]   rf   s        r9   watch_tickerzcryptocom.watch_tickerD  ss       !!!!!!!!!V$$$vd|3&&{F;;;;;;;;;r:   c                    |                      |d          }|                      |d          }|                     |          }|                     |dg           }t          dt	          |                    D ]H}||         }|                     ||          }	|	d         }
|	| j        |
<   |                    |	|           Id S )Nr   rw   rx   r   rH   )r   r   rY   r[   r\   parse_tickertickersr   )r7   rC   rD   rf   r   r]   rx   rd   tickerparsedrH   s              r9   handle_tickerzcryptocom.handle_tickerQ  s    . &&w??##G->??!!(++w33q#d))$$ 	0 	0A!WF&&vv66FH%F#)DL NN6;////	0 	0r:   1mc                 r  K   |                                   d{V  |                     |          }|d         }|                     | j        ||          }d|z   dz   |d         z   }|                     ||           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
        :see: https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#candlestick-time_frame-instrument_name
        :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
        NrH   zcandlestick.rU   r<   r   T)rW   r]   r   
timeframesr   r   r   r   )
r7   rH   	timeframer   rI   rM   r]   intervalrf   ohlcvs
             r9   watch_ohlcvzcryptocom.watch_ohlcvs  s       !!!!!!!!!V$$!##DOY	JJ)H4s:VD\I''V<<<<<<<<? 	2NN6511E))%q$GGGr:   c                    |                      |d          }|                      |d          }|                     |          }|d         }|                      |d          }|                     |          }|                     | j        |i           | j        |<   |                     | j        |         |          }	|	;|                     | j        dd          }
t          |
          }	|	| j        |         |<   |                     |d          }t          dt          |                    D ]5}||         }| 
                    ||          }|	                    |           6|                    |	|           d S )	Nr   rw   rH   r   
OHLCVLimitr   rx   r   )r   r   find_timeframerY   ohlcvsr?   r2   r   r[   r\   parse_ohlcvr_   r   )r7   rC   rD   rf   r   r]   rH   r   r   r   rI   rx   rd   tickr   s                  r9   handle_ohlcvzcryptocom.handle_ohlcv  sg    &&w??##G->??!!(++!##GZ88''11	"oodk62FFFV!4i@@>%%dlL$GGE*511F-3DK	*w//q#d))$$ 	" 	"A7D%%dF33FMM&!!!!v{+++++r:   c                 H  K   |                                   d{V  d}||                     |          }|d         }d}||dz   |d         z   n|}|                     ||           d{V }| j        r|                    ||          }|                     ||||d          S )aU  
        watches information on multiple orders made by the user
        :see: https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#user-order-instrument_name
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        NrH   
user.orderrU   r<   Tr   )r7   rH   r   rI   rM   r]   rf   orderss           r9   watch_orderszcryptocom.watch_orders  r   r:   c                 Z   |                      |d          }|                      |d          }|                     |dg           }t          |          }|dk    r| j        0|                     | j        dd          }t          |          | _        | j        }	|                     |          }
t          dt          |
                    D ]}|		                    |
|                    |
                    |	|           |
                    |	|           |
                    |	d           d S d S )Nr{   r   rx   r   ordersLimitr   r   )r   rY   r\   r   r?   r2   r   parse_ordersr[   r_   r   )r7   rC   rD   r   r{   r   r   ordersLengthrI   r   r   rd   s               r9   handle_orderszcryptocom.handle_orders  s'   > ""7I66$($4$4Wn$M$M!&"556{{!{"))$,tLL4U;;[F&&v..F1c&kk** ) )fQi((((NN6#<===NN67+++NN6<00000 r:   c                 B  K   |                                   d{V  |                                  d{V  | j        d         d         d         }|                                 }dddgi|d}d	}|                     |          }|                     |          sd
d                    |          z   }|                     |          }	|                     |	|           | 	                    ddd          }
| 
                    ddd          }|
r=|r;| j        4|	                    d           d{V }|                     ||||d          S |                     |||                     ||                     d{V }| j        r|S |                     | j        |||d          S )a  
        watch all open positions
        :see: https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#user-position_balance
        :param str[]|None symbols: list of unified market symbols
        :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>`
        Nr,   r   r+   	subscribechannelsuser.position_balancer=   rM   r   	positions::,r&   r.   Tr/   )rW   authenticater1   r   rX   is_emptyjoinrC   set_positions_cachehandle_option	safe_boolr   futurefilter_by_symbols_since_limitwatchextendr   )r7   rO   r   rI   rM   urlr<   requestrf   rC   r.   r/   snapshotnewPositionss                 r9   watch_positionszcryptocom.watch_positions  s      !!!!!!!!!!!!!!!!!!it$Y/ZZ\\!45 
 
 "%%g..}}W%% 	3'!2!22KS!!  111!%!3!34DF^`d!e!e!%0@BZ\`!a!a! 	]&< 	]AW#]]+CDDDDDDDDH55hPUW[\\\!ZZ[$++gv:V:VWWWWWWWW? 	 11$.'5RWY]^^^r:   c                     |                      ddd          }|r@d}||j        vr3|                    |           |                     | j        ||           d S d S t                      | _        d S )Nr&   r.   F)r   futuresr   spawnload_positions_snapshotr   r   )r7   rC   typerO   r.   rf   s         r9   r   zcryptocom.set_positions_cache  s    !%!3!34DF^`e!f!f! 	82K6>11k***

47MMMMM 21 677DNNNr:   c                   K   |                                   d {V }t                      | _        | j        }t          dt	          |                    D ]<}||         }|                     |dd          }|dk    r|                    |           =|j        |         }|                    |           |                    |d           d S )Nr   	contractsr   )	fetch_positionsr   r   r[   r\   safe_numberr_   r   r   )	r7   rC   rf   r   cacherd   positionr   r   s	            r9   r   z!cryptocom.load_positions_snapshot  s      ..00000000	133q#i..)) 	' 	'A |H((;BBI1}}X&&&,uuk*****r:   c                 6   |                      |dg           }|                      |di           }|                      |dg           }| j        t                      | _        | j        }g }t          dt	          |                    D ]I}||         }	|                     |	          }
|                    |
           |                    |
           J|                     |d          }t          dt	          |                    D ]}||         }|                    d          }|d         }|                    d          }| 	                    |d|d	          }| 
                    |          s|                    ||           |                    |d           d S )
Nrx   r   r   zpositions::r   ri   r   rH   F)rY   r   r   r[   r\   parse_positionr_   find_message_hashessplitfilter_by_arrayr   r   )r7   rC   rD   rx   	firstDatarawPositionsr   r   rd   rawPositionr   rb   rf   partssymbolsStringrO   r   s                    r9   handle_positionszcryptocom.handle_positions'  s   6 w33OOD!R00	y+rBB>!577DNq#l++,, 	# 	#A&q/K**;77H)))LL""""00GGq#m,,-- 	7 	7A'*K%%d++E!!HM#))#..G,,\8WeTTI==++ 7y+666|[11111r:   c                 B   K   d}|                      ||           d{V S )ax  
        watch balance and get the amount of funds available for trading or funds locked in orders
        :see: https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#user-balance
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        user.balanceN)r   )r7   rM   rf   s      r9   watch_balancezcryptocom.watch_balanceY  s5       %11+vFFFFFFFFFr:   c                    |                      |d          }|                     |dg           }|                     |d         dg           }|| j        d<   t          dt	          |                    D ]}||         }|                      |d          }|                     |          }	|                                 }
|                      |d          |
d<   |                      |d	          |
d
<   |
| j        |	<   |                     | j                  | _        |                    | j        |           |                      |d          }|                    | j        |           d S )Nr   rx   r   position_balancesinforw   quantitytotalreserved_qtyusedr<   )	r   rY   balancer[   r\   safe_currency_codeaccountsafe_balancer   )r7   rC   rD   rf   rx   positionBalancesrd   r  
currencyIdcoder  messageHashRequests               r9   handle_balancezcryptocom.handle_balancec  sY   \ &&w??w33??474GLL#Vq#.//00 	; 	;A&q)G))'3DEEJ**:66DllnnG#//DDGG"..wGGGFO!(DL,,T\::DLLt|[111!--gt<<t|%788888r:   r   siderp   ro   c                    K   |                                   d{V  |                     ||||||          }d|d}|                                 }|                     ||           d{V S )a  
        :see: https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order
        create a trade order
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nprivate/create-orderr=   rM   )rW   create_order_requestr   watch_private_request)	r7   rH   r   r  rp   ro   rM   r   rf   s	            r9   create_order_wszcryptocom.create_order_ws  s       !!!!!!!!!**64vufUU,
 
 jjll//WEEEEEEEEEr:   c                     |                      |d          }|                     |di           }|                     |          }|                    ||           d S )Nr<   result)r   rY   parse_orderr   )r7   rC   rD   rf   rawOrderorders         r9   handle_orderzcryptocom.handle_order  s[     &&w55??7Hb99  **uk*****r:   r<   c                    K   |                                   d{V  |                     d|i|          }d|d}|                                 }|                     ||           d{V S )a  
        cancels an open order
        :see: https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-order
        :param str id: the order id of the order to cancel
        :param str [symbol]: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Norder_idprivate/cancel-orderr  )rW   r   r   r  )r7   r<   rH   rM   r   rf   s         r9   cancel_order_wszcryptocom.cancel_order_ws  s       !!!!!!!!!
  -
 
 jjll//WEEEEEEEEEr:   c                    K   |                                   d{V  d}d|                     i |          d}|&|                     |          }|d         |d         d<   |                                 }|                     ||           d{V S )a  
        cancel all open orders
        :see: https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-all-orders
        :param str symbol: unified market symbol of the orders to cancel
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict} Returns exchange raw message {@link https://docs.ccxt.com/#/?id=order-structure:
        Nprivate/cancel-all-ordersr  r<   rM   rw   )rW   r   r]   r   r  )r7   rH   rM   r]   r   rf   s         r9   cancel_all_orders_wszcryptocom.cancel_all_orders_ws  s       !!!!!!!!!1kk"f--
 
 [[((F39$<GH/0jjll//WEEEEEEEEEr:   c                 ^    |                      |d          }|                    ||           d S )Nr<   )r   r   )r7   rC   rD   rf   s       r9   handle_cancel_all_ordersz"cryptocom.handle_cancel_all_orders  s3     &&w55w,,,,,r:   c                    K   | j         d         d         d         }|                                 }dd|gi|d}|                     ||          }|                     ||||           d {V S Nr,   r   r*   r   r   r   )r1   r   r   r   r7   rf   rM   r   r<   r   rD   s          r9   r   zcryptocom.watch_public  s      it$X.ZZ\\![M 
 
 ++gv..ZZ[';GGGGGGGGGr:   c                    K   | j         d         d         d         }|                                 }dd|i|d}|                     ||          }|                     ||||           d {V S r+  )r1   r   r4   watch_multiple)r7   rb   ra   rM   r   r<   r   rD   s           r9   r`   zcryptocom.watch_public_multiple  s      it$X.ZZ\\!F 
 
 ""7F33((mWmTTTTTTTTTr:   c                    K   |                                   d {V  | j        d         d         d         }||d}|                     ||          }|                     |t	          |          |d           d {V S )Nr,   r   r+   )r<   r   T)r   r1   r   r   r^   )r7   r   rM   r   r   rD   s         r9   r  zcryptocom.watch_private_request  s      !!!!!!!!!it$Y/
 
 ++gv..ZZSZZ$?????????r:   c                   K   |                                   d {V  | j        d         d         d         }|                                 }dd|gi|d}|                     ||          }|                     ||||           d {V S )Nr,   r   r+   r   r   r   )r   r1   r   r   r   r,  s          r9   r   z!cryptocom.watch_private_subscribe  s      !!!!!!!!!it$Y/ZZ\\![M 
 
 ++gv..ZZ[';GGGGGGGGGr:   c                    |                      |d          }	 |r|dk    r|| j        dz   |                     |          z   }|                     | j        d         ||           |                     |d          }|"|                     | j        d         ||           dS # t          $ r_}t          |t                    r*d}|
                    ||           ||j        v r|j        |= n|
                    |           Y d }~d	S d }~ww xY w)
Nr  0r   exactrD   broadFauthenticatedT)r   r<   rA   throw_exactly_matched_exception
exceptionsrY   throw_broadly_matched_exceptionr@   
isinstancer   rejectsubscriptions)r7   rC   rD   	errorCodefeedbackmessageStringrE   rf   s           r9   handle_error_messagezcryptocom.handle_error_message-  s0    $$Wf55		 lY#--7S=499W+=+==44T_W5MyZbccc $ C C ,889QS`bjkkk5 	 	 	!011 !-a---&"666,[9a   44444	s   BB 
D(ADDc           
         | j         | j        | j        | j        | j        | j        | j        | j        | j        d	}|                     |dd          }|                     |d          }|/|	                    d          dk    r|                     ||           |+|
                    d          r|                     ||           |                     ||          }| |||           d S d S )N)	candlestickr   trader~   zbook.updater   r   r  r   r  r  r{   r   r   )r   r   r   r   r   r  r   safe_value_2r   find
startswithrY   )r7   rC   rD   methodsr  r{   r=   s          r9   handle_subscribezcryptocom.handle_subscribeI  s   ,('*1,, /%)%:

 

 ""7Hf==""6955W\\,%?%?"%D%Dvv...W%7%7%E%Evv...'22F66""""" r:   c           	         |                      ||          rd S |                     |d          }| j        | j        | j        | j        | j        | j        | j        | j        d}|                     ||          }| |||           d S d S )Nr=   )r   zpublic/heartbeatpublic/authr  r#  r&  zprivate/close-positionr   )r?  r   handle_pinghandle_authenticater   r)  rH  rY   )r7   rC   rD   r=   rG  
callMethods         r9   handle_messagezcryptocom.handle_messagea  s    > $$VW55 	F!!'844  $ 03$($5$($5)-)F&*&7.	
 	
 __Wf55
!Jvw''''' "!r:   c                 v  K   |                                   | j        d         d         d         }|                     |          }d}|                    |          }|                     |j        |          }|d}t          |                                           }||z   | j        z   |z   }	| 	                    | 
                    |	          | 
                    | j                  t          j                  }
|||| j        |
d}|                     ||          }|                     ||||           | d {V S )Nr,   r   r+   r5  rJ  )r<   r   r=   api_keysig)check_required_credentialsr1   rC   r   rY   r;  r^   r   apiKeyhmacencodesecrethashlibsha256r   r   )r7   rM   r   rC   rf   r   r5  r=   r   auth	signaturer   rD   s                r9   r   zcryptocom.authenticate  s-     '')))it$Y/S!!%{++(<kJJ "F

%%EE>DK/%7D		$++d"3"3T[[5M5Mw~^^I ;  G kk'622GJJsK+>>>||||||r:   c                 >    |                      | j        ||           d S N)r   rG   )r7   rC   rD   s      r9   rK  zcryptocom.handle_ping  s     

49fg.....r:   c                 f    |                      |j        d          }|                    d           d S )Nr5  T)rY   r   r   )r7   rC   rD   r   s       r9   rL  zcryptocom.handle_authenticate  s1     AAtr:   r\  );__name__
__module____qualname__r6   rG   r^   r   r   rN   r   rL   rr   ru   r   r   r   r   r   r   r   r   r   r   r   listr   r   r
   r   r   r   r   r   r   r   r   r   r  r  r   r   floatr	   r  r   r$  r'  r)  r   r`   r  r   r?  rH  rN  r   rK  rL  __classcell__)r8   s   @r9   r   r      sB       ' ' ' ' 'R
  
  
  @DB P PS P PS\ P P P P SW_a $! $!$s) $!C $!fo $! $! $! $!L- - -3 3 3V/ V/ V/ V/ V/p <@d[] 
S 
S 
SS 
S 
Sbfglbm 
S 
S 
S 
S OSaenp S Sd3i S S[^ Suyz  vA S S S S2*0F *0 *0 *0 *0X 37TX\eg U UC Us URU Ulpqvlw U U U U, 68 < < <F < < < < 0F  0  0  0  0D 8<$]ajl H H HC HWZ Hquvzq{ H H H H*,6 , , , ,< 04$UYbd U U UC Us Uimnsit U U U U,.1 .1F .1 .1 .1 .1` 8<$]ajl !_ !_W !_C !_WZ !_quv~q !_ !_ !_ !_F8 8& 8 8 8 8 8+ + +02 02 02d *, G G G G G G=9V =9 =9 =9 =9~ pt|~ F FC Fy F	 F[` Fil F  DI F F F F*+6 + + + +" <@ F F FS Fu F F F F( 8<B F F F F F F(	-v 	- 	- 	- 	- 68 H H H H IK U U U U 9; @ @ @ @ AC H H H H6    8#v # # # #0.(V .( .( .( .(` )+    ./& / / / /&        r:   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r   rW  ccxt.base.typesr   r   r	   r
   r   r   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   async_supportr    r:   r9   <module>rm     sV       A  A  A  A  A  A  A  A  A  A  A  A  } } } } } } } } } } } } } } } } } } } } } } } } } } } } 4 4 4 4 4 4       0 0 0 0 0 0 ) ) ) ) ) ) ) ) ) ) ) )_ _ _ _ _", _ _ _ _ _r:   