
    !:hT                    4   d dl m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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" 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) d dl*m+Z+  G d dee      Z,y)    )Exchange)ImplicitAPIN)AccountAnyBalances
CurrenciesCurrencyDepositAddressIntLedgerEntryMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeesTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)RateLimitExceeded)OnMaintenance)	TICK_SIZE)Precisec                       e Zd Zdef fdZi fdefdZi fdee   fdZ	i fdee
   fdZd ZdefdZi fdefdZd	i fd
ededefdZdHdededefdZd	i fdedefdZi fd
edefdZdHdededefdZd	d	d	i fd
ede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 fdZ!dHde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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	d	d	i fd!ed
ededefd#Z*d	d	d	i fd
edededee'   fd$Z+d	d	d	i fd
ededede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.d(e/d)e0d*e1f
d+Z2d	i fd!ed
efd,Z3d	i fd
efd-Z4i fd.Z5d	i fd/ed)e0d0ede6fd1Z7d2 Z8dHd3ed4e9de:fd5Z;d	d	d	i fd/edededee:   fd6Z<d	d	d	i fd/edededee6   fd7Z=d	d	d	i fd/edededee6   fd8Z>d	d	d	i fd/edededee6   fd9Z?d: Z@dHd;ed4e9de6fd<ZAi fd/edeBfd=ZCd>d?i d	d	fd@ZDd/eEdAedBedCedDedEefdFZFd>d?i d	d	i fdGZG xZHS )Icoinbaseexchangereturnc                    | j                  t        t        |          i ddddddgddd	| j                  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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d0di d1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?d@dAddBddCdDdEdFdGdHdIdJdKdLdMdNdNdOdPdQdQdOdRdSdTdUgdVdWddddXdYdZg d[ig d\g d]g d^d_dOd`dadbidct
        dddd| j                  de      | j                  df      dgdddhdhdhdhdidjdkdhdhdhdhdidldkdmdndodddd dddd dddddpddddddddqd dddrdrddsdddddtddddddudddrdrddddvdddrdwdrddddxdydEidz	d{d|id d d}d d d}d~ddi ddddddddddddddddddddddddddddddddddddddddddddddddddidt        t        t        t        t        t        t        t        t        d	t        t        t        t        t        t        t        ddi      S )Nidr(   namezCoinbase Exchange	countriesUS	rateLimitd   	userAgentchromeproThasCORSspotmarginFswapfutureoptioncancelAllOrderscancelOrdercreateDepositAddresscreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchAccountsfetchBalancefetchClosedOrdersfetchCurrenciesfetchDepositAddressfetchDepositsfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchLedgerfetchMarginModefetchMarketsfetchMyTrades
fetchOHLCVfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsemulatedfetchWithdrawalswithdraw
timeframes<   ,  i  i  i`T  iQ )1m5m15m1h6h1dhostnamezexchange.coinbase.comurlsz0https://api-public.sandbox.exchange.coinbase.com)publicprivatezQhttps://github.com/ccxt/ccxt/assets/43336371/34a65553-88aa-4a38-a714-064bd228b97ezhttps://api.{hostname}zhttps://coinbase.com/z.https://docs.cloud.coinbase.com/exchange/docs/z#https://docs.pro.coinbase.com/#feeszIhttps://support.pro.coinbase.com/customer/en/portal/articles/2945310-fees)testlogoapiwwwdocfeesrequiredCredentials)apiKeysecretpasswordrx   get)
currenciesproductszproducts/{id}zproducts/{id}/bookzproducts/{id}/candleszproducts/{id}/statszproducts/{id}/tickerzproducts/{id}/tradestimezproducts/spark-lineszproducts/volume-summary)$zaddress-bookaccountszaccounts/{id}zaccounts/{id}/holdszaccounts/{id}/ledgerzaccounts/{id}/transferszcoinbase-accountsfillsfundingr{   zmargin/profile_informationzmargin/buying_powerzmargin/withdrawal_powerzmargin/withdrawal_power_allzmargin/exit_planzmargin/liquidation_historyzmargin/position_refresh_amountszmargin/statusoracleordersorders/{id}orders/client:{client_oid}z
otc/orderszpayment-methodspositionprofileszprofiles/{id}zreports/{report_id}	transfersztransfers/{transfer_id}zusers/self/exchange-limitszusers/self/hold-balanceszusers/self/trailing-volumezwithdrawals/fee-estimatezconversions/{conversion_id}zconversions/fees)conversionszdeposits/coinbase-accountzdeposits/payment-methodz coinbase-accounts/{id}/addresseszfunding/repayr   zposition/closezprofiles/margin-transferzprofiles/transferreportszwithdrawals/coinbasezwithdrawals/coinbase-accountzwithdrawals/cryptozwithdrawals/payment-method)r   r   r   )r   postdeletecommonCurrenciesCGLDCELOprecisionModer{   z0.004z0.006)	tierBased
percentagemakertakerr   g333333?   )BCHBTCLTCETHEURUSD
   )r   r   rh   deposit)tradingr   features)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergi )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   )r   r   r   r   r   r   r      )r   r   r   daysBackCanceledr   r   r   r   r   )	sandboxr>   createOrdersrQ   rT   rS   rV   rE   rR   extendsdefault)linearinverse)r   r6   r8   r9   optionsnetworksr   bitcoinr   ethereumSOLsolanaARBONEarbitrumAVAXC	avacchainMATICpolygonBASEbaseSUIsuiOPoptimismNEARnearAPTaptosKAVAkavaBLASTblastXLMstellarSEIseiADAcardanoCOREcoredaoalgorandosmosiscelohederazksyncstackstezoselrondlitecoincosmosfilecoinpolkadotdogecoinrippledash)ALGOOSMOr   HBARZKSYNCSTXXTZEGLDr   ATOMFILDOTDOGEXRPDASH
