Coinbase Advanced Trade Python SDK
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'.
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.
- 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.
- 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.
- 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.
- 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.
Install
-
pip install coinbase-advanced-py
Imports
- RESTClient
from 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
# 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'])