
    i~                    0   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 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Balances
CurrenciesCurrencyIntMarketMarketInterfaceNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)InvalidOrder)OrderNotFound)NotSupported)RateLimitExceeded)InvalidNonce)	TICK_SIZE)Precisec                       e Zd Z fdZi fdZi fdee         fdZi fdee         fdZi fdee         fdZ	i fdee         fdZ
d Zi fd	efd
Zdddi fdededefdZdddi fdededefdZdddi f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 Zd^dedefdZd^dedefdZi fdee         fdZi fdZi fdZdefdZ defdZ!i fdZ"i fde#fdZ$di fd e%de&fd!Z'di fd e%fd"Z(di fd e%fd#Z)i fdede*fd$Z+i fdefd%Z,i fdefd&Z-d^dede*fd'Z.i fd(Z/i fde0fd)Z1dddi fd	ededefd*Z2d+ Z3d, Z4d^defd-Z5i fd.Z6di fdefd/Z7ddi fd	edefd0Z8i fded1e9fd2Z:di fded3e;d4e<d5e9d6e=f
d7Z>d^dede?fd8Z@d9 ZAd: ZBd; ZCdi fd<edefd=ZDdi fdefd>ZEddi fd<eded3e;d4e<d5e=d6e=fd?ZFdi fd<edefd@ZGdddAi fdedededee?         fdBZHdddi fdededefdCZIdddi fdedededee?         fdDZJdddi fdedededee?         fdEZKdddi fdededefdFZLdGddi fdedededeeM         fdHZNd^dedeMfdIZOddi fdedededee         fdJZPdddi fdededefdKZQdi fdededeRfdLZSdi fd e%fdMZTdi fd	ed5e9fdNZUi fd	efdOZVd^defdPZWi fd	ed5e9d<efdQZXdi fd<ed	efdRZYdi fded4e<de?fdSZZdi fd e%fdTZ[i fdefdUZ\d^defdVZ]d_dWedXedYefdZZ^g d[i ddfd\Z_d] Z` xZaS )`coinbasec                 T   |                      t          t          |                                           i ddddddgddd	d
ddd| j        d         dddi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d0dd1dd2dd3dd4dd5di d6dd7dd8dd9dd:d;d<dd=dd>dd?dd@ddAddBddCddDddEddFddGdi dHddIddJddKddLddMddNddOddPddQddRddSddTddUddVddWddXddddddddddddddddYdZd[d\d]id^d_d`gdadbgdcdddedddfdgdhdididididididididjii dkdidldidmdidndidodidpdidqdidrdidsdidtdidudidvdidwdidxdidydidzdid{dididid|didididididididididididididid}didid~dididdddhddiii dddddddddddddddddddddddddddddddddddddddddddddddddddddddddidddddddd|                     d          |                     d          dd|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          gg	|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          gg	ddidt          di dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          t          t          t          t          t          dȜt          t          dɜdʜddddddddddԜdddiddg dڢddiddgddgdddddddddddddi          S )Nidr%   nameCoinbase	countriesUSproT	rateLimit"   versionv2	userAgentchromeheadersz
CB-VERSIONz
2018-05-30hasCORSspotmarginFswapfutureoption	addMargincancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateLimitBuyOrdercreateLimitSellOrdercreateMarketBuyOrdercreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrdercreateMarketSellOrderWithCostcreateOrdercreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderdeposit	editOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressemulatedfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL2OrderBookfetchLedgerfetchLeveragefetchLeverageTiersfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyBuysfetchMySellsfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionModefetchPositions)fetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchWithdrawalsreduceMarginsetLeveragesetMarginModesetPositionModewithdrawurlszchttps://user-images.githubusercontent.com/1294454/40811661-b6eceae2-653a-11e8-829e-10bfadb078cf.jpgrestzhttps://api.coinbase.comzhttps://www.coinbase.comz&https://developers.coinbase.com/api/v2z?https://docs.cloud.coinbase.com/advanced-trade-api/docs/welcomezYhttps://support.coinbase.com/customer/portal/articles/2109597-buy-sell-bank-transfer-feesz&https://www.coinbase.com/advanced-feesz6https://www.coinbase.com/join/58cbe25a355148797479dbd2)logoapiwwwdocfeesreferralrequiredCredentials)apiKeysecretr   getg333333%@)
currencieszcurrencies/cryptotimezexchange-rateszusers/{user_id}zprices/{symbol}/buyzprices/{symbol}/sellzprices/{symbol}/spotaccountsaccounts/{account_id}accounts/{account_id}/addressesz,accounts/{account_id}/addresses/{address_id}z9accounts/{account_id}/addresses/{address_id}/transactions"accounts/{account_id}/transactions3accounts/{account_id}/transactions/{transaction_id}accounts/{account_id}/buysz#accounts/{account_id}/buys/{buy_id}accounts/{account_id}/sellsz%accounts/{account_id}/sells/{sell_id}accounts/{account_id}/depositsz+accounts/{account_id}/deposits/{deposit_id}!accounts/{account_id}/withdrawalsz1accounts/{account_id}/withdrawals/{withdrawal_id}zpayment-methodsz#payment-methods/{payment_method_id})userz	user/auth)r   zaccounts/{account_id}/primaryr   r   z<accounts/{account_id}/transactions/{transaction_id}/completez:accounts/{account_id}/transactions/{transaction_id}/resendr   z*accounts/{account_id}/buys/{buy_id}/commitr   z,accounts/{account_id}/sells/{sell_id}/commitr   z2accounts/{account_id}/deposits/{deposit_id}/commitr   z8accounts/{account_id}/withdrawals/{withdrawal_id}/commit)r   r   )zaccounts/{id}r   )r   postputdelete)publicprivatezbrokerage/time   zbrokerage/accounts   z!brokerage/accounts/{account_uuid}z!brokerage/orders/historical/batchz!brokerage/orders/historical/fillsz&brokerage/orders/historical/{order_id}zbrokerage/productszbrokerage/products/{product_id}z'brokerage/products/{product_id}/candlesz&brokerage/products/{product_id}/tickerzbrokerage/best_bid_askzbrokerage/product_bookzbrokerage/transaction_summarybrokerage/portfolios%brokerage/portfolios/{portfolio_uuid}"brokerage/convert/trade/{trade_id}zbrokerage/cfm/balance_summaryzbrokerage/cfm/positions)z$brokerage/cfm/positions/{product_id}brokerage/cfm/sweepsz)brokerage/intx/portfolio/{portfolio_uuid}z)brokerage/intx/positions/{portfolio_uuid}z2brokerage/intx/positions/{portfolio_uuid}/{symbol}zbrokerage/payment_methodsz-brokerage/payment_methods/{payment_method_id})zbrokerage/orderszbrokerage/orders/batch_cancelzbrokerage/orders/editzbrokerage/orders/edit_previewzbrokerage/orders/previewr   zbrokerage/portfolios/move_fundszbrokerage/convert/quoter   zbrokerage/cfm/sweeps/schedulezbrokerage/intx/allocatezbrokerage/orders/close_position)r   r   )r0   v3r   tradingz0.006z0.00401000050000z0.0025100000z0.0021000000z0.001815000000z0.001675000000z0.0012	250000000z0.0008	400000000z0.0005z0.0015z0.001z0.0006z0.0003z0.0)takermaker)r   r   	tierBased
percentagetiersprecisionMode
exceptionstwo_factor_requiredparam_requiredvalidation_errorinvalid_requestpersonal_details_requiredidentity_verification_requiredjumio_verification_required&jumio_face_match_verification_requiredunverified_emailauthentication_errorinvalid_authentication_methodinvalid_tokenrevoked_tokenexpired_tokeninvalid_scope	not_foundrate_limit_exceeded)internal_server_errorUNSUPPORTED_ORDER_CONFIGURATIONINSUFFICIENT_FUNDPERMISSION_DENIEDINVALID_ARGUMENT)zrequest timestamp expiredz%order with self orderID was not found)exactbroad
timeframes
ONE_MINUTEFIVE_MINUTEFIFTEEN_MINUTETHIRTY_MINUTEONE_HOURTWO_HOURSIX_HOURONE_DAY)1m5m15m30m1h2h6h1dcommonCurrenciesCGLDCELOoptionsccxt)zBUSD-USDz	CBETH-ETHzDAI-USDzGUSD-USDzGYEN-USDzPAX-USDzPAX-USDTzUSDC-EURzUSDC-GBPzUSDT-EURzUSDT-GBPzUSDT-USDz	USDT-USDCzWBTC-BTCexpiresi  walletfiatACCOUNT_TYPE_CRYPTOACCOUNT_TYPE_FIATethereumstellar)ERC20XLMfetchMarketsV3fetchTickerV3fetchTickersV3fetchAccountsV3v2PrivateGetAccountsv2PublicGetTimeUSD)brokerIdstablePairsrY   r   
v3Accountsnetworks!createMarketBuyOrderRequiresPriceadvancedrl   r|   r}   rP   rQ   r~   user_native_currency)deep_extendsuperr%   describe
userAgentsparse_numberr"   r   r   r    r   r   r!   r   )self	__class__s    S/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/coinbase.pyr  zcoinbase.describe   s[   h 5 5 > > @ @ YC
*YC
JYC
 $YC
 4	YC
 YC
 tYC
 2YC
 lYC
   SSS %S 	S
 %S %S US tS S $US  S 'S &tS 'S 'S  /!S" ,U#S S$ (%S& 0'S( t)S* &t+S, (-S. '/S0 (1S2 "43S4 45S6 T7S8  9S: ;S<  =S> +E?S@ )%ASB &tCSD $TES S SF 'GSH (ISJ "4KSL MSN &zOSP (QSR 1$SST  USV &uWSX #EYSZ *5[S\ $U]S^ "5_S` *5aSb +EcSd #EeSf tgS S Sh  iSj %ekSl "5mSn oSp !%qSr tsSt uSv  wSx dySz +E{S| "4}S~ dS@ !$ASB tCSD  ESF $UGSH !$IS SJ ',*/# $!##($)$( %$!&#( eS S S!YC
H }6 2<U
 p< U IYC