exceptions)	zInsufficient fundsNotFoundzInvalid API Keyzinvalid signaturezInvalid PassphrasezInvalid order idzPrivate rate limit exceededzTrading pair not availablezProduct not found)zOrder already donezorder not foundzprice too smallzprice too precisezunder maintenancezsize is too smallzCancel only mode)exactbroad)deep_extendsuperr(   describe
userAgentsr%   parse_numberr   r"   r   r!   r#   r   r$   )self	__class__s    O/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/coinbaseexchange.pyr	  zcoinbaseexchange.describe   s$   &6 F H xK
$xK
'xK
 $xK
 	xK

 2xK
 4xK
  444 %4 	4
 %4 %4 "44 t4 '4 t4 (4 '4 (4 "44  4  !4" $T#4$ "4%4& &u'4(  )4* +D+4, &u-4. #E/40 *5142 $U344 t546 "5748 94:  ;4< d=4> "4?4@ dA4B !$C4D tE4F #DG4H  I4J 'K4L $UM4N !%O4P *5Q4R (S4T %eU4V tW4X Y4Z T[4\ t]4^ "5_4` #Da4b $Zc4d #De4f Dg4xK
x yxK
H /IxK
J PQ l67 /G9_KxK
l " $mxK
v   %L o<!MwxK
R !SxK
X YYxK
Z !%"&!..w7!..w7	 "'"'    #!!  !   #! [xK
R #&*(,,0,1).+06:#'#'"&#'	( #($)$)+027/4#')$, %)&+!$$*%+*.& ',#($)*/	# ',!$#($)*/( ',!$$*%+#($)*/$ ',!$$*,-%+#($)*/	*  #ACJ y ##
 ##YPSxK
t  E9E :E
 8E jE [E YE FE 5E *E FE  7!E$ F%E, W-E. 9/E2 53E8 99E< I=E> '%"$ ' $" % & %%%&#"GEGuxK
D *; -':)<*=(43D2B)5
 +8'4'3)5)6)5(5ExK
 x x	    c                    | j                  |      }i }t        dt        |            D ]  }||   }| j                  |d      }| j                  |d      }| j	                  |      }| j                  |di       }	i }
| j                  |dg       }t        dt        |            D ]  }||   }| j                  |d      }| j                  |      }|| j                  |d      || j                  |d      dk(  ddddd	| j                  |d
      | j                  |d      di| j                  |d      |d|
|<    | j                  |||| j                  |	d      || j                  |d      dk(  ddd| j                  |d      | j                  |	d      dd| j                  |	d
      | j                  |	d      dd|
d      ||<    |S )a0  
        fetches all available currencies on an exchange

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getcurrencies

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   r+   r,   detailssupported_networksstatusonlineNrh   min_withdrawal_amountmax_withdrawal_amountminmaxcontract_address)r+   r,   networkactiverh   r   fee	precisionlimitscontractinfotypemax_precisionmin_size)amountrh   )r+   coder!  r"  r,   r  r   rh   r  r  r  r   )
publicGetCurrenciesrangelensafe_stringsafe_currency_code	safe_dict	safe_listnetwork_id_to_codesafe_numbersafe_currency_structure)r  paramsresponseresulticurrencyr+   r,   r&  r  r   supportedNetworksjr  	networkIdnetworkCodes                   r  fetch_currenciesz!coinbaseexchange.fetch_currencies  s(    ++F3T q#h-( 4	A{H!!(D1B##Hf5D**2.DnnXy"=GH $x9Mr R1c"345 +A. ,,Wd;	"55i@# ,,Wf=*"..wAXM $#!%"#'#3#3G=T#U#'#3#3G=T#U% !% 0 0:L M#!)%	,  77 ((&9**8X>(J !--hH  $//D#
  $//9PQ#//9PQ!	 %+9 F4L=4	j r  c                    | j                  |      }g }t        dt        |            D ]-  }||   }| j                  |d      }|j	                  d      \  }}| j                  |      }	| j                  |      }
| j                  |d      }|j                  | j                  | j                  d   i d|d|	dz   |
z   d|	d	|
d
dd|d|ddddddd| j                  |d      ddddddd|dk(  dddddddddd| j                  |d      | j                  |d      dddddddddd| j                  |d       ddd!d|d"
             0 |S )#a8  
        retrieves data on all markets for coinbaseexchange

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproducts

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r   r+   -r  r   symbol/r   quotesettleNbaseIdquoteIdsettleIdr"  r6   Tr7   margin_enabledr8   Fr9   r:   r  r  r   r   base_incrementquote_increment)r%  pricer  min_market_funds)r   r%  rG  cost)
r   contractSizeexpiryexpiryDatetimestrike
optionTyper  r  createdr!  )publicGetProductsr(  r)  r*  splitr+  appendextendr{   
safe_valuer/  )r  r1  r2  r3  r4  marketr+   rA  rB  r   r?  r  s               r  fetch_marketszcoinbaseexchange.fetch_markets  s7    ))&1b q#h-( :	Aa[F!!&$/B hhsmOFG **62D++G4E%%fh7FMM$++dii	&: 0=b0=$*u,0= 0= 	0=
 $0= &0= 70= D0= 0= 0= $//&2BC0= 0= %0= %0= 6X-0=  E!0=" $#0=$   $"&""..v7GH!--f6GH  $#!
  $#
  $#
  $//8JK#$  _0= 0 0:	v r  c                 h    | j                          | j                  |      }| j                  ||      S )ax  
        fetch all the accounts associated with a profile

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounts

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
        )load_marketsprivateGetAccountsparse_accountsr  r1  r2  s      r  fetch_accountszcoinbaseexchange.fetch_accountsy  s5     	**62* ""8V44r  c                 r    | j                  |d      }| j                  |d      d | j                  |      |dS )Nr5  r+   )r+   r"  r&  r!  )r*  r+  )r  account
