
    ei,                         d dl Zd dl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 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)ArrayCacheBySymbolById)	AnyIntOrder	OrderBookStrStringsTickerTickersTrade)List)ExchangeError)ArgumentsRequiredc            
       n    e Zd Zdef fdZdi fdedefdZd)dededefdZdi fdeded	e	fd
Z
di fdededed	e	fdZ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 Zd)dZddi fdedededee         fdZi fdedefdZddi fd	ee         dededee         fdZi fd	ee         defdZd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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#d  Z$d! Z%d)d"Z&d# Z'd$ Z(d% Z)d& Z*d' Z+d( Z, xZ-S )*coinbasereturnc                    |                      t          t          |                                           i ddddddddddddd	dd
dddddddddddddddddddddddddddddddiidddddddd          S )NwsTcancelAllOrdersWsFcancelOrdersWscancelOrderWscreateOrderWseditOrderWsfetchBalanceWsfetchOpenOrdersWsfetchOrderWsfetchTradesWswatchBalancewatchMyTrades
watchOHLCVwatchOrderBookwatchOrderBookForSymbolswatchOrderswatchTicker)watchTickerswatchTradeswatchTradesForSymbolsunWatchTickerunWatchTickersunWatchTradesunWatchOrdersunWatchTradesForSymbolsapiz$wss://advanced-trade-ws.coinbase.com  bidsasks)bidoffer)tradesLimitordersLimitmyTradesLimitsides)hasurlsoptions)deep_extendsuperr   describe)self	__class__s    O/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/pro/coinbase.pyr<   zcoinbase.describe   sp   h 5 5 > > @ @d#U !%  	
   u !% $U       e !$ +D  t!" t#$ !%#)-!%"&!%!%+/3  8 @  $#!%!# 	 C*C
 *C
 * * *	    Nname	isPrivatec                   K   |                                   d{V  d}|}g }t          |t                    rH|                     |          }|                     |          }	|	}|dz   d                    |          z   }n(|&|                     |          }|dz   |z   }|d         g}| j        d         d         }
d||d}|r*|                     || 	                    ||                    }| 
                    |
|||           d{V S )	a  
 @ignore
        subscribes to a websocket channel

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-overview#subscribe

        :param str name: the name of the channel
        :param boolean isPrivate: whether the channel is private or not
        :param str [symbol]: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: subscription to a websocket channel
        N::,idr-   r   	subscribetypeproduct_idschannel)load_markets
isinstancelistmarket_symbols
market_idsjoinmarketr8   extendcreate_ws_authwatch)r=   rA   rB   symbolparamsrR   messageHash
productIdssymbols	marketIdsurlrG   s               r?   rG   zcoinbase.subscribe>   sA      !!!!!!!!!
fd## 	())&11G00I"J%,sxx/?/??KK[[((F+.K ,Jit$%
 
	  	VIt/B/B4/T/TUUIZZ[)[IIIIIIIIIr@   topicc                 8  K   |                                   d{V  |                     | j        dd          rt          | j        dz             d| j        d<   d}|}d|z   }g }t          |t                    rc|                     |          }	|                     |	          }
|
}|dz   d	                    |          z   }|dz   d	                    |          z   }n0|.| 
                    |          }|dz   |z   }|dz   |z   }|d	         g}| j        d
         d         }d||d}|g|g|d|gd}|r*|                     ||                     ||                    }|| j        d<   |                     |||||           d{V }d| j        d<   d| j        d<   |S )a  
 @ignore
        unSubscribes to a websocket channel

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-overview#subscribe

        :param str topic: unified topic
        :param str name: the name of the channel
        :param boolean isPrivate: whether the channel is private or not
        :param str [symbol]: unified market symbol
        :returns dict: subscription to a websocket channel
        NunSubscriptionPendingFX another unSubscription is pending, coinbase does not support concurrent unSubscriptionsTunsubscribe:rD   rE   rF   r-   r   unsubscriberH   messageHashessubMessageHashesr]   rb   rZ   unSubscription)rL   	safe_boolr9   r   rF   rM   rN   rO   rP   rQ   rR   r8   rS   rT   rU   )r=   r]   rA   rB   rV   rR   watchMessageHashunWatchMessageHashrY   rZ   r[   r\   messagesubscriptionress                  r?   un_subscribezcoinbase.un_subscribee   s!      !!!!!!!!!>>$,(?GG 	F  +E  !E  F  F  F04,-+d2
fd## 
	())&11G00I"J/$6&9I9II!3d!:SXXf=M=M!M[[((F#d{V3!3d!:V!C ,Jit$ "%
 
 11!1 2x
 
  	Rkk'4+>+>tZ+P+PQQG)5%&JJs$6ASUabbbbbbbb05,-)-%&
r@   rZ   c                    K   |                                   d{V  g }g }|                     |dd          }t          dt          |                    D ]W}||         }|                     |          }	|	d         }
|                    |
           |                    |dz   |z              X| j        d         d         }d||d	}|r*|                     ||                     ||                    }| 	                    ||||           d{V S )
