
    eia                    <   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,dS )    )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                   P    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dJd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dJd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!dJdede"fdZ#dd	d	i fd
ededededee"         f
dZ$i fdefdZ%defdZ&dJd 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d0ed*e0d1ed2ede6f
d3Z7d4 Z8dJd5ed6e9de:fd7Z;d	d	d	i fd0edededee:         fd8Z<d	d	d	i fd0edededee6         fd9Z=d	d	d	i fd0edededee6         fd:Z>d	d	d	i fd0edededee6         fd;Z?d< Z@dJd=ed6e9de6fd>ZAi fd0edeBfd?ZCd@dAi d	d	fdBZDd0eEdCedDedEedFedGefdHZFd@dAi d	d	i fdIZG xZHS )Kcoinbaseexchangereturnc                 `   |                      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d@ddAdi dBddCddDddEddFddGddHddIddJddKddLddMddNddOddPddQddRdi dSddTddUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdi ddddeddfddgddhddiddjddkdldmddnddoddpddqddrddsddtdduddddvdwdxdydzd{d|d}d~ddddddddddddddgddddddddg dig dg dg ddddddidt
          ddd|                     d          |                     d          dddddddddddddddddddddddd dddd dddddddddddddd ddddddddddddddddddddddddddddddddddddyid	ddid d dd d ddddi 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	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelAllOrderscancelOrdercloseAllPositionsclosePositioncreateDepositAddresscreateOrder$createOrderWithTakeProfitAndStopLoss&createOrderWithTakeProfitAndStopLossWscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchAccountsfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositsfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchLedgerfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricesfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsemulatedfetchVolatilityHistoryfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginrepayMarginsetLeverage	setMarginsetMarginMode)setPositionMode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passwordr   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)0z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}conversionszconversions/feeszloans/lending-overviewzloans/lending-overview-xmzloans/loan-previewzloans/loan-preview-xmzloans/repayment-previewzloans/repayment-preview-xmzloans/interest/{loan_id}z loans/interest/history/{loan_id}zloans/interestzloans/assetsloans)r   z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-methodz
loans/openzloans/repay-interestzloans/repay-principal)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   r   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   )	sandboxrD   createOrdersrv   r~   r{   r   rT   rw   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    S/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/coinbaseexchange.pyr?  zcoinbaseexchange.describe   s   &6 = = F F H H |K
$|K
'|K
 $|K
 	|K

 2|K
 4|K
  iii %i 	i
 %i %i Ui $Ui 'i i "4i ti $Ui  i 'i  t!i" 7#i i$ 9%%i& &u'i( ()i* '+i, (-i. "4/i0  1i2 3i4 &u5i6 "57i8 +E9i: )%;i< #E=i> ,U?i@ $TAiB 'CiD (Ei i iF "4GiH &uIiJ  KiL +DMiN &uOiP 'QiR (SiT #EUiV *5WiX $UYiZ u[i\ "5]i^ *5_i` +Eaib )%cid teif  gi i ih !%iij %ekil $Umin &uoip -eqir /sit "5uiv #Ewix +Eyiz {i| !%}i~ "5i@ &uAiB +ECiD  EiF dGiH $UIi i iJ +EKiL %eMiN "4OiP uQiR #ESiT dUiV !$WiX tYiZ #D[i\  ]i^ '_i` $Uaib !%cid *5eif (gih %eiij )%ki i il )%min toip qir Tsit tuiv "5wix #Dyiz $Z{i| )%}i~ #Di@ AiB #ECiD &uEiF uGiH uIiJ UKiL  Mi iN $) Qi i i|K
b  c|K
r /s|K
t PQ  l67  /G9_ u|K
V " $ $W|K
`     1 1 1d  &  MK K!\ \a|K
Z ![|K
` Ya|K
b !%"&!..w77!..w77	  "'"'    #!! !  !   #!     c|K
Z #&*(,,0,1).+06:#'#'"&#'	( ( #($)$)+027/4#')$ $, %)&+!$$*%+*.& & ',#($)*/	# # ',!$#($)*/( ( ',!$$*%+#($)*/$ $ ',!$$*,-%+#($)*/	* 	*  #AC CJ y ## 
 ## YP P[|K
|
  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 E EG}