h "$ $iYC
p  *.15$(.2/3374848	  	  & 3T  >t  KD	 
 XY]  A$  RSW  9$  B4  :4  DT  =d  J4  @  PQU   .t! " B4# $ %))-'     , )-=A?CBF\`Z^:>JN;?LP>BRVAEX\! !" 6:$(   
 .2SW# #U.  . < <~ ,a  0! ?  @  @	 
 Ea  1!  >q  Fq  Ea  5a  5a  <Q  3A  DQ  A!   <Q! " 6q# $ EF45IJIJRS9:MN1     6 12=>56=>8945?@78BC=>78?@! !  DQ  FG45# #[1  1 8 8}w wqYC
` !..w77!..w77!%"& "..s33T5F5Fw5O5OP!..w779J9J79S9ST!..w779J9J89T9TU!..x88$:K:KG:T:TU!..y994;L;LX;V;VW!..z::D<M<Mh<W<WX!..z::D<M<Mh<W<WX!..{;;T=N=Nx=X=XY!..{;;T=N=Nx=X=XY
" "..s33T5F5Fw5O5OP!..w779J9J89T9TU!..w779J9J89T9TU!..x88$:K:KG:T:TU!..y994;L;LX;V;VW!..z::D<M<Mh<W<WX!..z::D<M<Mh<W<WX!..{;;T=N=Nu=U=UV!..{;;T=N=Nu=U=UV
"  aYC
` YaYC
b )+>$m ' &}	
 01D 56I 23F =>Q '(; +,? 45H $%8 $%8 $%8 $%8   !" *+<#$ .;7A)3)9(2-  2 2>=J 3 cYC
^	 "#'&   	 	_	YC
r	 !s	YC
x	 "  H   H   Ht$  *'
 ($  6:  0. 0!2 6.(-7 y	YC
 YC
 Y Y Y	    c                 V   |                      | j        dd          }|                      |d|          }|                     |d          }d}|dk    r-|                     |          }|                     |di           }n|                     |          }|                     |dd          S )a  
        fetches the current integer timestamp in milliseconds from the exchange server
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-time#http-request
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.method]: 'v2PublicGetTime' or 'v3PublicGetBrokerageTime' default is 'v2PublicGetTime'
        :returns int: the current integer timestamp in milliseconds from the exchange server
        r~   r   methodNdataepochepochSeconds)safe_stringr   omitr   	safe_dictv3PublicGetBrokerageTimesafe_timestamp_2)r  paramsdefaultMethodr  responses        r	  
fetch_timezcoinbase.fetch_timew  s     (({DUVV!!&(MBB68,,&&&++F33H ~~h;;HH44V<<H $$XwGGGr
  returnc                     |                      | j        dd          }|dk    r|                     |          S |                     |          S )a  
        fetch all the accounts associated with a profile
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getaccounts
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-accounts#list-accounts
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :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 dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
        rP   r   )r  r   fetch_accounts_v3fetch_accounts_v2r  r  r  s      r	  fetch_accountszcoinbase.fetch_accounts  sR     !!$,ARSS&&&))&111%%f---r
  c                 T   |                                   d}|                     |dd          \  }}|r|                     dd d d |ddd d	  	        S ddi}|                     |                     ||                    }|                     |dg           }|                     |d	i           }|                     |d          }|                     |dg           }t          |          }	|	d
z
  }
|                     ||
          }||dk    r
||d<   |||
<   | 	                    ||          S )NFrP   paginatenext_starting_afterstarting_afterd   limitr  
paginationr    )
load_marketshandle_option_and_paramsfetch_paginated_call_cursorr   extend	safe_listr  r  lenparse_accounts)r  r  r   requestr  r  r%  cursorr   length	lastIndexlasts               r	  r  zcoinbase.fetch_accounts_v2  se   88R\]]& 	S33OT4QUW]_t  wG  IM  OR  S  S  SS
 ,,T[[&-I-IJJZ ~~h33^^HlB??
!!*.CDD>>(FB77XQJ	~~h	22Vr\\*0D&'"&HY""4000r
  c                    |                                   d}|                     |dd          \  }}|r|                     dd d d |ddd d	  	        S ddi}|                     |                     ||                    }|                     |dg           }t          |          }|dz
  }|                     ||          }|                     |d          }	|	|	d	k    r
|	|d<   |||<   | 	                    ||          S )
NFrP   r   r/  r#  r$  r   r   r&  )
r'  r(  r)  v3PrivateGetBrokerageAccountsr*  r+  r,  r  r  r-  )
r  r  r   r.  r  r   r0  r1  r2  r/  s
             r	  r  zcoinbase.fetch_accounts_v3  s"   88R\]]& 	~33OT4QUW]_giqswy|}}}S
 55dkk'66R6RSS> >>(J;;XQJ	~~h	22!!(H55Vr\\#DN"&HY""8V444r
  c                 6   |                      |          }|                     |dg           }g }t          dt          |                    D ]L}||         }|                    |                     |d          |                     |d          d|d           M|S )as  
        fetch all the portfolios
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getportfolios
        :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
        
portfoliosr   uuidtypeNr'   r8  codeinfo)v3PrivateGetBrokeragePortfoliosr+  ranger,  appendr  )r  r  r  r6  resulti	portfolios          r	  fetch_portfolioszcoinbase.fetch_portfolios  s     77??^^HlB??
q#j//** 	 	A"1IMM&&y&99((F;;!	      r
  c                    |                      |d          }|                     |d          }|                     |di           }|                     |d|          }|                     |d          }|                     |d          }|                    d          }|                     |dd          ||                     |d	          n||                     |          |d
S )Nactivecurrencyr:  r(   r8   r'   r7  r   r9  )	safe_boolr  r  splitsafe_string_2safe_string_lowersafe_currency_code)	r  accountrD  currencyIdV3rE  
currencyIdtypeV3typeV2partss	            r	  parse_accountzcoinbase.parse_account/  s    p 22''<<>>':r::%%hEE
!!'622!!'622S!!$$WdF;;9?9KD**5!444RX++J77	
 
 	
r
  r:  c                 N   |                      |d          }|                     |d          }|h|                                  t          dt	          | j                            D ]1}| j        |         }|d         |k    r|d         dk    r
|d         } n2|t          | j        dz             d|i}|                     | 	                    ||                    }| 
                    |d	i           }|                      |d
          }	|                      |d          }
||	|
|dS )a  
        create a currency deposit address
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-addresses#create-address
        :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>`
        
account_idNr   r:  r8  r   r'   zs createDepositAddress() could not find the account with matching currency code, specify an `account_id` extra paramr  destination_tagaddress)rE  tagrV  r;  )r  r  load_accountsr=  r,  r   r   r'   'v2PrivatePostAccountsAccountIdAddressesr*  r  )r  r:  r  	accountIdr@  rL  r.  r  r  rW  rV  s              r	  create_deposit_addresszcoinbase.create_deposit_addressu  sX    $$V\::	6<00   1c$-0011  -*6?d**wv(/J/J 'IE  +`  !`  a  a  a)
 ??GU[@\@\]]J ~~h33t%677""433	
 
 	
r
  Nsymbolsincer$  c                    |                      ||          }|                                  |                     |ddg          }|                     |                     ||                    }|                     |d         d||          S )a!  
         * @ignore
        fetch sells
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-sells#list-sells
        :param str symbol: not used by coinbase fetchMySells()
        :param int [since]: timestamp in ms of the earliest sell, default is None
        :param int [limit]: max number of sells to return, default is 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>`
        rT  rZ  r  N)prepare_account_requestr'  r  "v2PrivateGetAccountsAccountIdSellsr*  parse_trades)r  r\  r]  r$  r  r.  querysellss           r	  fetch_my_sellszcoinbase.fetch_my_sells  s     ..uf==		&<"=>>77GU8S8STT  veUCCCr
  c                    |                      ||          }|                                  |                     |ddg          }|                     |                     ||                    }|                     |d         d||          S )a  
         * @ignore
        fetch buys
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-buys#list-buys
        :param str symbol: not used by coinbase fetchMyBuys()
        :param int [since]: timestamp in ms of the earliest buy, default is None
        :param int [limit]: max number of buys to return, default is 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>`
        rT  rZ  r  N)r_  r'  r  !v2PrivateGetAccountsAccountIdBuysr*  ra  )r  r\  r]  r$  r  r.  rb  buyss           r	  fetch_my_buyszcoinbase.fetch_my_buys  s     ..uf==		&<"=>>55dkk'56Q6QRR  ftUEBBBr
  c                     d }|                      |||          \  }}|                                   t          | |          |                     ||                    }|                     |d         d ||          S )Nr  )*prepare_account_request_with_currency_coder'  getattrr*  parse_transactions)r  r  r:  r]  r$  r  r.  r  s           r	  fetch_transactions_with_methodz'coinbase.fetch_transactions_with_method  s|    II$PUW]^^(74((Wf)E)EFF&&x'7ueLLLr
  c                 4    |                      d||||          S )a<  
        fetch all withdrawals made from an account
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-withdrawals#list-withdrawals
        :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>`
        (v2PrivateGetAccountsAccountIdWithdrawalsrm  r  r:  r]  r$  r  s        r	  fetch_withdrawalszcoinbase.fetch_withdrawals  s%     223]_cejlqsyzzzr
  c                 4    |                      d||||          S )a+  
        fetch all deposits made to an account
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-deposits#list-deposits
        :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>`
        %v2PrivateGetAccountsAccountIdDepositsrp  rq  s        r	  fetch_depositszcoinbase.fetch_deposits  s%     223Z\`bginpvwwwr
  c                 <    dddd}|                      |||          S )Npendingokcanceled)created	completedry  r  r  statusstatusess      r	  parse_transaction_statusz!coinbase.parse_transaction_status  s1     "
 

 &&999r
  rE  c                 t   |                      |d          }d }d }|dk    rF|                     |di           }|                     |di           }|                     |di           }n.|                     |di           }|                     |di           }|                     |                      |d                    }||                     |d	          }|rd
nd}|                      |d          }	|                      |d          }
|                      |d          }|                      |d          }|                     |di           }|                      |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iS )Nr8  sendnetworktransaction_amounttransaction_feesubtotalfeer~  	committedrx  rw  r'   rE  
created_attorV  r;  txid	timestampdatetime	addressToaddressFromrW  tagTotagFromresourceamountupdated
updated_atcostrE  )r  r  r  rG  	parse8601safe_numberrK  )r  transactionrE  transactionTypeamountAndCurrencyObject	feeObjectr  r~  r  r'   rN  feeCurrencyIdr  toObject	toAddresss                  r	  parse_transactionzcoinbase.parse_transaction  s   f **;??"&	f$$nn[)R@@G&*nnW>RTV&W&W#w0A2FFII&*nn[*b&Q&Q#{E2>>I..t/?/?X/V/VWW>{K@@I&5TTIFk400%%&=zJJ
((J??##K>>>>+tR88$$Xy99	
K
"
 B
 11	

 
 t
 y
 
 4
 4
 T
 t
 D$$[*==
 d&&'>II
 //
HEE
  f!
" t~~d&6&6{L&Q&QRR#
$ ((H== 33MBB %
 
 	
r
  marketc                    d }|                      |di           }|                      |di           }|                      |di           }|                      |di           }|                     |d          }|                     ||d          }|	|d         }nb|                     |d          }	|                     |d          }
|	4|
2|                     |	          }|                     |
          }|d	z   |z   }|                     |d
          }|                     |d          }d }|                     |d          }|r|}t          j        ||          }|                     |d          }|                     |d|          }|                     |d|          }d }d }||t          j        ||          }n|}||t          j        ||          }n|}|                     |d          }|                     |d| 	                    |                    }||
||d         }| 
                    |g d          }|                     |dd          }|                     |d          }|                     ||                     |dd          |                     |d          |                     |          ||d |dk    rd n||dk    rd n||||||                     |          dd          S )Ntotalr  r  r  
product_id-r\  rE  /size_in_quotepricesize
commissionquote)r  
trade_timer   r  sideliquidity_indicatorr'   trade_idorder_idunknown_order_sideunknown_liquidity_indicatorr  )r;  r'   orderr  r  r\  r8  r  takerOrMakerr  r  r  r  )r  r  safe_marketrK  rG  r#   
string_div
string_mulr  r  safe_string_nsafe_string_lower_2rJ  
safe_traderI  r  )r  trader  r\  totalObjectamountObjectsubtotalObjectr  marketIdbaseIdquoteIdbaser  sizeInQuotev3Pricev3Costv3Amount	v3FeeCostamountString
costStringpriceStringr  r  feeCostr  r  r  s                              r	  parse_tradezcoinbase.parse_trade  sF   | nnUGR88~~eXr::z2>>NN5%44	##E<88!!(FC88H%FF%%lJ??F&&{J??G")<..v66//88e+nnUO<<""5'22##E622 	=F)(G<<H$$UL99	''hII%%nhGG
")A!,ZFFKK!K#,*B%k<@@DDD((J??""9h8I8I)8T8TUU!(:AT"7OM%%e-Q-Q-QRR''z6BB--e5JKK$$UD*==%%eZ8811 !%999DD%15R%R%RDDYe " 33MBB  
  
   	r
  c                     |                      | j        dd          }|dk    r|                     |          S |                     |          S )a  
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getproducts
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-currencies#get-fiat-currencies
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates#get-exchange-rates
        retrieves data on all markets for coinbase
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        rl   r   )r  r   fetch_markets_v3fetch_markets_v2r  s      r	  fetch_marketszcoinbase.fetch_markets#  sR     !!$,@PQQ%%%((000$$V,,,r
  c                    |                      |          }|                     |di           }|                     |di           }|                     |dg           }|                     |d          }|                     |                     |di           di           }t	          |                                          }g }	t          dt          |                    D ]	}
||
         }|                     |          }||v rdnd}|dk    rt          dt          |                    D ]}||         }| 	                    |d          }|                     |          }|	
                    i d|d	z   |z   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 dddd d d d d d d d d dd d dd d dd d d|                     |d          d dd |d!	           |	S )"Nr   exchangeRatesr  r'   ratesr   r   cryptor  r\  r  r  r  settler  r  settleIdr8  r6   Tr7   Fr8   r9   r:   rD  contractlinearr  r  minmaxmin_sizeleverager  r  r  )	inversecontractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitsr;  )fetch_currencies_from_cacher  r+  index_bylistkeysr=  r,  rK  r  r>  r  )r  r  r  r   r  r  dataByIdr  baseIdsr?  r@  r  r  r8  jquoteCurrencyr  r  s                     r	  r  zcoinbase.fetch_markets_v21  s   33F;;^^HlB??
x"EE~~j&"55==t,,t~~mVRHH'SUVVuzz||$$q#g,,'' 9	 9	AQZF**622D$0066xDxq#d)),, 3 3A$(GM"..}dCCG 33G<<EMM /#fslW4/# $*u"4/# /#  	/#
 !$/# !&/# "7/# #D/# /# /# !%/# /# !%/# !%/# !$/#  #E!/#" !$#/#$ $((,"&*."&&*&*%)& & (,'+) )
 (,'+' '
 (,'+& &
 (,'7'7z'R'R'+% %# #$ !.]/# /# /# / / / /` r
  c                 4   |                      |          |                     |          g}g }	 |                      |                     |ddi                    |                      |                     |ddd                    |                     |                     |ddi                    |                     |                     |ddd                    g}n# t          $ r}g }Y d }~nd }~ww xY w|}d }	 |}n# t          $ r}g }Y d }~nd }~ww xY w|                     |di           }|                     |di           }|                     |di           }	|                     |di           }