a  
 @ignore
        subscribes to a websocket channel

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-overview#subscribe

        :param str name: the name of the channel
        :param boolean isPrivate: whether the channel is private or not
        :param str[] [symbols]: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: subscription to a websocket channel
        NFr   rF   rD   r-   r   rG   rH   )
rL   rO   rangelenrR   appendr8   rS   rT   watch_multiple)r=   rA   rB   rZ   rW   rY   rd   irV   rR   marketIdr\   rG   s                r?   subscribe_multiplezcoinbase.subscribe_multiple   sC      !!!!!!!!!
%%gtU;;q#g,,'' 	7 	7AQZF[[((Fd|Hh'''  v!56666it$%
 
	
  	VIt/B/B4/T/TUUI((mYVVVVVVVVVr@   c                 ,  K   |                      | j        dd          rt          | j        dz             d| j        d<   |                                  d{V  g }g }g }|                     |dd          }t          dt          |                    D ]u}	||	         }
|                     |
          }|d         }|	                    |           |	                    |dz   |
z              |	                    d	|z   dz   |
z              v| j
        d
         d         }d||d}|r*|                     ||                     ||                    }|||d|d}|| j        d<   |                     |||||           d{V }d| j        d<   d| j        d<   |S )a  
 @ignore
        unsubscribes to a websocket channel

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-overview#subscribe

        :param str topic: unified topic
        :param str name: the name of the channel
        :param boolean isPrivate: whether the channel is private or not
        :param str[] [symbols]: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: subscription to a websocket channel
        r_   Fr`   TNr   rF   rD   ra   r-   r   rb   rH   rc   rf   )rg   r9   r   rF   rL   rO   ro   rp   rR   rq   r8   rS   rT   rr   )r=   r]   rA   rB   rZ   rW   rY   watchMessageHashesunWatchMessageHashesrs   rV   rR   rt   r\   rj   rk   rl   s                    r?   un_subscribe_multiplezcoinbase.un_subscribe_multiple   s
      >>$,(?GG 	F  +E  !E  F  F  F04,-!!!!!!!!!
!%%gtU;;q#g,,'' 	O 	OAQZF[[((Fd|Hh'''%%dTkF&:;;; ''(=(Dv(MNNNNit$!%
 

  	Rkk'4+>+>tZ+P+PQQG1 2
 
 *6%&''-A7L`bnoooooooo05,-)-%&
