> ## 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

> Build trading bots, charting tools, and backtesting pipelines with CoinGecko API

> [card] [Set up your API key](https://docs.coingecko.com/docs/setting-up-your-api-key.md)

> [card] [Build faster with AI](https://docs.coingecko.com/ai-integration.md#coding-agents)

> [!NOTE]
>
> **TL;DR**\\
>
> Use [/simple/price](https://docs.coingecko.com/reference/simple-price.md) for spot prices, [/coins/\{id}/ohlc](https://docs.coingecko.com/reference/coins-id-ohlc.md) for candlestick charts, [/coins/\{id}/market\_chart/range](https://docs.coingecko.com/reference/coins-id-market-chart-range.md) for backtesting, and the onchain [OHLCV](https://docs.coingecko.com/reference/pool-ohlcv-contract-address.md) endpoints for sub-minute DEX data.

> Replace `YOUR_API_KEY` in the examples below with your actual key. [Get one here →](https://www.coingecko.com/en/api/pricing)

## CEX Trading Workflow

**1. Screen assets — /coins/markets**

Scan the market to find what to trade. Returns bulk data for ranking by volume, price change, or market cap.

> [tab] Pro API
>
> ```bash theme={null}
> curl -X GET \
>   "https://pro-api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=volume_desc&per_page=50&price_change_percentage=1h,24h,7d" \
>   -H "x-cg-pro-api-key: YOUR_API_KEY"
> ```
>
> > [Coins Markets →](https://docs.coingecko.com/reference/coins-markets.md)

> [tab] Demo API
>
> ```bash theme={null}
> curl -X GET \
>   "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=volume_desc&per_page=50&price_change_percentage=1h,24h,7d" \
>   -H "x-cg-demo-api-key: YOUR_API_KEY"
> ```
>
> > [Coins Markets →](https://docs.coingecko.com/demo/reference/coins-markets.md)

| Key param | Use |
| - | - |
| `order` | `volume_desc` surfaces the most liquid assets |
| `price_change_percentage` | `1h,24h,7d` for multi-timeframe momentum |
| `per_page` | Up to 250 per page |

**2. Monitor prices — /simple/price**

Poll spot prices for your selected assets. Minimal overhead — ideal for trading loops.

> [tab] Pro API
>
> ```bash 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"
> ```
>
> > [Simple Price →](https://docs.coingecko.com/reference/simple-price.md)

> [tab] Demo API
>
> ```bash theme={null}
> curl -X GET \
>   "https://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-demo-api-key: YOUR_API_KEY"
> ```
>
> > [Simple Price →](https://docs.coingecko.com/demo/reference/simple-price.md)

```json theme={null}
{
  "bitcoin": {
    "usd": 67432.51,
    "usd_24h_vol": 28394567890.12,
    "usd_24h_change": 2.34
  }
}
```

> [!TIP]
>
> For onchain tokens not listed on CoinGecko, use [Onchain Simple Price](https://docs.coingecko.com/reference/onchain-simple-price.md) — returns prices by contract address on any supported network.

**3. Analyze charts — /coins/\{id}/ohlc**

Fetch OHLC candles for technical analysis (RSI, MACD, Bollinger Bands, etc.).

> [tab] Pro API
>
> ```bash 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"
> ```
>
> > [Coin OHLC →](https://docs.coingecko.com/reference/coins-id-ohlc.md)

> [tab] Demo API
>
> ```bash theme={null}
> curl -X GET \
>   "https://api.coingecko.com/api/v3/coins/bitcoin/ohlc?vs_currency=usd&days=30" \
>   -H "x-cg-demo-api-key: YOUR_API_KEY"
> ```
>
> > [Coin OHLC →](https://docs.coingecko.com/demo/reference/coins-id-ohlc.md)

Response format: `[timestamp, open, high, low, close]` — timestamp is the candle **close** time.

> [!NOTE]
>
> **Auto-granularity** based on `days`:
>
> * 1–2 days → 30-min candles
> * 3–30 days → 4-hour candles
> * 31+ days → 4-day candles
>
> Paid plans can override with `interval=daily` or `interval=hourly`.

**4. Find execution venue — /coins/\{id}/tickers**

Compare trading pairs across CEXs and DEXs — bid/ask spreads, volume, and market depth.

> [tab] Pro API
>
> ```bash 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"
> ```
>
> > [Coin Tickers →](https://docs.coingecko.com/reference/coins-id-tickers.md)

> [tab] Demo API
>
> ```bash theme={null}
> curl -X GET \
>   "https://api.coingecko.com/api/v3/coins/bitcoin/tickers?exchange_ids=binance,coinbase&depth=true&order=volume_desc" \
>   -H "x-cg-demo-api-key: YOUR_API_KEY"
> ```
>
> > [Coin Tickers →](https://docs.coingecko.com/demo/reference/coins-id-tickers.md)

| Key param | Use |
| - | - |
| `exchange_ids` | Filter to exchanges you trade on |
| `depth` | Includes `cost_to_move_up_usd` / `cost_to_move_down_usd` — how much capital moves price 2% |

**5. Backtest — /coins/\{id}/ohlc/range or /market\_chart/range**

Pull historical data for a specific time window.

* **OHLC candles** for a custom range:

> [tab] Pro API
>
> ```bash 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"
> ```
>
> > [OHLC Range →](https://docs.coingecko.com/reference/coins-id-ohlc-range.md)

> [tab] Demo API
>
> `/coins/{id}/ohlc/range` is not available on the Demo API.\\
>
> [Upgrade to Pro →](https://www.coingecko.com/en/api/pricing)

* **Price + volume + market cap** for a custom range:

> [tab] Pro API
>
> ```bash 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"
> ```
>
> > [Market Chart Range →](https://docs.coingecko.com/reference/coins-id-market-chart-range.md)

> [tab] Demo API
>
> ```bash theme={null}
> curl -X GET \
>   "https://api.coingecko.com/api/v3/coins/ethereum/market_chart/range?vs_currency=usd&from=2024-01-01&to=2024-12-31" \
>   -H "x-cg-demo-api-key: YOUR_API_KEY"
> ```
>
> > [Market Chart Range →](https://docs.coingecko.com/demo/reference/coins-id-market-chart-range.md)

Both accept ISO dates and UNIX timestamps for `from`/`to`.

***

## Onchain DEX Trading

For DeFi-native strategies — pool-level OHLCV with sub-minute granularity and individual trade feeds.

**1. Pool OHLCV — sub-minute candles**

Supports `second`, `minute`, `hour`, and `day` timeframes with customizable aggregation (e.g., 5-min candles).

> [tab] Pro API
>
> ```bash 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"
> ```
>
> > [Pool OHLCV →](https://docs.coingecko.com/reference/pool-ohlcv-contract-address.md) | [Token OHLCV →](https://docs.coingecko.com/reference/token-ohlcv-token-address.md)

> [tab] Demo API
>
> ```bash theme={null}
> curl -X GET \
>   "https://api.coingecko.com/api/v3/onchain/networks/eth/pools/0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640/ohlcv/minute?aggregate=5&limit=100&currency=usd" \
>   -H "x-cg-demo-api-key: YOUR_API_KEY"
> ```
>
> > [Pool OHLCV →](https://docs.coingecko.com/demo/reference/pool-ohlcv-contract-address.md)

Response format: `[timestamp, open, high, low, close, volume]`.

| Key param | Use |
| - | - |
| `aggregate` | Combine candles — `5` for 5-min, `4` for 4-hour |
| `limit` | Up to 1000 data points |
| `before_timestamp` | Paginate backward for historical data |
| `currency` | `usd` for fiat or `token` for base-token denomination |

**2. Trade feed**

Monitor execution, analyze microstructure, or trigger alerts on large swaps.

> [tab] Pro API
>
> ```bash 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"
> ```
>
> > [Pool Trades →](https://docs.coingecko.com/reference/pool-trades-contract-address.md) | [Token Trades →](https://docs.coingecko.com/reference/token-trades-contract-address.md)

> [tab] Demo API
>
> ```bash theme={null}
> curl -X GET \
>   "https://api.coingecko.com/api/v3/onchain/networks/eth/pools/0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640/trades?trade_volume_in_usd_greater_than=10000" \
>   -H "x-cg-demo-api-key: YOUR_API_KEY"
> ```
>
> > [Pool Trades →](https://docs.coingecko.com/demo/reference/pool-trades-contract-address.md)

Use `trade_volume_in_usd_greater_than` to filter noise. On **Analyst & above**, set `trading_period` to `7d` or `30d` to look further back than the 24-hour default, and page through the results with `cursor`.


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