|                     |di           }|                     |di           }|                     |d	i           }|                     |d	i           }|                     |d	i           }|                     |d
g           }g }t          dt          |                    D ]1}|                    | 	                    ||         |                     2|                     |	d
g           }t          dt          |                    D ]1}|                    | 
                    ||         |                     2|                     |
d
g           }t          dt          |                    D ]1}|                    | 
                    ||         |                     2|S )Nproduct_typeFUTURE	PERPETUAL)r  contract_expiry_typer   r      r   fee_tierproducts)v3PrivateGetBrokerageProducts'v3PrivateGetBrokerageTransactionSummaryr*  	Exceptionr  r+  r=  r,  r>  parse_spot_marketparse_contract_market)r  r  spotUnresolvedPromisesunresolvedContractPromisesepromisescontractPromisesr6   r   expiringFuturesperpetualFuturesexpiringFeesperpetualFeesfeeTierexpiringFeeTierperpetualFeeTierr  r?  r@  
futureDataperpetualDatas                        r	  r  zcoinbase.fetch_markets_v3v  s   ..v6688@@"
 &("	,224;;vX`Ga3b3bcc224;;vX`  {F  HG  HG  4H  4H  I  I<<T[[R`bjQk=l=lmm<<T[[bj  EP  RQ  RQ  >R  >R  S  S	*&&  	, 	, 	,)+&&&&&&	,)	"9 	" 	" 	"!	"~~h2..~~h2....)91bAA>>*:ArBB~~&62>>'7B??( ..z266..z2FF>>-RHH~~dJ33q#d))$$ 	D 	DAMM$00a'BBCCCC^^OZDD
q#j//** 	V 	VAMM$44Z]OTTUUUU'7RHHq#m,,-- 	Z 	ZAMM$44]15EGWXXYYYYs0   B,C 
C1%C,,C19C< <
DDDc                    |                      |d          }|                      |d          }|                      |d          }|                     |          }|                     |          }|                     |d          }|                     |d          }	|                     | j        dg           }
|                     i d|d|d	z   |z   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 |                     ||
          rdn|                     |d          |                     ||
          rdn|                     |d          d d d d d |                     |d          | 	                    |dd           d!d d d"|                     |d#          |                     |d$          d"d d d"|                     |d%          |                     |d&          d"d'd |d(          S ))Nr  base_currency_idquote_currency_idr  trading_disabledr   r'   r\  r  r  r  r  r  r  r  r8  r6   r7   r8   Fr9   r:   rD  r  r  gh㈵>taker_fee_rateg        maker_fee_ratebase_incrementprice_incrementquote_incrementr  r  base_min_sizebase_max_sizequote_min_sizequote_max_sizer  r  r   r   r  r  r  r  r  r  r  rz  r;  )
r  rK  rJ  rG  r+  r   safe_market_structurein_arrayr  safe_number_2)r  r  r  r'   r  r  r  r  
marketTypetradingDisabledr   s              r	  r  zcoinbase.parse_spot_market  s   @ fl33!!&*<==""6+>??&&v..''00++FNCC
..1CDDnnT\="EE)) 2+
"2+
dSj5(2+
 D2+
 U	2+

 d2+
 f2+
 w2+
 2+
 J2+
 Z6)2+
 d2+
 E2+
 e2+
 e2+
 /)2+
  !2+
" d#2+
$  $b+ > >oWWDDTDTU\^nDoDo MM"k::kSS@P@PQXZj@k@k "**63CDD++F4EGXYY    
  ++FODD++FODD 
   
  ++F4DEE++F4DEE  $ c2+
 2+
 2+
 2 2 2	r
  c                    |                      |d          }|                     |di           }|                      |d          }|                     |d          }|                      |d          }|                     |          }|dk    }	|                      |d          }
|                      |d          }|                     |
          }|                     |          }|                     |d	          }|d
z   |z   }d }|	rd}|dz   |z   }n#d}|dz   |z   dz   |                     |          z   }|                     |d          }|                     |d          }|r|n|                     d          }|r|n|                     d          }|                     i d|d|d|d|d|d|
d|d|d|ddddd|	d|	 ddd | d!d"d#d"d|||||d d |                     |d$          | 	                    |d%d&          d'd d d(|                     |d)          |                     |d*          d(d d d(|                     |d+          |                     |d,          d(d-d |d.          S )/Nr  future_product_detailsr  contract_sizecontract_expiryr  contract_root_unitr  is_disabledr  r8   :r9   r  r  r  z0.06z0.04r'   r\  r  r  r  r  r  r  r8  r6   Fr7   r:   rD  r  Tr  r  r  r  r  r  r  r  r  r  r  r  )
r  r  r  r  rK  rG  yymmddr  r  r  )r  r  r  r'   futureProductDetailscontractExpiryTyper  contractExpireexpireTimestampisSwapr  r  r  r  r  r\  r8  takerFeeRatemakerFeeRater   r   s                        r	  r  zcoinbase.parse_contract_market  s   l fl33#~~f6NPRSS!--.BDZ[[''(<oNN))*>@QRR..88$3!!"68LMM""6+>??&&v..''00..??e# 	ODc\E)FFDc\E)C/$++o2N2NNF''1ABB''1ABB ,K$2C2CF2K2K ,K$2C2CF2K2K)) 2+
"2+
f2+
 D2+
 U	2+

 e2+
 f2+
 w2+
 2+
 D2+
 E2+
 e2+
 F2+
 &j2+
 e2+
 /)2+
  !2+
" d#2+
$ (%,**63CDD++F4EGXYY    
  ++FODD++FODD 
   
  ++F4DEE++F4DEE  $ c2+
 2+
 2+
 2 2 2	r
  c                    |                      | j        di           }|                     |d          }|                     |dd          }|                                 }|	||z
  |k    r|                     |          |                     |          g}|}|                      |di           }|                      |di           }	|                     |dg           }
|                     |	dg           }|                     |          }|                     || 	                    |
|          ||d          | j        d<   |                      | j        di           S )	NrY   r  r     r   r   r  )r   r  r  )
r  r   safe_integermillisecondsv2PublicGetCurrenciesv2PublicGetCurrenciesCryptor+  v2PublicGetExchangeRatesr*  array_concat)r  r  r   r  r   nowr  promisesResultfiatResponsecryptoResponsefiatData
cryptoDatar  s                r	  r  z$coinbase.fetch_currencies_from_cache  sc   ../@"EE%%g{;;	##GY==!!C)Ow#>#>**6220088H &N>>.!R@@L "^^NArBBN ~~lFB??HCCJ 99&AAM.2kk'"//*EE!. D D / /DL*+
 ~~dl,=rBBBr
  c                 f   |                      |          }|                     |dg           }i }i }i }t          dt          |                    D ]}||         }|                     |d          }	|                     |dd          }