|K
L *; -':)<*=(43D2B)5
 
 +8'4'3)5)6)5(5  M|K
 |K
 | | |	    c                 `   |                      |          }i }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |          }|                     |di           }	i }
|                     |dg           }t          dt          |                    D ]}||         }|                     |d          }|                     |          }||                     |d          ||                     |d          dk    ddddd	|                     |d
          |                     |d          di|                     |d          |d|
|<   | 	                    ||||                     |	d          ||                     |d          dk    ddd|                     |d          |                     |	d          dd|                     |	d
          |                     |	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onlineNr   min_withdrawal_amountmax_withdrawal_amountminmaxcontract_address)r+   r,   networkactiver   r   fee	precisionlimitscontractinfotypemax_precisionmin_size)amountr   )r+   coderW  rX  r,   rR  r   r   rS  rT  rU  r   )
publicGetCurrenciesrangelensafe_stringsafe_currency_code	safe_dict	safe_listnetwork_id_to_codesafe_numbersafe_currency_structure)rB  paramsresponseresulticurrencyr+   r,   r\  rG  r   supportedNetworksjrQ  	networkIdnetworkCodes                   rD  fetch_currenciesz!coinbaseexchange.fetch_currencies  s    ++F33T q#h--(( 4	 4	A{H!!(D11B##Hf55D**2..DnnXy"==GH $x9Mr R R1c"34455  +A. ,,Wd;;	"55i@@# ,,Wf==*"..wAAXM $#!%"#'#3#3G=T#U#U#'#3#3G=T#U#U% % !% 0 0:L M M#!) )%%$  77 ((&99**8X>>(J !--hHH  $//DD# 
  $//9PQQ#//9PQQ! !	 	 %+9 9  F4LL. rE  c                 (   |                      |          }g }t          dt          |                    D ][}||         }|                     |d          }|                    d          \  }}|                     |          }	|                     |          }
|                     |d          }|                    |                     | j        d         i d|d|	dz   |
z   d|	d	|
d
dd|d|ddddddd| 	                    |d          ddddddd|dk    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 )#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+   -rI  r   symbol/r  quotesettleNbaseIdquoteIdsettleIdrX  r6   Tr7   margin_enabledr8   Fr9   r:   rR  rJ  rV  r   base_incrementquote_increment)r[  pricerM  min_market_funds)r   r[  r}  cost)
r   contractSizeexpiryexpiryDatetimestrike
optionTyperT  rU  createdrW  )publicGetProductsr^  r_  r`  splitra  appendextendr   
safe_valuere  )rB  rg  rh  ri  rj  marketr+   rw  rx  r  ru  rI  s               rD  fetch_marketszcoinbaseexchange.fetch_marketsE  s    ))&11b q#h--(( :	 :	Aa[F!!&$//B hhsmmOFG **622D++G44E%%fh77FMM$++di	&: 0=b0=$*u,0= 0= 	0=
 $0= &0= 70= D0= 0= 0= $//&2BCC0= 0= %0= %0= 6X-0=  E!0=" $#0=$   $"&""..v7GHH!--f6GHH   $#! !
  $# 
  $# 
  $//8JKK#  $  _0= 0= 0= 0 0 0 0 0 0b rE  c                     |                                   |                     |          }|                     ||          S )av  
        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rB  rg  rh  s      rD  fetch_accountszcoinbaseexchange.fetch_accounts  sA     	**622* ""8V444rE  c                     |                      |d          }|                      |d          d |                     |          |dS )Nrk  r+   )r+   rX  r\  rW  )r`  ra  )rB  account
currencyIds      rD  parse_accountzcoinbaseexchange.parse_account  sR     %%gz::
""7D11++J77	
 
 	
rE  c                    d|i}t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |                     |d          |d	<   |||<   |                     |          S )
NrW  r   rk  	availablefreeholdusedbalancetotal)r^  r_  r`  ra  r  safe_balance)rB  rh  ri  rj  r  r  r\  r  s           rD  parse_balancezcoinbaseexchange.parse_balance  s    )q#h--(( 	# 	#AqkG))':>>J**:66DllnnG"..wDDGFO"..w??GFO#//CCGG"F4LL  (((rE  c                 ~    |                                   |                     |          }|                     |          S )ax  
        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>`
        )r  r  r  r  s      rD  fetch_balancezcoinbaseexchange.fetch_balance  s=     	**622!!(+++rE  Nrs  r   c                    |                                   |                     |          dd}|                     |                     ||                    }|                     ||          }|                     |d          |d<   |S )aM  

        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)r  	market_idpublicGetProductsIdBookr  parse_order_booksafe_integer)rB  rs  r   rg  requestrh  	orderbooks          rD  fetch_order_bookz!coinbaseexchange.fetch_order_book  s     	
 ..((
 
 //GV0L0LMM  ))(F;;	!..xDD	'rE  tickerr  c                    d }d }d }d }d }d }d }	d }
|d n|d         }t          |t                    r+|                     |d          }|                                 }n|                     |                     |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|          S )Nrs     r   bidaskhighlowopenr}  lastvolume	timestampdatetime	bidVolume	askVolumevwapclosepreviousClosechanger   average)
baseVolumequoteVolumerW  )	
isinstancelistr`  milliseconds	parse8601r  safe_string_2safe_tickeriso8601)rB  r  r  r  r  r  r  r  r  r  r  rs  s               rD  parse_tickerzcoinbaseexchange.parse_ticker2  s=   F 	 .vh/?fd## 	8##FA..D))++IItvv'F'FGGI""6511C""6511C##FF33D""6511C##FF33D%%fgv>>D%%fh77F !
f!
!
 Y//!
 D	!

 3!
 3!
 !
 3!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ !)!
 !
 !