currencyIds      r  parse_accountzcoinbaseexchange.parse_account  sD     %%gz:
""7D1++J7	
 	
r  c                 X   d|i}t        dt        |            D ]~  }||   }| j                  |d      }| j                  |      }| j	                         }| j                  |d      |d<   | j                  |d      |d<   | j                  |d      |d	<   |||<    | j                  |      S )
Nr!  r   r5  	availablefreeholdusedbalancetotal)r(  r)  r*  r+  r^  safe_balance)r  r2  r3  r4  rf  r_  r&  r^  s           r  parse_balancezcoinbaseexchange.parse_balance  s    )q#h-( 	#AqkG))':>J**:6DllnG"..wDGFO"..w?GFO#//CGG"F4L	#   ((r  c                 f    | j                          | j                  |      }| j                  |      S )az  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounts

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        )rX  rY  ri  r[  s      r  fetch_balancezcoinbaseexchange.fetch_balance  s1     	**62!!(++r  Nr=  r   c                     | j                          | j                  |      dd}| j                  | j                  ||            }| j	                  ||      }| j                  |d      |d<   |S )aO  

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductbook

        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
           )r+   levelsequencenonce)rX  	market_idpublicGetProductsIdBookrS  parse_order_booksafe_integer)r  r=  r   r1  requestr2  	orderbooks          r  fetch_order_bookz!coinbaseexchange.fetch_order_book  sv     	
 ..(
 //GV0LM  ))(F;	!..xD	'r  tickerrU  c                    d }d }d }d }d }d }d }	d }
|d n|d   }t        |t              r#| j                  |d      }| j                         }n| j	                  | j                  |d            }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  |d	d
      }| j                  |d      }
| j                  i d|d|d| j                  |      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=     r   bidaskhighlowopenrG  lastvolume	timestampdatetime	bidVolume	askVolumevwapclosepreviousClosechanger   average)
baseVolumequoteVolumer!  )	
isinstancelistr*  milliseconds	parse8601rT  safe_string_2safe_tickeriso8601)r  rx  rU  r  r{  r|  r  r}  r~  r  r  r=  s               r  parse_tickerzcoinbaseexchange.parse_ticker  s   F 	 .vh/?fd###FA.D))+Itvv'FGI""651C""651C##FF3D""651C##FF3D%%fgv>D%%fh7F !
f!
!
 Y/!
 D	!

 3!
 3!
 !
 3!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ !)!