|                     |
          }|                     |d          }|                                | j        d         |<   |                                | j        d         |<   ||
||	d
nd|                     |d          dd	d	d	d	| 	                    |d          d	dd	d	ddd||<   |	|                                }|||<   |||<   | 
                    || j        d                   | j        d<   | 
                    || j        d                   | j        d<   |S )a  
        fetches all available currencies on an exchange
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-currencies#get-fiat-currencies
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates#get-exchange-rates
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   r   asset_idr'   r:  r(   r   networksByIdNr  r   Tr  r  )r  r   )r;  r'   r:  r8  r(   rD  rN   r   r  r  r  )r  r+  r=  r,  r  rI  rK  lowerr   r  r*  )r  r  r  r   r?  r   r>  r@  rE  assetIdr'   r:  r(   lowerCaseNames                 r	  fetch_currencieszcoinbase.fetch_currencies  s    33F;;^^HlB??
L q#j//** !	3 !	3A!!}H&&x<<G##HdF;;B**2..D##Hf55D-1ZZ\\DL$T*15DL(. %,%8v((6:: !  $//*EE# 
  $#! !	 	 F4L, " $

!..2]+#';;xj9Q#R#RZ '+{{<nA]'^'^^$r
  symbolsc                     |                      | j        dd          }|dk    r|                     ||          S |                     ||          S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getproducts
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates#get-exchange-rates
        :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   )r  r   fetch_tickers_v3fetch_tickers_v2)r  rC  r  r  s       r	  fetch_tickerszcoinbase.fetch_tickersV  sV     !!$,@PQQ%%%((&999$$Wf555r
  c                    |                                   |                     |          }i }|                     |                     ||                    }|                     |di           }|                     |di           }|                     |d          }i }t          |                                          }	d}
t          dt          |	                    D ]P}|	|         }||
z   |z   }| 
                    |d |
          }|d         }|                     ||         |          ||<   Q|                     |d|          S )Nr  r  rE  r  r   r\  )r'  market_symbolsr4  r*  r  r  r  r  r=  r,  r  parse_tickerfilter_by_array_tickers)r  rC  r  r.  r  r  r  r  r?  r  	delimiterr@  r  r  r  r\  s                   r	  rF  zcoinbase.fetch_tickers_v2d  sB   %%g..
 00Wf1M1MNN ~~h33tWb11""444uzz||$$	q#g,,'' 	F 	FAQZF	)G3H%%hi@@FH%F!..uV}fEEF6NN++FHgFFFr
  c                 *   |                                   |                     |          }i }||                     |          |d<   |                     |                     ||                    }|                     |dg           }i }t          dt          |                    D ]X}||         }|                     |d          }	| 	                    |	d d          }
|
d         }| 
                    ||
          ||<   Y|                     |d|          S )Nproduct_idsr  r   r  r  r\  )r'  rI  
market_idsr  r*  r+  r=  r,  r  r  rJ  rK  )r  rC  r  r.  r  r  r?  r@  entryr  r  r\  s               r	  rE  zcoinbase.fetch_tickers_v3  s   %%g..%)__W%=%=GM"55dkk'66R6RSSL ~~h
B77q#d))$$ 	> 	>AGE''|<<H%%hc::FH%F!..uf==F6NN++FHgFFFr
  c                     |                      | j        dd          }|dk    r|                     ||          S |                     ||          S )a&  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getmarkettrades
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices#get-spot-price
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices#get-buy-price
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices#get-sell-price
        :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|   r   )r  r   fetch_ticker_v3fetch_ticker_v2)r  r\  r  r  s       r	  fetch_tickerzcoinbase.fetch_ticker  sT     !!$,OO_$$''777##FF333r
  c                 H   |                                   |                     |          }|                     d|d         i|          }|                     |          }|                     |          }|                     |          }|                     |di           }|                     |di           }	|                     |di           }
|                     |
d          |                     |	d          |                     |d          d}|                     ||          S )Nr\  r'   r  r  )bidaskr  )	r'  r  r*  v2PublicGetPricesSymbolSpotv2PublicGetPricesSymbolBuyv2PublicGetPricesSymbolSellr  r  rJ  )r  r\  r  r  r.  r6   rW  rV  spotDataaskDatabidData
bidAskLasts               r	  rS  zcoinbase.fetch_ticker_v2  s&   V$$++fTl
  //88 --g66 ..w77 >>$33..fb11..fb11##GX66##GX66%%h99
 


   V444r
  c                    |                                   |                     |          }|d         dd}|                     |                     ||                    }|                     |dg           }|                     |d         |          }|                     |d          |d<   |                     |d          |d	<   |S )
Nr'   r   )r  r$  tradesr   best_bidrV  best_askrW  )r'  r  ,v3PrivateGetBrokerageProductsProductIdTickerr*  r+  rJ  r  )r  r\  r  r  r.  r  r  tickers           r	  rR  zcoinbase.fetch_ticker_v3  s    V$$ ,
 
 DDT[[QXZ`EaEabb& ~~h"55""47F33((:>>u((:>>ur
  c                 >   |                      |d          }|                      |d          }d }d }d|v r|                     |dg           }|                     |dg           }|                      |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|          S )NrV  rW  bidsasksr   r  r  r  r   r\  r  r  r2  highlow	bidVolume	askVolumevwapopenclosepreviousClosechanger   price_percentage_change_24haverage)
baseVolumequoteVolumer;  )r  r+  r  safe_tickersafe_symbolr  )r  rd  r  rV  rW  rj  rk  rf  rg  r  r2  r  s               r	  rJ  zcoinbase.parse_ticker  sB   b vu--vu--		f>>&&"55D>>&&"55D""47G44C((a&99I""47G44C((a&99I##FL9900##FF33 !
d&&x88!
11!
 !
 3	!

 3!
 D!
 D!
 4!
 !
 !
 D!
 D!
 T!
 T!
 d!
  $**63PQQ!!
" t#!
$ )!
 !
 !
* +  	r
  c                    |                      |ddg           }|                     |d| j        d                   }|                     |d| j        d                   }d|i}t          dt	          |                    D ]\}||         }|                     |d          }	|                     |	|          r|                     |d          }
|
|                     |
d          }|                     |          }|                     |
d	          }|}|                     ||          }|| 	                                }||d
<   ||d<   n<t          j        |d
         |          |d
<   t          j        |d         |          |d<   |||<   |                     |	|          r9|                     |d          }|                     |d          }|
||                     |d          }|                     |          }|                     |d          }|                     |d          }t          j        ||          }|                     ||          }|$| 	                                }||d
<   ||d<   ||d<   nZt          j        |d
         |          |d
<   t          j        |d         |          |d<   t          j        |d         |          |d<   |||<   ^|                     |          S )Nr  r   r8  r   r;  r   balancerE  r  freer  available_balanceholdvalueused)safe_list_2r+  r   r=  r,  r  r  r  rK  rL  r#   
string_addsafe_balance)r  r  r  balancesr   r   r?  brx  r8  r|  rN  r:  r  ry  rL  	availabler{  r}  s                      r	  parse_custom_balancezcoinbase.parse_custom_balance}  s   ##Hfj"EE>>&&$,z2JKK^^FFDL4NOO
(#q#h--(( &	+ &	+AqkG##GV44D}}T8,, #+w	::$!%!1!1%!D!DJ22:>>D ,,UH==E D"nnVT::G"&,,..*.+0((*1*<WV_e*T*T+2+=gg>NPU+V+V(#*F4LtZ00 + NN74GHH	~~gv66(T-=!%!1!1)Z!H!HJ22:>>D++D'::D++Iw??D#.tT::E"nnVT::G"&,,..*.*.+0((*1*<WV_d*S*S*1*<WV_d*S*S+2+=gg>NPU+V+V(#*F4L  (((r
  c                 ^   |                                   i }d}|                     |dd          }|                     |dg          }d}|                     dd|          \  }}|                     | j        dd          }|dk    r*|                     |                     ||                    }ne|s|dk    r/d|d<   |                     |                     ||                    }n.d	|d<   | 	                    |                     ||                    }||d
<   | 
                    ||          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getaccounts
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-accounts#list-accounts
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getfcmbalancesummary
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.v3]: default False, set True to use v3 api endpoint
        :param dict [params.type]: "spot"(default) or "swap" or "future"
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nr   FrQ   r4  r9      r$  r#  r8  )r'  rG  r  handle_market_type_and_paramsr  r   &v3PrivateGetBrokerageCfmBalanceSummaryr*  r4  r   r  )r  r  r.  r  isV3r  r  s          r	  fetch_balancezcoinbase.fetch_balance  sD    	~~fdE226D6**
!??PTV\]]
F!!$,@_``!!BB4;;wX^C_C_``HH 	O"AAA"GG99$++gv:V:VWWHH"GG00Wf1M1MNNHP $v((6:::r
  c                 ~   |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S d}||                     |          }d}|                     |||          \  }}|                     |                     ||                    }|                     |d         |||          }	t          |	          }
|
d	k    r|	S |
d
z
  }| 	                    |	|          }| 	                    |di           }| 
                    |d          }||dk    r
||d<   ||	|<   |	S )ar  
        fetch the history of changes, actions done by the user or operations that altered balance of the user
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-transactions#list-transactions
        :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 entrys to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :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 dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger-structure>`
        Frh   r   r!  r"  Nr#  r  r   r   r%  r&  )r'  r(  r)  rE  rj  )v2PrivateGetAccountsAccountIdTransactionsr*  parse_ledgerr,  r  r  )r  r:  r]  r$  r  r   rE  r.  r  ledgerr0  r1  r2  r%  r/  s                  r	  fetch_ledgerzcoinbase.fetch_ledger  s    	88PZ[[& 	S33M4PUW]_t  wG  IM  OR  S  S  S}}T**HII$PUW]^^ AA$++gW]B^B^__""8F#3XueLLVQ;;MQJ	~~fi00^^HlB??
!!*.CDDVr\\*0D&' $F9r
  c                 8    ddi}|                      |||          S )Nr{  rx  r|  )r  r~  typess      r	  parse_ledger_entry_statusz"coinbase.parse_ledger_entry_status6  s(    
 vv666r
  c           
      H    dddddddddd	}|                      |||          S )Nr  r  )	buysellfiat_depositfiat_withdrawalexchange_depositexchange_withdrawalr  pro_depositpro_withdrawalr|  r  r8  r  s      r	  parse_ledger_entry_typez coinbase.parse_ledger_entry_type<  sC    ), -#0!(+

 

 tT222r
  c                 .   |                      |di           }|                     |d          }d }t          j        |d          rd}t          j        |          }nd}|                     |d          }|                     ||          }d }|                      |di           }	|                      |	d          }