* +  	rE  symbolsc                 >   |                                   |                     |          }i }|                     |                     ||                    }i }t	          |                                          }d}t          dt          |                    D ]p}||         }	|                     ||	g           }
|                     |
dg           }| 	                    |	d|          }|d         }| 
                    ||          ||<   q|                     |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>`
        rr  r   Nrs  )r  market_symbolspublicGetProductsSparkLinesr  r  keysr^  r_  r  safe_marketr  filter_by_array_tickers)rB  r  rg  r  rh  ri  	marketIds	delimiterrj  marketIdentryfirstr  rs  s                 rD  fetch_tickerszcoinbaseexchange.fetch_tickers  s    	%%g..33DKK4P4PQQ* ))		q#i..)) 	> 	>A |HOOHh;;EOOE1b11E%%hi@@FH%F!..uf==F6NN++FHgFFFrE  c                 &   |                                   |                     |          }d|d         i}|                     | j        dd          } t	          | |          |                     ||                    }|                     ||          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)r  r  r`  r   getattrr  r  )rB  rs  rg  r  r  methodrh  s          rD  fetch_tickerzcoinbaseexchange.fetch_ticker  s     	V$$&,
 !!$,0CE`aa(74((Wf)E)EFF.   6222rE  tradec                    |                      |                     |dd                    }|                     |d          }|                     ||d          }d }d }d }|                     |d          }|S|dz   }	|                     ||	          }|                     |d          }
|
 |
dk    rd	nd
}|                     ||          }|                     |dd          }||d         |d}|                     |d          }|d         dk    rdnd}|                     |d          }|                     |d          }|                     |d          }||||d         dk    rdnd}|                     |d          }|                     |d          }|                     |||||                     |          |d         d ||||||d|          S )Nr   
created_at
product_idrr  rx  _value	liquidityTr   r   	fill_feesrS  ru  r  rk  ratetrade_idsidebuysellorder_idmaker_order_idtaker_order_idr}  sizers  )r+   orderrW  r  r  rs  rX  takerOrMakerr  r}  r[  rS  r  )r  r  r`  r  safe_string_lower
safe_trader  )rB  r  r  r  r  feeRater  r  feeCurrencyId	costFieldr  feeCostrS  r+   r  orderIdmakerOrderIdtakerOrderIdr}  r[  s                       rD  parse_tradezcoinbaseexchange.parse_trade  s,   . NN4#5#5eV\#R#RSS	##E<88!!(FC88..vyAA$%0I##E955D((<<I$+4+;+;ww'**6<@@$$UK??w
 

 eZ00-500vvu""5*55''/?@@''/?@@l&>\E]"6]e3355&D  00!!%00"Y//X&( 
  
   	rE  sincec                 ^   |t          | j        dz             d}|                     |dd          \  }}|r|                     d||||d          S |                                  |                     |          }d|d         i}|||d	<   ||                     |          |d