* + 	r  symbolsc                    | j                          | j                  |      }i }| j                  | j                  ||            }i }t	        |j                               }d}t        dt        |            D ]Z  }||   }	| j                  ||	g       }
| j                  |
dg       }| j                  |	d|      }|d   }| j                  ||      ||<   \ | j                  |d|      S )a)  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproduct

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        r<  r   Nr=  )rX  market_symbolspublicGetProductsSparkLinesrS  r  keysr(  r)  rT  safe_marketr  filter_by_array_tickers)r  r  r1  ru  r2  r3  	marketIds	delimiterr4  marketIdentryfirstrU  r=  s                 r  fetch_tickerszcoinbaseexchange.fetch_tickers=  s     	%%g.33DKK4PQ* )		q#i.) 	>A |HOOHh;EOOE1b1E%%hi@FH%F!..uf=F6N	> ++FHgFFr  c                     | j                          | j                  |      }d|d   i}| j                  | j                  dd      } t	        | |      | j                  ||            }| j                  ||      S )a  

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductticker

        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r+   fetchTickerMethodpublicGetProductsIdTicker)rX  rU  r*  r   getattrrS  r  )r  r=  r1  rU  ru  methodr2  s          r  fetch_tickerzcoinbaseexchange.fetch_tickerk  s}     	V$&,
 !!$,,0CE`a(74(Wf)EF.   622r  tradec                     | j                  | j                  |dd            }| j                  |d      }| j                  ||d      }d }d }d }| j	                  |d      }|F|dz   }	| j                  ||	      }| j                  |d      }
|
|
dk(  rd	nd
}| j                  ||      }| j                  |dd      }||d   |d}| j                  |d      }|d   dk(  rdnd}| j                  |d      }| j                  |d      }| j                  |d      }||||d   dk(  rdnd}| j                  |d      }| j                  |d      }| j                  ||||| j                  |      |d   d ||||||d|      S )Nr   
created_at
product_idr<  rB  _value	liquidityTr   r   	fill_feesr  r?  rI  r5  ratetrade_idsidebuysellorder_idmaker_order_idtaker_order_idrG  sizer=  )r+   orderr!  r  r  r=  r"  takerOrMakerr  rG  r%  r  rI  )r  r  r*  r  safe_string_lower
safe_trader  )r  r  rU  r  r  feeRater  rI  feeCurrencyId	costFieldr  feeCostr  r+   r  orderIdmakerOrderIdtakerOrderIdrG  r%  s                       r  parse_tradezcoinbaseexchange.parse_trade  s   . NN4#5#5eV\#RS	##E<8!!(FC8..vyA$%0I##E95D((<I$+4+;w'**6<@$$UK?w

 eZ0-50vu""5*5''/?@''/?@l&>\E]"6]e35&D  0!!%0"Y/X&( 
  	r  sincec                    |t        | j                  dz         d}| j                  |dd      \  }}|r| j                  d||||d      S | j	                          | j                  |      }d|d   i}|||d<   || j                  |      |d	<   | j                  |d
d      }|'| j                  |d
g      }| j                  |      |d<   | j                  | j                  ||            }	| j                  |	|||      S )aK  

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getfills

        fetch all trades made by the user
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch trades for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        z+ fetchMyTrades() requires a symbol argumentFrQ   paginater0   r  r+   r   
start_dateuntilend_date)r   r+   handle_option_and_paramsfetch_paginated_call_dynamicrX  rU  r  safe_value_2omitprivateGetFillsrS  parse_trades)
r  r=  r  r   r1  r  rU  ru  r  r2  s
             r  fetch_my_tradesz coinbaseexchange.fetch_my_trades  s$    >#DGG.[$[\\88R\]&44_feUZ\bdghhV$&,
 $GG$(LL$7GL!!!&':>YYvy1F"&,,u"5GJ''GV(DE  65%@@r  c                     | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  ||||      S )a;  

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproducttrades

        get the list of most recent trades for a particular symbol
        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r+   r   )rX  rU  publicGetProductsIdTradesrS  r  )r  r=  r  r   r1  rU  ru  r2  s           r  fetch_tradeszcoinbaseexchange.fetch_trades  st     	V$&,
 $GG11$++gv2NO   65%@@r  c                    | j                          | j                  |      }| j                  |d      }| j                  |d      }i }t        dt	        | j
                              D ]  }| j
                  |   }||||ddd||<    |S )ae  
        fetch the trading fees for multiple markets

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getfees

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        maker_fee_ratetaker_fee_rater   T)r!  r=  r   r   r   r   )rX  privateGetFeesr/  r(  r)  r  )r  r1  r2  r   r   r3  r4  r=  s           r  fetch_trading_feesz#coinbaseexchange.fetch_trading_fees  s     	&&v.   +;<  +;<q#dll+, 		A\\!_F  "!F6N		 r  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr      rm  r   rz     )safe_timestampr/  )r  ohlcvrU  s      r  parse_ohlcvzcoinbaseexchange.parse_ohlcv@  sn     q)UA&UA&UA&UA&UA&
 	
r  rl   c           	         | j                          d}| j                  |ddd      \  }}|r| j                  d|||||d      S | j                  |      }| j	                  | j
                  |      }d|d   i}	|||	d<   n||	d<   | j                  |dd      }
| j                  |dg      }|| j                  |      |	d	<   |d}nt        d|      }|
l|d
z  }| j                  ||z        r+| j                  | j                  |dz
  |z  |            |	d<   n<| j                  | j                  ||z  |            |	d<   n| j                  |
      |	d<   | j                  | j                  |	|            }| j                  |||||      S )a  

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductcandles

        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch trades for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        FrR   r  rk   r+   granularityr  endstarti  r   )rX  r  "fetch_paginated_call_deterministicrU  rt  ri   r  r  r  r  is_round_numbersumpublicGetProductsIdCandlesrS  parse_ohlcvs)r  r=  	timeframer  r   r1  r  rU  parsedTimeframeru  r  parsedTimeframeMillisecondsr2  s                r  fetch_ohlcvzcoinbaseexchange.fetch_ohlcvT  s    	88z[`a&::<QVX]_hjpruvvV$++DOOYG&,
 &%4GM"%.GM"!!&'596G9-#||E2GG}C}.=.D+''0K(KL%)\\$((EAIId;dfk2l%mGEN%)\\$((5C^;^`e2f%gGEN!%e!4224;;w3OP   69eUKKr  c                 H    | j                  |      }| j                  |d      S )a  
        fetches the current integer timestamp in milliseconds from the exchange server
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        epoch)publicGetTimer  r[  s      r  
fetch_timezcoinbaseexchange.fetch_time  s)     %%f- ""8W55r  r  c                 :    ddddddd}| j                  |||      S )Nr  closedcanceled)pendingr  r  doner  	cancelingr*  )r  r  statusess      r  parse_order_statusz#coinbaseexchange.parse_order_status  s2    "
 &&99r  r  c                    | j                  | j                  |d            }| j                  |d      }| j                  ||d      }| j                  | j                  |d            }| j                  |d      }|dk(  r|dk(  rd}| j                  |d      }| j                  |d	      }| j                  |d
