> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# onPredictionEventBarsUpdated

> Live-streamed bar chart data to track price changes over time for a prediction event. Codex API GraphQL subscription reference.

## GraphQL

```
type Subscription {
  # Requires a Growth or Enterprise plan.
  onPredictionEventBarsUpdated(
    eventId: String!
  ): OnPredictionEventBarsUpdatedResponse
}

type PredictionEventBarOhlc {
  o: String!
  h: String!
  l: String!
  c: String!
}

type PredictionEventBar {
  t: Int!
  volumeUsd: String!
  buyVolumeUsd: String
  sellVolumeUsd: String
  totalVolumeUsd: String!
  venueVolumeUsd: String
  volumeCollateralToken: String
  buyVolumeCollateralToken: String
  sellVolumeCollateralToken: String
  totalVolumeCollateralToken: String
  venueVolumeCollateralToken: String
  trades: Int!
  uniqueTraders: Int
  lastEventTimestamp: Int!
  liquidityUsd: PredictionEventBarOhlc
  liquidityCollateralToken: PredictionEventBarOhlc
  openInterestUsd: PredictionEventBarOhlc
  openInterestCollateralToken: PredictionEventBarOhlc
}

type PredictionEventResolutionBarData {
  min1: PredictionEventBar
  min5: PredictionEventBar
  min15: PredictionEventBar
  min30: PredictionEventBar
  hour1: PredictionEventBar
  hour4: PredictionEventBar
  hour12: PredictionEventBar
  day1: PredictionEventBar
  week1: PredictionEventBar
}

type OnPredictionEventBarsUpdatedResponse {
  eventId: String!
  bars: PredictionEventResolutionBarData!
}
```

## Subscription example

[Test this query in the Explorer →](https://docs.codex.io/explore.md)

```graphql theme={null}
subscription {
  onPredictionEventBarsUpdated(eventId: "67284:Polymarket:0xc5d563a36ae78145c45a50134d48a1215220f80a:137") {
    bars {
      min1 {
        t
        volumeUsd
        buyVolumeUsd
        sellVolumeUsd
        totalVolumeUsd
        venueVolumeUsd
        volumeCollateralToken
        trades
        uniqueTraders
        lastEventTimestamp
        liquidityUsd {
          o
          h
          l
          c
        }
        openInterestUsd {
          o
          h
          l
          c
        }
      }
      min5 {
        t
        volumeUsd
        trades
        uniqueTraders
        liquidityUsd {
          o
          h
          l
          c
        }
      }
      min15 {
        t
        volumeUsd
        trades
      }
      hour1 {
        t
        volumeUsd
        totalVolumeUsd
        trades
      }
      hour4 {
        t
        volumeUsd
      }
      day1 {
        t
        volumeUsd
        totalVolumeUsd
      }
    }
  }
}
```

```json Example Response theme={null}
{
  "data": {
    "onPredictionEventBarsUpdated": {
      "bars": {
        "min1": {
          "t": 1773357360,
          "volumeUsd": "1047.043738",
          "buyVolumeUsd": "1046.940304",
          "sellVolumeUsd": "0.103434",
          "totalVolumeUsd": "183698948.904681",
          "venueVolumeUsd": "350603420.708316",
          "volumeCollateralToken": "1047.10344",
          "trades": 5,
          "uniqueTraders": 2,
          "lastEventTimestamp": 1773357373,
          "liquidityUsd": {
            "o": "40568747.579197",
            "h": "40569107.283499",
            "l": "40568639.455529",
            "c": "40568771.326025"
          },
          "openInterestUsd": {
            "o": "34058066.149446",
            "h": "34058066.149446",
            "l": "34058066.149446",
            "c": "34058066.149446"
          }
        },
        "min5": {
          "t": 1773357300,
          "volumeUsd": "3347.885241",
          "trades": 10,
          "uniqueTraders": 3,
          "liquidityUsd": {
            "o": "40571553.036979",
            "h": "40571553.036979",
            "l": "40568639.455529",
            "c": "40568771.326025"
          }
        },
        "min15": {
          "t": 1773357300,
          "volumeUsd": "3347.885241",
          "trades": 10
        },
        "hour1": {
          "t": 1773356400,
          "volumeUsd": "29290.703467",
          "totalVolumeUsd": "183698948.904681",
          "trades": 72
        },
        "hour4": {
          "t": 1773345600,
          "volumeUsd": "129468.523663"
        },
        "day1": {
          "t": 1773273600,
          "volumeUsd": "8580175.57018",
          "totalVolumeUsd": "183698948.904681"
        }
      }
    }
  }
}
```

### Usage Guidelines

* **Event ID format** varies by platform:
  * **Polymarket**: `<eventSlug>:Polymarket:<exchangeAddress>:<networkId>` (e.g., `67284:Polymarket:0xc5d563a36ae78145c45a50134d48a1215220f80a:137`)
  * **Kalshi**: `<eventSlug>:Kalshi` (e.g., `KXMVESPORTSMULTIGAMEEXTENDED-S2026350C4EF9BCE:Kalshi`)
* Subscribe using `eventId` to receive live bar chart data for a prediction event
* Bars are provided across multiple resolutions simultaneously: `min1`, `min5`, `min15`, `min30`, `hour1`, `hour4`, `hour12`, `day1`, and `week1`
* Updates stream whenever new trading activity occurs, recalculating affected bars

### Troubleshooting Tips

> [accordion] Which resolution should I use for charting?
>
> Choose based on your timeframe: `min1` for tick-by-tick updates, `min5` or `min15` for short-term charts (1-hour view), `hour1` or `hour4` for medium-term (1-day to 1-week view), and `day1` or `week1` for long-term historical views. Request only the resolutions you need to reduce data volume.

> [accordion] What does the timestamp (t) represent?
>
> The `t` field is the Unix timestamp marking the start of that bar's time period. For example, a 5-minute bar with `t: 1710345600` covers the period from that timestamp to 5 minutes later (1710345900). Bars are aligned to clean intervals (e.g., :00, :05, :10 for 5-minute bars).

> [accordion] How do I interpret OHLC values for liquidity and open interest?
>
> OHLC (Open, High, Low, Close) shows the range and direction of liquidity or open interest during that bar. `o` is the value at the bar's start, `h` is the maximum, `l` is the minimum, and `c` is the value at the bar's end. This helps visualize how capital flow changed over time.

> [accordion] What's the difference between volumeUsd and totalVolumeUsd?
>
> `volumeUsd` is the trading volume that occurred during that specific bar period, while `totalVolumeUsd` is the cumulative all-time volume for the event up to that bar. Use `volumeUsd` for bar charts and `totalVolumeUsd` to show total market size.

> [accordion] How often are bars updated?
>
> Bars update in real-time as trades occur. When a new trade happens, all affected bars (across all resolutions) are recalculated and pushed via the subscription. High-activity events may send updates multiple times per second during peak trading.

> [accordion] Do all resolutions always have data?
>
> No. Bars only exist if there was activity during that time period. For events with sparse trading, you may receive null values for smaller resolutions (e.g., `min1` or `min5`) while larger resolutions (e.g., `hour1`, `day1`) have data. Check for null before rendering.

> [accordion] How do I handle bar updates for completed periods?
>
> Bars are considered "complete" once their time period has passed. For example, a 1-minute bar starting at 12:00:00 is complete after 12:01:00. You can update your chart in real-time for the current incomplete bar and treat completed bars as final. Use `lastEventTimestamp` to determine freshness.


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