<   |                     |dd          }|/|                     |dg          }|                     |          |d<   | 	                    | 
                    ||                    }	|                     |	|||          S )aI  

        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>`
        Nz+ fetchMyTrades() requires a symbol argumentFrv   paginater0   r  r+   r   
start_dateuntilend_date)r   r+   handle_option_and_paramsfetch_paginated_call_dynamicr  r  r  safe_value_2omitprivateGetFillsr  parse_trades)
rB  rs  r  r   rg  r  r  r  r   rh  s
             rD  fetch_my_tradesz coinbaseexchange.fetch_my_trades  sO    >#DG.[$[\\\88R\]]& 	i44_feUZ\bdghhhV$$&,
 $GG$(LL$7$7GL!!!&':>>YYvy11F"&,,u"5"5GJ''GV(D(DEE  65%@@@rE  c                     |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     ||||          S )a9  

        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+   Nr   )r  r  publicGetProductsIdTradesr  r  )rB  rs  r  r   rg  r  r  rh  s           rD  fetch_tradeszcoinbaseexchange.fetch_tradesB  s     	V$$&,
 $GG11$++gv2N2NOO   65%@@@rE  c                 0   |                                   |                     |          }|                     |d          }|                     |d          }i }t          dt	          | j                            D ]}| j        |         }||||ddd||<   |S )ac  
        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)rW  rs  r   r   r   r   )r  privateGetFeesre  r^  r_  r  )rB  rg  rh  r   r   ri  rj  rs  s           rD  fetch_trading_feesz#coinbaseexchange.fetch_trading_feesc  s     	&&v..   +;<<  +;<<q#dl++,, 		 		A\!_F  "! F6NN rE  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr      r  r   r     )safe_timestampre  )rB  ohlcvr  s      rD  parse_ohlcvzcoinbaseexchange.parse_ohlcv  s     q))UA&&UA&&UA&&UA&&UA&&
 	
rE  r   	timeframec           	         |                                   d}|                     |ddd          \  }}|r|                     d|||||d          S |                     |          }|                     | j        |          }d|d         i}	|||	d<   n||	d<   |                     |dd	          }
|                     |dg          }||                     |          |	d
<   |d}nt          d|          }|
|dz  }| 
                    ||z            r3|                     |                     |dz
  |z  |                    |	d	<   nH|                     |                     ||z  |                    |	d	<   n|                     |
          |	d	<   |                     |                     |	|                    }|                     |||||          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
        Frw   r  r   r+   Ngranularityr   endstarti  r   )r  r  "fetch_paginated_call_deterministicr  r  r   r  r  r  rN  is_round_numbersumpublicGetProductsIdCandlesr  parse_ohlcvs)rB  rs  r  r  r   rg  r  r  parsedTimeframer  r   parsedTimeframeMillisecondsrh  s                rD  fetch_ohlcvzcoinbaseexchange.fetch_ohlcv  s    	88z[`aa& 	w::<QVX]_hjpruvvvV$$++DOYGG&,
 &%4GM""%.GM"!!&'5996G9--#||E22GG}C}.=.D+''0K(KLL h%)\\$((EAIId;dfk2l2l%m%mGENN%)\\$((5C^;^`e2f2f%g%gGENN!%e!4!4224;;w3O3OPP   69eUKKKrE  c                 X    |                      |          }|                     |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      rD  
fetch_timezcoinbaseexchange.fetch_time  s/     %%f-- ""8W555rE  rI  c                 B    ddddddd}|                      |||          S )Nr  closedcanceled)pendingrR  r  doner*  	cancelingr`  )rB  rI  statusess      rD  parse_order_statusz#coinbaseexchange.parse_order_status  s:    "
 
 &&999rE  r  c                 L   |                      |                     |d                    }|                     |d          }|                     ||d          }|                     |                     |d                    }|                     |d          }|dk    r|dk    r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"|          S )#Nr  r  rr  rI  done_reasonr)  r*  r}  filled_sizer  executed_valuer  ru  r  r+   rX  r  time_in_force	post_only
stop_price
client_oidclientOrderIdrW  r  r  lastTradeTimestamprs  r   postOnlyr   r  r[  filled)	remainingrS  r  trades)r  r`  r  r0  re  r  
safe_orderr  )rB  r  r  r  r  rI  
doneReasonr}  r<  r[  r  r  rS  r+   rX  r  r   r;  r   r9  s                       rD  parse_orderzcoinbaseexchange.parse_order  s   , NN4#3#3E<#H#HII	##E<88!!(FC88(()9)9%)J)JKK%%e];;
hZ:%=%=F  00!!%77!!%88'788""5+66"7O C
 eT**v..v..&&uo>>??5+66''|<<((==  
" 
] 
 E 
 	 

 Y// 
 !$ 
 f 
 fX& 
 D 
 ; 
  
 D 
 U 
 L 
 D 
  f! 
" f# 
$ + 
  
  
, -  	rE  r+   c                 6   |                                   i }|                     |dd          }d}|d}||d<   nd}||d<   |                     |ddg          } t          | |          |                     ||                    }|                     |          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>`
        r9  r8  NprivateGetOrdersIdr+   privateGetOrdersClientClientOid)r  r  r  r  r  rA  )rB  r+   rs  rg  r  r9  r  rh  s           rD  fetch_orderzcoinbaseexchange.fetch_order2  s     	**6?LQQ )FGDMM6F$1GL!YYv'FGGF(74((Wf)E)EFF)))rE  c                     |                                   d}||                     |          }d|i}|                     |                     ||                    }|                     ||||          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  )r  r  r  r  r  )	rB  r+   rs  r  r   rg  r  r  rh  s	            rD  fetch_order_tradesz#coinbaseexchange.fetch_order_tradesK  s{     	[[((F
 ''GV(D(DEE  65%@@@rE  c           	      b    ddi}|                      ||||                     ||                    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>`
        rI  allfetch_open_ordersr  rB  rs  r  r   rg  r  s         rD  fetch_orderszcoinbaseexchange.fetch_orders_  s;     e
 %%feUDKKQW<X<XYYYrE  c                 :   |                                   d}|                     |dd          \  }}|r|                     d||||d          S i }d}| |                     |          }|d         |d<   |||d<   ||                     |          |d	<   |                     |d