|
G|                     |
d          }|                     ||          }|                     |
d          }||d}|                     |                     |d	                    }|                     |d
          }|                     |                     |d                    }| 	                    |                     |d                    }|                     |d          }d }|2|
                    d          }t          |          }|dk    r|d         }||||                     |          ||d d |||                     |          d d ||dS )Nr  r   outinrE  r  r  r  r  r'   r8  r~  resource_pathr  r   )r;  r'   r  r  	directionrL  referenceIdreferenceAccountr8  rE  r  beforeafterr~  r  )r  r  r#   	string_lt
string_negrK  r  r  r  r  rH  r,  iso8601r  )r  itemrE  
amountInfor  r  rN  r:  r  networkInfofeeInfor  feeCurrencyCode	feeAmountr  r'   r8  r~  pathrZ  rQ  numPartss                         r	  parse_ledger_entryzcoinbase.parse_ledger_entryJ  s6   h ^^D(B77
!!*h77	VS)) 	I'//FFI%%j*==
&&z8<< nnT9b99...?@@ ,,WjAAM"55mXNNO(((;;I!+ C NN4#3#3D,#G#GHH	dD))++D,<,<T6,J,JKK//0@0@x0P0PQQo66	JJsOOE5zzH!||!!H	"Y//"  $''//
 
 	
r
  c                     |                                   |                     d|           t          dt          | j                            D ]%}| j        |         }|d         |k    r
|d         c S &d S )NFr   r:  r'   )r'  rX  r=  r,  r   )r  r:  r  r@  rL  s        r	  find_account_idzcoinbase.find_account_idz	  s    5&)))q#dm,,-- 	% 	%AmA&Gv$&&t}$$$ 'tr
  c                 |    |                      |dd          }|t          | j        dz             d|i}|||d<   |S )NrT  rZ  zN prepareAccountRequest() method requires an account_id(or accountId) parameterr$  )rI  r   r'   )r  r$  r  rZ  r.  s        r	  r_  z coinbase.prepare_account_request	  sX    &&v|[II	#DG.~$~)
 $GGr
  c                    |                      |dd          }|                     |ddg          }|K|t          | j        dz             |                     ||          }|t          | j        dz   |z             d|i}|||d<   ||gS )NrT  rZ  zz prepareAccountRequestWithCurrencyCode() method requires an account_id(or accountId) parameter OR a currency code argumentzG prepareAccountRequestWithCurrencyCode() could not find account id for r$  )rI  r  r   r'   r  r   )r  r:  r$  r  rZ  r.  s         r	  rj  z3coinbase.prepare_account_request_with_currency_code	  s    &&v|[II	6L+#>??|'  3o  )o  p  p  p,,T6::I #DG.w$wz~$~)
 $GG  r
  r  c                     |                                   |                     |          }|d         st          | j        dz             d|d<   |                     |dd|d|          S )a  
        create a market buy order by providing the symbol and cost
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_postorder
        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r6   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr   r  r  N)r'  r  r   r'   create_order)r  r\  r  r  r  s        r	  !create_market_buy_order_with_costz*coinbase.create_market_buy_order_with_cost	  ss     	V$$f~ 	ftw)ddeee6;23  5$fMMMr
  r8  r  r  r  c                    |                                   |                     |          }|                     | j        dd          }|dz   |                                 z   |d         |                                d}	|                     |g d          }
|                     |d          }|                     |d          }|
d	u}|d	u}|d	u}|                     |d
          }|dk    rdn|                     |ddd          }|                     |d          }|                     |d          }|dk    r|r|
|dk    rdnd}|dk    s|d|t          | j
        dz             d|                     ||          |                     ||          |                     ||
          ||di|	d<   nd|                     ||          |                     ||          |                     ||
          |di|	d<   n|s|rd	}|r#|
|dk    rdnd}|                     ||          }n"|
|dk    rdnd}|                     ||          }d|                     ||          |                     ||          ||di|	d<   n|dk    s|O|t          | j
        dz             d|                     ||          |                     ||          ||di|	d<   n|dk    r4d |                     ||          |                     ||          d!i|	d<   nrd"|                     ||          |                     ||          |d#i|	d<   n=|s|s|rt          | j
        d$z             |d%         r|dk    rd	}d}|                     |d&d'd          \  }}|                     |d(          }|                     |d(          }||                     ||          }n|ro|t#          | j
        d)z             |                     |          }|                     |          }t'          j        ||          }|                     ||          }n|                     ||          }d*d+|ii|	d<   nd*d,|                     ||          ii|	d<   |                     |d-          }||d.k    rd/|	d0<   n|d1k    rd2|	d0<   |                     |g d3          }|                     |d4d5d          }d	}|rX|                     |d4d5g          }|                     |	d6          }	|                     |                     |	|                    }n)|                     |                     |	|                    }|                     |d7          }|dur|                     |d8          }|                     |d9          } |                     |d:          }!|S|                     | j        d;         | |!           |                     | j        d<         | |!           t          |!          |                     |d=i           }"|                     |"|          S )>a  
        create a trade order
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_postorder
        :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 you want to trade in units of the base currency, quote currency for 'market' 'buy' orders
        :param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.stopPrice]: price to trigger stop orders
        :param float [params.triggerPrice]: price to trigger stop orders
        :param float [params.stopLossPrice]: price to trigger stop-loss orders
        :param float [params.takeProfitPrice]: price to trigger take-profit orders
        :param bool [params.postOnly]: True or False
        :param str [params.timeInForce]: 'GTC', 'IOC', 'GTD' or 'PO'
        :param str [params.stop_direction]: 'UNKNOWN_STOP_DIRECTION', 'STOP_DIRECTION_STOP_UP', 'STOP_DIRECTION_STOP_DOWN' the direction the stopPrice is triggered from
        :param str [params.end_time]: '2023-05-25T17:01:05.092Z' for 'GTD' orders
        :param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
        :param boolean [params.preview]: default to False, wether to use the test/preview endpoint or not
        :param float [params.leverage]: default to 1, the leverage to use for the order
        :param str [params.marginMode]: 'cross' or 'isolated'
        :param str [params.retail_portfolio_id]: portfolio uid
        :param boolean [params.is_max]: Used in conjunction with tradable_balance to indicate the user wants to use their entire tradable balance
        :param str [params.tradable_balance]: amount of tradable balance
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   r   r  r'   )client_order_idr  r  )	stopPrice
stop_pricetriggerPricestopLossPricetakeProfitPriceNtimeInForcePOTpostOnly	post_onlyFend_timestop_directionr$  r  STOP_DIRECTION_STOP_DOWNSTOP_DIRECTION_STOP_UPGTDz= createOrder() requires an end_time parameter for a GTD orderstop_limit_stop_limit_gtd)	base_sizelimit_pricer  r  r  order_configurationstop_limit_stop_limit_gtc)r  r  r  r  limit_limit_gtd)r  r  r  r  IOCsor_limit_ioc)r  r  limit_limit_gtc)r  r  r  z3 createOrder() only stop limit orders are supportedr6   rH   r   r  a	   createOrder() requires a price argument for market buy orders on spot markets to calculate the total amount to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argumentmarket_market_ioc
quote_sizer  
marginModeisolatedISOLATEDmargin_typecrossCROSS)r  r  r  r  r  r  stopDirectionr  clientOrderIdr  r  r  r  previewtestr  successerror_responseerrormessager   r   success_response)r'  r  r  r   r7  uppersafe_number_nr  safe_bool_2r   r'   amount_to_precisionprice_to_precisionr   r(  r  cost_to_precisionr   number_to_stringr#   r  #v3PrivatePostBrokerageOrdersPreviewr*  v3PrivatePostBrokerageOrdersrG  r  throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionparse_order)#r  r\  r8  r  r  r  r  r  r'   r.  r  r  r  isStop
isStopLossisTakeProfitr  r  endTimer  r  r  r   r  r  r  costRequestr  r  r  r  errorResponse
errorTitleerrorMessager  s#                                      r	  r  zcoinbase.create_order	  s   6 	V$$dlJ??!Cx$))++5 ,JJLL
 

 &&v/Z/Z/Z[[	((AA**63DEE$&"$.
&d2&&v}=='4//44d6F6Fvz[fhm6n6n""6:66((1ABB7?? D (CG5==$>$>WoM5((g.A+DG6u,uvvv3)-)A)A&&)Q)Q+/+B+B65+Q+Q*.*A*A&)*T*T.;(/6 66G122 4)-)A)A&&)Q)Q+/+B+B65+Q+Q*.*A*A&)*T*T.;	6 66G122  ,| ,# T$,EIU]](@(@Ys#'#:#:6=#Q#QLL$,GKu}}(B(B[s#'#:#:6?#S#SL/%)%=%=ff%M%M'+'>'>vu'M'M&2*7	2 22-..  5((g.A+DG6u,uvvv))-)A)A&&)Q)Q+/+B+B65+Q+Q(/)1	, ,6G122 !E))')-)A)A&&)Q)Q+/+B+B65+Q+Q* *6G122 *)-)A)A&&)Q)Q+/+B+B65+Q+Q)1, ,6G122  d d| d"47-b#bcccf~ 45==481<@<Y<YZ`bo  rU  W[  =\  =\916''776622# 2264@@EE6 	C}*47  6A  ,A  B  B  B'+'<'<V'D'D&*&;&;E&B&B&-&8{&S&S $ 6 6v{ K K 2266BBE'$e*2-.. (#T%=%=ff%M%M*2-.
 %%fl;;
!Z'')3&&w&&)0&6  $i  $i  $i  j  j""69feDD 	WYYv	6':;;Fii):;;G??GU[@\@\]]HH88Wf9U9UVVHL ..955$ NN85EFFM))-AAJ++M9EEL(44T_W5Mz[ghhh44T_W5Mz[ghhh#L111~~h(:B??f---r
  c                    |                      |d          }|                     ||d          }||                     |          }|                     |di           }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                     |d	          }|d up|d up|d u}|	d up|
d u}d }d }d }d }|rQd }||}n||}n|}|                      |d
          }|                      |d          }|                     |d          }nw|r_|	|	n|
}|                      |d
          }|                      |d          }|                     |d          }|                      |d          }n|                      |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*|          S )+Nr  r  r  r  r  r  r  r  r  r  r  r  r  created_time
