Coinbase Advanced Trade Python SDK
raw JSON → 1.8.2 verified Tue May 12 auth: no python install: verified quickstart: verified
Official Coinbase Advanced Trade API Python SDK. Current version: 1.8.2 (Mar 2026). TWO deprecated packages to avoid: 'coinbase' (old Coinbase Commerce SDK, EOL) and 'cbpro' (Coinbase Pro, discontinued). The correct package is 'coinbase-advanced-py'. Uses CDP (Coinbase Developer Platform) API keys with EC private key format — NOT the old HMAC API key format. Import is 'from coinbase.rest import RESTClient'.
pip install coinbase-advanced-py Common errors
error ModuleNotFoundError: No module named 'coinbase_advanced' ↓
cause This error occurs when attempting to import a module named `coinbase_advanced`, which is not the correct top-level package for the official `coinbase-advanced-py` SDK.
fix
Ensure you have installed the correct package (
pip install coinbase-advanced-py) and use the correct import statements, such as from coinbase.rest import RESTClient for REST operations or from coinbase.websocket import WSClient for WebSocket operations. error 401 Unauthorized ↓
cause Authentication failed, most commonly due to an incorrect CDP API key, an improperly formatted EC private key (API secret), an expired JWT token, or missing/incorrect authentication headers.
fix
Verify that your API key ID (
organizations/{org_id}/apiKeys/{key_id}) and API secret (the full multi-line EC private key string including -----BEGIN EC PRIVATE KEY----- and -----END EC PRIVATE KEY-----) are correct and properly configured. Ensure your JWT token is valid and not expired. error 403 Forbidden / Permission denied ↓
cause The API key being used lacks the necessary permissions to perform the requested action on the Coinbase Advanced Trade platform.
fix
Navigate to the Coinbase Developer Platform, review the permissions associated with your API key, and ensure that they cover the specific actions you are attempting to execute (e.g., 'trade', 'wallet:accounts:read', 'wallet:deposits:create').
error Invalid request (HTTP 400) ↓
cause The API request is malformed, contains invalid data, or is missing required parameters for the specific endpoint being called.
fix
Carefully review the Coinbase Advanced Trade API documentation for the endpoint you are using to ensure all required fields and parameters are present, correctly formatted, and contain valid values, paying attention to request body schema, query parameters, path parameters, and headers.
Warnings
breaking Package name is 'coinbase-advanced-py' but import is 'from coinbase.rest import RESTClient'. The 'coinbase' PyPI package is a completely different old SDK (Coinbase Commerce). Do not confuse them. ↓
fix pip install coinbase-advanced-py; from coinbase.rest import RESTClient
breaking Coinbase Pro (cbpro) discontinued. All LLM and tutorial code using cbpro or the old Coinbase Pro API is broken. Migrate to coinbase-advanced-py. ↓
fix pip install coinbase-advanced-py. Migration guide at docs.cdp.coinbase.com
breaking CDP API keys use EC private key format (PEM). Old HMAC-based API keys (key + secret string) are not compatible with coinbase-advanced-py. Must generate new CDP keys. ↓
fix Generate CDP API key from developer.coinbase.com — downloads a JSON file with name and privateKey fields.
gotcha client_order_id must be unique per order. Setting to empty string '' auto-generates a UUID. Reusing the same client_order_id for different orders causes idempotent rejection. ↓
fix Use client_order_id='' for auto-generation, or generate your own UUID.
gotcha quote_size (in USD) vs base_size (in BTC) for market orders. market_order_buy uses quote_size to buy X dollars of crypto. market_order_sell uses base_size to sell X units of crypto. ↓
fix Buy $10 of BTC: quote_size='10'. Sell 0.001 BTC: base_size='0.001'.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.69s 39.3M
3.10 slim (glibc) - - 0.50s 40M
3.11 alpine (musl) - - 0.91s 42.0M
3.11 slim (glibc) - - 0.73s 42M
3.12 alpine (musl) - - 0.79s 33.6M
3.12 slim (glibc) - - 0.80s 34M
3.13 alpine (musl) - - 0.78s 33.2M
3.13 slim (glibc) - - 0.76s 34M
3.9 alpine (musl) - - 0.63s 39.3M
3.9 slim (glibc) - - 0.58s 40M
Imports
- RESTClient wrong
# Wrong: old coinbase package from coinbase.wallet.client import Client client = Client(api_key, api_secret) # old Commerce SDK # Wrong: cbpro (Coinbase Pro — discontinued) import cbpro auth_client = cbpro.AuthenticatedClient(key, secret, passphrase)correctfrom coinbase.rest import RESTClient import os # CDP API key format — EC private key client = RESTClient( api_key='organizations/{org_id}/apiKeys/{key_id}', api_secret='-----BEGIN EC PRIVATE KEY-----\nYOUR KEY\n-----END EC PRIVATE KEY-----\n' ) # Or from key file downloaded from Coinbase CDP dashboard client = RESTClient(key_file='path/to/cdp_api_key.json') # List accounts accounts = client.get_accounts() print(accounts.to_dict()) # Place market buy order order = client.market_order_buy( client_order_id='', # empty string = auto-generate product_id='BTC-USD', quote_size='10' # $10 worth of BTC )
Quickstart verified last tested: 2026-04-23
# pip install coinbase-advanced-py
from coinbase.rest import RESTClient
# From CDP dashboard: Advanced Trade API key
client = RESTClient(key_file='cdp_api_key.json')
# Get accounts
accounts = client.get_accounts()
for acct in accounts['accounts']:
print(acct['name'], acct['available_balance']['value'])
# Get BTC-USD product info
product = client.get_product(product_id='BTC-USD')
print(product['price'])
# Place market buy ($10 of BTC)
order = client.market_order_buy(
client_order_id='', # auto-generate
product_id='BTC-USD',
quote_size='10'
)
print(order['success'])