d          }|/|                     |d
g          }|                     |          |d<   |                     |                     ||                    }	| 	                    |	|||          S )aa  

        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>`
        Fr{   r  r0   Nr+   r  r   r  r   r  )
r  r  r  r  r  r  r  privateGetOrdersr  parse_orders)
rB  rs  r  r   rg  r  r  r  r   rh  s
             rD  rK  z"coinbaseexchange.fetch_open_ordersq  sC    	88ART^__& 	k445FPUW\^dfijjj[[((F$*4LGL!$GG$(LL$7$7GL!!!&':>>YYvy11F"&,,u"5"5GJ((Wf)E)EFF  65%@@@rE  c           	      b    ddi}|                      ||||                     ||                    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>`
        rI  r,  rJ  rL  s         rD  fetch_closed_ordersz$coinbaseexchange.fetch_closed_orders  s;     f
 %%feUDKKQW<X<XYYYrE  rX  r  r[  r}  c                    |                                   |                     |          }|||d         d}|                     |dd          }	|	|	|d<   |                     |g d          }
|
|                     ||
          |d<   |                     |dd	          }|||d	<   |                     |d
dd          }|rd|d<   |                     |g d          }|dk    r3|                     ||          |d<   |                     ||          |d<   nt|dk    rn|                     |dd          }||||z  }n|                     |ddg          }|| 	                    ||          |d<   n|                     ||          |d<   | 
                    |                     ||                    }|                     ||          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+   )rX  r  r  r9  r8  N)	stopPricer7  r   r7  r   r5  r;  r6  FT)	r   r5  rT  r7  r9  r8  r;  r6  r   r   r}  r  r  r  funds)r  r  r  safe_number_nprice_to_precisionr  r  amount_to_precisionsafe_number_2cost_to_precisionprivatePostOrdersr  rA  )rB  rs  rX  r  r[  r}  rg  r  r  r9  r   r   r;  r  rh  s                  rD  create_orderzcoinbaseexchange.create_order  s$    	V$$  ,
 
( **6?LQQ$$1GL!))&2]2]2]^^#$($;$;FL$Q$QGL!((PP"'2GO$$$VZeLL 	(#'GK 6  $g  $g  $g  h  h7??#66vuEEGG"66vvFFGFOOX%%ffg>>D|$!E>D6FG+<==#'#9#9&$#G#G  "&":":66"J"J))$++gv*F*FGG( &111rE  c                    |                                   i }|                     |dd          }d}|d}||d<   nd}||d<   |                     |ddg          }d}| |                     |          }|d         |d<    t	          | |          |                     ||                    }|                     d	|i          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>`
        r9  r8  NprivateDeleteOrdersIdr+   "privateDeleteOrdersClientClientOidrs  r  rW  )r  r  r  r  r  r  r?  )	rB  r+   rs  rg  r  r9  r  r  rh  s	            rD  cancel_orderzcoinbaseexchange.cancel_order  s     	
 **6?LQQ ,FGDMM9F$1GL!YYv'FGGF[[((F$*8$4GL!(74((Wf)E)EFF1222rE  c                     |                                   i }d}| |                     |          }|d         |d<   |                     |                     ||                    }|                     d|i          g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>`
        Nrs  r  rW  )r  r  privateDeleteOrdersr  r?  )rB  rs  rg  r  r  rh  s         rD  cancel_all_ordersz"coinbaseexchange.cancel_all_orders  s     	[[((F$*8$4GL!++DKK,H,HII 23344rE  c                 ,    |                      |          S N)privateGetPaymentMethods)rB  rg  s     rD  fetch_payment_methodsz&coinbaseexchange.fetch_payment_methods-  s    ,,V444rE  r\  addresstagc                    |                      ||          \  }}|                     |           |                                  |                     |          }|d         |d}d}d|v r|dz  }nd|v r|dz  }n|dz  }||d	<   |||d<    t	          | |          |                     ||                    }	|	s-t          | j        dz   |                     |	          z             | 	                    |	|          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+   )rk  r[  privatePostWithdrawalspayment_method_idPaymentMethodcoinbase_account_idCoinbaseAccountCryptocrypto_addressNdestination_tagz withdraw() error: )