|      }	| j                  |d      }
| j	                  |d      }d }|	||d   d d}| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j	                  |d      }| j                  |d      }| j                  i d|d|d|d|d| j                  |      dd d|d|d   d|d|d|d|d|d|d|
d |	d!|d |d d d"|      S )#Nr  r  r<  r  done_reasonr  r  rG  filled_sizer  executed_valuer  r?  r  r+   r"  r  time_in_force	post_only
stop_price
client_oidclientOrderIdr!  r  r  lastTradeTimestampr=  r   postOnlyr   rI  r%  filled)	remainingr  r  trades)r  r*  r  r  r/  rT  
safe_orderr  )r  r  rU  r  r  r  
doneReasonrG  r  r%  rI  r  r  r+   r"  r  r   r  r   r  s                       r  parse_orderzcoinbaseexchange.parse_order  s   , NN4#3#3E<#HI	##E<8!!(FC8(()9)9%)JK%%e];
hZ:%=F  0!!%7!!%8'78""5+6"7OC
 eT*v.v.&&uo>??5+6''|<((=  
" 
] 
 E 
 	 

 Y/ 
 !$ 
 f 
 fX& 
 D 
 ; 
  
 D 
 U 
 L 
 D 
  f! 
" f# 
$ + 
, - 	r  r+   c                     | j                          i }| j                  |dd      }d}|d}||d<   nd}||d<   | j                  |ddg      } t        | |      | j	                  ||            }| j                  |      S )a  

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorder

        fetches information on an order made by the user
        :param str id: the order id
        :param str symbol: not used by coinbaseexchange fetchOrder
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  NprivateGetOrdersIdr+   privateGetOrdersClientClientOid)rX  r  r  r  rS  r  )r  r+   r=  r1  ru  r  r  r2  s           r  fetch_orderzcoinbaseexchange.fetch_order  s     	**6?LQ )FGDM6F$1GL!YYv'FGF(74(Wf)EF))r  c                     | j                          d}|| j                  |      }d|i}| j                  | j                  ||            }| j	                  ||||      S )a  
        fetch all the trades made from a single order
        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades 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>`
        Nr  )rX  rU  r  rS  r  )	r  r+   r=  r  r   r1  rU  ru  r2  s	            r  fetch_order_tradesz#coinbaseexchange.fetch_order_trades  si     	[[(F
 ''GV(DE  65%@@r  c           	      R    ddi}| j                  |||| j                  ||            S )a  

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorders

        fetches information on multiple orders made by the user
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch open orders for
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  allfetch_open_ordersrS  r  r=  r  r   r1  ru  s         r  fetch_orderszcoinbaseexchange.fetch_orders  s5     e
 %%feUDKKQW<XYYr  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||d      S i }d}|| j                  |      }|d   |d<   |||d<   || j	                  |      |d	<   | j                  |d
d      }|'| j                  |d
g      }| j	                  |      |d<   | j                  | j                  ||            }	| j                  |	|||      S )ac  

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorders

        fetch all unfilled currently open orders
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch open orders for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        FrS   r  r0   Nr+   r  r   r  r  r  )
rX  r  r  rU  r  r  r  privateGetOrdersrS  parse_orders)
r  r=  r  r   r1  r  ru  rU  r  r2  s
             r  r  z"coinbaseexchange.fetch_open_orders-  s    	88ART^_&445FPUW\^dfijj[[(F$*4LGL!$GG$(LL$7GL!!!&':>YYvy1F"&,,u"5GJ((Wf)EF  65%@@r  c           	      R    ddi}| j                  |||| j                  ||            S )a  

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorders

        fetches information on multiple closed orders made by the user
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch open orders for
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  r  r  s         r  fetch_closed_ordersz$coinbaseexchange.fetch_closed_ordersP  s5     f
 %%feUDKKQW<XYYr  r"  r  r%  rG  c                    | j                          | j                  |      }|||d   d}| j                  |dd      }	|	|	|d<   | j                  |g d      }
|
| j	                  ||
      |d<   | j                  |dd      }|||d<   | j                  |d	d
d      }|rd|d
<   | j                  |g d      }|dk(  r+| j	                  ||      |d<   | j                  ||      |d<   nc|dk(  r^| j                  |dd      }||||z  }n| j                  |ddg      }|| j                  ||      |d<   n| j                  ||      |d<   | j                  | j                  ||            }| j                  ||      S )a  

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postorders

        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>`
        r+   )r"  r  r  r  r  )	stopPricer  r   r  r   r  r  r   FT)	r   r  r  r  r  r  r  r   r   r   rG  r  rU  rI  funds)rX  rU  r  safe_number_nprice_to_precisionr  r  amount_to_precisionsafe_number_2cost_to_precisionprivatePostOrdersrS  r  )r  r=  r"  r  r%  rG  r1  rU  ru  r  r   r   r  rI  r2  s                  r  create_orderzcoinbaseexchange.create_orderb  s    	V$  ,
