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

# OnchainPoolStats

> Real-time rolling buy/sell stats by pool address

### Notes

* Streams rolling buy/sell stats for pools by network and pool address, the same stats returned by [Specific Pool Data by Pool Address](https://docs.coingecko.com/reference/pool-address.md).
* Lookup format: `network_id:pool_address` (e.g. `eth:0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640`).
* Find supported network IDs via [Networks List](https://docs.coingecko.com/reference/networks-list.md).
* Stats are from the base token's perspective.
* All six windows are sent in every message.
* Total volume is `bvo` + `svo`. Net buy volume is `bvo` − `svo`.

**Update Frequency:**\
Pushed when a pool's stats change, about 7 seconds after a swap.

### Data Payload

| Key | Field | Type | Description | Example |
| - | - | - | - | - |
| `c` | `channel_type` | string | Channel type subscribed to. | `G5` |
| `n` | `network_id` | string | Blockchain network identifier. | `eth` |
| `pa` | `pool_address` | string | Pool contract address. | `0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640` |
| `m5`, `m15`, `m30`, `h1`, `h6`, `h24` | `window` | object | Stats for each rolling window: 5m, 15m, 30m, 1h, 6h, 24h. | – |
| `{window}.b` | `buys` | number | Buy trades in the window. | 42 |
| `{window}.s` | `sells` | number | Sell trades in the window. | 36 |
| `{window}.by` | `buyers` | number | Unique buyers in the window. | 40 |
| `{window}.sl` | `sellers` | number | Unique sellers in the window. | 31 |
| `{window}.bvo` | `buy_volume_usd` | number | Buy volume in USD. | 15193.08 |
| `{window}.svo` | `sell_volume_usd` | number | Sell volume in USD. | 43904.49 |
| `t` | `timestamp` | integer | UNIX timestamp (s) of the stats snapshot. | 1790552626 |

***

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

**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 OnchainPoolStats

**Input:**

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

**Output:**

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

***

### 3. Stream Pool Stats

**Input:**

```json wrap theme={null}
{"command":"message","identifier":"{\"channel\":\"OnchainPoolStats\"}","data":"{\"network_id:pool_addresses\":[\"eth:0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640\"],\"action\":\"set_pools\"}"}
```

**Output:**

```json theme={null}
{
  "code": 2000,
  "message": "Subscription successful for eth:0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"
}
```

**Streaming output:**

```json theme={null}
{
  "c": "G5",
  "n": "eth",
  "pa": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
  "m5": { "b": 42, "s": 36, "by": 40, "sl": 31, "bvo": 15193.078597182, "svo": 43904.4937286058 },
  "m15": { "b": 122, "s": 107, "by": 96, "sl": 82, "bvo": 114599.310956502, "svo": 142538.913095514 },
  "m30": { "b": 312, "s": 269, "by": 191, "sl": 173, "bvo": 446949.800347959, "svo": 238371.748663375 },
  "h1": { "b": 534, "s": 422, "by": 260, "sl": 255, "bvo": 887478.427468627, "svo": 520519.921639103 },
  "h6": { "b": 1410, "s": 1220, "by": 580, "sl": 519, "bvo": 3710174.1254709, "svo": 3797551.66291745 },
  "h24": { "b": 3544, "s": 3424, "by": 1305, "sl": 1304, "bvo": 13539384.9948402, "svo": 13828012.0768187 },
  "t": 1790552626
}
```

> [!NOTE]
>
> Output keys may appear in any order.

***

### 4. Unsubscribe

**Unsubscribe from a specific pool:**

```json wrap theme={null}
{"command":"message","identifier":"{\"channel\":\"OnchainPoolStats\"}","data":"{\"network_id:pool_addresses\":[\"eth:0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640\"],\"action\":\"unset_pools\"}"}
```

```json theme={null}
{
  "code": 2000,
  "message": "Unsubscription is successful for eth:0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"
}
```

**Unsubscribe from the channel entirely:**

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

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

***


## AsyncAPI

````yaml websocket/asyncapi.json onchainpoolstats
id: onchainpoolstats
title: Onchainpoolstats
description: Real-time rolling buy/sell stats by pool address
servers:
  - id: production
    protocol: wss
    host: stream.coingecko.com
    bindings: []
    variables: []
address: /v1
parameters: []
bindings: []
operations:
  - &ref_1
    id: subscribeToOnchainPoolStats
    title: 'OnchainPoolStats: Subscribe'
    description: >-
      To subscribe to the OnchainPoolStats channel for receiving rolling pool
      stats updates
    type: receive
    messages:
      - &ref_4
        id: subscribe
        payload:
          - name: Subscribe to OnchainPoolStats
            description: Subscribe to the OnchainPoolStats 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-81>
            identifier:
              type: string
              default: '{"channel":"OnchainPoolStats"}'
              description: JSON string specifying the target channel
              x-parser-schema-id: <anonymous-schema-82>
          x-parser-schema-id: <anonymous-schema-80>
        title: Subscribe to OnchainPoolStats
        description: Subscribe to the OnchainPoolStats 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: onchainpoolstats
  - &ref_2
    id: streamOnchainPoolStats
    title: 'OnchainPoolStats: Stream Data'
    description: >-
      To set which pools to stream rolling stats for, by network and pool
      address
    type: receive
    messages:
      - &ref_5
        id: stream
        payload:
          - name: Stream OnchainPoolStats Data
            description: Set pools to receive rolling stats 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, format:
                  network_id:pool_address
                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-84>
            identifier:
              type: string
              default: '{"channel":"OnchainPoolStats"}'
              description: JSON string specifying the target channel
              x-parser-schema-id: <anonymous-schema-85>
            data:
              type: string
              default: >-
                {"network_id:pool_addresses":["eth:0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"],"action":"set_pools"}
              example: >-
                {"network_id:pool_addresses":["eth:0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"],"action":"set_pools"}
              description: >-
                JSON string with network_id:pool_addresses array, format:
                network_id:pool_address
              x-parser-schema-id: <anonymous-schema-86>
          x-parser-schema-id: <anonymous-schema-83>
        title: Stream OnchainPoolStats Data
        description: Set pools to receive rolling stats 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: receiveOnchainPoolStatsUpdates
    title: 'OnchainPoolStats: Receive Updates'
    description: >-
      To receive rolling buy/sell trade counts, unique traders, and buy/sell
      volume for each window
    type: send
    messages:
      - &ref_6
        id: update
        payload:
          - name: OnchainPoolStats Update
            description: Rolling pool buy/sell stats update from server
            type: object
            properties:
              - name: c
                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: m5
                type: object
                description: Rolling 5m stats
                required: false
                properties:
                  - name: b
                    type: number
                    description: Buy trades in the window
                    required: false
                  - name: s
                    type: number
                    description: Sell trades in the window
                    required: false
                  - name: by
                    type: number
                    description: Unique buyers in the window
                    required: false
                  - name: sl
                    type: number
                    description: Unique sellers in the window
                    required: false
                  - name: bvo
                    type: number
                    description: Buy volume in USD
                    required: false
                  - name: svo
                    type: number
                    description: Sell volume in USD
                    required: false
              - name: m15
                type: object
                description: Rolling 15m stats
                required: false
                properties:
                  - name: b
                    type: number
                    description: Buy trades in the window
                    required: false
                  - name: s
                    type: number
                    description: Sell trades in the window
                    required: false
                  - name: by
                    type: number
                    description: Unique buyers in the window
                    required: false
                  - name: sl
                    type: number
                    description: Unique sellers in the window
                    required: false
                  - name: bvo
                    type: number
                    description: Buy volume in USD
                    required: false
                  - name: svo
                    type: number
                    description: Sell volume in USD
                    required: false
              - name: m30
                type: object
                description: Rolling 30m stats
                required: false
                properties:
                  - name: b
                    type: number
                    description: Buy trades in the window
                    required: false
                  - name: s
                    type: number
                    description: Sell trades in the window
                    required: false
                  - name: by
                    type: number
                    description: Unique buyers in the window
                    required: false
                  - name: sl
                    type: number
                    description: Unique sellers in the window
                    required: false
                  - name: bvo
                    type: number
                    description: Buy volume in USD
                    required: false
                  - name: svo
                    type: number
                    description: Sell volume in USD
                    required: false
              - name: h1
                type: object
                description: Rolling 1h stats
                required: false
                properties:
                  - name: b
                    type: number
                    description: Buy trades in the window
                    required: false
                  - name: s
                    type: number
                    description: Sell trades in the window
                    required: false
                  - name: by
                    type: number
                    description: Unique buyers in the window
                    required: false
                  - name: sl
                    type: number
                    description: Unique sellers in the window
                    required: false
                  - name: bvo
                    type: number
                    description: Buy volume in USD
                    required: false
                  - name: svo
                    type: number
                    description: Sell volume in USD
                    required: false
              - name: h6
                type: object
                description: Rolling 6h stats
                required: false
                properties:
                  - name: b
                    type: number
                    description: Buy trades in the window
                    required: false
                  - name: s
                    type: number
                    description: Sell trades in the window
                    required: false
                  - name: by
                    type: number
                    description: Unique buyers in the window
                    required: false
                  - name: sl
                    type: number
                    description: Unique sellers in the window
                    required: false
                  - name: bvo
                    type: number
                    description: Buy volume in USD
                    required: false
                  - name: svo
                    type: number
                    description: Sell volume in USD
                    required: false
              - name: h24
                type: object
                description: Rolling 24h stats
                required: false
                properties:
                  - name: b
                    type: number
                    description: Buy trades in the window
                    required: false
                  - name: s
                    type: number
                    description: Sell trades in the window
                    required: false
                  - name: by
                    type: number
                    description: Unique buyers in the window
                    required: false
                  - name: sl
                    type: number
                    description: Unique sellers in the window
                    required: false
                  - name: bvo
                    type: number
                    description: Buy volume in USD
                    required: false
                  - name: svo
                    type: number
                    description: Sell volume in USD
                    required: false
              - name: t
                type: integer
                description: UNIX timestamp in seconds
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            c:
              type: string
              example: G5
              description: Channel type
              x-parser-schema-id: <anonymous-schema-88>
            'n':
              type: string
              example: eth
              description: Network identifier
              x-parser-schema-id: <anonymous-schema-89>
            pa:
              type: string
              example: '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640'
              description: Pool contract address
              x-parser-schema-id: <anonymous-schema-90>
            m5:
              type: object
              description: Rolling 5m stats
              properties:
                b:
                  type: number
                  example: 42
                  description: Buy trades in the window
                  x-parser-schema-id: <anonymous-schema-92>
                s:
                  type: number
                  example: 36
                  description: Sell trades in the window
                  x-parser-schema-id: <anonymous-schema-93>
                by:
                  type: number
                  example: 40
                  description: Unique buyers in the window
                  x-parser-schema-id: <anonymous-schema-94>
                sl:
                  type: number
                  example: 31
                  description: Unique sellers in the window
                  x-parser-schema-id: <anonymous-schema-95>
                bvo:
                  type: number
                  example: 15193.078597182
                  description: Buy volume in USD
                  x-parser-schema-id: <anonymous-schema-96>
                svo:
                  type: number
                  example: 43904.4937286058
                  description: Sell volume in USD
                  x-parser-schema-id: <anonymous-schema-97>
              x-parser-schema-id: <anonymous-schema-91>
            m15:
              type: object
              description: Rolling 15m stats
              properties:
                b:
                  type: number
                  example: 122
                  description: Buy trades in the window
                  x-parser-schema-id: <anonymous-schema-99>
                s:
                  type: number
                  example: 107
                  description: Sell trades in the window
                  x-parser-schema-id: <anonymous-schema-100>
                by:
                  type: number
                  example: 96
                  description: Unique buyers in the window
                  x-parser-schema-id: <anonymous-schema-101>
                sl:
                  type: number
                  example: 82
                  description: Unique sellers in the window
                  x-parser-schema-id: <anonymous-schema-102>
                bvo:
                  type: number
                  example: 114599.310956502
                  description: Buy volume in USD
                  x-parser-schema-id: <anonymous-schema-103>
                svo:
                  type: number
                  example: 142538.913095514
                  description: Sell volume in USD
                  x-parser-schema-id: <anonymous-schema-104>
              x-parser-schema-id: <anonymous-schema-98>
            m30:
              type: object
              description: Rolling 30m stats
              properties:
                b:
                  type: number
                  example: 312
                  description: Buy trades in the window
                  x-parser-schema-id: <anonymous-schema-106>
                s:
                  type: number
                  example: 269
                  description: Sell trades in the window
                  x-parser-schema-id: <anonymous-schema-107>
                by:
                  type: number
                  example: 191
                  description: Unique buyers in the window
                  x-parser-schema-id: <anonymous-schema-108>
                sl:
                  type: number
                  example: 173
                  description: Unique sellers in the window
                  x-parser-schema-id: <anonymous-schema-109>
                bvo:
                  type: number
                  example: 446949.800347959
                  description: Buy volume in USD
                  x-parser-schema-id: <anonymous-schema-110>
                svo:
                  type: number
                  example: 238371.748663375
                  description: Sell volume in USD
                  x-parser-schema-id: <anonymous-schema-111>
              x-parser-schema-id: <anonymous-schema-105>
            h1:
              type: object
              description: Rolling 1h stats
              properties:
                b:
                  type: number
                  example: 534
                  description: Buy trades in the window
                  x-parser-schema-id: <anonymous-schema-113>
                s:
                  type: number
                  example: 422
                  description: Sell trades in the window
                  x-parser-schema-id: <anonymous-schema-114>
                by:
                  type: number
                  example: 260
                  description: Unique buyers in the window
                  x-parser-schema-id: <anonymous-schema-115>
                sl:
                  type: number
                  example: 255
                  description: Unique sellers in the window
                  x-parser-schema-id: <anonymous-schema-116>
                bvo:
                  type: number
                  example: 887478.427468627
                  description: Buy volume in USD
                  x-parser-schema-id: <anonymous-schema-117>
                svo:
                  type: number
                  example: 520519.921639103
                  description: Sell volume in USD
                  x-parser-schema-id: <anonymous-schema-118>
              x-parser-schema-id: <anonymous-schema-112>
            h6:
              type: object
              description: Rolling 6h stats
              properties:
                b:
                  type: number
                  example: 1410
                  description: Buy trades in the window
                  x-parser-schema-id: <anonymous-schema-120>
                s:
                  type: number
                  example: 1220
                  description: Sell trades in the window
                  x-parser-schema-id: <anonymous-schema-121>
                by:
                  type: number
                  example: 580
                  description: Unique buyers in the window
                  x-parser-schema-id: <anonymous-schema-122>
                sl:
                  type: number
                  example: 519
                  description: Unique sellers in the window
                  x-parser-schema-id: <anonymous-schema-123>
                bvo:
                  type: number
                  example: 3710174.1254709
                  description: Buy volume in USD
                  x-parser-schema-id: <anonymous-schema-124>
                svo:
                  type: number
                  example: 3797551.66291745
                  description: Sell volume in USD
                  x-parser-schema-id: <anonymous-schema-125>
              x-parser-schema-id: <anonymous-schema-119>
            h24:
              type: object
              description: Rolling 24h stats
              properties:
                b:
                  type: number
                  example: 3544
                  description: Buy trades in the window
                  x-parser-schema-id: <anonymous-schema-127>
                s:
                  type: number
                  example: 3424
                  description: Sell trades in the window
                  x-parser-schema-id: <anonymous-schema-128>
                by:
                  type: number
                  example: 1305
                  description: Unique buyers in the window
                  x-parser-schema-id: <anonymous-schema-129>
                sl:
                  type: number
                  example: 1304
                  description: Unique sellers in the window
                  x-parser-schema-id: <anonymous-schema-130>
                bvo:
                  type: number
                  example: 13539384.9948402
                  description: Buy volume in USD
                  x-parser-schema-id: <anonymous-schema-131>
                svo:
                  type: number
                  example: 13828012.0768187
                  description: Sell volume in USD
                  x-parser-schema-id: <anonymous-schema-132>
              x-parser-schema-id: <anonymous-schema-126>
            t:
              type: integer
              example: 1790552626
              description: UNIX timestamp in seconds
              x-parser-schema-id: <anonymous-schema-133>
          x-parser-schema-id: <anonymous-schema-87>
        title: OnchainPoolStats Update
        description: Rolling pool buy/sell stats update from server
        example: |-
          {
            "c": "G5",
            "n": "eth",
            "pa": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
            "m5": {
              "b": 42,
              "s": 36,
              "by": 40,
              "sl": 31,
              "bvo": 15193.078597182,
              "svo": 43904.4937286058
            },
            "m15": {
              "b": 122,
              "s": 107,
              "by": 96,
              "sl": 82,
              "bvo": 114599.310956502,
              "svo": 142538.913095514
            },
            "m30": {
              "b": 312,
              "s": 269,
              "by": 191,
              "sl": 173,
              "bvo": 446949.800347959,
              "svo": 238371.748663375
            },
            "h1": {
              "b": 534,
              "s": 422,
              "by": 260,
              "sl": 255,
              "bvo": 887478.427468627,
              "svo": 520519.921639103
            },
            "h6": {
              "b": 1410,
              "s": 1220,
              "by": 580,
              "sl": 519,
              "bvo": 3710174.1254709,
              "svo": 3797551.66291745
            },
            "h24": {
              "b": 3544,
              "s": 3424,
              "by": 1305,
              "sl": 1304,
              "bvo": 13539384.9948402,
              "svo": 13828012.0768187
            },
            "t": 1790552626
          }
        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: onchainpoolstats
securitySchemes:
  - id: cgApiKey
    name: x_cg_pro_api_key
    type: httpApiKey
    description: CoinGecko API key
    in: query
    extensions: []

````

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