total_feesr  r;  r'   r  r  r  r  r  lastTradeTimestampr\  r8  
order_typer  time_in_forcer  r  r  r  r  r  filledfilled_size	remainingaverage_filled_pricer~  r  )r  rr  r~  r  r`  )r  rv  r  r  rG  
safe_orderr  parse_order_typeparse_time_in_forcerJ  parse_order_status)r  r  r  r  r\  orderConfigurationlimitGTClimitGTDlimitIOCstopLimitGTCstopLimitGTD	marketIOCisLimitr  r  r  r  r  target
stopTargetr  	totalFeescurrencyFees                          r	  r  zcoinbase.parse_order
  s/   ~ ##E<88!!(FC88[[((F!^^E3H"MM>>"46GHH>>"46GHH>>"4oFF~~&8:UVV~~&8:UVVNN#57JKK	D(]hd.B]X\H\t+JT1I 	>F#!%!!$$V];;E%%fk::F~~fk::HH 	>*6*BJ$$Z??E%%j+>>F~~j+>>H++JEELL%%i==F##E>::$$UL99	!(: /K  
E 
$""5*55 
 T--e5FGG 
 11	 

  
 !$ 
 f 
 D))$*:*:5,*O*OPP 
 433D4D4DUO4\4\]] 
  
 D**5&99 
 U 
  
 L 
 f 
  d&&um<<! 
" # 
$ ''/EFF--d.>.>uh.O.OPP((=='  3 
  
  
4 5  	r
  c                 B    dddddd d}|                      |||          S )Nrm  closedry  )OPENFILLED	CANCELLEDEXPIREDFAILEDUNKNOWN_ORDER_STATUSr|  r}  s      r	  r  zcoinbase.parse_order_status  s:    #! $(
 
 &&999r
  c                 N    |dk    rd S ddddd}|                      |||          S )NUNKNOWN_ORDER_TYPEr  r$  )MARKETLIMITSTOP
STOP_LIMITr|  r  s      r	  r  zcoinbase.parse_order_type  sE    '''4!	
 
 tT222r
  c                 @    ddddd d}|                      |||          S )NGTCr  r  FOK)GOOD_UNTIL_CANCELLEDGOOD_UNTIL_DATE_TIMEIMMEDIATE_OR_CANCELFILL_OR_KILLUNKNOWN_TIME_IN_FORCEr|  )r  r  timeInForcess      r	  r  zcoinbase.parse_time_in_force  s7    $)$)#(!%)
 
 k;GGGr
  r'   c                     |                                   |                     |g||          }|                     |di           S )a  
        cancels an open order
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_cancelorders
        :param str id: order id
        :param str symbol: not used by coinbase cancelOrder()
        :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'  cancel_ordersr  )r  r'   r\  r  orderss        r	  cancel_orderzcoinbase.cancel_order%  sE     	##RD&&99~~fa,,,r
  c                    |                                   d}||                     |          }d|i}|                     |                     ||                    }|                     |dg           }t          dt          |                    D ]9}|                     ||         d          }	|	durt          | j	        dz             :| 
                    ||          S )a  
        cancel multiple orders
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_cancelorders
        :param str[] ids: order ids
        :param str symbol: not used by coinbase cancelOrders()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        N	order_idsresultsr   r  Tz? cancelOrders() has failed, check your arguments and parameters)r'  r  'v3PrivatePostBrokerageOrdersBatchCancelr*  r+  r=  r,  rG  r   r'   parse_orders)
r  idsr\  r  r  r.  r  r+  r@  r  s
             r	  r*  zcoinbase.cancel_orders2  s     	[[((F
 ??GU[@\@\]] )R88q#f++&& 	n 	nAnnVAY	::Gd"" +l!lmmm #  000r
  c                    |                                   |                     |          }d|i}	||                     ||          |	d<   ||                     ||          |	d<   |                     |ddd          }
d}|
rB|                     |ddg          }|                     |                     |	|                    }n)|                     |                     |	|                    }| 	                    ||          S )aV  
        edit a trade order
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_editorder
        :param str id: cancel order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fullfilled, in units of the base currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.preview]: default to False, wether to use the test/preview endpoint or not
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  Nr  r  r  r  F)
r'  r  r  r  r  r  'v3PrivatePostBrokerageOrdersEditPreviewr*   v3PrivatePostBrokerageOrdersEditr  )r  r'   r\  r8  r  r  r  r  r  r.  r  r  s               r	  
edit_orderzcoinbase.edit_orderU  s    	V$$
 "66vvFFGFO#66vuEEGG""69feDD 	[YYv	6':;;FCCDKKPWY_D`D`aaHH<<T[[RX=Y=YZZH &111r
  c                    |                                   d}||                     |          }d|i}|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        fetches information on an order made by the user
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_gethistoricalorder
        :param str id: the order id
        :param str symbol: unified market symbol that 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>`
        Nr  r  )r'  r  ,v3PrivateGetBrokerageOrdersHistoricalOrderIdr*  r  r  )r  r'   r\  r  r  r.  r  r  s           r	  fetch_orderzcoinbase.fetch_order~  s     	[[((F
 DDT[[QXZ`EaEabbP x"55v...r
  r#  c                    |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S d}||                     |          }i }||d         |d<   |||d	<   ||                     |          |d
<   |                     |ddg          }|0|                     |ddg          }|                     |          |d<   |                     |                     ||                    }	| 	                    |	dg           }
| 
                    |
d          }|                     |	d          }||dk    r
||d<   ||
d<   |                     |
|||          S )a  
        fetches information on multiple orders made by the user
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_gethistoricalorders
        :param str symbol: unified market symbol that the orders were made in
        :param int [since]: the earliest time in ms to fetch orders
        :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 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 Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Frv   r   r/  Nr/  r'   r  r$  
start_dateuntiltillend_dater+  r   r&  )r'  r(  r)  r  r  safe_integer_nr  *v3PrivateGetBrokerageOrdersHistoricalBatchr*  r+  r  r  r1  )r  r\  r]  r$  r  r   r  r.  r<  r  r+  firstr/  s                r	  fetch_orderszcoinbase.fetch_orders  s    	88PZ[[& 	A33M65RWY_aiksuy{  A  A  A[[((F$*4LGL!$GG$(LL$7$7GL!##FWf,=>>YYv'899F"&,,u"5"5GJBB4;;wX^C_C_``V (B77vq))!!(H55Vr\\$E(OF1I  >>>r
  c                    |                                   d }||                     |          }d|i}||d         |d<   |d}||d<   ||                     |          |d<   |                     |ddg          }|0|                     |ddg          }|                     |          |d	<   |                     |                     ||                    }	|                     |	d
g           }
|                     |
d          }| 	                    |	d          }||dk    r
||d<   ||
d<   | 
                    |
|||          S )Norder_statusr'   r  r#  r$  r;  r<  r=  r>  r+  r   r/  r&  )r'  r  r  r?  r  r@  r*  r+  r  r  r1  )r  r~  r\  r]  r$  r  r  r.  r<  r  r+  rA  r/  s                r	  fetch_orders_by_statuszcoinbase.fetch_orders_by_status  sl   [[((FF
 $*4LGL!=E $(LL$7$7GL!##FWf,=>>YYv'899F"&,,u"5"5GJBB4;;wX^C_C_``V (B77vq))!!(H55Vr\\$E(OF1I  >>>r
  c                     |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S |                     d||||          S )a  
        fetches information on all currently open orders
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_gethistoricalorders
        :param str symbol: unified market symbol of the orders
        :param int [since]: timestamp in ms of the earliest order, default is None
        :param int [limit]: the maximum number of open order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :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)
        :param int [params.until]: the latest time in ms to fetch trades for
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Frs   r   r/  Nr#  r  r'  r(  r)  rE  r  r\  r]  r$  r  r   s         r	  fetch_open_orderszcoinbase.fetch_open_ordersQ  s     	88ART^__& 	D334EvuV[]cemowy}  @C  D  D  D**665%PPPr
  c                     |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S |                     d||||          S )a  
        fetches information on multiple closed orders made by the user
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_gethistoricalorders
        :param str symbol: unified market symbol of the orders
        :param int [since]: timestamp in ms of the earliest order, default is None
        :param int [limit]: the maximum number of closed order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :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)
        :param int [params.until]: the latest time in ms to fetch trades for
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        FrV   r   r/  Nr#  r  rG  rH  s         r	  fetch_closed_orderszcoinbase.fetch_closed_ordersd  s     	88ATV`aa& 	F334GQVX]_egoqy{  BE  F  F  F**8VUE6RRRr
  c                 4    |                      d||||          S )ae  
        fetches information on multiple canceled orders made by the user
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_gethistoricalorders
        :param str symbol: unified market symbol of the orders
        :param int [since]: timestamp in ms of the earliest order, default is None
        :param int [limit]: the maximum number of canceled order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  )rE  )r  r\  r]  r$  r  s        r	  fetch_canceled_orderszcoinbase.fetch_canceled_ordersw  s      **;ufUUUr
  r   c           
         |                                   d}||nt          ||          }d}|                     |ddd          \  }}|r|                     d||||||dz
            S |                     |          }|d         |                     | j        ||          d}	|                     |g d	          }
|                     |d
dg          }| 	                    |          }||z  }d}|,| 
                    |                     |dz                      }nCt          |                                           }t          j        |t          |                    }||	d<   | 
                    |
          }|
"t          j        |t          |                    }||	d<   |                     |                     |	|                    }|                     |dg           }|                     |||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getcandles
        :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, not used by coinbase
        :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
        i,  NFrq   r   r   r'   )r  granularity)r<  r=  endr<  r=  r/  startrP  candles)r'  r  r(  "fetch_paginated_call_deterministicr  r  r   r?  r  parse_timeframer  parse_to_intstrsecondsr#   
string_subr  -v3PrivateGetBrokerageProductsProductIdCandlesr*  r+  parse_ohlcvs)r  r\  	timeframer]  r$  r  maxLimitr   r  r.  r<  durationrequestedDurationsinceStringr6  	endStringr  rR  s                     r	  fetch_ohlcvzcoinbase.fetch_ohlcv  s    	"]UH1E1E88z[`aa& 	@::<QVX]_hjprz}~r~V$$ ,++DOY	RR
 
 ##F,D,D,DEE6GV#455''	22!H,//0A0A%$,0O0OPPKKdllnn%%C!,S#6G2H2HIIK&))%00	=*;<M8N8NOOI"EEdkkRY[aFbFbcc ..9b99  &)UEJJJr
  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )NrQ  rm  rh  ri  rn  volume)safe_timestampr  )r  ohlcvr  s      r	  parse_ohlcvzcoinbase.parse_ohlcv  s     w//UF++UF++UE**UG,,UH--
 	
r
  c                 n   |                                   |                     |          }d|d         i}|.|                     |                     |dz                      |d<   |t	          |d          |d<   d}|                     |dd          \  }}|/|                     |                     |dz                      |d	<   n|t          | j        d