r@   rY   c                    i }|                      |                                           }|                                  | j                            d          dk    p| j                            d          }||z   d                    |          z   }|s_| j        |d<   ||d<   |                     | 	                    |          | 	                    | j                  t          j                  |d<   n| j                            d          rt          | j        dz             |                     | j        d	          }|                     | j        d
d          }|                                 }	|	|dz   |	k     r)|                     |	          }
|
| j        d	<   |	| j        d
<   |                     | j        d	          |d<   |S )Nzorganizations/r   z
-----BEGINrE   api_key	timestamp	signaturezV apiKey should contain the name(eg: organizations/3b910e93....) and not the public keywsTokenwsTokenTimestampx   jwt)number_to_stringsecondscheck_required_credentialsapiKeyfindsecret
startswithrQ   hmacencodehashlibsha256r   rF   safe_stringr9   safe_integercreate_auth_token)r=   rA   rY   rG   r|   isCloudAPiKeyauthcurrentTokentokenTimestampr   tokens              r?   rT   zcoinbase.create_ws_auth   s   	))$,,..99	'')))))*:;;q@kdkF\F\]iFjFj4#((:"6"66 	I#';Ii %.Ik"%)YYt{{4/@/@$++dkBZBZ\c\j%k%kIk""{%%l33 L'  3K  )K  L  L  L++DL)DDL!..t|=OQRSSNllnnG#~';g'E'E..w77*/Y'3:/0#//iHHIer@   rV   c                 z   K   |                                   d{V  d}|                     |d||           d{V S )a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-channels#ticker-channel

        :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tickerF)rL   rG   r=   rV   rW   rA   s       r?   watch_tickerzcoinbase.watch_ticker  s[       !!!!!!!!!^^D%@@@@@@@@@r@   c                 z   K   |                                   d{V  d}|                     d|d|           d{V S )a  
        stops watching a price ticker

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-channels#ticker-channel

        :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   FrL   rm   r   s       r?   un_watch_tickerzcoinbase.un_watch_ticker  s]       !!!!!!!!!&&xufEEEEEEEEEr@   c                    K   |                                   d{V  || j        }d}|                     |d||           d{V }| j        ri }|d         }|||<   |S | j        S )a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-channels#ticker-batch-channel

        :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>`
        Nticker_batchFrV   )rL   rZ   ru   
newUpdatestickers)r=   rZ   rW   rA   r   r   rV   s          r?   watch_tickerszcoinbase.watch_tickers"  s       !!!!!!!!!?lG..tUGVLLLLLLLL? 	GH%F$GFON|r@   c                    K   |                                   d{V  || j        }|                     ddd|           d{V S )a  
        stop watching

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-channels#ticker-batch-channel

        :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>`
        Nr   r   F)rL   rZ   ry   )r=   rZ   rW   s      r?   un_watch_tickerszcoinbase.un_watch_tickers8  se       !!!!!!!!!?lG//.%QXYYYYYYYYYr@   c                    |                      |d          }|                     |dg           }|                      |d          }|                     |          }g }t          dt	          |                    D ]}||         }	|                     |	dg           }
t          dt	          |
                    D ]}|
|         }|                      |d          }|#|                     |          }||d<   ||d<   |d         }|| j        |<   |                    |           |d	z   |z   }|                    ||           | 	                    |||           d S )
NrK   eventsr|   r   r   
product_iddatetimerV   rD   )
r   	safe_list	parse8601ro   rp   parse_ws_tickerr   rq   resolvetry_resolve_usdc)r=   clientrj   rK   r   r   r|   
newTickersrs   
tickersObjr   jr   
wsMarketIdresultrV   rX   s                    r?   handle_tickerszcoinbase.handle_tickersG  s   t ""7I66266##G[99NN8,,	
q#f++&& 	C 	CAJnnZB??G1c'll++ C C !--flCC
%--f55&/{#%-z")'-V$!!&)))%nv5v{333%%fk6BBBBC	C 	Cr@   c           	         |                      |d          }d }|                     |d          }|                     i d|d|                     ||d          d|d|                     |          d|                      |d	          d
|                      |d          d|                      |d          d|                      |d          d|                      |d          d|                      |d          dd dd d|d|dd dd d|                      |d          d |                      |d          d d          S )Nr   priceinforV   -r|   r   high	high_24_hlowlow_24_hr1   best_bid	bidVolumebest_bid_quantityaskbest_ask	askVolumebest_ask_quantityvwapopencloselastpreviousClosechange
percentageprice_percent_chg_24_hvolume_24_h)average
baseVolumequoteVolume)r   safe_numbersafe_tickersafe_symboliso8601)r=   r   rR   rt   r|   r   s         r?   r   zcoinbase.parse_ws_ticker  s   & ##FL99	00 !
F!
d&&x==!
 !
 Y//	!

 D$$V[99!
 4##FJ77!
 4##FJ77!
 ))&2EFF!
 4##FJ77!
 ))&2EFF!
 D!
 D!
 T!
 D!
 T!
  d!!
