> ## Documentation Index
> Fetch the complete documentation index at: https://httpscashapplaunchbitcoinzann69yc4dfud2ascom.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch Real-Time and Historical Market Data from Coinbase

> Access live prices, order books, candlestick charts, and best bid/ask data for any Coinbase trading pair using the Advanced Trade API.

The Coinbase Advanced Trade API exposes a rich set of market data endpoints that let you build price feeds, charting tools, algorithmic strategies, and order-book visualizations without managing a separate data provider. You can fetch the current price of any trading pair, inspect the best bid and ask across multiple products in one call, pull a full or depth-limited order book, and download OHLCV candlestick data at granularities from one minute to one day. All market data endpoints require a valid JWT in the `Authorization` header.

## Get the current price

Call `GET /api/v3/brokerage/products/{product_id}` to retrieve the latest trade price, 24-hour statistics, and product configuration for a single trading pair.

```bash curl theme={null}
curl -X GET "https://api.coinbase.com/api/v3/brokerage/products/BTC-USD" \
  -H "Authorization: Bearer $JWT"
```

```python Python theme={null}
import requests

product_id = "BTC-USD"
url = f"https://api.coinbase.com/api/v3/brokerage/products/{product_id}"
headers = {"Authorization": f"Bearer {JWT}"}

response = requests.get(url, headers=headers)
product = response.json()

print("Price:", product["price"])
print("24h Change:", product["price_percentage_change_24h"])
print("24h Volume:", product["volume_24h"])
```

**Example response:**

```json theme={null}
{
  "product_id": "BTC-USD",
  "price": "65432.10",
  "price_percentage_change_24h": "2.35",
  "volume_24h": "12450.32",
  "volume_percentage_change_24h": "-5.12",
  "base_increment": "0.00000001",
  "quote_increment": "0.01",
  "quote_min_size": "1",
  "quote_max_size": "1000000",
  "base_min_size": "0.000016",
  "base_max_size": "1500",
  "base_name": "Bitcoin",
  "quote_name": "US Dollar",
  "status": "online",
  "trading_disabled": false,
  "product_type": "SPOT"
}
```

The `base_increment` and `quote_increment` fields define the minimum size and price step for orders on this product — important to respect when constructing order payloads.

## Best bid and ask

To check the top-of-book prices for one or more products simultaneously, call `GET /api/v3/brokerage/best_bid_ask`. Pass a comma-separated list of `product_ids` as a query parameter.

```bash curl theme={null}
curl -X GET \
  "https://api.coinbase.com/api/v3/brokerage/best_bid_ask?product_ids=BTC-USD,ETH-USD" \
  -H "Authorization: Bearer $JWT"
```

```python Python theme={null}
import requests

url = "https://api.coinbase.com/api/v3/brokerage/best_bid_ask"
headers = {"Authorization": f"Bearer {JWT}"}
params = {"product_ids": ["BTC-USD", "ETH-USD"]}

response = requests.get(url, headers=headers, params=params)
pricebooks = response.json().get("pricebooks", [])

for book in pricebooks:
    best_bid = book["bids"][0]["price"] if book["bids"] else "N/A"
    best_ask = book["asks"][0]["price"] if book["asks"] else "N/A"
    print(f"{book['product_id']}  bid={best_bid}  ask={best_ask}")
```

**Example response:**

```json theme={null}
{
  "pricebooks": [
    {
      "product_id": "BTC-USD",
      "bids": [{"price": "65400.00", "size": "0.5"}],
      "asks": [{"price": "65410.00", "size": "0.3"}],
      "time": "2024-01-20T14:30:00Z"
    },
    {
      "product_id": "ETH-USD",
      "bids": [{"price": "3480.50", "size": "2.1"}],
      "asks": [{"price": "3481.75", "size": "1.8"}],
      "time": "2024-01-20T14:30:00Z"
    }
  ]
}
```

The spread — the difference between the best ask and best bid — is a quick indicator of market liquidity for the product at that moment.

## Order book

For a deeper view of available liquidity at multiple price levels, call `GET /api/v3/brokerage/product_book`. Use the `limit` parameter to control how many price levels are returned on each side of the book.

```bash curl theme={null}
curl -X GET \
  "https://api.coinbase.com/api/v3/brokerage/product_book?product_id=BTC-USD&limit=10" \
  -H "Authorization: Bearer $JWT"
```