z             |                     | 	                    ||                    }| 
                    |dg           }	|                     |	|||          S )a:  
        get the list of most recent trades for a particular symbol
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getmarkettrades
        :param str symbol: unified market symbol of the trades
        :param int [since]: not used by coinbase fetchTrades
        :param int [limit]: the maximum number of trade structures 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'   Nr/  rQ  r$  r   r<  rP  zI fetchTrades() requires a `until` parameter when you use `since` argumentr`  )r'  r  r  rU  r  r(  r   r'   rc  r*  r+  ra  )
r  r\  r]  r$  r  r  r.  r<  r  r`  s
             r	  fetch_tradeszcoinbase.fetch_trades  sD    	V$$&,
 #44T5F5Fut|5T5TUUGG"5$//GG55fmWUUv!2243D3DUT\3R3RSSGENN#DG.y$yzzzDDT[[QXZ`EaEabb" (B77  >>>r
  c                    |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S d}||                     |          }i }||d         |d<   |||d	<   ||                     |          |d
<   |                     |ddg          }|0|                     |ddg          }|                     |          |d<   |                     |                     ||                    }	| 	                    |	dg           }
| 
                    |
d          }|                     |	d          }||dk    r
||d<   ||
d<   |                     |
|||          S )aq  
        fetch all trades made by the user
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getfills
        :param str symbol: unified market symbol of the trades
        :param int [since]: timestamp in ms of the earliest order, default is None
        :param int [limit]: the maximum number of trade structures 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 Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Frp   r   r/  Nr#  r'   r  r$  start_sequence_timestampr<  r=  end_sequence_timestampfillsr   r&  )r'  r(  r)  r  r  r?  r  *v3PrivateGetBrokerageOrdersHistoricalFillsr*  r+  r  r  ra  )r  r\  r]  r$  r  r   r  r.  r<  r  r`  rA  r/  s                r	  fetch_my_tradeszcoinbase.fetch_my_trades  s    	88R\]]& 	B33OVUTY[ackmuw{  ~A  B  B  B[[((F$*4LGL!$GG26,,u2E2EG./##FWf,=>>YYv'899F04U0C0CG,-BB4;;wX^C_C_``0 '266vq))!!(H55Vr\\$E(OF1I  >>>r
  c           	         |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |di           }|                     |d          }|                     |          }	|                     |||	ddd	d
          S )a`  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getproductbook
        :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  r'   Nr$  	pricebookr   rf  rg  r  r  )r'  r   v3PrivateGetBrokerageProductBookr*  r  r  r  parse_order_book)
r  r\  r$  r  r  r.  r  r  r   r  s
             r	  fetch_order_bookzcoinbase.fetch_order_book@  s     	V$$&,
 $GG88Wf9U9UVV* ~~hR88f--NN4((	$$T69ffgW]^^^r
  c                 8   |                                   |                     |          }i }||                     |          |d<   |                     |                     ||                    }|                     |dg           }|                     ||          S )a  
        fetches the bid and ask price and volume for multiple markets
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getbestbidask
        :param str[] [symbols]: unified symbols of the markets to fetch the bids and asks for, all markets 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>`
        NrN  
pricebooks)r'  rI  rO  v3PrivateGetBrokerageBestBidAskr*  r+  parse_tickers)r  rC  r  r.  r  tickerss         r	  fetch_bids_askszcoinbase.fetch_bids_asksj  s     	%%g..%)__W%=%=GM"77GV8T8TUU. ..<<<!!'7333r
  c                 ~   |                      ||          \  }}|                     |           |                                  |                     |          }|                     |dd          }|                     |ddg          }|K|t          | j        dz             |                     ||          }|t          | j        dz   |z             |d|||d         d}|||d	<   | 
                    |                     ||                    }	|                     |	d
i           }
|                     |
|          S )a  
        make a withdrawal
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-transactions#send-money
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str [tag]: an optional tag for the withdrawal
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        rT  rZ  NzV withdraw() requires an account_id(or accountId) parameter OR a currency code argumentz* withdraw() could not find account id for r  r'   )rT  r8  r  r  rE  rU  r  )handle_withdraw_tag_and_paramscheck_addressr'  rE  rI  r  r   r'   r  r   *v2PrivatePostAccountsAccountIdTransactionsr*  r  r  )r  r:  r  rV  rW  r  rE  rZ  r.  r  r  s              r	  r   zcoinbase.withdraw  sk    99#vFFV7###==&&&&v|[II	6L+#>??|'  3K  )K  L  L  L,,T6::I #DG.Z$Z]a$abbb# 
 
 ?),G%&BB4;;wX^C_C_``j ~~h33%%dH555r
  c                 n   |                                   |                     |          }d}|                     |d                   \  }}|                     |                     ||                    }|                     |dg           }|                     |dd          }|                     |d          S )a  
        fetch the deposit address for a currency associated with self account
        :see: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postcoinbaseaccountaddresses
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nr:  r  Fr  )r'  rE  rj  &v2PrivateGetAccountsAccountIdAddressesr*  r+  parse_deposit_addressesr  )r  r:  r  rE  r.  r  r  addressStructuress           r	  "fetch_deposit_addresses_by_networkz+coinbase.fetch_deposit_addresses_by_network  s     	==&&II(SYJZ[[>>t{{7TZ?[?[\\p ~~h33 88tUKK}}.	:::r
  c                    |                      |d          }|                     |           |                      |d          }|                     d |          }|                      |d          }|                    d          }|                      |d          }|                     |d          }	||                     ||          ||                      |	d          |                     ||          dS )	NrV  r  address_labelrF  r   address_inforU  )r;  rE  rV  rW  r  )r  r|  rK  rH  r  network_id_to_code)
r  depositAddressrE  rV  	networkIdr:  addressLabelsplitAddressLabelr  addressInfos
             r	  parse_deposit_addresszcoinbase.parse_deposit_address1  s    X "">9==7###$$^Y??	&&tX66''HH(..s33##$5q99nn^^DD"//(CC##K1BCC..y$??
 
 	
r
  c                 $   |                                   |                     |dd          }|                     |ddg          }|K|t          | j        dz             |                     ||          }|t          | j        dz   |z             ||                     |          |                                |d}| 	                    | 
                    ||                    }|                     |di           }|                     |          S )ag  
        make a deposit
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-deposits#deposit-funds
        :param str code: unified currency code
        :param float amount: the amount to deposit
        :param str id: the payment method id to be used for the deposit, can be retrieved from v2PrivateGetPaymentMethods
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountId]: the id of the account to deposit into
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        rT  rZ  NzU deposit() requires an account_id(or accountId) parameter OR a currency code argumentz) deposit() could not find account id for )rT  r  rE  payment_methodr  )r'  rI  r  r   r'   r  r   r  r  &v2PrivatePostAccountsAccountIdDepositsr*  r  r  )	r  r:  r  r'   r  rZ  r.  r  r  s	            r	  rN   zcoinbase.depositm  s*    	&&v|[II	6L+#>??|'  3J  )J  K  K  K,,T6::I #DG.Y$Y\`$`aaa#++F33

 	
 
 >>t{{7TZ?[?[\\J ~~h33%%d+++r
  c                    |                                   |                     |dd          }|                     |ddg          }|K|t          | j        dz             |                     ||          }|t          | j        dz   |z             ||d}|                     |                     ||                    }| 	                    |di           }| 
                    |          S )a4  
        fetch information on a deposit, fiat only, for crypto transactions use fetchLedger
        :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-deposits#show-deposit
        :param str id: deposit id
        :param str [code]: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountId]: the id of the account that the funds were deposited into
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        rT  rZ  NzZ fetchDeposit() requires an account_id(or accountId) parameter OR a currency code argumentz. fetchDeposit() could not find account id for )rT  
deposit_idr  )r'  rI  r  r   r'   r  r   .v2PrivateGetAccountsAccountIdDepositsDepositIdr*  r  r  )r  r'   r:  r  rZ  r.  r  r  s           r	  fetch_depositzcoinbase.fetch_deposit  s    	&&v|[II	6L+#>??|'  3O  )O  P  P  P,,T6::I #DG.^$^ae$efff#
 
 FFt{{SZ\bGcGcddJ ~~h33%%d+++r
  c                    |                                   |                     |          }|d         st          | j        dz             |                     |dd          }|                     |d          }d|d         i}|t          | j        dz             ||d<   |                     |                     ||                    }| 	                    |d	i           }| 
                    |          S )
a  
        *futures only* closes open positions for a market
        :see: https://coinbase-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
        :param str symbol: Unified CCXT market symbol
        :param str [side]: not used by coinbase
        :param dict [params]: extra parameters specific to the coinbase api endpoint
         * @param {str}  params.clientOrderId *mandatory* the client order id of the position to close
        :param float [params.size]: the size of the position to close, optional
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r9   z3 closePosition() only supported for futures marketsr  r  r  r'   Nz3 closePosition() requires a clientOrderId parameterr  )r'  r  r   r'   rI  r  r   )v3PrivatePostBrokerageOrdersClosePositionr*  r  r  )	r  r\  r  r  r  r  r.  r  r  s	            r	  close_positionzcoinbase.close_position  s     	V$$h 	`tw)^^___**63DoVV6?33&,
  #DG.c$cddd%2!"AA$++gW]B^B^__x);R@@&&&r
  c                 $   |                                   |                     |          }d}||                     |d                   }d}|                     d||          \  }}d}|dk    r|                     |          }nbd}|                     |dd          \  }}|t          | j        dz             d|i}|                     | 	                    ||                    }| 
                    |dg           }|                     ||          S )	aU  
        fetch all open positions
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getfcmpositions
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getintxpositions
        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.portfolio]: the portfolio UUID to fetch positions for
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nr   ry   r9   rA  z fetchPositions() requires a "portfolio" value in params(eg: dbcb91e7-2bc9-515), or set.options["portfolio"]. You can get a list of portfolios with fetchPortfolios()portfolio_uuid	positions)r'  rI  r  r  !v3PrivateGetBrokerageCfmPositionsr(  r   r'   /v3PrivateGetBrokerageIntxPositionsPortfolioUuidr*  r+  parse_positions)	r  rC  r  r  r8  r  rA  r.  r  s	            r	  fetch_positionszcoinbase.fetch_positions	  s:    	%%g..[[,,F99:JFTZ[[f8==fEEHHI $ = =fFVXc d dIv '  3Z  )Z  [  [  [ )G KKDKKX_agLhLhiiHNN8["==	##Iw777r
  c                 N   |                                   |                     |          }d}|d         r]|                     |d          }|t          | j        dz             d|i}|                     |                     ||                    }nid}|                     |dd          \  }}|t          | j        dz             |d         |d	}|                     |                     ||                    }| 	                    |d
i           }	| 
                    |	|          S )aT  
        fetch data on a single open contract trade position
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getintxposition
        :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getfcmposition
        :param str symbol: unified market symbol of the market the position is held in, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.product_id]: *futures only* the product id of the position to fetch, required for futures markets only
        :param str [params.portfolio]: *perpetual/swaps only* the portfolio UUID to fetch the position for, required for perpetual/swaps markets only
        :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nr9   r  z2 fetchPosition() requires a "product_id" in paramsry   rA  z fetchPosition() requires a "portfolio" value in params(eg: dbcb91e7-2bc9-515), or set.options["portfolio"]. You can get a list of portfolios with fetchPortfolios()r'   )r\  r  position)r'  r  r  r   r'   *v3PrivateGetBrokerageCfmPositionsProductIdr*  r(  5v3PrivateGetBrokerageIntxPositionsPortfolioUuidSymbolr  parse_position)
