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

# Trading

> Power your trading strategies with real-time prices, OHLC candles, historical tick data, and cross-exchange execution insights from CoinGecko API.

<Note>
  ### TL;DR

  Use [/simple/price](/reference/simple-price) for low-latency spot prices, [/coins/\{id}/ohlc](/reference/coins-id-ohlc) for candlestick charts, [/coins/\{id}/market\_chart/range](/reference/coins-id-market-chart-range) for backtesting, and the onchain [/ohlcv/\{timeframe}](/reference/pool-ohlcv-contract-address) endpoints for second-level granularity on DEX pools.
</Note>

<br />

**Real-time market data** is the backbone of any trading system — whether you're building an **automated bot**, a **custom charting interface**, or **backtesting** a strategy against **historical data**.

This guide walks you through the CoinGecko API endpoints that matter most for trading workflows, and ties them together into a [complete workflow](#putting-it-all-together) at the end:

* **Fetching real-time prices** for execution logic and portfolio valuation
* **Pulling OHLC candle data** at multiple granularities for technical analysis
* **Accessing historical market data** to backtest and validate strategies
* **Tracking onchain trades** and liquidity for DeFi execution

Estimated reading time: **10 minutes**

<Tip>
  **Want to get started even faster?**<br />Copy the contents of this page from [trading.md](https://docs.coingecko.com/docs/trading.md) and paste it directly into your AI tool for instant context.
</Tip>

<Card title="Navigate the API faster with AI" icon="sparkles" href="https://docs.coingecko.com/skills">
  Install the CoinGecko SKILL to give your AI coding agent built-in knowledge of every endpoint, parameter, and workflow. Setup takes less than 3 minutes.
</Card>

***

## Endpoint Overview

| Endpoint                                                                         | What It Gives You                                                      | Best For                                               |
| -------------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ------------------------------------------------------ |
| [/simple/price](/reference/simple-price)                                         | Real-time spot prices with optional market cap, volume, and 24h change | Low-latency price feeds for execution logic            |
| [/coins/markets](/reference/coins-markets)                                       | Bulk market data for multiple coins in a single call                   | Screening and ranking assets by volume or price change |
| [/coins/\{id}/ohlc](/reference/coins-id-ohlc)                                    | Open-High-Low-Close candles                                            | Technical analysis and candlestick charting            |
| [/coins/\{id}/ohlc/range](/reference/coins-id-ohlc-range)                        | OHLC candles for a custom date range                                   | Backtesting with precise time windows                  |
| [/coins/\{id}/market\_chart/range](/reference/coins-id-market-chart-range)       | Price, market cap, and volume over a custom date range                 | Historical backtesting and trend analysis              |
| [/coins/\{id}/tickers](/reference/coins-id-tickers)                              | Trading pairs across CEXs and DEXs with bid/ask and volume             | Finding best execution venue                           |
| [/onchain/networks/../pools/../ohlcv/..](/reference/pool-ohlcv-contract-address) | Pool-level OHLCV with minute and second granularity                    | High-frequency DEX trading strategies                  |
| [/onchain/networks/../pools/../trades](/reference/pool-trades-contract-address)  | Last 300 trades in the past 24 hours for a pool                        | Execution monitoring and market microstructure         |

<Callout icon="key" color="#FFC107" iconType="regular">
  Replace `YOUR_API_KEY` in the examples below with your actual CoinGecko API key.<br />Don't have one yet? [Get your API key here](https://www.coingecko.com/en/api/pricing).
</Callout>

***

## Real-Time Prices — `/simple/price`

*🔗 More endpoint details [here](/reference/simple-price)*

The fastest way to get current prices. This endpoint supports querying multiple coins in a single request and returns data with minimal overhead — ideal for polling in a trading loop.

**Example request:**

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://pro-api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,solana&vs_currencies=usd&include_24hr_vol=true&include_24hr_change=true" \
    -H "x-cg-pro-api-key: YOUR_API_KEY"
  ```
</CodeGroup>

**Key parameters:**

| Parameter             | Why It Matters                                                              |
| --------------------- | --------------------------------------------------------------------------- |
| `ids` / `symbols`     | Query by CoinGecko ID or ticker symbol — use whichever fits your data model |
| `vs_currencies`       | Get prices in multiple fiat or crypto currencies simultaneously             |
| `include_24hr_vol`    | Essential for volume-weighted execution decisions                           |
| `include_24hr_change` | Useful for momentum-based strategies                                        |
| `precision`           | Control decimal precision to match your system's requirements               |

**Response highlights:**

<CodeGroup>
  ```json JSON theme={null}
  {
    "bitcoin": {
      "usd": 67432.51,
      "usd_24h_vol": 28394567890.12,
      "usd_24h_change": 2.34567
    },
    "ethereum": {
      "usd": 3456.78,
      "usd_24h_vol": 15234567890.45,
      "usd_24h_change": 1.23456
    }
  }
  ```
</CodeGroup>

<Tip>
  For onchain tokens not listed on CoinGecko, use the [Onchain Simple Price](/reference/onchain-simple-price) endpoint instead — it returns real-time prices by contract address across any supported network.
</Tip>

***

## Market Screening — `/coins/markets`

*🔗 More endpoint details [here](/reference/coins-markets)*

When you need to scan across many assets at once — for example, to rank coins by 24h volume or identify top movers — this endpoint returns rich market data in bulk.

**Example request:**

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://pro-api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=volume_desc&per_page=50&page=1&price_change_percentage=1h,24h,7d" \
    -H "x-cg-pro-api-key: YOUR_API_KEY"
  ```
</CodeGroup>

**Key parameters:**

| Parameter                 | Why It Matters                                                  |
| ------------------------- | --------------------------------------------------------------- |
| `order`                   | Sort by `volume_desc` to surface the most liquid assets first   |
| `price_change_percentage` | Include `1h,24h,7d` to spot momentum across multiple timeframes |
| `per_page`                | Up to 250 results per page — reduces the number of calls needed |

**Response highlights:**

<CodeGroup>
  ```json JSON theme={null}
  {
    "id": "bitcoin",
    "symbol": "btc",
    "current_price": 67432.51,
    "market_cap": 1326789012345,
    "total_volume": 28394567890,
    "price_change_percentage_1h_in_currency": 0.12,
    "price_change_percentage_24h_in_currency": 2.34,
    "price_change_percentage_7d_in_currency": 5.67,
    "high_24h": 68100.00,
    "low_24h": 65800.00
  }
  ```
</CodeGroup>

***

## OHLC Candle Data

### `/coins/{id}/ohlc`

*🔗 More endpoint details [here](/reference/coins-id-ohlc)*

Returns Open-High-Low-Close candle data — the foundation for candlestick charts and most technical indicators (RSI, MACD, Bollinger Bands, etc.).

**Example request:**

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://pro-api.coingecko.com/api/v3/coins/bitcoin/ohlc?vs_currency=usd&days=30" \
    -H "x-cg-pro-api-key: YOUR_API_KEY"
  ```
</CodeGroup>

**Response format:**

<CodeGroup>
  ```json JSON theme={null}
  [
    [1709424000000, 62345.12, 62890.45, 62100.00, 62567.89],
    [1709438400000, 62567.89, 63100.00, 62400.00, 62890.12]
  ]
  ```
</CodeGroup>

Each array entry is `[timestamp, open, high, low, close]`.<br />The timestamp marks the **close** time of the candle.

<Note>
  **Candle granularity is automatic** based on the `days` parameter:

  * **1-2 days:** 30-minute candles
  * **3-30 days:** 4-hour candles
  * **31+ days:** 4-day candles

  Paid plan subscribers can override this with `interval=daily` or `interval=hourly`:

  * `daily` works for 1, 7, 14, 30, 90, and 180 days
  * `hourly` works for 1, 7, 14, 30, and 90 days
</Note>

### `/coins/{id}/ohlc/range`

*🔗 More endpoint details [here](/reference/coins-id-ohlc-range)*

When you need OHLC data for a specific time window — perfect for backtesting a strategy against a defined period.

**Example request:**

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://pro-api.coingecko.com/api/v3/coins/bitcoin/ohlc/range?vs_currency=usd&from=2024-01-01&to=2024-06-30&interval=daily" \
    -H "x-cg-pro-api-key: YOUR_API_KEY"
  ```
</CodeGroup>

The `from` and `to` parameters accept both ISO date strings and UNIX timestamps, giving you flexibility in how you define your backtest window.

***

## Historical Data for Backtesting — `/coins/{id}/market_chart/range`

*🔗 More endpoint details [here](/reference/coins-id-market-chart-range)*

Returns price, market cap, and total volume over a custom date range — ideal when your strategy depends on more than just OHLC (e.g., volume-weighted signals or market cap thresholds).

**Example request:**

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://pro-api.coingecko.com/api/v3/coins/ethereum/market_chart/range?vs_currency=usd&from=2024-01-01&to=2024-12-31" \
    -H "x-cg-pro-api-key: YOUR_API_KEY"
  ```
</CodeGroup>

**Response highlights:**

<CodeGroup>
  ```json JSON theme={null}
  {
    "prices": [
      [1704067200000, 2282.51],
      [1704153600000, 2356.78]
    ],
    "market_caps": [
      [1704067200000, 274256789012],
      [1704153600000, 283156789012]
    ],
    "total_volumes": [
      [1704067200000, 8234567890],
      [1704153600000, 9123456789]
    ]
  }
  ```
</CodeGroup>

<Note>
  Data granularity is automatic based on the date range. Leave the `interval` parameter empty for auto granularity, or specify `daily` or `hourly` for consistent data points.
</Note>

***

## Cross-Exchange Execution — `/coins/{id}/tickers`

*🔗 More endpoint details [here](/reference/coins-id-tickers)*

Shows where a coin is traded and at what price — across both centralized and decentralized exchanges. This is invaluable for finding the best execution venue or identifying arbitrage opportunities.

**Example request:**

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://pro-api.coingecko.com/api/v3/coins/bitcoin/tickers?exchange_ids=binance,coinbase&depth=true&order=volume_desc" \
    -H "x-cg-pro-api-key: YOUR_API_KEY"
  ```
</CodeGroup>

**Key parameters:**

| Parameter      | Why It Matters                                                                      |
| -------------- | ----------------------------------------------------------------------------------- |
| `exchange_ids` | Filter to specific exchanges you actually trade on                                  |
| `depth`        | Includes cost-to-move-price (2% bid/ask spread metrics) — critical for large orders |
| `order`        | Sort by `volume_desc` to prioritize the most liquid pairs                           |

**Response highlights:**

<CodeGroup>
  ```json JSON theme={null}
  {
    "tickers": [
      {
        "base": "BTC",
        "target": "USDT",
        "market": {
          "name": "Binance",
          "identifier": "binance"
        },
        "last": 67432.51,
        "volume": 12345.67,
        "bid_ask_spread_percentage": 0.01,
        "cost_to_move_up_usd": 523456.78,
        "cost_to_move_down_usd": 498765.43,
        "trust_score": "green"
      }
    ]
  }
  ```
</CodeGroup>

The `cost_to_move_up_usd` and `cost_to_move_down_usd` fields tell you how much capital it takes to move the price by 2% in either direction — a direct measure of market depth.

***

## Onchain DEX Trading

For DeFi-native strategies, the onchain endpoints provide granular, pool-level data that you won't find in traditional market data feeds.

### Pool OHLCV with Sub-Minute Granularity — `/onchain/networks/../pools/../ohlcv/..`

*🔗 More endpoint details [here](/reference/pool-ohlcv-contract-address)*

The [Pool OHLCV](/reference/pool-ohlcv-contract-address) and [Token OHLCV](/reference/token-ohlcv-token-address) endpoints support `day`, `hour`, `minute`, and `second` timeframes — with customizable aggregation periods (e.g., 5-minute or 15-minute candles).

**Example request** (5-minute candles for a Uniswap V3 ETH/USDC pool):

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://pro-api.coingecko.com/api/v3/onchain/networks/eth/pools/0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640/ohlcv/minute?aggregate=5&limit=100&currency=usd" \
    -H "x-cg-pro-api-key: YOUR_API_KEY"
  ```
</CodeGroup>

**Key parameters:**

| Parameter          | Why It Matters                                                           |
| ------------------ | ------------------------------------------------------------------------ |
| `timeframe`        | Choose `second`, `minute`, `hour`, or `day`                              |
| `aggregate`        | Combine candles (e.g., `5` for 5-minute candles, `4` for 4-hour candles) |
| `limit`            | Up to 1000 data points per request                                       |
| `before_timestamp` | Paginate backward in time for historical data                            |
| `currency`         | `usd` for fiat-denominated or `token` for base-token denomination        |

**Response highlights:**

<CodeGroup>
  ```json JSON theme={null}
  {
    "data": {
      "attributes": {
        "ohlcv_list": [
          [1709424300, 3456.78, 3462.10, 3450.00, 3458.90, 1234567.89]
        ]
      }
    }
  }
  ```
</CodeGroup>

Each entry is `[timestamp, open, high, low, close, volume]`.

### Onchain Trade Feed — `/onchain/networks/../pools/../trades`

*🔗 More endpoint details [here](/reference/pool-trades-contract-address)*

The [Pool Trades](/reference/pool-trades-contract-address) endpoint returns the last 300 trades in the past 24 hours for a specific pool — useful for monitoring execution, analyzing market microstructure, or triggering alerts on large swaps.

**Example request:**

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://pro-api.coingecko.com/api/v3/onchain/networks/eth/pools/0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640/trades?trade_volume_in_usd_greater_than=10000" \
    -H "x-cg-pro-api-key: YOUR_API_KEY"
  ```
</CodeGroup>

**Key parameters:**

| Parameter                          | Why It Matters                                          |
| ---------------------------------- | ------------------------------------------------------- |
| `trade_volume_in_usd_greater_than` | Filter out noise — only see trades above your threshold |

**Response highlights:**

<CodeGroup>
  ```json JSON theme={null}
  {
    "data": [
      {
        "attributes": {
          "block_number": 19345678,
          "block_timestamp": "2024-03-15T10:30:00Z",
          "kind": "buy",
          "volume_in_usd": "52345.67",
          "from_token_amount": "15.234",
          "to_token_amount": "52345.67",
          "price_from_in_usd": "3437.12",
          "tx_hash": "0xabc...def"
        }
      }
    ]
  }
  ```
</CodeGroup>

<Tip>
  Use the [Token Trades](/reference/token-trades-contract-address) endpoint to see trades across **all pools** for a given token, rather than a single pool.
</Tip>

***

## Putting It All Together

Here's how these endpoints fit into a typical trading workflow:

1. **Screen and select assets** — Use `/coins/markets` to rank by volume and momentum
2. **Monitor real-time prices** — Poll `/simple/price` for low-latency price updates
3. **Analyze charts** — Fetch `/coins/{id}/ohlc` for technical analysis
4. **Find execution venues** — Query `/coins/{id}/tickers` with `depth=true` for best spread and liquidity
5. **Backtest strategies** — Pull historical data from `/coins/{id}/ohlc/range` or `/coins/{id}/market_chart/range`
6. **Trade onchain** — Use onchain OHLCV for sub-minute signals and the trades endpoint for execution monitoring

<br />

<Card title="Integrate with CoinGecko MCP Server" icon="server" href="https://docs.coingecko.com/docs/mcp-server">
  Connect your AI agent directly to CoinGecko's API using our MCP server — enabling real-time crypto data queries from tools like Claude Desktop, Cursor, and more.
</Card>

***

Have feedback or need help? Reach out to `eason.lim@coingecko[dot]com`


Built with [Mintlify](https://mintlify.com).