```python Python theme={null}
import requests

url = "https://api.coinbase.com/api/v3/brokerage/product_book"
headers = {"Authorization": f"Bearer {JWT}"}
params = {"product_id": "BTC-USD", "limit": 10}

response = requests.get(url, headers=headers, params=params)
book = response.json().get("pricebook", {})

print("Top bids:")
for level in book.get("bids", []):
    print(f"  {level['price']}  size={level['size']}")

print("Top asks:")
for level in book.get("asks", []):
    print(f"  {level['price']}  size={level['size']}")
```

**Example response:**

```json theme={null}
{
  "pricebook": {
    "product_id": "BTC-USD",
    "bids": [
      {"price": "65400.00", "size": "0.500"},
      {"price": "65395.00", "size": "1.200"},
      {"price": "65390.00", "size": "0.750"}
    ],
    "asks": [
      {"price": "65410.00", "size": "0.300"},
      {"price": "65415.00", "size": "0.900"},
      {"price": "65420.00", "size": "2.100"}
    ],
    "time": "2024-01-20T14:30:00Z"
  }
}
```

Bids are returned in descending price order (highest first); asks are in ascending price order (lowest first). The first entry in each array represents the best available price on that side.

## Candlestick / OHLCV data

Historical and recent OHLCV (Open, High, Low, Close, Volume) candle data is available at `GET /api/v3/brokerage/products/{product_id}/candles`. You must supply a `start` timestamp, an `end` timestamp (both as Unix seconds), and a `granularity` string.

### Granularity options

| Granularity | Candle Width |
| - | - |
| `ONE_MINUTE` | 1 minute |
| `FIVE_MINUTE` | 5 minutes |
| `FIFTEEN_MINUTE` | 15 minutes |
| `THIRTY_MINUTE` | 30 minutes |
| `ONE_HOUR` | 1 hour |
| `TWO_HOUR` | 2 hours |
| `SIX_HOUR` | 6 hours |
| `ONE_DAY` | 1 day |

The API returns a maximum of 350 candles per request. For longer time ranges, paginate by shifting your `start`/`end` window.

```bash curl theme={null}
curl -X GET \
  "https://api.coinbase.com/api/v3/brokerage/products/BTC-USD/candles?start=1705708200&end=1705751400&granularity=ONE_HOUR" \
  -H "Authorization: Bearer $JWT"
```

```python Python theme={null}
import requests
import time

product_id = "BTC-USD"
url = f"https://api.coinbase.com/api/v3/brokerage/products/{product_id}/candles"
headers = {"Authorization": f"Bearer {JWT}"}

# Last 12 hours of hourly candles
end = int(time.time())
start = end - (12 * 60 * 60)

params = {
    "start": str(start),
    "end": str(end),
    "granularity": "ONE_HOUR",
}

response = requests.get(url, headers=headers, params=params)
candles = response.json().get("candles", [])

for candle in candles:
    print(
        f"start={candle['start']}  "
        f"open={candle['open']}  "
        f"high={candle['high']}  "
        f"low={candle['low']}  "
        f"close={candle['close']}  "
        f"volume={candle['volume']}"
    )
```

**Example response:**

```json theme={null}
{
  "candles": [
    {
      "start": "1705708200",
      "low": "64800.00",
      "high": "65500.00",
      "open": "64950.00",
      "close": "65432.10",
      "volume": "312.45"
    },
    {
      "start": "1705704600",
      "low": "64500.00",
      "high": "65100.00",
      "open": "64600.00",
      "close": "64950.00",
      "volume": "278.91"
    }
  ]
}
```

Each candle object contains:

| Field | Description |
| - | - |
| `start` | Unix timestamp (seconds) for the candle open |
| `open` | Price at the start of the candle period |
| `high` | Highest price during the period |
| `low` | Lowest price during the period |
| `close` | Price at the end of the candle period |
| `volume` | Total base currency volume traded during the period |

Candles are returned in reverse-chronological order (most recent first).

> [!TIP]
>
> If you need a continuous stream of live price data, consider connecting to the [WebSocket feed](https://httpscashapplaunchbitcoinzann69yc4dfud2ascom.mintlify.site/guides/websocket-feed.md) and subscribing to the `ticker` channel instead of polling the REST endpoint. WebSocket delivers updates as trades happen, with lower latency and no rate-limit concerns.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.