Skip to main content
Coinbase Advanced Trade is a crypto exchange with deep liquidity across hundreds of trading pairs. Horizon connects to Coinbase for spot crypto trading and cross-asset strategies alongside prediction markets.

Quick Setup

hz.run(
    name="crypto_mm",
    exchange=hz.Coinbase(api_key="...", api_secret="..."),
    mode="live",
    ...
)

Credentials

hz.Coinbase(api_key="organizations/...", api_secret="-----BEGIN EC...")

Coinbase Configuration

@dataclass
class Coinbase:
    api_key: str | None = None
    api_secret: str | None = None
    api_url: str = "https://api.coinbase.com/api/v3/brokerage"
FieldDefaultDescription
api_keyNoneCoinbase API key (env: COINBASE_API_KEY)
api_secretNoneCoinbase API secret (env: COINBASE_API_SECRET)
api_urlhttps://api.coinbase.com/api/v3/brokerageOverride API base URL

Authentication

Coinbase uses HMAC-SHA256 signature auth. Three headers are sent on every request:
  • CB-ACCESS-KEY: {api_key}
  • CB-ACCESS-SIGN: HMAC-SHA256(timestamp + method + path + body)
  • CB-ACCESS-TIMESTAMP: {unix_timestamp}

Market Data Feed

Real-time crypto ticker via WebSocket:
hz.run(
    feeds={
        "btc": hz.CoinbaseFeed(product_ids=["BTC-USD"]),
        "eth": hz.CoinbaseFeed(product_ids=["ETH-USD", "SOL-USD"]),
    },
    ...
)
The feed connects to wss://advanced-trade-ws.coinbase.com and subscribes to the ticker channel with authenticated messages. Each product gets its own snapshot entry keyed by {feed_name}:{PRODUCT_ID} (e.g., btc:BTC-USD), plus a feed-level entry with the latest update.
FieldTypeDefaultDescription
product_idslist[str]requiredTrading pairs to subscribe (e.g., ["BTC-USD", "ETH-USD"])
api_keystrNoneOverride API key (defaults to env vars)
api_secretstrNoneOverride API secret (defaults to env vars)

Symbol Mapping

Coinbase uses product IDs in BASE-QUOTE format:
market = hz.Market(id="BTC-USD", name="Bitcoin / USD")
Horizon FieldCoinbase FieldNotes
OrderRequest.market_idproduct_ide.g., “BTC-USD”, “ETH-USD”
OrderRequest.order_sideside"BUY" or "SELL"
OrderRequest.pricelimit_priceLimit order price
OrderRequest.sizebase_sizeBase currency amount
Coinbase uses Side.Long for all positions. Prediction market concepts like Side.Yes / Side.No do not apply to crypto orders.

Multi-Exchange

Use Coinbase alongside prediction markets for crypto-correlated hedging:
hz.run(
    name="crypto_hedge",
    exchange=[
        hz.Polymarket(),    # prediction market
        hz.Coinbase(),      # crypto hedge
    ],
    feeds={
        "btc_pred": hz.PolymarketBook("will-btc-hit-150k"),
        "btc_spot": hz.CoinbaseFeed(product_ids=["BTC-USD"]),
    },
    pipeline=[my_strategy],
)

Getting API Keys

  1. Sign in at coinbase.com/advanced-trade
  2. Go to Settings > API
  3. Create a new API key with Trade permissions
  4. Save both the API key and secret securely