
    ":h                         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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 d d	lm Z   G d
 dejB                  jD                        Z"y)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)AnyBalancesIntMarketNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTickersTrade)Client)List)ExchangeError)AuthenticationError)NetworkError)ChecksumErrorc                       e Zd Zdef fdZ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 Zd ZdefdZddi fdedededee   fdZi f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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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!dHde"de#defdZ$di fd	edefdZ%defd Z&dHd!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efd%Z+dddi fdedededee,   fd&Z-dHdefd'Z.dddi fd	edededee/   fd(Z0dHded	efd)Z1d* Z2d+ Z3i fde4fd,Z5defd-Z6di fded.e7d/e8d0e9d1e:de,fd2Z;defd3Z<di fd4edede,fd5Z=di fdefd6Z>defd7Z?i fd8Z@i fd9ZAi i fd:ed	ee   d;ee   d<ee   d=ee   f
d>ZBi fd?ZCi fd@ZDdefdAZEdefdBZFdefdCZGi fdDZHdefdEZIdefdFZJdefdGZK xZLS )I	cryptocomreturnc                     | j                  t        t        |          i ddddddddddddddd	dd
dddddddddddddddddddidddddddddidi d      S )NwsTwatchBalancewatchTickerwatchTickerswatchBidsAskswatchMyTradeswatchTradeswatchTradesForSymbolswatchOrderBookwatchOrderBookForSymbolswatchOrders
watchOHLCVwatchPositionscreateOrderWscancelOrderWscancelAllOrdersz*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test)fetchPositionsSnapshotawaitPositionsSnapshotchecksum)r,   r(   )hasurlsoptions	streaming)deep_extendsuperr   describe)self	__class__s    L/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/pro/cryptocom.pyr=   zcryptocom.describe   s5   i ? Ad t 	
     t ( !$ +D t d !$      "4!( "N#M LJ /3.2#
 #Q*D
 * *	    c                   K   	 |j                  | j                  |d      dd       d {    y 7 # t        $ rE}t        | j                  dz   | j                  |      z         }|j                  |       Y d }~y d }~ww xY ww)Nidzpublic/respond-heartbeat)rC   methodz pong failed with error )sendsafe_integer	Exceptionr   rC   jsonreset)r>   clientmessageeerrors        r@   pongzcryptocom.pongA   sp     	 ++T%6%6w%EQklmmm 	  +E!E		RS!TUELL	 s6   B'3 13 B3 	B;A<7B<BBNsymbollimitc                 F   K   | j                  |g||       d{   S 7 w)a  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        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)r>   rO   rP   paramss       r@   watch_order_bookzcryptocom.watch_order_bookM   s%      66xOOOO   !!c                 D   K   | j                  |g|       d{   S 7 w)aS  
        unWatches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        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 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)un_watch_order_book_for_symbolsr>   rO   rS   s      r@   un_watch_order_bookzcryptocom.un_watch_order_book\   s#      996(FKKKK     symbolsc                   K   | j                          d{    | j                  |      }g }g }|sd}| j                  |d      }|i |d<   d}d}| j                  |ddd      \  }}| j                  |dd|      \  }}||d   d<   d}	d}
| j                  |dd      \  }	}| j                  |dd|	      \  }
}|
|
|d   d<   t	        d	t        |            D ]Y  }||   }| j                  |      }d
|d   z   dz   t        |      z   }d|d   z   }|j                  |       |j                  |       [ | j                  |||       d{   }|j                         S 7 H7 w)a  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        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   rS   r(   bookSubscriptionTypeSNAPSHOT_AND_UPDATEr)   bookUpdateFrequencyr   book.rC   .
orderbook:rO   )load_marketsmarket_symbols
safe_valuehandle_option_and_paramsrangelenmarketstrappendwatch_public_multiplerP   )r>   r[   rP   rS   topicsmessageHashestopicParamsr^   bookSubscriptionType2r`   bookUpdateFrequency2irO   rj   currentTopicmessageHash	orderbooks                    r@   rR   z&cryptocom.watch_order_book_for_symbolsj   s     !!!%%g.Eoofh7!F8# $'+'D'DVM]_u  xM  (N$f(,(E(EfNh  kA  CW  )X%v3Hx/0"#&*&C&CFL\^s&t#V'+'D'DVMgi~  AT  (U$f+7KF834q#g,' 	(AQZF[[(F'&,6<s5zIL&)99K  -MM,'	( 44]FFSS	  9 	"6 Ts"   E#ED2E#	E!
E#!E#c                   K   | j                          d{    | j                  |      }g }g }g }| j                  |dd      }| j                  |d      }|i |d<   d}d}	| j	                  |ddd      \  }}| j	                  |dd|      \  }	}|	|d   d<   d}
d}| j	                  |dd	      \  }
}| j	                  |dd	|
      \  }}|||d   d<   t        d
t        |            D ]m  }||   }| j                  |      }d|d   z   dz   t        |      z   }d|d   z   }|j                  |       |j                  d|z          |j                  |       o | j                  d|||||       d{   S 7 `7 w)ax  
        unWatches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#book-instrument_name

        :param str[] symbols: unified array of symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.limit]: orderbook limit, default is 50
        :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
        NrP   r]   rS   r(   r^   r_   r)   r`   r   ra   rC   rb   rc   rO   zunsubscribe:rv   )rd   re   rF   rf   rg   rh   ri   rj   rk   rl   un_watch_public_multiple)r>   r[   rS   rn   subMessageHashesro   rP   rp   r^   rq   r`   rr   rs   rO   rj   rt   ru   s                    r@   rW   z)cryptocom.un_watch_order_book_for_symbols   s     !!!%%g.!!&'26oofh7!F8# $'+'D'DVM]_u  xM  (N$f(,(E(EfNh  kA  CW  )X%v3Hx/0"#&*&C&CFL\^s&t#V'+'D'DVMgi~  AT  (U$f+7KF834q#g,' 	(AQZF[[(F'&,6<s5zIL&)99K##K0  +!=>MM,'	( 22;Xhjprxyyy9 	"8 zs"   E;E6EE;1E92E;9E;c                     | j                  |d      }| j                  |d      }| j                  |d      }|j                  |||g       y )Nr         )
safe_floatrF   
storeArray)r>   booksidedeltapriceamountcounts         r@   handle_deltazcryptocom.handle_delta   sI    q)*!!%+UFE23rA   c                 b    t        dt        |            D ]  }| j                  |||           y )Nr   )rh   ri   r   )r>   r   deltasrs   s       r@   handle_deltaszcryptocom.handle_deltas   s0    q#f+& 	3Ahq	2	3rA   rJ   c                    | j                  |d      }| j                  |      }|d   }| j                  |d      }| j                  |d      }| j                  |d      }|| j                  vr1| j                  |d      }| j                  i |      | j                  |<   | j                  |   }	| j                  |d      }
| j                  |dd	      }|}|
d
k(  r5|	j                  i        ||	d<   ||	d<   | j                  |      |	d<   ||	d<   nn| j                  |di       }| j                  |d      }|	d   }||k7  r?| j                  ddd      }|r*t        | j                  dz   | j                  |      z         | j                  |	d   | j                  |dg              | j                  |	d   | j                  |dg              ||	d<   |	| j                  |<   d|z   }|j                  |	|       y )Ninstrument_namerO   datar   tdepthchannelusbook	timestampdatetimenonceupdatepur(   r6   T asksbidsrc   )safe_stringsafe_marketrf   rF   
orderbookscounted_order_booksafe_integer_2rI   iso8601handle_optionr   rC   orderbook_checksum_messager   resolve)r>   rJ   rK   marketIdrj   rO   r   r   rP   rv   r   r   bookspreviousNoncecurrentNoncer6   ru   s                    r@   handle_order_bookzcryptocom.handle_order_book   s   p ##G->?!!(+!w/tQ'%%dC0	$//)%%gw7E&*&=&=b%&HDOOF#OOF+	""7I6##D#s3fOOB"(Ih%.Ik"$(LL$;Ij!!&IgOOD(B7E --dD9M$W-L},--.>
DQ'#8W8WX^8_(_``9V,dooeVR.PQ9V,dooeVR.PQ"	'"+"V+y+.rA   sincec                 H   K   | j                  |g|||       d{   S 7 w)a<  
        get the list of most recent trades for a particular symbol

        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)r>   rO   r   rP   rS   s        r@   watch_tradeszcryptocom.watch_trades$  s'      22F8UE6RRRRs   " "c                 D   K   | j                  |g|       d{   S 7 w)a  
        get the list of most recent trades for a particular symbol

        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 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)un_watch_trades_for_symbolsrX   s      r@   un_watch_tradeszcryptocom.un_watch_trades2  s#      55vhGGGGrZ   c                   K   | j                          d{    | j                  |      }g }t        dt        |            D ]1  }||   }| j	                  |      }d|d   z   }	|j                  |	       3 | j                  |||       d{   }