" $**63KLL#!
$ **6=AA)!
 !
 !
   	r@   sincelimitc                   K   |                                   d{V  |                     |          }d}|                     |d||           d{V }| j        r|                    ||          }|                     |||dd          S )a>  
        get the list of most recent trades for a particular symbol

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-channels#market-trades-channel

        :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market_tradesFr|   T)rL   rV   rG   r   getLimitfilter_by_since_limit)r=   rV   r   r   rW   rA   tradess          r?   watch_tradeszcoinbase.watch_trades  s       !!!!!!!!!V$$~~dE66BBBBBBBB? 	3OOFE22E))&%TRRRr@   c                 z   K   |                                   d{V  d}|                     d|d|           d{V S )a  
        stops watching the list of most recent trades for a particular symbol

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-channels#market-trades-channel

        :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>`
        Nr   r   Fr   r   s       r?   un_watch_tradeszcoinbase.un_watch_trades  s]       !!!!!!!!!&&xufEEEEEEEEEr@   c                 >  K   |                                   d{V  d}|                     |d||           d{V }| j        rB|                     |d          }|                     |d          }|                    ||          }|                     |||dd          S )aA  
        get the list of most recent trades for a particular symbol

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-channels#market-trades-channel

        :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   Fr   rV   r|   T)rL   ru   r   	safe_dictr   r   r   )	r=   rZ   r   r   rW   rA   r   firsttradeSymbols	            r?   watch_trades_for_symbolsz!coinbase.watch_trades_for_symbols  s       !!!!!!!!!..tUGVLLLLLLLL? 	8NN61--E**5(;;KOOK77E))&%TRRRr@   c                 |   K   |                                   d{V  d}|                     d|d||           d{V S )a  
        get the list of most recent trades for a particular symbol

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-channels#market-trades-channel

        :param str[] symbols: unified symbol of the market to fetch trades for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        Nr   r   F)rL   ry   )r=   rZ   rW   rA   s       r?   un_watch_trades_for_symbolsz$coinbase.un_watch_trades_for_symbols  s`       !!!!!!!!!//$wPVWWWWWWWWWr@   c                    K   |                                   d{V  d}|                     |d||           d{V }| j        r|                    ||          }|                     |||dd          S )aG  
        watches information on multiple orders made by the user

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-channels#user-channel

        :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>`
        NuserTr|   )rL   rG   r   r   r   )r=   rV   r   r   rW   rA   orderss          r?   watch_orderszcoinbase.watch_orders*  s       !!!!!!!!!~~dD&&AAAAAAAA? 	3OOFE22E))&%TRRRr@   c                    K   |                                   d{V  d}|                     d|d|                     |                     d{V S )a  
        stops watching information on multiple orders made by the user

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-channels#user-channel

        :param str [symbol]: unified market symbol of the market orders were made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr   r   T)rL   rm   rV   r   s       r?   un_watch_orderszcoinbase.un_watch_orders=  si       !!!!!!!!!&&xtT[[=P=PQQQQQQQQQr@   c                    K   |                                   d{V  d}|                     |          }|d         }|                     |d||           d{V }|                                S )aN  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-channels#level2-channel

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/?id=order-book-structure>` indexed by market symbols
        Nlevel2rV   F)rL   rR   rG   r   )r=   rV   r   rW   rA   rR   	orderbooks          r?   watch_order_bookzcoinbase.watch_order_bookK  s       !!!!!!!!!V$$!..uffEEEEEEEE	   r@   c                    K   |                                   d{V  |                     |          }d}|                     d|d|           d{V S )a  
        stops watching information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-channels#level2-channel

        :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
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/?id=order-book-structure>` indexed by market symbols
        Nr   r   F)rL   rV   rm   r   s       r?   un_watch_order_bookzcoinbase.un_watch_order_book]  sn       !!!!!!!!!V$$&&{D%HHHHHHHHHr@   c                    K   |                                   d{V  d}|                     |d||           d{V }|                                S )a1  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-channels#level2-channel

        :param str[] symbols: unified array of symbols
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/?id=order-book-structure>` indexed by market symbols
        Nr   F)rL   ru   r   )r=   rZ   r   rW   rA   r   s         r?   watch_order_book_for_symbolsz%coinbase.watch_order_book_for_symbolsl  sl       !!!!!!!!!11$wOOOOOOOO	   r@   c                 0   |                      |d          }|                     |d          }|                      |d          }|                     |d          }|                     |d          }|                     |          }d|z   }	|                     | j        |          }
