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

# predictionEventBars

> Returns bar data for a prediction event.

<Info>
  **Prediction Market data is currently in beta**. It is actively being worked on and improved, but may be unreliable. Polymarket and Kalshi data are live.

  At least for the time being, this endpoint requires a Growth or Enterprise plan. [Learn more](https://dashboard.codex.io/dashboard/billing?utm_source=codex\&utm_medium=docs\&utm_campaign=billing).
</Info>

<div data-generated>
  ## GraphQL

  ```
  type Query {
    # Requires a Growth or Enterprise plan.
    predictionEventBars(
      input: PredictionEventBarsInput!
    ): PredictionEventBarsResponse
  }

  enum PredictionProtocol {
    POLYMARKET
    KALSHI
  }

  enum PredictionEventStatus {
    OPEN
    SUSPENDED
    RESOLVED
    CANCELLED
    PENDING
  }

  type PredictionResolution {
    result: String
    source: String
  }

  type PredictionSubSubcategory {
    name: String!
    slug: String!
  }

  type PredictionSubcategory {
    name: String!
    slug: String!
    subcategories: [PredictionSubSubcategory!]
  }

  type PredictionCategory {
    name: String!
    slug: String!
    subcategories: [PredictionSubcategory!]
  }

  enum PredictionMetadataType {
    SPORTS
  }

  type SportsTeam {
    abbreviation: String!
    altAbbreviations: [String!]
    name: String
    league: String
    logo: String
    alias: String
    color: String
    providerId: Int
    isHome: Boolean
  }

  enum SportsTimezone {
    UTC
  }

  type KalshiSportsTickerComponents {
    rawTicker: String!
    seriesPrefix: String!
    seriesSport: String
    teamTailRaw: String
    homeAbbreviation: String
    awayAbbreviation: String
  }

  type DecomposedVenueTicker {
    kalshiSports: KalshiSportsTickerComponents
  }

  type SportsEventEnrichedMetadata {
    league: String
    teams: [SportsTeam!]
    gameStartDate: String
    gameStartTime: String
    gameStartTimeSeconds: Int
    gameStartTimezone: SportsTimezone
    decomposedVenueTicker: DecomposedVenueTicker
  }

  type PredictionEventEnrichedMetadata {
    metadataType: PredictionMetadataType!
    sports: SportsEventEnrichedMetadata
  }

  type PredictionEvent {
    id: String!
    protocol: PredictionProtocol!
    venueEventId: String!
    venueSeriesId: String
    status: PredictionEventStatus!
    question: String!
    url: String!
    rulesPrimary: String!
    rulesSecondary: String
    tags: [String!]!
    opensAt: Int!
    closesAt: Int
    resolvesAt: Int
    resolvedAt: Int
    resolution: PredictionResolution
    imageLargeUrl: String
    imageThumbUrl: String
    imageSmallUrl: String
    createdAt: Int!
    updatedAt: Int!
    networkId: Int
    marketIds: [String!]
    categories: [PredictionCategory!]
    enrichedMetadata: PredictionEventEnrichedMetadata
  }

  type SportsMarketEnrichedMetadata {
    sportsMarketType: String
    league: String
    teams: [SportsTeam!]
    gameStartDate: String
    gameStartTime: String
    gameStartTimeSeconds: Int
    gameStartTimezone: SportsTimezone
  }

  type PredictionMarketEnrichedMetadata {
    metadataType: PredictionMetadataType!
    sports: SportsMarketEnrichedMetadata
  }

  type PredictionMarket {
    id: String!
    protocol: PredictionProtocol!
    venueMarketId: String!
    venueMarketSlug: String
    eventId: String
    venueEventId: String
    question: String
    label: String
    suggestedLabel: String
    eventLabel: String
    rules: String
    rules2: String
    venueOutcomeIds: [String!]!
    outcomeIds: [String!]!
    outcomeLabels: [String!]
    resolution: PredictionResolution
    imageLargeUrl: String
    imageThumbUrl: String
    imageSmallUrl: String
    createdAt: Int
    updatedAt: Int
    opensAt: Int
    closesAt: Int
    resolvesAt: Int
    resolvedAt: Int
    observedAt: Int!
    networkId: Int
    exchangeAddress: String
    categories: [PredictionCategory!]
    winningOutcomeId: String
    enrichedMetadata: PredictionMarketEnrichedMetadata
  }

  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 PredictionEventBarsResponse {
    eventId: String!
    predictionEvent: PredictionEvent
    predictionMarkets: [PredictionMarket!]!
    bars: [PredictionEventBar!]!
  }

  enum PredictionEventBarsResolution {
    min1
    min5
    min15
    min30
    hour1
    hour4
    hour12
    day1
    week1
  }

  input PredictionEventBarsInput {
    eventId: String!
    from: Int!
    to: Int!
    resolution: PredictionEventBarsResolution!
    countback: Int
    removeEmptyBars: Boolean
  }
  ```
</div>

## Example Query

<a href="/explore" target="_blank" rel="noopener noreferrer">Test this query in the Explorer →</a>

Get last 30 daily bars using countback:

```graphql theme={null}
{
  predictionEventBars(input: {
    eventId: "67284:Polymarket:0xc5d563a36ae78145c45a50134d48a1215220f80a:137"
    from: 0
    to: 1772658000
    resolution: day1
    countback: 30
    removeEmptyBars: true
  }) {
    eventId
    predictionEvent {
      question
      status
    }
    bars {
      t
      volumeUsd
      totalVolumeUsd
      venueVolumeUsd
      trades
      uniqueTraders
      lastEventTimestamp
      liquidityUsd {
        o
        h
        l
        c
      }
    }
  }
}
```

## Example Response

```json Example Response (truncated) theme={null}
{
  "data": {
    "predictionEventBars": {
      "eventId": "67284:Polymarket:0xc5d563a36ae78145c45a50134d48a1215220f80a:137",
      "predictionEvent": {
        "question": "Fed decision in March?",
        "status": "OPEN"
      },
      "bars": [
        {
          "t": 1772582400,
          "volumeUsd": "4906325.281156",
          "totalVolumeUsd": "112199853.153373",
          "venueVolumeUsd": "209027531.42911",
          "trades": 6336,
          "uniqueTraders": 2226,
          "lastEventTimestamp": 1772668739,
          "liquidityUsd": {
            "o": "8244955.561824",
            "h": "13362151.737655",
            "l": "7993263.732354",
            "c": "13127851.388841"
          }
        }
        // ... 29 more bars
      ]
    }
  }
}
```

## Usage Guidelines

Bar data provides time-series OHLC (Open, High, Low, Close) aggregates for prediction events. Each bar represents a specific time period and includes volume metrics, liquidity snapshots, open interest, and trader activity.

Key characteristics:

* **Event ID format**: The `eventId` format varies by platform:
  * **Polymarket**: `<eventSlug>:Polymarket:<exchangeAddress>:<networkId>` (e.g., `67284:Polymarket:0xc5d563a36ae78145c45a50134d48a1215220f80a:137`)
  * **Kalshi**: `<eventSlug>:Kalshi` (e.g., `KXMVESPORTSMULTIGAMEEXTENDED-S2026350C4EF9BCE:Kalshi`)
* **Time-series format**: Each bar has a timestamp (`t`) representing the start of the period
* **OHLC structure**: Metrics like `liquidityUsd` and `openInterestUsd` contain `o`, `h`, `l`, `c` values
* **Multiple resolutions**: From 1-minute to 1-week intervals
* **Volume tracking**: Separate buy/sell volumes in both USD and collateral tokens
* **Trader metrics**: Track unique traders and trade counts per period

## Troubleshooting Tips

<AccordionGroup>
  <Accordion title="Why are some bars missing?">
    Bars are only created when there's activity during that time period. Use `removeEmptyBars: false` to include zero-activity bars in the response. This is especially important for charting applications that need continuous time series.
  </Accordion>

  <Accordion title="How do I calculate net volume?">
    Net volume = `buyVolumeUsd` - `sellVolumeUsd`. A positive value indicates more buying pressure, while negative indicates more selling pressure. This can be useful for identifying sentiment shifts.
  </Accordion>

  <Accordion title="What's the difference between volumeUsd, totalVolumeUsd, and venueVolumeUsd?">
    * `volumeUsd`: Volume during this specific bar period
    * `totalVolumeUsd`: Cumulative all-time volume as of the bar close
    * `venueVolumeUsd`: Cumulative volume as reported by the venue (may differ due to timing)
  </Accordion>

  <Accordion title="Why do OHLC values seem unusual for liquidity?">
    Unlike price data, liquidity OHLC represents snapshots taken during the period, not transaction values. High values indicate peak liquidity, low values indicate liquidity drops. These can help identify periods of market stress or high activity.
  </Accordion>

  <Accordion title="How should I choose the right resolution?">
    * `min1`, `min5`, `min15`: For real-time monitoring and high-frequency analysis
    * `hour1`, `hour4`: For intraday trends and active market analysis
    * `day1`, `week1`: For long-term trends and historical analysis

    Consider your data retention needs and query performance when choosing resolution.
  </Accordion>

  <Accordion title="What does uniqueTraders count?">
    The number of unique trader addresses that executed at least one trade during the bar period. This metric helps gauge market participation breadth. A high volume with low unique traders may indicate whale activity.
  </Accordion>

  <Accordion title="How do I handle the countback parameter?">
    `countback` lets you request a specific number of bars working backwards from the `to` timestamp. When using `countback`, the `from` parameter is still required but effectively ignored. This is useful for "last N periods" queries without calculating timestamps.
  </Accordion>
</AccordionGroup>

### Related Recipes

* [Prediction Event Dashboard](/recipes/predictions/event-dashboard): Use event bars for volume, liquidity, and open interest charts
* [Prediction Charts](/recipes/predictions/charts): Render event-level aggregated charts alongside market-level charts