| j                  r6| j                  |
d      }| j                  |d      }|
j                  ||      }| j                  |
||dd      S 7 7 ]w)a?  
        get the list of most recent trades for a particular symbol

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#trade-instrument_name

        :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>`
        Nr   trade.rC   rO   r   T)rd   re   rh   ri   rj   rl   rm   
newUpdatesrf   r   getLimitfilter_by_since_limit)r>   r[   r   rP   rS   rn   rs   rO   rj   rt   tradesfirsttradeSymbols                r@   r   z"cryptocom.watch_trades_for_symbols>  s      !!!%%g.q#g,' 	(AQZF[[(F(6$<7LMM,'		(
 11&&&II??OOFA.E**5(;KOOK7E))&%TRR 	" Js#   C-C)A6C-C+AC-+C-c                 h  K   | j                          d{    | j                  |      }g }g }t        dt        |            D ]H  }||   }| j	                  |      }d|d   z   }|j                  d|d   z          |j                  |       J | j                  d|||||       d{   S 7 7 w)a  
        get the list of most recent trades for a particular symbol

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#trade-instrument_name

        :param str[] [symbols]: list of unified market symbols to unwatch 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>`
        Nr   r   rC   zunsubscribe:trades:rO   r   )rd   re   rh   ri   rj   rl   rx   )	r>   r[   rS   rn   ro   rs   rO   rj   rt   s	            r@   r   z%cryptocom.un_watch_trades_for_symbolsY  s      !!!%%g.q#g,' 	(AQZF[[(F(6$<7L  !69I!IJMM,'	( 228WmU[]ceklll 	" ms"   B2B.BB2)B0*B20B2c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }|d   }| j                  | j                  |      }|7| j	                  | j
                  dd      }	t        |	      }|| j                  |<   | j                  |dg       }
