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

# OnchainOHLCV

> Real-time onchain OHLCV candlestick updates by pool address

### Notes

* Streams real-time OHLCV (Open, High, Low, Close, Volume) candlestick data by network and pool address.
* Lookup format: `network_id:pool_address` (e.g. `bsc:0x172fcd41e0913e95784454622d1c3724f546f849`).
* Interval options: `1s` / `1m` / `5m` / `15m` / `1h` / `2h` / `4h` / `8h` / `12h` / `1d`.
* Stream based on `base` or `quote` token of a pool.
* Find supported network IDs via [Networks List](/reference/networks-list).
* Use [Top Pools by Token Address](/reference/top-pools-contract-address) to find the most liquid pool address.
* Fields may return `null` when data is unavailable. Ensure your application handles null values.

<Note>
  Each unique combination of interval and token for a given pool counts as a distinct subscription towards your max subscription limit.
</Note>

<Callout icon="clock-rotate-left" color="#2196F3" iconType="regular">
  <strong>Update Frequency:</strong><br />As fast as \~1 second for actively traded pools.
</Callout>

### Data Payload

| Key  | Field          | Type    | Description                           | Example                                      |
| ---- | -------------- | ------- | ------------------------------------- | -------------------------------------------- |
| `ch` | `channel_type` | string  | Channel type subscribed to.           | `G3`                                         |
| `n`  | `network_id`   | string  | Blockchain network identifier.        | `bsc`                                        |
| `pa` | `pool_address` | string  | Pool contract address.                | `0x172fcd41e0913e95784454622d1c3724f546f849` |
| `to` | `token`        | string  | Token side (`base` or `quote`).       | `base`                                       |
| `i`  | `interval`     | string  | Candle interval.                      | `1m`                                         |
| `o`  | `open`         | number  | Open price in USD.                    | 1.0005                                       |
| `h`  | `high`         | number  | High price in USD.                    | 1.0006                                       |
| `l`  | `low`          | number  | Low price in USD.                     | 0.9999                                       |
| `c`  | `close`        | number  | Close price in USD.                   | 0.9999                                       |
| `v`  | `volume`       | number  | Volume in USD.                        | 59672.13                                     |
| `t`  | `timestamp`    | integer | Candle open time, UNIX timestamp (s). | 1780841100                                   |

***

### 1. Establish Connection

```bash theme={null}
wss://stream.coingecko.com/v1?x_cg_pro_api_key=YOUR_KEY
```

<Tip>You can also pass the key as a header: `x-cg-pro-api-key: YOUR_KEY`</Tip>

**Output:**

```json theme={null}
{
  "code": 3000,
  "message": "Connection established",
  "uuid": "YOUR_SESSION_ID"
}
```

```json theme={null}
{
  "type": "welcome",
  "sid": "YOUR_SESSION_ID"
}
```

***

### 2. Subscribe to OnchainOHLCV

**Input:**

```json wrap theme={null}
{"command":"subscribe","identifier":"{\"channel\":\"OnchainOHLCV\"}"}
```

**Output:**

```json theme={null}
{
  "type": "confirm_subscription",
  "identifier": "{\"channel\":\"OnchainOHLCV\"}"
}
```

***

### 3. Stream OHLCV Data

**Input:**

```json wrap theme={null}
{"command":"message","identifier":"{\"channel\":\"OnchainOHLCV\"}","data":"{\"network_id:pool_addresses\":[\"bsc:0x172fcd41e0913e95784454622d1c3724f546f849\"],\"interval\":\"1m\",\"token\":\"base\",\"action\":\"set_pools\"}"}
```

**Output:**

```json theme={null}
{
  "code": 2000,
  "message": "Subscription successful for bsc:0x172fcd41e0913e95784454622d1c3724f546f849:1m:base"
}
```

**Streaming output:**

```json theme={null}
{
  "ch": "G3",
  "n": "bsc",
  "pa": "0x172fcd41e0913e95784454622d1c3724f546f849",
  "to": "base",
  "i": "1m",
  "o": 1.00052534269941,
  "h": 1.00063525778742,
  "l": 0.999952061655863,
  "c": 0.999952061655863,
  "v": 59672.13452671968,
  "t": 1780841100
}
```

<Note>Output keys may appear in any order.</Note>

***