r  r\  r  r  r  	productIdfutureRequestrA  r.  r  s
             r	  fetch_positionzcoinbase.fetch_position)  sU    	V$$( 	p((>>I '2f(fgggiM FFt{{S`bhGiGijjHHI $ = =fFVXc d dIv '  3Y  )Y  Z  Z  Z ,"+ G QQRVR]R]^egmRnRnooH>>(J;;""8V444r
  c                    |                      |dd          }|                     ||          }|                      |d          }d }|
|dk    rdnd}|                     |di           }|                      |d          }|d	k    rd
nd}|                     |di           }	|                     |di           }
|                     |
d          }|                     |di           }|                     |di           }|                     i d|d|                      |d          d|                     ||          d|                     |d          d|d|d|                     |d          d|                     |	d          dd dd d|                     |d          d|d         dd dd d |d!d d"d d d d d |                     |d#          d d |                     |d$          d d d d%          S )&Nr\  r&  r  MARGIN_TYPE_CROSSr  r  position_notionalposition_sidePOSITION_SIDE_LONGlongshortunrealized_pnlliquidation_pricer|  rl  portfolio_summaryr;  r'   r  notionalr  liquidationPrice
entryPriceunrealizedPnlrealizedPnlr   	contractsnet_sizer  	markPrice	lastPricer  hedgedr  
collateralr  )r  lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentager  initialMargininitialMarginPercentager  marginRatior  r  )r  r  r  r  safe_positionrv  )r  r  r  r  	rawMarginr  notionalObjectpositionSider  unrealizedPNLObjectliquidationPriceObjectr  
vwapObjectsummaryObjects                 r	  r  zcoinbase.parse_positionL  s   t ##Hh;;!!(F33$$X}==	
 %.2E%E%EJJ2ErJJ''/BB&*>>>vvW"nnX7GLL!%:Mr!R!R++,BGLL^^Hfb99
x1DbII!! #
H#
$""8\::#
 d&&x88#
 ((AA	#

 *#
  0#
 $**:w??#
 T--.A7KK#
 4#
 $#
 ))(J??#
 F>2#
 #
 #
 D#
  d!#
" ##
$ #'!%+/**=,GG!'+((:>>!#9#
 #
 #
   	r
  rW  r  urlc           
      `   d }|A|dz   |                     dd          z   }|                    d          }|dk    r
|d|         }|                     d          }dgd||d	z   | j        |d
}|||d<   |                     ||                     | j                  dd| j        |dd          }|S )NrF  zhttps://r&  ?r      retail_rest_api_proxyzcoinbase-cloudx   )audissnbfexpsubiaturisha256FES256)kidnoncealg)replacefindrandom_bytesr   jwtencoder   )	r  rW  r  r  r  quesPosr  r.  tokens	            r	  create_auth_tokenzcoinbase.create_auth_token  s    ?3,Z!<!<<ChhsmmG {{!G)n!!"%%+,#S=;
 
 ? GEN$++dk":":HeUYU`kp  zA  NB  NB  C  Cr
  GETc                 $   |d         }|d         dk    }|dk    }	|	rdnd}
d|
z   dz   |                      ||          z   }|                     ||                     |                    }|}|dk    r|r|d	|                     |          z   z  }| j        d
         d         |z   }|r|                     | j        d          }d }||}n| j        r!|                     d          sd| j        z   }nu|                                  | 	                                }d}|dk    r|r| 
                    |          }|}n|	s|r|d	|                     |          z   z  }| j                            d          dk    p| j                            d          }|rN| j                            d          rt!          | j        dz             |                     |||          }d|z   }nt'          | 	                                          }||z   |z   |z   }|                     |                     |          |                     | j                  t,          j                  }| j        ||dd}|"|dd}|dk    r|r| 
                    |          }||||dS )Nr   r   r   r   zapi/v3r0   r  r  r  r   r   AuthorizationFzBearer r&  zorganizations/z
-----BEGINzV apiKey should contain the name(eg: organizations/3b910e93....) and not the public keyzapplication/json)zCB-ACCESS-KEYzCB-ACCESS-SIGNzCB-ACCESS-TIMESTAMPContent-Type)r  r  )r  r  bodyr3   )implode_paramsr  extract_paramsurlencode_with_array_repeatr   r  r3   r  check_required_credentialsrW  json	urlencoder   r  r   
startswithr   r'   r  rV  hmacr  hashlibr  )r  r  r   r  r  r3   r  r/   signedr  pathPartfullPathrb  	savedPathr  authorizationauthorizationStringrW  payloadisCloudAPiKeyr  timestampStringauth	signatures                           r	  signzcoinbase.sign  s   a&Q9$$ $/884>C'$*=*=dF*K*KK		&$"5"5d";";<<	U?? JC$"B"B5"I"IIIiv&1 A	0 ,,T\?KKM"&(&3## 4D$C$CE$J$J 4&/$*&<##//111,,..U?? '#yy//"& C  C#sT^^E-B-B'BBG
 "&!1!12B!C!Cq!H sdkNdNdeqNrNr  !{--l;; T/  ;S  1S  T  T  T& !227FCHHE*3e*;''&)$,,..&9&9O*V3i?'ID $		$++d*;*;T[[=U=UW^We f fI)-*3/>(:	 G #.%8$6  U?? 0#yy//fdwOOOr
  c
                 H   |d S | j         dz   |z   }
|                     |d          }|i|                     |d          }|                     | j        d         ||
           |                     | j        d         ||
           t          |
          |                     |d          }|t          |t                    rt          |          }|dk    r|                     |d         d          }|                     |d         d	          }|S|                     | j        d         ||
           |                     | j        d         ||
           t          |
          | j
        d
         }d|vr/|s-t          | j         dz   |                     |          z             d S )NrF  r  error_descriptionr   r   errorsr   r'   r  r   r  z$ failed due to a malformed response )r'   r  r  r   r  r   r+  
isinstancer  r,  r   r  )r  r:  reasonr  r  r3   r  r  requestHeadersrequestBodyfeedback	errorCoder  r  	numErrorsadvancedTrades                   r	  handle_errorszcoinbase.handle_errors;  s   47S=4' $$Xw77	 ++H6IJJL001I9V^___001I<Yabbb)))(33&$'' 6KK	q== $ 0 0D A AI#'#3#3F1Iy#I#IL ,<<T_W=UW`bjkkk<<T_W=UWcemnnn+H555Z0(""]"*P PSWS\S\]eSfSf fgggtr
  )N)NN)b__name__
__module____qualname__r  r  r   r   r  r  r  rB  rR  rV  r[  r   r	   rd  rh  rm  r   rr  ru  r  r   r  r
   r   r  r  r  r  r   r  r  r  r   rB  r   r   rG  rF  rE  r   rT  rS  rR  rJ  r  r   r  r  r  r  r  r  r_  rj  floatr  r   r   r   r  r   r  r  r  r  r,  r*  r6  r9  rB  rE  rI  rK  rM  r  ra  rf  rh  rn  r   rs  ry  r   r  r  rN   r  r  r  r  r  r  r  r  __classcell__)r  s   @r	  r%   r%      s*       Z Z Z Z Zx
 !#  H  H  H  HD %' . .4= . . . . (* @1 @1d7m @1 @1 @1 @1D (* 05 05d7m 05 05 05 05d ')  T']    (D
 D
 D
L 8: C
 C
3 C
 C
 C
 C
J ,0dQU^` D DS D D3 D D D D$ +/TPT]_ C CC Cs C# C C C C$ BFTXgktv M M3 Mc Mad M M M M -1tRV_a { {c { {C {fjkvfw { { { { *.Dt\^ x x3 xc x xcghsct x x x x: : :]
 ]
x ]
; ]
 ]
 ]
 ]
~{ { {5 { { { {z $& - -$v, - - - - ') C C C CJ ') ; ; ; ;zZO Z Z Z Zx@ @ @ @ @D 24 +C +C +C +CZ ') V VZ V V V Vp 04B 6 6W 67 6 6 6 6 37r G G G G G GB 37r 4G 4G 4G 4G 4G 4Gl 02 4 43 4f 4 4 4 4  35 5 5c 5 5 5 58 35  c    @t t6 tV t t t tl 57 ,) ,) ,) ,)\ $& c; c;( c; c; c; c;J (,$TZ\ $ $ $C $s $ $ $ $L7 7 73 3 3n
 n
 n
 n
 n
 n
`	 ,.     48 	 	S 	 	 	 	 FJX\eg ! !s !RU ! ! ! !  RT N N N5 N N N N  gksu Q. Q.3 Q.i Q.y Q.RW Q.`c Q. Q. Q. Q.fB B B5 B B B BH	: 	: 	:	3 	3 	3H H H 37r - -s -C - - - - 04B !1 !1 !1 !1 !1 !1F `drv  @B '2 '2S '2# '2Y '2i '2Y\ '2lo '2 '2 '2 '2R 26b 9/ 9/c 9/3 9/ 9/ 9/ 9/v *.Ds[] P? P?3 P?c P? P?bfglbm P? P? P? P?d <@daenp D? D?S D? D?[^ D? D? D? D?L /3TXac Q Q Q3 Qc Qhlmrhs Q Q Q Q& 154VZce S S# SS SPS Sjnotju S S S S& 37TX\eg 
V 
VC 
Vs 
VRU 
V 
V 
V 
V 26DW[df 9K 9K# 9Kc 9KQT 9Kkoptku 9K 9K 9K 9Kv
 
 
4 
 
 
 
, 6:UW +? +?3 +?s +?# +?\`af\g +? +? +? +?Z -1tRV_a =? =?c =? =?C =? =? =? =?~ :>b (_ (_s (_3 (_Y (_ (_ (_ (_T 26b %4 %4w %4 %4 %4 %4N ?C2 V6 V6S V6% V6 V6 V6 V6p DF F; F;s F; F; F; F;P:
 :
h :
 :
 :
 :
x AC @, @,C @, @,C @, @, @, @,D 26b =, =, =,3 =, =, =, =,~ =A ' 'S '	 'PU ' ' ' '6 26b 8 8w 8 8 8 8@ 24 !5 !5S !5 !5 !5 !5FE Ev E E E EN  c s    0  b$T NP NP NP NP`& & & & & & &r
  r%   )*ccxt.base.exchanger   ccxt.abstract.coinbaser   r  ccxt.base.typesr   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     sX   ( ' ' ' ' ' . . . . . .  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) . . . . . . ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %HA HA HA HA HAx HA HA HA HA HAr
  