t        |
      }|dk(  ry | j                  |
|      }t        dt        |            D ]  }|j                  ||           |j                  d	|z   d
      }|j                  ||       |j                  ||       y )Nr   r   subscriptionrO   tradesLimit  r   r   rb    )r   r   rf   r   rF   r9   r   ri   parse_tradesrh   rl   replacer   )r>   rJ   rK   r   r   symbolSpecificMessageHashrj   rO   storedrP   r   
dataLengthparsedTradesjchannelReplaceds                  r@   handle_tradeszcryptocom.handle_tradeso  s2   . ""7I6##G->?$($4$4Wn$M!!!(+!f5>%%dllM4HE&F"(DKKw3Y
?((v6q#l+, 	+AMM,q/*	+!//#."=v89v/rA   c                 2  K   | j                          d{    d}|| j                  |      }|d   }d}||dz   |d   z   n|}| j                  ||       d{   }| j                  r|j	                  ||      }| j                  ||||d      S 7 |7 9w)aQ  
        watches information on multiple trades made by the user

        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 <https://docs.ccxt.com/#/?id=trade-structure>`
        NrO   
user.traderb   rC   Trd   rj   watch_private_subscriber   r   filter_by_symbol_since_limit)r>   rO   r   rP   rS   rj   ru   r   s           r@   watch_my_tradeszcryptocom.watch_my_trades        !!![[(FH%F"=C=O{S(6$<7Va33KHH??OOFE2E00tTT 	" I"   BBABB8BBc                    K   | j                          d{    | j                  |      }d|d   z   }| j                  ||       d{   S 7 77 w)a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        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>`
        Nticker.rC   )rd   rj   watch_public)r>   rO   rS   rj   ru   s        r@   watch_tickerzcryptocom.watch_ticker  sW      !!!V$$vd|3&&{F;;; 	" <s!   AA2A	A
AAc                    K   | j                          d{    | j                  |      }d|d   z   }d|d   z   }| j                  d|d   g|g|g|g|       d{   S 7 J7 w)a  
        unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        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>`
        Nr   rC   unsubscribe:ticker:rO   ticker)rd   rj   rx   )r>   rO   rS   rj   subMessageHashru   s         r@   un_watch_tickerzcryptocom.un_watch_ticker  s      !!!V$'&,6+fX.>>228fX>N=OR]Q^ao`p  tB  sC  EK  L  L  	L	 	" Ls"   A%A!AA%A#A%#A%c                   K   | j                          d{    | j                  |dd      }g }| j                  |      }t        dt	        |            D ]  }||   }|j                  d|z           | j                  d   d   d   }| j                         }dd	|i|d
}	| j                  ||| j                  |	|      |       d{   }
| j                  ri }|
||
d   <   |S | j                  | j                  d|      S 7 7 ;w)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://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#ticker-instrument_name

        :param str[] symbols: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        NFr   r   r2   r    r0   	subscribechannelsrD   rS   r   rO   )rd   re   