handle_withdraw_tag_and_paramscheck_addressr  rk  r  r  r   r+   jsonparse_transaction)
rB  r\  r[  rh  ri  rg  rk  r  r  rh  s
             rD  r   zcoinbaseexchange.withdraw0  s2    99#vFFV7###==&& 
 
 *&((o%FF"f,,''FFhF(/G$%-0)*(74((Wf)E)EFF 	W*? ?$))HBUBU UVVV%%h999rE  c                 @    dddddd}|                      |||          S )Ntransferr  rS  rebate)rx  matchrS  ry  
conversionr.  )rB  rX  typess      rD  parse_ledger_entry_typez(coinbaseexchange.parse_ledger_entry_typeU  s7    "!
 
 tT222rE  itemrk  c                    |                      |d          }|                      |d          }d }|                      |d          }t          j        ||          }t          j        |d          rd}t          j        |          }nd}|                     |          }|                     |          }	|                     |          }
|                     |                     |d                    }|                     |                      |d                    }| 	                    d |          }|                     |d	i           }d }d }d }|d
k    rC|                      |d          }|                      |d          }|                      |d          }n|                      |d          }d}| 
                    ||||                     |          ||||||||
|	|d d|          S )Nr+   r[  r  0outinr  rX  rG  rx  fromtoprofile_transfer_idr  ok)rW  r+   r  r  	directionr  referenceAccountreferenceIdrX  rk  r[  beforeafterrI  rS  )r`  r&   
string_sub	string_lt
string_absrA  r  r  r}  ra  safe_ledger_entryr  )rB  r~  rk  r+   amountStringr  afterStringbeforeStringr[  r  r  r  rX  r\  rG  r  r  r  rI  s                      rD  parse_ledger_entryz#coinbaseexchange.parse_ledger_entry_  s   2 dD))''h77	&&tY77)+|DD\3// 	I"-l;;LLI""<00!!+..""<00NN4??4#F#FGG	++D,<,<T6,J,JKK&&tX66//$	266:&&w77G#//>>**74IJJKK**7J??K%%"Y//" 0&'
 '
  !  	rE  c                    |t          | j        dz             |                                  |                                  |                     |          }|                     | j        d          }|                     ||          }|t          | j        dz   |z             d|d         i}|| 	                    |          |d<   |||d<   | 
                    |dd	          }	|	/|                     |dg          }| 	                    |	          |d	<   |                     |                     ||                    }
t          d
t          |
                    D ]}||
|         d<   |                     |
|||          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-entry-structure>`
        Nz$ fetchLedger() requires a code paramr\  z- fetchLedger() could not find account id for r+   r  r   r   r  r   rk  )r   r+   r  load_accountsrk  index_byr   r  r   r  r  r  privateGetAccountsIdLedgerr  r^  r_  parse_ledger)rB  r\  r  r   rg  rk  accountsByCurrencyCoder  r  r   rh  rj  s               rD  fetch_ledgerzcoinbaseexchange.fetch_ledger  s    <#DG.T$TUUU==&&!%t}f!E!E//"8$???*Y Y\` `aaa'$-
 $(LL$7$7GL!$GG!!&':>>YYvy11F"&,,u"5"5GJ224;;w3O3OPPq#h--(( 	+ 	+A&*HQK
##  8UEBBBrE  c                    |                                   |                                  d}|                     |d          }|l|j|                     |          }|                     | j        d          }|                     ||          }|t          | j        dz   |z             |d         }i }	|||	d<   |||	d<   d}
|| 	                    | 
                    |	|                    }
t          dt          |
                    D ]Z}|                     |
|         d          }|                     | j        |          }|                     |d          }||
|         d<   [nT|                     | 
                    |	|                    }
t          dt          |
                    D ]}||