|
5|                     | j        dd          }t          |          }
|
| j        |<   t          dt          |                    D ]p}||         }|                      |d          }t          dt          |                    D ]2}||         }|
                    |                     |                     3q|                    |
|	           |                     ||	|
           d S )Nr   r   r   r   zmarket_trades::r3   r.   )r   
safe_valuer   r   r   r   r   r9   r   ro   rp   rq   parse_trader   r   )r=   r   rj   r   eventr   tradert   rV   rX   tradesArrayr3   rs   currentEventcurrentTradesr   items                    r?   handle_tradezcoinbase.handle_trade|  s   0 22**x00vq))##E<88!!(++'&0oodk6::++DL-NNK0==K"-DKq#f++&& 	; 	;A!!9L NN<BBM1c-0011 ; ;$Q'""4#3#3D#9#9::::; 	{K000fk;?????r@   c                 X   |                      |d          }g }| j        0|                     | j        dd          }t	          |          | _        t          dt          |                    D ]}||         }|                      |d          }t          dt          |                    D ]j}	||	         }
|                     |
          }| j        }|                     |
d          }||vr|	                    |           |	                    |           kt          dt          |                    D ][}||         }| 
                    |          }d|z   }|                    | j        |           |                     ||| j                   \|                    | j        d           d S )	Nr   r4   r.   r   r   r   zuser::r   )r   r   r   r9   r   ro   rp   parse_ws_orderr   rq   r   r   r   )r=   r   rj   r   r[   r   rs   r   responseOrdersr   responseOrderparsedcachedOrdersrt   rV   rX   s                   r?   handle_orderzcoinbase.handle_order  s   : 22	;%%dlM4HHE077DKq#f++&& 
	, 
	,A1IE!^^E8<<N1c.1122 , , .q 1,,];;#{++M<HH I--$$X...##F++++, q#i..)) 	D 	DA |H%%h//F"V+KNN4;444!!&+t{CCCCt{F+++++r@   c                    |                      |d          }|                      |d          }|                      |d          }|                     |dd          }|                     ||          }|                      |d          }|                     i d|d|                      |d          d	|d
|d|                     |          d|dd d|                      |d          dd dd d|                     |dd          d|                      |d          d|d|d|                      |d          d|                     |                      |d                    d|                      |d          |                      |d          |                      |d          |                     |                      |d                    |                      |d           |                      |d!          d"d d#          S )$Norder_idclient_order_idr   timecreation_time
stop_pricer   rV   rF   clientOrderIdr|   r   lastTradeTimestamprI   
order_typetimeInForcepostOnlyside
order_sider   limit_price	stopPricetriggerPriceamountcumulative_quantitycostfilled_valuer   	avg_priceleaves_quantitystatus
total_feesquote)r  currency)filled	remainingr  feer   )r   safe_string_2safe_market
safe_orderr   safe_string_lower_2	omit_zeroparse_order_status)r=   orderrR   rF   r  rt   r   r  s           r?   r   zcoinbase.parse_ws_order  s     eZ00((0ABB##E<88%%eV_EE!!(F33$$UL99	  
E 
d&&vx88 
 " 
 ]	 

 11 
  
 !$ 
 D$$UL99 
 4 
  
 D,,UFLII 
 T%%e];; 
  
 I 
 d&&u.CDD 
  DNN4#3#3E>#J#JKK! 
" t''{;;# 
$ &&u.CDD))%1BCC--d.>.>uh.O.OPP**5,?? ,,VW==  3 
  
  
   	r@   c                 X   t          dt          |                    D ]}||         }|                     |d          }|                     | j        d         |          }|                     |d          }|                     |d          }||         }	|	                    ||           d S )Nr   r  r6   price_levelnew_quantity)ro   rp   r   r9   r   store)
r=   r   updatesrs   r   sideIdr  r   r  orderbookSides
             r?   handle_order_book_helperz!coinbase.handle_order_book_helper  s    q#g,,'' 	/ 	/AAJE%%eV44F##DL$96BBD$$UM::E%%e^<<F%dOMv....	/ 	/r@   c                 :   |                      |d          }|                     |d          }t          dt          |                    D ]O}||         }|                      |dg           }|                     |d          }|                     |          }	|	d         }
d|
z   }|                     |j        |i           }|                     |d          }|                     |d	          }|d
k    r|                     i |          | j	        |
<   |
| j	        vr| j	        |
         | j	        |
         }| 
                    ||           |                     |          |d<   ||d<   |