market_idsrh   ri   rl   r8   r   watch_multipleextendr   filter_by_arraytickers)r>   r[   rS   ro   	marketIdsrs   r   urlrC   requestr   results               r@   watch_tickerszcryptocom.watch_tickers  s"     !!!%%gtU;OOG,	q#i.) 	7A |H  X!56	7 iit$X.ZZ\!M 
 **3t{{7TZ?[]jkk??F'-F6(#$M##DLL(GDD+ 	"  ls"   DDB1DD	:DDc                 f  K   | j                          d{    | j                  |dd      }g }g }| j                  |      }t        dt	        |            D ]4  }||   }||   }|j                  d|z          |j                  d|z          6 | j                  d|||||       d{   S 7 7 w)a  
        unWatches a price ticker

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#ticker-instrument_name

        :param str[] symbols: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        NFr   r   r   r   )rd   re   r   rh   ri   rl   rx   )	r>   r[   rS   ro   ry   r   rs   r   rO   s	            r@   un_watch_tickerszcryptocom.un_watch_tickers  s      !!!%%gtU;OOG,	q#i.) 	AA |HQZF##I$89  !6!?@		A
 228WmUegwy  A  A  	A 	" As"   B1B-BB1(B/)B1/B1c                 f   | j                  ||       | j                  |d      }| j                  |d      }| j                  |      }| j                  |dg       }t	        dt        |            D ]?  }||   }| j                  ||      }	|	d   }
|	| j                  |
<   |j                  |	|       A y )Nr   r   r   r   rO   )	handle_bid_askr   r   rf   rh   ri   parse_ws_tickerr   r   )r>   rJ   rK   ru   r   rj   r   rs   r   parsedrO   s              r@   handle_tickerzcryptocom.handle_ticker	  s    2 	FG,&&w?##G->?!!(+w3q#d)$ 	0A!WF))&&9FH%F#)DLL NN6;/	0rA   r   rj   c                    | j                  |d      }| j                  |d      }| j                  ||d      }| j                  |d      }| j                  |d      }| j                  i d|d   d|d| j	                  |      d	| j                  |d
      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      dd dd d|d|dd dd d| j                  |d      dd | j                  |d      |dk(  r| j                  |d       nd |d!|      S )"Nr   rs   _quotearO   r   r   highhlowlbidb	bidVolumebsaskk	askVolumeksvwapopencloselastpreviousClosechange
percentagecaveragevUSDvv)
baseVolumequoteVolumeinfo)rF   r   r   safe_tickerr   safe_number)r>   r   rj   r   r   r   r   s          r@   r   zcryptocom.parse_ws_ticker.  s   $ %%fc2	##FC0!!(FC8  1, !
fX&!
!
 Y/!
 D$$VS1	!

 4##FC0!
 4##FC0!
 ))&$7!
 4##FC0!
 ))&$7!
 D!
 D!
 T!
 D!
 T!
 d!
  $**637!!
" t#!
$ **637>Cun4++FD9SW)!
* + 	rA   c                 D  K   | j                          d{    | j                  |dd      }g }g }| j                  |      }t        dt	        |            D ]2  }||   }|j                  d||   z          |j                  d|z          4 | j                  d   d   d   }| j                         }	d	d
|i|	d}
| j                  ||| j                  |
|      |       d{   }| j                  ri }|||d   <   |S | j                  | j                  d|      S 7 7 <w)a  

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#ticker-instrument_name

        watches best bid & ask for symbols
        :param str[] symbols: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        NFr   bidask.r   r2   r    r0   r   r   r   rO   )rd   re   r   rh   ri   rl   r8   r   r   r   r   r   bidsasks)r>   r[   rS   ro   rn   r   rs   r   r   rC   r   
newTickersr   s                r@   watch_bids_askszcryptocom.watch_bids_asks\  s<     !!!%%gtU;OOG,	q#i.) 	0A |H  WQZ!78MM)h./	0 iit$X.ZZ\!F 
  ..sM4;;wX^C_anoo
??G,6GJx()N##DMM8WEE/ 	"$ ps"   D DC
D !D":D D c                     | j                  |dg       }| j                  |di       }| j                  |      }|d   }|| j                  |<   d|z   }|j	                  ||       y )Nr   r   rO   r  )	safe_list	safe_dictparse_ws_bid_askr  r   )r>   rJ   rK   r   r   parsedTickerrO   ru   s           r@   r   zcryptocom.handle_bid_ask  sf    ~~gvr2a,,,V4h' ,f&(|[1rA   c                 f   | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  ||| j	                  |      | j                  |d      | j                  |d      | j                  |d      | j                  |d      |d|      S )	Nrs   rO   r   r   r   r   r   )rO   r   r   r   r   r   r   r	  )r   r   rF   r
  r   )r>   r   rj   r   rO   r   s         r@   r  zcryptocom.parse_ws_bid_ask  s    ##FC0!!(F3!!&(3%%fc2	"Y/##FC0))&$7##FC0))&$7	!
 	 		rA   1mc                 ^  K   | j                          d{    | j                  |      }|d   }| j                  | j                  ||      }d|z   dz   |d   z   }| j	                  ||       d{   }	| j
                  r|	j                  ||      }| j                  |	||dd      S 7 7 9w)a  
        watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        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
        NrO   candlestick.rb   rC   r   T)rd   rj   r   