|         d<   |                     |
|||          S )	ag  
        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_idrk  )r  r  r`  rk  r  r   r  r   r+   privateGetTransfersr  r^  r_  accountsByIdprivateGetAccountsIdTransfersparse_transactions)rB  r\  r  r   rg  rk  r+   r  r  r  rh  rj  r  	codeInners                 rD  fetch_deposits_withdrawalsz+coinbaseexchange.fetch_deposits_withdrawals  s    	fd++:==..)-t}f)M)M&//*@$GG?'2n(nqu(uvvvT]>GDM$GG://GV0L0LMMH: 1c(mm,, 4 4!--hqk<HH
//$*;ZHH ,,Wf==	*3J''	4 99$++gv:V:VWWH6 1c(mm,, / /*.J''&&x5%HHHrE  c           	      ^    |                      ||||                     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>`
        rX  r   r  r  rB  r\  r  r   rg  s        rD  fetch_depositszcoinbaseexchange.fetch_deposits5  s4     ..tUE4;;PVXaObdjCkCklllrE  c           	      ^    |                      ||||                     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>`
        rX  r   r  r  s        rD  fetch_withdrawalsz"coinbaseexchange.fetch_withdrawalsD  s4     ..tUE4;;PVXbOcekClClmmmrE  c                     |                      |d          }|rdS |                      |d          }|                      |d          }|rdS |r|sdS dS )Ncanceled_atr*  processed_atcompleted_atr  failedr+  )r  )rB  transactionr*  	processed	completeds        rD  parse_transaction_statusz)coinbaseexchange.parse_transaction_statusS  sn    ??;>> 	:OOK@@	OOK@@	 	4 	y 	89rE  r  c                 *   |                      |di           }|                     |                     |d                    }|                     |d          }|                     ||          }|                     |d          }|                     |d          }|                     |d          }	|                     |d|	          }	d d d d}
|dk    rBd	}|                     |d
|	          }	|                     |d          }||||z  }||
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S ) NrG  r  rk  r[  rX  rq  )rk  r  r  r   
withdrawalsent_to_addressrS  r  rQ  rW  r+   txidcrypto_transaction_hashrI  r  r  rh  addressFrom	addressTori  rr  tagFromtagToupdatedr  F)commentinternalrS  )r  r  r`  ra  re  rd  r  r  )rB  r  rk  rG  r  r  r\  r[  rX  rh  rS  r  rn  s                rD  rv  z"coinbaseexchange.parse_transaction`  s   > //+y"==NN4#3#3K#N#NOO	%%k:>>
&&z8<<!!+x88V44""7,<=="";0@'JJ
 

 :D&&w0A7KKG&&w66G"%g%F%F"&J$$Wi88	
K
$"";55
 D$$W.GHH
 D	

 
 t..y99
 f
 d33K@@
 
 Y//
 w
 4
 ))'3CDD
 4##G->??
 t
  T!
" t~~d&6&6{N&S&STT#
$ )
 
 
 	
rE  c                    |                                   |                     |          }|                     | j        d          }|<|                                 }|| j        d<   |                     |d          | j        d<   |d         }|                     | j        d         |          }|#t          | j        dz   |z   dz   |z   dz             d|d         i}|                     | 	                    ||                    }| 
                    |d	          }	| 
                    |d
          }
||                     |	          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>`
        coinbaseAccountsNrk  coinbaseAccountsByCurrencyIdr+   z5 createDepositAddress() could not find currency code z with id = z0 in self.options['coinbaseAccountsByCurrencyId']rh  rr  )rk  rh  rQ  ri  rW  )r  rk  r  r   privateGetCoinbaseAccountsr  r    r+   &privatePostCoinbaseAccountsIdAddressesr  r`  rt  )rB  r\  rg  rk  r   r  r  r  rh  rh  ri  s              rD  create_deposit_addressz'coinbaseexchange.create_deposit_address  sw    	==&&??4<1CDD6688H/7DL+,;?==S];^;^DL78d^
//$,/M"NPZ[[? +b!bei!ily!y  }G  "G  J|  "|  }  }  }'$-
 >>t{{7TZ?[?[\\""8Y77x):;;))'22
 
 	
rE  r   GETc                    d|                      ||          z   }|                     ||                     |                    }|dk    r|r|d|                     |          z   z  }|                     | j        d         |                   |z   }	|dk    r|                                  t          |                                           }
d}|dk    r|r| 	                    |          }|}|
|z   |z   |z   }d }	 | 
                    | j                  }n)# t          $ r}t          | j        dz             d }~ww xY w|                     |                     |          |t"          j        d          }| j        ||
