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

<CardGroup cols={2}>
  <Card title="Set up your API key" icon="key" href="/docs/setting-up-your-api-key" horizontal arrow="true" />

  <Card title="Build faster with AI" icon="robot" href="/ai-integration#coding-agents" horizontal arrow="true" />
</CardGroup>

<Note>
  **TL;DR**<br />

  Use [/simple/price](/reference/simple-price) for 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](/reference/pool-ohlcv-contract-address) endpoints for sub-minute DEX data.
</Note>

> 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

<Steps>
  <Step title="Screen assets — /coins/markets">
    Scan the market to find what to trade. Returns bulk data for ranking by volume, price change, or market cap.

    <Tabs>
      <Tab title="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 →](/reference/coins-markets)
      </Tab>

      <Tab title="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 →](/demo/reference/coins-markets)
      </Tab>
    </Tabs>

    | 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                            |
  </Step>

  <Step title="Monitor prices — /simple/price">
    Poll spot prices for your selected assets. Minimal overhead — ideal for trading loops.

    <Tabs>
      <Tab title="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 →](/reference/simple-price)
      </Tab>

      <Tab title="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 →](/demo/reference/simple-price)
      </Tab>
    </Tabs>

    ```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](/reference/onchain-simple-price) — returns prices by contract address on any supported network.
    </Tip>
  </Step>

  <Step title="Analyze charts — /coins/{id}/ohlc">
    Fetch OHLC candles for technical analysis (RSI, MACD, Bollinger Bands, etc.).

    <Tabs>
      <Tab title="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 →](/reference/coins-id-ohlc)
      </Tab>

      <Tab title="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 →](/demo/reference/coins-id-ohlc)
      </Tab>
    </Tabs>

    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`.
    </Note>
  </Step>

  <Step title="Find execution venue — /coins/{id}/tickers">
    Compare trading pairs across CEXs and DEXs — bid/ask spreads, volume, and market depth.

    <Tabs>
      <Tab title="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 →](/reference/coins-id-tickers)
      </Tab>

      <Tab title="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 →](/demo/reference/coins-id-tickers)
      </Tab>
    </Tabs>

    | 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% |
  </Step>

  <Step title="Backtest — /coins/{id}/ohlc/range or /market_chart/range">
    Pull historical data for a specific time window.

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

    <Tabs>
      <Tab title="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 →](/reference/coins-id-ohlc-range)
      </Tab>

      <Tab title="Demo API">
        <Callout icon="key" color="#FFC107" iconType="regular">
          `/coins/{id}/ohlc/range` is not available on the Demo API.<br />
          [Upgrade to Pro →](https://www.coingecko.com/en/api/pricing)
        </Callout>
      </Tab>
    </Tabs>

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

    <Tabs>
      <Tab title="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 →](/reference/coins-id-market-chart-range)
      </Tab>

      <Tab title="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 →](/demo/reference/coins-id-market-chart-range)
      </Tab>
    </Tabs>

    Both accept ISO dates and UNIX timestamps for `from`/`to`.
  </Step>
</Steps>

***

## Onchain DEX Trading

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

<Steps>
  <Step title="Pool OHLCV — sub-minute candles">
    Supports `second`, `minute`, `hour`, and `day` timeframes with customizable aggregation (e.g., 5-min candles).

    <Tabs>
      <Tab title="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 →](/reference/pool-ohlcv-contract-address) | [Token OHLCV →](/reference/token-ohlcv-token-address)
      </Tab>

      <Tab title="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 →](/demo/reference/pool-ohlcv-contract-address) | [Token OHLCV →](/demo/reference/token-ohlcv-token-address)
      </Tab>
    </Tabs>

    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 |
  </Step>

  <Step title="Trade feed — last 300 trades">
    Monitor execution, analyze microstructure, or trigger alerts on large swaps.

    <Tabs>
      <Tab title="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 →](/reference/pool-trades-contract-address) | [Token Trades →](/reference/token-trades-contract-address)
      </Tab>

      <Tab title="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 →](/demo/reference/pool-trades-contract-address) | [Token Trades →](/demo/reference/token-trades-contract-address)
      </Tab>
    </Tabs>

    Use `trade_volume_in_usd_greater_than` to filter noise.
  </Step>
</Steps>