timeframesr   r   r   r   )
r>   rO   	timeframer   rP   rS   rj   intervalru   ohlcvs
             r@   watch_ohlcvzcryptocom.watch_ohlcv  s      !!!V$!##DOOY	J)H4s:VD\I''V<<??NN651E))%q$GG 	"
 =s"   B-B)AB-1B+28B-+B-c           	      @  K   | j                          d{    | j                  |      }|d   }| j                  | j                  ||      }d|z   dz   |d   z   }d|d   z   dz   |z   }d|d   |ggi}| j	                  d	|d   g|g|g|g||       d{   S 7 7 w)
a5  
        unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        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 dict [params]: extra parameters specific to the exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        NrO   r  rb   rC   zunsubscribe:ohlcv::symbolsAndTimeframesr  )rd   rj   r   r  rx   )	r>   rO   r  rS   rj   r  r   ru   	subExtends	            r@   un_watch_ohlcvzcryptocom.un_watch_ohlcv  s      !!!V$!##DOOY	J,x7#=tL*VH-==CiO"fX&6	%B$C
	 227VH=M<NQ\P]`n_o  sA  rB  DJ  LU  V  V  	V 	" Vs"   BBA>BBBBc                    | j                  |d      }| j                  |d      }| j                  |      }|d   }| j                  |d      }| j                  |      }| j                  | j                  |i       | j                  |<   | j                  | j                  |   |      }	|	:| j                  | j                  dd      }
t        |
      }	|	| j                  |   |<   | j                  |d      }t        dt        |            D ]*  }||   }| j                  ||      }|	j                  |       , |j                  |	|       y )	Nr   r   rO   r  
OHLCVLimitr   r   r   )r   r   find_timeframerf   ohlcvsrF   r9   r   rh   ri   parse_ohlcvrl   r   )r>   rJ   rK   ru   r   rj   rO   r  r  r   rP   r   rs   tickr   s                  r@   handle_ohlcvzcryptocom.handle_ohlcv  s8    &&w?##G->?!!(+!##GZ8''1	"oodkk62FFV!4i@>%%dllL$GE*51F-3DKK	*w/q#d)$ 	"A7D%%dF3FMM&!	" 	v{+rA   c                 2  K   | j                          d{    d}|| j                  |      }|d   }d}||dz   |d   z   n|}| j                  ||       d{   }| j                  r|j	                  ||      }| j                  ||||d      S 7 |7 9w)aQ  
        watches information on multiple orders made by the user

        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>`
        NrO   
user.orderrb   rC   Tr   )r>   rO   r   rP   rS   rj   ru   orderss           r@   watch_orderszcryptocom.watch_orders  r   r   c                    | j                  |d      }| j                  |d      }| j                  |dg       }t        |      }|dkD  r| j                  -| j	                  | j
                  dd      }t        |      | _        | j                  }	| j                  |      }
t        dt        |
            D ]  }|	j                  |
|           |j                  |	|       |j                  |	|       |j                  |	d       y y )Nr   r   r   r   ordersLimitr   r,  )r   rf   ri   r-  rF   r9   r   parse_ordersrh   rl   r   )r>   rJ   rK   r   r   r   r-  ordersLengthrP   r   r   rs   s               r@   handle_orderszcryptocom.handle_orders  s    > ""7I6$($4$4Wn$M!&"56{!{{"))$,,tL4U;[[F&&v.F1c&k* )fQi()NN6#<=NN67+NN6<0 rA   c                   K   | j                          d{    | j                          d{    | j                  d   d   d   }| j                         }dddgi|d}d	}| j	                  |      }| j                  |      sd
dj                  |      z   }| j                  |      }	| j                  |	|       | j                  ddd      }
| j                  ddd      }|
r<|r:| j                  .|	j                  d       d{   }| j                  ||||d      S | j                  ||| j                  ||             d{   }| j                  r|S | j                  | j                  |||d      S 7 b7 M7 w7 9w)a?  
        watch all open positions

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#user-position_balance

        :param str[] [symbols]: list of unified market symbols to watch positions for
        :param int [since]: the earliest time in ms to fetch positions for
        :param int [limit]: the maximum number of positions to retrieve
        :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>`
        Nr2   r    r1   r   r   user.position_balancer   	positions::,r,   r4   Tr5   )rd   authenticater8   r   re   is_emptyjoinrJ   set_positions_cacher   r6  futurefilter_by_symbols_since_limitwatchr   r   )r>   r[   r   rP   rS   r   rC   r   ru   rJ   r4   r5   snapshotnewPositionss                 r@   watch_positionszcryptocom.watch_positions+  s     !!!!!!iit$Y/ZZ\!45 
 "%%g.}}W%'!22KS!  1!%!3!34DF^`d!e!%!3!34DF^`d!e!&<AW#]]+CDDH55hPUW[\\!ZZ[$++gv:VWW??11$..'5RWY]^^3 	"!& EWsD   FE8FE;CFE>?FF 2F;F>F Fc                     | j                  ddd      }|r@d}||j                  vr/|j                  |       | j                  | j                  ||       y y t               | _        y )Nr,   r4   F)r   futuresr=  spawnload_positions_snapshotr   r6  )r>   rJ   typer[   r4   ru   s         r@   r<  zcryptocom.set_positions_cacheR  sa    !%!3!34DF^`e!f!2K6>>1k*