| j        d	d
}|	|||dS )Nrt  r  ?r   r    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_hostnamer   check_required_credentialsstrr  ru  base64_to_binaryr   	Exceptionr   r+   hmacencodehashlibsha256r   r   )rB  pathr   r  rg  r  r  r  queryr  r  payloadwhatr   e	signatures                   rD  signzcoinbaseexchange.sign  s   ++D&999		&$"5"5d";";<<U?? 73!6!666##DIe$4S$9::WD)++---

%%EG #99U++D"G6>G+g5DFU..t{;; U U U)$'4S*STTTU		$++d"3"3VW^XVVI!%"+',(, 2 G fdwOOOs   9D 
D:D55D:reasonr  r  r  r  c
                 V   |dk    s|dk    r|d         dk    rv|                      |d          }
| j        dz   |
z   }|                     | j        d         |
|           |                     | j        d         |
|           t          |          t          | j        dz   |z             d S )	Ni  i  r   {message r;  r<  )r`  r+   throw_exactly_matched_exceptionr9  throw_broadly_matched_exceptionr   )rB  r\  r  r  r  r  r  rh  requestHeadersrequestBodyr  feedbacks               rD  handle_errorszcoinbaseexchange.handle_errors  s    CKKTS[[Aw#~~**8Y??7S=7244T_W5MwX`aaa44T_W5MwX`aaa#H---# 4555trE  c           	          |                      |||||||          }t          |t                    s1d|v r-t          | j        dz   |                     |          z             |S )Nr  r  )fetch2r  r  r   r+   ru  )	rB  r  r   r  rg  r  r  configrh  s	            rD  r  zcoinbaseexchange.request  sg    ;;tS&&'4PP(C(( 	IH$$#DGcMDIIh4G4G$GHHHrE  re  )I__name__
__module____qualname__r   r?  r   rp  r   r   r  r   r  r  r   r  r  r  r   r   r  dictr   r  r   r   r  r  r   r  r   r  r  r   r  r  r  r#  r'  r0  r   rA  rE  rG  rM  rK  rR  r   r   floatr   r\  r`  rc  rg  r   r   r}  r	   r   r  r  r  r  r  r  rv  r
   r  r  intr  r  __classcell__)rC  s   @rD  r(   r(      s       }# } } } } } }~ ') i iZ i i i iV $& v v$v, v v v vp %' 5 54= 5 5 5 5B
 
 
&) ) ) ) ) $& , ,( , , , , :>b % %s %3 %Y % % % %NM M4 M M6 M M M M^ 04B ,G ,GW ,G7 ,G ,G ,G ,G\ 02 (3 (33 (3f (3 (3 (3 (3TC C Cv C C C C CJ -1tRV_a "A "Ac "A "AC "A "A "A "AH 6:UW A A3 As A# A\`af\g A A A AB )+  {    B
 
 
4 
 
 
 
( 9=4^bkm 6L 6L# 6L# 6LS 6LX[ 6Lrvw{r| 6L 6L 6L 6Lp !# 6 6s 6 6 6 6	: 	: 	: 	: 	:F F Fv F F F F FP 26b * *c *3 * * * *2 9=4^bkm A AS A# AS AX[ A A A A( *.Dt\^ Z Z3 Zc Z Zcghmcn Z Z Z Z$ /3TXac !A !A !A3 !Ac !Ahlmrhs !A !A !A !AF 154VZce Z Z# ZS ZPS Zjnotju Z Z Z Z$ gksu S2 S23 S2i S2y S2RW S2`c S2 S2 S2 S2j 37r 3 3s 3C 3 3 3 3> /32 5 5 5 5 5 5& ,. 5 5 5 5 KOWY #: #:S #:% #:# #:C #:^i #: #: #: #:J3 3 3D Dt Dx D; D D D DL (,$TZ\ +C +C +CC +Cs +Caefqar +C +C +C +CZ 6:[_hj aI aIs aI# aIUX aIost  pA aI aI aI aIF *.Dt\^ m m3 mc m mcghsct m m m m -1tRV_a n nc n nC nfjkvfw n n n n  K
 K
T K
X K
Q\ K
 K
 K
 K
Z 8: "
 "
3 "
n "
 "
 "
 "
H &eBSW P P P P>	# 	s 	 	c 	TX 	`c 	 	 	 	 !)r4VZce        rE  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(    rE  rD  <module>r     sr   ( ' ' ' ' ' 6 6 6 6 6 6  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . . . . . . . + + + + + + ) ) ) ) ) ) * * * * * * . . . . . . * * * * * * 4 4 4 4 4 4 % % % % % %g g g g gx g g g g grE  