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

> Subscribe to receive real-time OHLCV updates for pools, as seen on GeckoTerminal.com

This WebSocket channel allows you to subscribe to real-time OHLCV updates of a pool.

* Lookup by Network + Pool Address
* It will return **O**pen, **H**igh, **L**ow, **C**lose price and **V**olume data of the specified pool.

**Update Frequency**: as fast as 1s, for actively traded pools.

**Tips**: use this REST API endpoint [Top Pools by Token Address](https://docs.coingecko.com/reference/top-pools-contract-address) to obtain contract address of the most liquid pool.

<Note>
  ### **Notes**

  * Interval options: 1s / 1m / 5m / 15m / 1h / 2h / 4h / 8h / 12h / 1d
  * You may stream the pool ohlcv data based on `base` or `quote` token of a pool.
  * Please note that your subscription quota is based on the number of **unique data streams** you request. Each unique combination of an interval and token for a given pool is considered a **distinct subscription** and will count towards your max subscription limit.
</Note>

### Data Payload

|      | Field          | Type    | Description                                                                                                                | Example                    |
| ---- | -------------- | ------- | -------------------------------------------------------------------------------------------------------------------------- | -------------------------- |
| `ch` | `channel_type` | string  | Indicates the type of channel subscribed to.                                                                               | G3                         |
| `n`  | `network_id`   | string  | Identifier of the blockchain network. Check full list of IDs [here](https://api.geckoterminal.com/api/v2/networks?page=1). | eth                        |
| `pa` | `pool_address` | string  | Contract address of the pool.                                                                                              | `0x88e6a0c2dd6fcb..3f5640` |
| `to` | `token`        | string  | `base` or `quote` token                                                                                                    | `base`                     |
| `i`  | `interval`     | string  | Interval or resolution of the candle: 1s / 1m / 5m / 15m / 1h / 2h / 4h / 8h / 12h / 1d                                    | 1m                         |
| `o`  | `open`         | float   | Open price in USD                                                                                                          | 3539                       |
| `h`  | `high`         | float   | High price in USD                                                                                                          | 3541                       |
| `l`  | `low`          | float   | Low price in USD                                                                                                           | 3530                       |
| `c`  | `close`        | float   | Close price in USD                                                                                                         | 3531                       |
| `v`  | `volume`       | float   | Volume in USD                                                                                                              | 323333                     |
| `t`  | `timestamp`    | integer | Opening timestamp of candle interval                                                                                       | 1753803600                 |

**Tips**: The WebSocket payload will use the value `null` when specific data is unavailable. Ensure your application is capable of handling null values for fields that may not always have data.

***

## 1. Establish Connection to WebSocket

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

  OR

  wss://stream.coingecko.com/v1  
  x-cg-pro-api-key: YOUR_KEY
  ```
</CodeGroup>

## 2. Subscribe to a specific channel - OnchainOHLCV

**Input Example:**

<CodeGroup>
  ```json JSON theme={null}
  {"command":"subscribe","identifier":"{\"channel\":\"OnchainOHLCV\"}"}
  ```
</CodeGroup>

**Output Example**:

<CodeGroup>
  ```json JSON theme={null}
  {"type":"confirm_subscription","identifier":"{\"channel\":\"OnchainOHLCV\"}"}
  ```
</CodeGroup>

## 3. Stream OnchainOHLCV data

**Input Example:** (1 minute interval and base token of a pool)

* `Interval` options: 1s / 1m / 5m / 15m / 1h / 2h / 4h / 8h / 12h / 1d
* You may stream the pool ohlcv data of 'base' or 'quote' `token`.

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

**Output Example**:

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

**Output Example**:

<CodeGroup>
  ```json JSON theme={null}
  {
      "c": 0.999727235252031,
      "ch": "G3",
      "h": 0.999974654065411,
      "i": "1m",
      "l": 0.999353212178554,
      "n": "bsc",
      "o": 0.999570907451071,
      "pa": "0x172fcd41e0913e95784454622d1c3724f546f849",
      "t": 1753886760,
      "to": "base",
      "v": 63932.29404921795
  }
  ```
</CodeGroup>

The output keys will be in random order.

## Tips:

### Unsubscribe to stop streaming OnchainOHLCV data

**Input Example:** Unsubscribe for 1 specific pool data:

<CodeGroup>
  ```json JSON theme={null}
  {"command":"message","identifier":"{\"channel\":\"OnchainOHLCV\"}","data":"{\"network_id:pool_addresses\":[\"eth:0xc7bbec68d12a0d1830360f8ec58fa599ba1b0e9b\"],\"interval\":\"1m\",\"token\":\"base\",\"action\":\"unset_pools\"}"}
  ```
</CodeGroup>

**Output Example**:

<CodeGroup>
  ```json JSON theme={null}
  {
    "code":2000,
    "message":"Unsubscription is successful for eth:0xc7bbec68d12a0d1830360f8ec58fa599ba1b0e9b:1m:base"
  }
  ```
</CodeGroup>

**Input Example:** Unsubscribe from OnchainOHLCV channel and all pools data:

<CodeGroup>
  ```json JSON theme={null}
  {"command":"unsubscribe","identifier":"{\"channel\":\"OnchainOHLCV\"}"}
  ```
</CodeGroup>

**Output Example**:

<CodeGroup>
  ```json JSON theme={null}
  {
    "code":2000,
    "message":"Unsubscription is successful for all pools"
  }
  ```
</CodeGroup>


## AsyncAPI

````yaml websocket/asyncapi.json onchainohlcv
id: onchainohlcv
title: Onchainohlcv
description: ''
servers:
  - id: production
    protocol: wss
    host: stream.coingecko.com
    bindings: []
    variables: []
address: /v1
parameters: []
bindings: []
operations:
  - &ref_1
    id: subscribeToOnchainOHLCV
    title: 'OnchainOHLCV: Subscribe'
    description: Subscribe to OnchainOHLCV channel
    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: Command to subscribe to a channel
                enumValues:
                  - subscribe
                required: true
              - name: identifier
                type: string
                description: JSON string containing channel information
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            command:
              type: string
              enum:
                - subscribe
              default: subscribe
              example: subscribe
              description: Command to subscribe to a channel
              x-parser-schema-id: <anonymous-schema-53>
            identifier:
              type: string
              default: '{"channel":"OnchainOHLCV"}'
              example: '{"channel":"OnchainOHLCV"}'
              description: JSON string containing channel information
              x-parser-schema-id: <anonymous-schema-54>
          required:
            - command
            - identifier
          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: Request OHLCV streaming for pools
    type: receive
    messages:
      - &ref_5
        id: streamRequest
        payload:
          - name: Stream OnchainOHLCV Data
            description: Set pools to receive OHLCV updates
            type: object
            properties:
              - name: command
                type: string
                description: Command to send a message
                enumValues:
                  - message
                required: true
              - name: identifier
                type: string
                description: JSON string containing channel information
                required: true
              - name: data
                type: string
                description: >-
                  You may edit this. Format is network_id:pool_address. Interval
                  options: 1s/1m/5m/15m/1h/2h/4h/8h/12h/1d. Token: base or quote
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            command:
              type: string
              enum:
                - message
              default: message
              example: message
              description: Command to send a message
              x-parser-schema-id: <anonymous-schema-56>
            identifier:
              type: string
              default: '{"channel":"OnchainOHLCV"}'
              example: '{"channel":"OnchainOHLCV"}'
              description: JSON string containing channel information
              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: >-
                You may edit this. Format is network_id:pool_address. Interval
                options: 1s/1m/5m/15m/1h/2h/4h/8h/12h/1d. Token: base or quote
              x-parser-schema-id: <anonymous-schema-58>
          required:
            - command
            - identifier
            - data
          x-parser-schema-id: <anonymous-schema-55>
        title: Stream OnchainOHLCV Data
        description: Set pools to receive OHLCV updates
        example: |-
          {
            "command": "<string>",
            "identifier": "<string>",
            "data": "<string>"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: streamRequest
    bindings: []
    extensions: *ref_0
  - &ref_3
    id: receiveOnchainOHLCVUpdates
    title: 'OnchainOHLCV: Receive Updates'
    description: Receive real-time OHLCV updates
    type: send
    messages:
      - &ref_6
        id: ohlcvUpdate
        payload:
          - name: OnchainOHLCV Update
            description: Real-time OHLCV update
            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 (base or quote)
                required: false
              - name: i
                type: string
                description: 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: Opening timestamp of candle interval (UNIX)
                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 (base or quote)
              x-parser-schema-id: <anonymous-schema-63>
            i:
              type: string
              example: 1m
              description: Interval (1s/1m/5m/15m/1h/2h/4h/8h/12h/1d)
              x-parser-schema-id: <anonymous-schema-64>
            o:
              type: number
              example: 0.999570907451071
              description: Open price in USD
              x-parser-schema-id: <anonymous-schema-65>
            h:
              type: number
              example: 0.999974654065411
              description: High price in USD
              x-parser-schema-id: <anonymous-schema-66>
            l:
              type: number
              example: 0.999353212178554
              description: Low price in USD
              x-parser-schema-id: <anonymous-schema-67>
            c:
              type: number
              example: 0.999727235252031
              description: Close price in USD
              x-parser-schema-id: <anonymous-schema-68>
            v:
              type: number
              example: 63932.29404921795
              description: Volume in USD
              x-parser-schema-id: <anonymous-schema-69>
            t:
              type: integer
              example: 1753886760
              description: Opening timestamp of candle interval (UNIX)
              x-parser-schema-id: <anonymous-schema-70>
          x-parser-schema-id: <anonymous-schema-59>
        title: OnchainOHLCV Update
        description: Real-time OHLCV update
        example: |-
          {
            "ch": "<string>",
            "n": "<string>",
            "pa": "<string>",
            "to": "<string>",
            "i": "<string>",
            "o": 123,
            "h": 123,
            "l": 123,
            "c": 123,
            "v": 123,
            "t": 123
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: ohlcvUpdate
    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: Insert CoinGecko Pro API key to establish WebSocket connection
    in: query
    extensions: []

````