477M 2 67DNrA   c                 l  K   | j                          d {   }t               | _        | j                  }t        dt	        |            D ]1  }||   }| j                  |dd      }|dkD  s!|j                  |       3 |j                  |   }|j                  |       |j                  |d       y 7 w)Nr   	contractsr6  )	fetch_positionsr   r6  rh   ri   r  rl   rD  r   )	r>   rJ   ru   r6  cachers   positionrI  r=  s	            r@   rF  z!cryptocom.load_positions_snapshot\  s     ..00	13q#i.) 	'A |H((;BI1}X&		' ,uuk* 1s   B4B2AB4,AB4c                    | j                  |dg       }| j                  |di       }| j                  |dg       }| j                  t               | _        | j                  }g }t        dt	        |            D ]:  }||   }	| j                  |	      }
|j                  |
       |j                  |
       < | j                  |d      }t        dt	        |            D ]f  }||   }|j                  d      }|d   }|j                  d      }| j                  |d|d	      }| j                  |      rU|j                  ||       h |j                  |d       y )
Nr   r   r6  zpositions::r7  r{   r8  rO   F)rf   r6  r   rh   ri   parse_positionrl   find_message_hashessplitr   r:  r   )r>   rJ   rK   r   	firstDatarawPositionsrK  rA  rs   rawPositionrL  ro   ru   partssymbolsStringr[   r6  s                    r@   handle_positionszcryptocom.handle_positionsj  sL   6 w3OOD!R0	y+rB>>!57DNq#l+, 	#A&q/K**;7H)LL"		#
 00Gq#m,- 	7A'*K%%d+E!!HM#))#.G,,\8WeTI==+y+6	7 	|[1rA   c                 F   K   d}| j                  ||       d{   S 7 w)at  
        watch balance and get the amount of funds available for trading or funds locked in orders

        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   )r>   rS   ru   s      r@   watch_balancezcryptocom.watch_balance  s&      %11+vFFFFrU   c                    | j                  |d      }| j                  |dg       }| j                  |d   dg       }|| j                  d<   t        dt	        |            D ]  }||   }| j                  |d      }| j                  |      }	| j                         }