( **6?LQ$$1GL!))&2]^#$($;$;FL$QGL!((P"'2GO$$$VZeL#'GK 6  $g  h7?#66vuEGG"66vvFGFOX%%ffg>D|$!E>D6FG+<=#'#9#9&$#G "&":":66"J))$++gv*FG( &11r  c                    | j                          i }| j                  |dd      }d}|d}||d<   nd}||d<   | j                  |ddg      }d}|| j                  |      }|d   |d<    t	        | |      | j                  ||            S )	a  

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_deleteorder

        cancels an open order
        :param str id: order id
        :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>`
        r  r  NprivateDeleteOrdersIdr+   "privateDeleteOrdersClientClientOidr=  r  )rX  r  r  rU  r  rS  )r  r+   r=  r1  ru  r  r  rU  s           r  cancel_orderzcoinbaseexchange.cancel_order  s     	
 **6?LQ ,FGDM9F$1GL!YYv'FGF[[(F$*8$4GL!$wtV$T[[&%ABBr  c                     | j                          i }d}|| j                  |      }|d   |d<   | j                  | j                  ||            S )a  

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_deleteorders

        cancel all open orders
        :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
        :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  )rX  rU  privateDeleteOrdersrS  )r  r=  r1  ru  rU  s        r  cancel_all_ordersz"coinbaseexchange.cancel_all_orders  sY     	[[(F$*8$4GL!''GV(DEEr  c                 $    | j                  |      S N)privateGetPaymentMethods)r  r1  s     r  fetch_payment_methodsz&coinbaseexchange.fetch_payment_methods  s    ,,V44r  r&  addressc                    | j                  ||      \  }}| j                  |       | j                          | j                  |      }|d   |d}d}d|v r|dz  }nd|v r|dz  }n|dz  }||d	<   |||d
<    t	        | |      | j                  ||            }	|	s*t        | j                  dz   | j                  |	      z         | j                  |	|      S )a]  
        make a withdrawal

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postwithdrawpaymentmethod
        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postwithdrawcoinbaseaccount

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r+   )r5  r%  privatePostWithdrawalspayment_method_idPaymentMethodcoinbase_account_idCoinbaseAccountCryptocrypto_addressdestination_tagz withdraw() error: )
handle_withdraw_tag_and_paramscheck_addressrX  r5  r  rS  r   r+   jsonparse_transaction)
r  r&  r%  r2  tagr1  r5  ru  r  r2  s
             r  rh   zcoinbaseexchange.withdraw  s     99#vFV7#==& 
 *&(o%F"f,''FhF(/G$%-0)*(74(Wf)EF*? ?$))HBU UVV%%h99r  c                 8    dddddd}| j                  |||      S )Ntransferr  r  rebate)rB  matchr  rC  
conversionr  )r  r"  typess      r  parse_ledger_entry_typez(coinbaseexchange.parse_ledger_entry_type  s/    "!
 tT22r  itemr5  c                 @   | j                  |d      }| j                  |d      }d }| j                  |d      }t        j                  ||      }t        j                  |d      rd}t        j                  |      }nd}| j                  |      }| j                  |      }	| j                  |      }
| j                  | j                  |d            }| j                  | j                  |d            }| j                  d |      }| j                  |d	i       }d }d }d }|d
k(  r7| j                  |d      }| j                  |d      }| j                  |d      }n| j                  |d      }d}| j                  |||| j                  |      ||||||||
|	|d d|      S )Nr+   r%  rf  0outinr  r"  r  rB  fromtoprofile_transfer_idr  ok)r!  r+   r  r  	directionr^  referenceAccountreferenceIdr"  r5  r%  beforeafterr  r  )r*  r&   
string_sub	string_lt
string_absr  r  rT  rG  r+  safe_ledger_entryr  )r  rH  r5  r+   amountStringrQ  afterStringbeforeStringr%  rU  rT  r  r"  r&  r  r^  rR  rS  r  s                      r  parse_ledger_entryz#coinbaseexchange.parse_ledger_entry  s   2 dD)''h7	&&tY7))+|D\3/I"--l;LI""<0!!+.""<0NN4??4#FG	++D,<,<T6,JK&&tX6//$	26:&&w7G#//>**74IJK**7J?K%%"Y/" 0&'
  ! 	r  c                    |t        | j                  dz         | j                          | j                          | j	                  |      }| j                  | j                  d      }| j                  ||      }|t        | j                  dz   |z         d|d   i}|| j                  |      |d<   |||d<   | j                  |dd      }	|	'| j                  |dg      }| j                  |	      |d<   | j                  | j                  ||            }
t        d	t        |
            D ]
  }||
|   d
<    | j!                  |
|||      S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccountledger

        :param str code: unified currency code, default is None
        :param int [since]: timestamp in ms of the earliest ledger entry, default is None
        :param int [limit]: max number of ledger entries to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch trades for
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
        z$ fetchLedger() requires a code paramr&  z- fetchLedger() could not find account id for r+   r  r   r  r  r   r5  )r   r+   rX  load_accountsr5  index_byr   rT  r   r  r  r  privateGetAccountsIdLedgerrS  r(  r)  parse_ledger)r  r&  r  r   r1  r5  accountsByCurrencyCoder^  ru  r  r2  r4  s               r  fetch_ledgerzcoinbaseexchange.fetch_ledger_  s^    <#DGG.T$TUU==&!%t}}f!E//"8$??*Y Y\` `aa'$-
 $(LL$7GL!$GG!!&':>YYvy1F"&,,u"5GJ224;;w3OPq#h-( 	+A&*HQK
#	+  8UEBBr  c                    | j                          | j                          d}| j                  |d      }|c|a| j                  |      }| j	                  | j
                  d      }| j                  ||      }|t        | j                  dz   |z         |d   }i }	|||	d<   |||	d<   d}