### 4. Unsubscribe

**Unsubscribe from a specific pool:**

```json wrap theme={null}
{"command":"message","identifier":"{\"channel\":\"OnchainOHLCV\"}","data":"{\"network_id:pool_addresses\":[\"bsc:0x172fcd41e0913e95784454622d1c3724f546f849\"],\"interval\":\"1m\",\"token\":\"base\",\"action\":\"unset_pools\"}"}
```

```json theme={null}
{
  "code": 2000,
  "message": "Unsubscription is successful for bsc:0x172fcd41e0913e95784454622d1c3724f546f849:1m:base"
}
```

**Unsubscribe from the channel entirely:**

```json wrap theme={null}
{"command":"unsubscribe","identifier":"{\"channel\":\"OnchainOHLCV\"}"}
```

```json theme={null}
{
  "code": 2000,
  "message": "Unsubscription is successful for all pools"
}
```

***


## AsyncAPI

````yaml websocket/asyncapi.json onchainohlcv
id: onchainohlcv
title: Onchainohlcv
description: Real-time onchain OHLCV candlestick updates by pool address
servers:
  - id: production
    protocol: wss
    host: stream.coingecko.com
    bindings: []
    variables: []
address: /v1
parameters: []
bindings: []
operations:
  - &ref_1
    id: subscribeToOnchainOHLCV
    title: 'OnchainOHLCV: Subscribe'
    description: >-
      To subscribe to the OnchainOHLCV channel for receiving OHLCV candlestick
      updates
    type: receive
    messages:
      - &ref_4
        id: subscribe
        payload:
          - name: Subscribe to OnchainOHLCV
            description: Subscribe to the OnchainOHLCV channel
            type: object
            properties:
              - name: command
                type: string
                description: Subscription command
                enumValues:
                  - subscribe
                required: true
              - name: identifier
                type: string
                description: JSON string specifying the target channel
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - command
            - identifier
          properties:
            command:
              type: string
              enum:
                - subscribe
              default: subscribe
              description: Subscription command
              x-parser-schema-id: <anonymous-schema-53>
            identifier:
              type: string
              default: '{"channel":"OnchainOHLCV"}'
              description: JSON string specifying the target channel
              x-parser-schema-id: <anonymous-schema-54>
          x-parser-schema-id: <anonymous-schema-52>
        title: Subscribe to OnchainOHLCV
        description: Subscribe to the OnchainOHLCV channel
        example: |-
          {
            "command": "<string>",
            "identifier": "<string>"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: subscribe
    bindings: []
    extensions: &ref_0
      - id: x-parser-unique-object-id
        value: onchainohlcv
  - &ref_2
    id: streamOnchainOHLCV
    title: 'OnchainOHLCV: Stream Data'
    description: To set which pools, intervals, and token sides to stream OHLCV data for
    type: receive
    messages:
      - &ref_5
        id: stream
        payload:
          - name: Stream OnchainOHLCV Data
            description: Set pools to receive OHLCV updates for
            type: object
            properties:
              - name: command
                type: string
                description: Message command
                enumValues:
                  - message
                required: true
              - name: identifier
                type: string
                description: JSON string specifying the target channel
                required: true
              - name: data
                type: string
                description: >-
                  JSON string with network_id:pool_addresses array, interval
                  (1s/1m/5m/15m/1h/2h/4h/8h/12h/1d), and token (base or quote)
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - command
            - identifier
            - data
          properties:
            command:
              type: string
              enum:
                - message
              default: message
              description: Message command
              x-parser-schema-id: <anonymous-schema-56>
            identifier:
              type: string
              default: '{"channel":"OnchainOHLCV"}'
              description: JSON string specifying the target channel
              x-parser-schema-id: <anonymous-schema-57>
            data:
              type: string
              default: >-
                {"network_id:pool_addresses":["bsc:0x172fcd41e0913e95784454622d1c3724f546f849"],"interval":"1m","token":"base","action":"set_pools"}
              example: >-
                {"network_id:pool_addresses":["bsc:0x172fcd41e0913e95784454622d1c3724f546f849"],"interval":"1m","token":"base","action":"set_pools"}
              description: >-
                JSON string with network_id:pool_addresses array, interval
                (1s/1m/5m/15m/1h/2h/4h/8h/12h/1d), and token (base or quote)
              x-parser-schema-id: <anonymous-schema-58>
          x-parser-schema-id: <anonymous-schema-55>
        title: Stream OnchainOHLCV Data
        description: Set pools to receive OHLCV updates for
        example: |-
          {
            "command": "<string>",
            "identifier": "<string>",
            "data": "<string>"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: stream
    bindings: []
    extensions: *ref_0
  - &ref_3
    id: receiveOnchainOHLCVUpdates
    title: 'OnchainOHLCV: Receive Updates'
    description: >-
      To receive real-time OHLCV candlestick updates including open, high, low,
      close, and volume
    type: send
    messages:
      - &ref_6
        id: update
        payload:
          - name: OnchainOHLCV Update
            description: Real-time OHLCV candlestick update from server
            type: object
            properties:
              - name: ch
                type: string
                description: Channel type
                required: false
              - name: 'n'
                type: string
                description: Network identifier
                required: false
              - name: pa
                type: string
                description: Pool contract address
                required: false
              - name: to
                type: string
                description: Token side (base or quote)
                required: false
              - name: i
                type: string
                description: Candle interval (1s/1m/5m/15m/1h/2h/4h/8h/12h/1d)
                required: false
              - name: o
                type: number
                description: Open price in USD
                required: false
              - name: h
                type: number
                description: High price in USD
                required: false
              - name: l
                type: number
                description: Low price in USD
                required: false
              - name: c
                type: number
                description: Close price in USD
                required: false
              - name: v
                type: number
                description: Volume in USD
                required: false
              - name: t
                type: integer
                description: Candle open time, UNIX timestamp in seconds
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            ch:
              type: string
              example: G3
              description: Channel type
              x-parser-schema-id: <anonymous-schema-60>
            'n':
              type: string
              example: bsc
              description: Network identifier
              x-parser-schema-id: <anonymous-schema-61>
            pa:
              type: string
              example: '0x172fcd41e0913e95784454622d1c3724f546f849'
              description: Pool contract address
              x-parser-schema-id: <anonymous-schema-62>
            to:
              type: string
              example: base
              description: Token side (base or quote)
              x-parser-schema-id: <anonymous-schema-63>
            i:
              type: string
              example: 1m
              description: Candle interval (1s/1m/5m/15m/1h/2h/4h/8h/12h/1d)
              x-parser-schema-id: <anonymous-schema-64>
            o:
              type: number
              example: 1.00052534269941
              description: Open price in USD
              x-parser-schema-id: <anonymous-schema-65>
            h:
              type: number
              example: 1.00063525778742
              description: High price in USD
              x-parser-schema-id: <anonymous-schema-66>
            l:
              type: number
              example: 0.999952061655863
              description: Low price in USD
              x-parser-schema-id: <anonymous-schema-67>
            c:
              type: number
              example: 0.999952061655863
              description: Close price in USD
              x-parser-schema-id: <anonymous-schema-68>
            v:
              type: number
              example: 59672.13452671968
              description: Volume in USD
              x-parser-schema-id: <anonymous-schema-69>
            t:
              type: integer
              example: 1780841100
              description: Candle open time, UNIX timestamp in seconds
              x-parser-schema-id: <anonymous-schema-70>
          x-parser-schema-id: <anonymous-schema-59>
        title: OnchainOHLCV Update
        description: Real-time OHLCV candlestick update from server
        example: |-
          {
            "ch": "G3",
            "n": "bsc",
            "pa": "0x172fcd41e0913e95784454622d1c3724f546f849",
            "to": "base",
            "i": "1m",
            "o": 1.00052534269941,
            "h": 1.00063525778742,
            "l": 0.999952061655863,
            "c": 0.999952061655863,
            "v": 59672.13452671968,
            "t": 1780841100
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: update
    bindings: []
    extensions: *ref_0
sendOperations:
  - *ref_1
  - *ref_2
receiveOperations:
  - *ref_3
sendMessages:
  - *ref_4
  - *ref_5
receiveMessages:
  - *ref_6
extensions:
  - id: x-parser-unique-object-id
    value: onchainohlcv
securitySchemes:
  - id: cgApiKey
    name: x_cg_pro_api_key
    type: httpApiKey
    description: CoinGecko API key
    in: query
    extensions: []

````