| j                  |d      |
d<   | j                  |d	      |
d
<   |
| j                  |	<   | j                  | j                        | _         |j                  | j                  |       | j                  |d      }|j                  | j                  |       y )Nr   r   r   position_balancesr	  r   quantitytotalreserved_qtyusedrC   )	r   rf   balancerh   ri   safe_currency_codeaccountsafe_balancer   )r>   rJ   rK   ru   r   positionBalancesrs   r`  
currencyIdcoderb  messageHashRequests               r@   handle_balancezcryptocom.handle_balance  s.   \ &&w?w3??474GL#Vq#./0 	;A&q)G))'3DEJ**:6DllnG#//DGG"..wGGFO!(DLL,,T\\:DL	; 	t||[1!--gt<t||%78rA   rG  sider   r   c                    K   | j                          d{    | j                  ||||||      }d|d}| j                         }| j                  ||       d{   S 7 I7 w)a  

        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 fulfilled, 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rD   rS   )rd   create_order_requestr   watch_private_request)	r>   rO   rG  ri  r   r   rS   r   ru   s	            r@   create_order_wszcryptocom.create_order_ws  sp      !!!**64vufU,
 jjl//WEEE 	" Fs"   A$A AA$A"A$"A$c                     | j                  |d      }| j                  |di       }| j                  |      }|j                  ||       y )NrC   r   )r   rf   parse_orderr   )r>   rJ   rK   ru   rawOrderorders         r@   handle_orderzcryptocom.handle_order  sF     &&w5??7Hb9  *uk*rA   rC   c                    K   | j                          d{    | j                  d|i|      }d|d}| j                         }| j                  ||       d{   S 7 G7 w)a  
        cancels an open order

        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-orderrl  )rd   r   r   rn  )r>   rC   rO   rS   r   ru   s         r@   cancel_order_wszcryptocom.cancel_order_ws  ss      !!!
 -
 jjl//WEEE 	" Fs"   A"AAA"A A" A"c                    K   | j                          d{    d}d| j                  i |      d}|| j                  |      }|d   |d   d<   | j                         }| j	                  ||       d{   S 7 c7 w)a  
        cancel all open orders

        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-ordersrl  rC   rS   r   )rd   r   rj   r   rn  )r>   rO   rS   rj   r   ru   s         r@   cancel_all_orders_wszcryptocom.cancel_all_orders_ws%  s      !!!1kk"f-
 [[(F39$<GH/0jjl//WEEE 	" Fs"   A>A:AA>5A<6A><A>c                 L    | j                  |d      }|j                  ||       y )NrC   )r   r   )r>   rJ   rK   ru   s       r@   handle_cancel_all_ordersz"cryptocom.handle_cancel_all_orders;  s$     &&w5w,rA   c                    K   | j                   d   d   d   }| j                         }dd|gi|d}| j                  ||      }| j                  ||||       d {   S 7 wNr2   r    r0   r   r   r   )r8   r   r   r?  r>   ru   rS   r   rC   r   rK   s          r@   r   zcryptocom.watch_publicF  sq     iit$X.ZZ\![M 
 ++gv.ZZ[';GGGGs   AA!AA!c                    K   | j                   d   d   d   }| j                         }dd|i|d}| j                  ||      }| j                  ||||       d {   S 7 wr  )r8   r   r;   r   )r>   ro   rn   rS   r   rC   r   rK   s           r@   rm   zcryptocom.watch_public_multipleS  ss     iit$X.ZZ\!F 
 ""7F3((mWmTTTTs   AA AA topicro   ry   rn   c           
        K   | j                   d   d   d   }| j                         }	dd|i|	t        |	      d}
t        |	      ||||d}| j                  |
|      }| j	                  ||||| j                  ||             d {   S 7 w)Nr2   r    r0   unsubscriber   )rD   rS   r   rC   )rC   r  r[   ry   ro   )r8   r   rk   r;   r   r   )r>   r  r[   ro   ry   rn   rS   r"  r   rC   r   r   rK   s                r@   rx   z"cryptocom.un_watch_public_multiple`  s     iit$X.ZZ\#F b'
 b' 0*
 ""7F3((mWmUYU`U`amoxUyzzzzs   BBB
Bc                    K   | j                          d {    | j                  d   d   d   }||d}| j                  ||      }| j                  |t	        |      |d       d {   S 7 U7 w)Nr2   r    r1   )rC   r   T)r9  r8   r   r?  rk   )r>   r   rS   r   r   rK   s         r@   rn  zcryptocom.watch_private_requestu  sw     !!!iit$Y/
 ++gv.ZZSZ$??? 	" @s"   A0A,AA0'A.(A0.A0c                    K   | j                          d {    | j                  d   d   d   }| j                         }dd|gi|d}| j                  ||      }| j	                  ||||       d {   S 7 `7 w)Nr2   r    r1   r   r   r   )r9  r8   r   r   r?  r  s          r@   r   z!cryptocom.watch_private_subscribe  s     !!!iit$Y/ZZ\![M 
 ++gv.ZZ[';GGG 	" Hs"   A;A7AA;2A93A;9A;c                 ,   | j                  |d      }| j                  |d      }	 |r|dk7  r| j                  dz   | j                  |      z   }| j                  | j                  d   ||       | j                  |d      }| | j                  | j                  d   ||       t        |      y# t        $ r\}t        |t              r0d	}|j                  ||       ||j                  v r |j                  |= n|j                  ||       Y d }~y
d }~ww xY w)NrC   rf  0r   exactrK   broadFauthenticatedT)r   rC   rH   throw_exactly_matched_exception
exceptionsrf   throw_broadly_matched_exceptionr   rG   
isinstancer   rejectsubscriptions)	r>   rJ   rK   rC   	errorCodefeedbackmessageStringrL   ru   s	            r@   handle_error_messagezcryptocom.handle_error_message  s
    gt,$$Wf5		Y#-77S=499W+==44T__W5MyZbc $ C ,889QS`bjk#H-- 	!01-a-&"6"66,,[9a$	s   BB. .	D7ADDc           
         | j                   | j                  | j                  | j                  | j                  | j                  | j                  | j
                  | j                  d	}| j                  |dd      }| j                  |d      }|&|j                  d      dkD  r| j                  ||       |#|j                  d      r| j	                  ||       | j                  ||      }|
 |||       y y )N)	candlestickr   trader   zbook.updater,  r   rX  r5  r   r	  r   r   r,  )r*  r   r   r   r3  rh  rV  safe_value_2r   find