|| j                  | j                  |	|            }
t        dt        |
            D ]M  }| j                  |
|   d      }| j                  | j                  |      }| j                  |d      }||
|   d<   O nC| j                  | j                  |	|            }
t        dt        |
            D ]
  }||
|   d<    | j                  |
|||      S )	ai  
        fetch history of deposits and withdrawals

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_gettransfers
        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounttransfers

        :param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
        :param int [limit]: max number of deposit/withdrawals to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.id]: account id, when defined, the endpoint used is '/accounts/{account_id}/transfers/' instead of '/transfers/'
        :returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr+   r&  z: fetchDepositsWithdrawals() could not find account id for r   r   
account_idr5  )rX  r_  r*  r5  r`  r   rT  r   r+   privateGetTransfersrS  r(  r)  accountsByIdprivateGetAccountsIdTransfersparse_transactions)r  r&  r  r   r1  r5  r+   rc  r^  ru  r2  r4  rf  	codeInners                 r  fetch_deposits_withdrawalsz+coinbaseexchange.fetch_deposits_withdrawals  s    	fd+:==.)-t}}f)M&//*@$G?'2n(nqu(uvvT]>GDM$GG://GV0LMH: 1c(m, 4!--hqk<H
//$*;*;ZH ,,Wf=	*3J'	4 99$++gv:VWH6 1c(m, /*.J'/&&x5%HHr  c           	      N    | j                  |||| j                  ddi|            S )a  
        fetch all deposits made to an account

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_gettransfers
        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounttransfers

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        r"  r   rl  rS  r  r&  r  r   r1  s        r  fetch_depositszcoinbaseexchange.fetch_deposits  s.     ..tUE4;;PVXaObdjCkllr  c           	      N    | j                  |||| j                  ddi|            S )a  
        fetch all withdrawals made from an account

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_gettransfers
        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounttransfers

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        r"  rh   rn  ro  s        r  fetch_withdrawalsz"coinbaseexchange.fetch_withdrawals  s.     ..tUE4;;PVXbOcekClmmr  c                     | j                  |d      }|ry| j                  |d      }| j                  |d      }|ry|r|syy)Ncanceled_atr  processed_atcompleted_atrP  failedr  )rT  )r  transactionr  	processed	completeds        r  parse_transaction_statusz)coinbaseexchange.parse_transaction_status  sI    ??;>OOK@	OOK@	yr  rx  c                    | j                  |di       }| j                  | j                  |d            }| j                  |d      }| j                  ||      }| j	                  |d      }| j                  |d      }| j                  |d      }	| j                  |d|	      }	d d d d}
|dk(  r:d	}| j                  |d
|	      }	| j	                  |d      }||||z  }||
d<   ||
d<   | j                  |d      }i d|d| j                  |d      d| j                  |d      d|d|d| j                  |      d|d| j                  |      d|d| j                  |      d|	dd d| j                  |d      d| j                  |d      dd dd d| j                  | j                  |d            d d|
dS ) Nr  r  r5  r%  r"  r:  )r5  rI  r  rh   
withdrawalsent_to_addressr  rI  r  r!  r+   txidcrypto_transaction_hashr  r  r  r2  addressFrom	addressTor@  r;  tagFromtagToupdatedru  F)commentinternalr  )rT  r  r*  r+  r/  r.  r{  r  )r  rx  r5  r  r  r_  r&  r%  r"  r2  r  r  r8  s                r  r?  z"coinbaseexchange.parse_transaction  so   > //+y"=NN4#3#3K#NO	%%k:>
&&z8<!!+x8V4""7,<="";0@'J

 :D&&w0A7KG&&w6G"%g%F%F"&J$$Wi8	
K
$"";5
 D$$W.GH
 D	

 
 t..y9
 f
 d33K@
 
 Y/
 w
 4
 ))'3CD
 4##G->?
 t
  T!
" t~~d&6&6{N&ST#
$ )
 	
r  c                 V   | j                          | j                  |      }| j                  | j                  d      }|>| j	                         }|| j                  d<   | j                  |d      | j                  d<   |d   }| j                  | j                  d   |      }|$t        | j                  dz   |z   dz   |z   dz         d|d   i}| j                  | j                  ||            }| j                  |d	      }	| j                  |d
      }
|| j                  |	      d|
|dS )a  
        create a currency deposit address

        https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postcoinbaseaccountaddresses

        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        coinbaseAccountsNr5  coinbaseAccountsByCurrencyIdr+   z5 createDepositAddress() could not find currency code z with id = z0 in self.options['coinbaseAccountsByCurrencyId']r2  r;  )r5  r2  r  r@  r!  )rX  r5  rT  r   privateGetCoinbaseAccountsr`  r    r+   &privatePostCoinbaseAccountsIdAddressesrS  r*  r=  )r  r&  r1  r5  r   r_  r^  ru  r2  r2  r@  s              r  create_deposit_addressz'coinbaseexchange.create_deposit_addressg  sR    	==&??4<<1CD668H/7DLL+,;?==S];^DLL78d^