|d<   |                    ||           |                     |||           Qd S )Nr   r|   r   r*  r   rV   zlevel2::r   rI   snapshotr   )r   r   ro   rp   r   r   subscriptionsr   
order_book
orderbooksr-  r   r   r   )r=   r   rj   r   r   rs   r   r*  rt   rR   rV   rX   rk   r   rI   r   s                   r?   handle_order_bookzcoinbase.handle_order_book  s   : 22##G[99q#f++&& 	B 	BA1IEnnUIr::G''|<<H%%h//FH%F$v-K??6+?bQQL%%lG<<E##E622Dz!!*.//"e*D*D'do--4?63J3R/I)))W===%)^^H%=%=Ik"$,Ij!"(IhNN9k222!!&+yAAAA-	B 	Br@   c                     |                     d          s|                     d          r|                    ||dz              d S d S )Nz/USDz-USDC)endswithr   )r=   r   rX   r   s       r?   r   zcoinbase.try_resolve_usdcQ  sV    '' 	6;+?+?+G+G 	6NN6;#455555	6 	6r@   c                 2   |                      |dg           }|                     |di           }d|v }t          |d                                                   }t	          |          }|r|dk    r|                     | j        di           }|                      |dg           }	|                      |dg           }
t          dt	          |	                    D ])}|	|         }|
|         }|                     |||           *| 	                    |           |S )Nr   r   r0  rf   rd   re   )
r   r   rN   keysrp   r   r9   ro   clean_unsubscriptionclean_cache)r=   r   rj   r   
firstEventisUnsubsubKeyssubKeysLengthunSubObjectrd   re   rs   rX   subHashs                 r?   handle_subscription_statusz#coinbase.handle_subscription_statusU  s"   * 266__VQ33
"j0z/27799::G 	*}))..7GLLK NN;LLM#~~k;MrRR1c-0011 H H+A.*1-))&';GGGG[)))r@   c                     |S N )r=   r   rj   s      r?   handle_heartbeatszcoinbase.handle_heartbeatsz  s	    " r@   c                 Z   |                      |d          }| j        | j        | j        | j        | j        | j        | j        d}|                      |d          }|dk    r%|                      |d          }t          |          |                     ||          }|r |||           d S d S )NrK   )r0  r   r   r   r   l2_data
heartbeatsrI   errorrj   )	r   rA  r   r   r  r3  rE  r   r   )r=   r   rj   rK   methodsrI   errorMessagemethods           r?   handle_messagezcoinbase.handle_message  s    ""7I66!<) /!.%-0
 
 007??++GY??L---'22 	$F67#####	$ 	$r@   rC  ).__name__
__module____qualname__r   r<   strboolrG   rm   r	   ru   ry   r   rT   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r-  r3  r   rA  rE  rM  __classcell__)r>   s   @r?   r   r      s&       +# + + + + + +Z BFb %J %JC %JD %J %J %J %JN4 4 43 44 4 4 4 4l W[ce W WS WT WG W W W WB fjrt 0 0 0C 0D 0[b 0 0 0 0d3 DI    0 68 A A AF A A A A 9; F FC Fv F F F F 6:"  7     , 9=R Z Zg ZC Z Z Z ZoC oC oCb+ + + +Z <@d[] S S SS S Sbfglbm S S S S( 9; F FC Fs F F F F OSaenp S Sd3i S S[^ Suyz  vA S S S S* LN X Xc XRU X X X X 04$UYbd S S SC Ss Simnsit S S S S& 37r R RC Rc R R R R @DB ! !S ! !S\ ! ! ! !$ =? I I I3 I I I I SW_a ! !$s) !C !fo ! ! ! ! +@ +@ +@Z3, 3, 3,j0 0 0 0d/ / /5B 5B 5Bn6 6 6# # #J  &$ $ $ $ $ $ $r@   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   ccxt.base.typesr   r   r   r   r   r	   r
   r   r   typingr   ccxt.base.errorsr   r   async_supportr   rD  r@   r?   <module>r[     s        C C C C C C  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \       * * * * * * . . . . . .O$ O$ O$ O$ O$t!* O$ O$ O$ O$ O$r@   