startswithrf   )r>   rJ   rK   methodsr   r   rD   s          r@   handle_subscribezcryptocom.handle_subscribe  s    ,,((''**11,,,, //%)%:%:

 ""7Hf=""695W\\,%?"%Dvv.W%7%7%Evv.'266" rA   c           
      V   | j                  ||      ry | j                  |d      }| j                  | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  d	}| j                  ||      }|
 |||       y y )NrD   )	r   zpublic/heartbeatpublic/authrk  rw  rz  zprivate/close-positionr   r  )	r  r   handle_pinghandle_authenticatert  r}  r  handle_unsubscriberf   )r>   rJ   rK   rD   r  
callMethods         r@   handle_messagezcryptocom.handle_message  s    D $$VW5!!'84   $ 0 033$($5$5$($5$5)-)F)F&*&7&7..22

 __Wf5
!vw' "rA   c                 R  K   | j                          | j                  d   d   d   }| j                  |      }d}|j                  |      }| j	                  |j
                  |      }|d}t        | j                               }||z   | j                  z   |z   }	| j                  | j                  |	      | j                  | j                        t        j                        }
|||| j                  |
d}| j                  ||      }| j                  ||||       | d {   S 7 w)Nr2   r    r1   r  r  )rC   r   rD   api_keysig)check_required_credentialsr8   rJ   r=  rf   r  rk   r   apiKeyhmacencodesecrethashlibsha256r   r?  )r>   rS   r   rJ   ru   r=  r  rD   r   auth	signaturer   rK   s                r@   r9  zcryptocom.authenticate  s    '')iit$Y/S!%{+(<(<kJ "F

%EE>DKK/%7D		$++d"3T[[5Mw~~^I ;; G kk'62GJJsK+>||s   DD' D%!D'c                 >    | j                  | j                  ||       y N)rE  rN   )r>   rJ   rK   s      r@   r  zcryptocom.handle_ping  s    

499fg.rA   c                 ^    | j                  |j                  d      }|j                  d       y )Nr  T)rf   rD  r   )r>   rJ   rK   r=  s       r@   r  zcryptocom.handle_authenticate  s$     AtrA   c                    | j                  |d      }t        |j                  j                               }t	        dt        |            D ]  }||   }||j                  vr|j                  d      s)|j                  |   }| j                  |d      }||k7  rP| j                  |dg       }	| j                  |dg       }
t	        dt        |	            D ]  }|	|   }|
|   }| j                  |||       ! | j                  |        y )NrC   r   r  ro   ry   )
r   listr  keysrh   ri   r  r  clean_unsubscriptionclean_cache)r>   rJ   rK   rC   r  rs   ru   r   subIdro   ry   r   	unsubHashsubHashs                 r@   r  zcryptocom.handle_unsubscribe  s   gt,F((--/0q#d)$ 	/Aq'K6#7#77%%m4%33K@((t<; $|_b Q#'>>,@RTV#W q#m"45 JA -a 0I.q1G--fgyIJ   .!	/rA   r  )M__name__
__module____qualname__r   r=   rN   rk   r	   r   rT   rY   r   rR   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   dictr
   r   r  r   r  r  r  r#  r*  r   r.  r3  r   rB  r<  rF  rV  r   rY  rh  r   r   floatr   ro  rt  rx  r{  r}  r   rm   rx   rn  r   r  r  r  r9  r  r  r  __classcell__)r?   s   @r@   r   r      s2   +# +Z
  @DB PS P PS\ P =? L L3 L SW_a )!$s) )!C )!fo )!V PR )zT#Y )zV_ )zV43X/ X/t <@d[] S SS S Sbfglbm S 9; 
HC 
HtE{ 
H OSaenp Sd3i S S[^ Suyz  vA S6 LN mc mRU m,*0F *0X 37TX\eg UC Us URU Ulpqvlw U0 68 < <F < 9; LC Ls L  6:" E7 E EB 9=R Ag AC A,#0F #0J,d ,F ,f ,\ 8<B !FW !F7 !FF2V 2  8<$]ajl H HC HWZ Hquvzq{ H. ;?r V3 Vc V,,6 ,< 04$UYbd U UC Us Uimnsit U0.1F .1` 8<$]ajl %_W %_C %_WZ %_quv~q %_N8& 8 8+02d *, 
G 
G=9V =9~ pt|~ FC Fy F	 F[` Fil F  DI F.+6 +" <@ F FS Fu F, 8<B F F,	-v 	- 68 H IK U _a  mo {C {$s) {\`ad\e {y}  B  zC {  MQ  RU  MV {* 9; @ AC H6 <#v #02(V 2(h )+ ./& /& / /rA   r   )#ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r   r  ccxt.base.typesr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   r   async_supportr    rA   r@   <module>r     sc     A  A  T  T  T  T  T 4  * 0 ) *Y/"",, Y/rA   