//$,,/M"NPZ[? +b!bei!ily!y  }G  "G  J|  "|  }  }'$-
 >>t{{7TZ?[\""8Y7x):;))'2
 	
r  rt   GETc                    d| j                  ||      z   }| j                  || j                  |            }|dk(  r|r|d| j                  |      z   z  }| j	                  | j
                  d   |         |z   }	|dk(  r| j                          t        | j                               }
d}|dk7  r|r| j                  |      }|}|
|z   |z   |z   }d }	 | j                  | j                        }| j                  | j!                  |      |t"        j$                  d      }| j&                  ||
| j(                  d	d
}|	|||dS # t        $ r}t        | j                  dz         d }~ww xY w)Nr>  r  ?rx   ru    z sign() invalid base64 secretbase64zapplication/json)zCB-ACCESS-KEYzCB-ACCESS-SIGNzCB-ACCESS-TIMESTAMPzCB-ACCESS-PASSPHRASEzContent-Type)urlr  bodyheaders)implode_paramsr  extract_params	urlencodeimplode_hostnamers   check_required_credentialsstrrp  r>  base64_to_binaryr~   	Exceptionr   r+   hmacencodehashlibsha256r}   r   )r  pathrx   r  r1  r  r  ru  queryr  rp  payloadwhatr~   e	signatures                   r  signzcoinbaseexchange.sign  sl   ++D&99		&$"5"5d";<U?3!666##DIIe$4S$9:WD)++-

%EG99U+D"G6>G+g5DFU..t{{; 		$++d"3VW^^XVI!%"+',(, 2G fdwOO  U)$''4S*STTUs   E   	E&	E!!E&reasonr  r  r  r  c
                 <   |dk(  s|dk(  r|d   dk(  ro| j                  |d      }
| j                  dz   |
z   }| j                  | j                  d   |
|       | j	                  | j                  d   |
|       t        |      t        | j                  dz   |z         y )	Ni  i  r   {message r  r  )r*  r+   throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr   )r  r&  r  r  r  r  r  r2  requestHeadersrequestBodyr  feedbacks               r  handle_errorszcoinbaseexchange.handle_errors  s    CKTS[Aw#~**8Y?77S=7244T__W5MwX`a44T__W5MwX`a#H--# 455r  c           	          | j                  |||||||      }t        |t              s.d|v r*t        | j                  dz   | j                  |      z         |S )Nr  r  )fetch2r  r  r   r+   r>  )	r  r  rx   r  r1  r  r  configr2  s	            r  ru  zcoinbaseexchange.request  sT    ;;tS&&'4P(C(H$#DGGcMDIIh4G$GHHr  r/  )I__name__
__module____qualname__r   r	  r   r:  r   r   rV  r   r\  r`  r   ri  rk  r  r   r   rw  dictr   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   floatr   r&  r*  r-  r1  r   rh   rG  r	   r   r]  rd  rl  rp  rr  r{  r?  r
   r  r  intr  ru  __classcell__)r  s   @r  r(   r(      s^   y# yv ') iZ iV $& v$v, vp %' 54= 5B
&) ) $& ,( , :>b %s %3 %Y %NM4 M M6 M^ 04B ,GW ,G7 ,G\ 02 (33 (3f (3TC Cv C CJ -1tRV_a "Ac "A "AC "AH 6:UW A3 As A# A\`af\g AB )+ { B
 
4 
( 26DW[df 6L# 6Lc 6LQT 6Lkoptku 6Lp !# 6s 6	: 	:F Fv F FP 26b *c *3 *2 9=4^bkm AS A# AS AX[ A( *.Dt\^ Z3 Zc Z Zcghmcn Z$ /3TXac !A !A3 !Ac !Ahlmrhs !AF 154VZce Z# ZS ZPS Zjnotju Z$ gksu S23 S2i S2y S2RW S2`c S2j 37r Cs CC C< /32 F F$ ,. 5 DHPR #:S #:% #:# #:Wb #:J3Dt Dx D; DL (,$TZ\ +C +CC +Cs +Caefqar +CZ 6:[_hj aIs aI# aIUX aIost  pA aIF *.Dt\^ m3 mc m mcghsct m -1tRV_a nc n nC nfjkvfw nK
T K
X K
Q\ K
Z 8: "
3 "
n "
H &eBSW P>	# 	s 	 	c 	TX 	`c 	 !)r4VZce r  r(   )-ccxt.base.exchanger   ccxt.abstract.coinbaseexchanger   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r    r!   r"   r#   r$   ccxt.base.decimal_to_precisionr%   ccxt.base.preciser&   r(    r  r  <module>r     sk    ( 6  `  `  `  `  `  `  * 0 - . . + ) * . * 4 %ax ar  