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

# predictionEventTopMarketsBars

> Returns bar data for top markets inside 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.
    predictionEventTopMarketsBars(
      input: PredictionEventTopMarketsBarsInput!
    ): PredictionEventTopMarketsBarsResponse
  }

  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 PredictionMarketBarOhlc {
    o: String!
    h: String!
    l: String!
    c: String!
  }

  type PredictionOutcomeBar {
    venueOutcomeId: String!
    trades: Int
    buys: Int
    sells: Int
    volumeShares: String
    buyVolumeShares: String
    sellVolumeShares: String
    volumeUsd: String
    buyVolumeUsd: String
    sellVolumeUsd: String
    volumeCollateralToken: String
    buyVolumeCollateralToken: String
    sellVolumeCollateralToken: String
    priceUsd: PredictionMarketBarOhlc
    priceCollateralToken: PredictionMarketBarOhlc
    liquidityUsd: PredictionMarketBarOhlc
    liquidityCollateralToken: PredictionMarketBarOhlc
    bidUsd: PredictionMarketBarOhlc
    bidCollateralToken: PredictionMarketBarOhlc
    askUsd: PredictionMarketBarOhlc
    askCollateralToken: PredictionMarketBarOhlc
    twoPercentBidDepthUsd: PredictionMarketBarOhlc
    twoPercentBidDepthCollateralToken: PredictionMarketBarOhlc
    twoPercentAskDepthUsd: PredictionMarketBarOhlc
    twoPercentAskDepthCollateralToken: PredictionMarketBarOhlc
  }

  type PredictionMarketBar {
    t: Int!
    volumeUsd: String
    volumeCollateralToken: String
    volumeShares: String
    uniqueTraders: Int
    lastEventTimestamp: Int
    trades: Int
    allTimeVolumeUsd: String
    allTimeVenueVolumeUsd: String
    allTimeVolumeCollateralToken: String
    allTimeVenueVolumeCollateralToken: String
    openInterestUsd: PredictionMarketBarOhlc
    outcome0: PredictionOutcomeBar
    outcome1: PredictionOutcomeBar
  }

  type PredictionMarketBarsResponse {
    marketId: String!
    predictionMarket: PredictionMarket!
    predictionEvent: PredictionEvent!
    bars: [PredictionMarketBar!]!
  }

  type PredictionEventTopMarketsBarsResponse {
    eventId: String!
    predictionEvent: PredictionEvent
    marketBars: [PredictionMarketBarsResponse!]!
  }

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

  enum PredictionMarketRankingAttribute {
    timestamp
    lastTransactionAt
    age
    createdAt
    expectedLifespan
    opensAt
    closesAt
    resolvesAt
    trendingScore5m
    trendingScore1h
    trendingScore4h
    trendingScore12h
    trendingScore24h
    trendingScore1w
    relevanceScore5m
    relevanceScore1h
    relevanceScore4h
    relevanceScore12h
    relevanceScore24h
    relevanceScore1w
    competitiveScore5m
    competitiveScore1h
    competitiveScore4h
    competitiveScore12h
    competitiveScore24h
    competitiveScore1w
    liquidityUsd
    liquidityCT
    liquidityChange5m
    liquidityChange1h
    liquidityChange4h
    liquidityChange12h
    liquidityChange24h
    liquidityChange1w
    openInterestUsd
    openInterestCT
    openInterestChange5m
    openInterestChange1h
    openInterestChange4h
    openInterestChange12h
    openInterestChange24h
    openInterestChange1w
    volumeUsd5m
    volumeUsd1h
    volumeUsd4h
    volumeUsd12h
    volumeUsd24h
    volumeUsd1w
    volumeUsdAll
    volumeCTAll
    venueVolumeUsd
    venueVolumeCT
    volumeChange5m
    volumeChange1h
    volumeChange4h
    volumeChange12h
    volumeChange24h
    volumeChange1w
    trades5m
    trades1h
    trades4h
    trades12h
    trades24h
    trades1w
    avgTradeSizeUsd5m
    avgTradeSizeUsd1h
    avgTradeSizeUsd4h
    avgTradeSizeUsd12h
    avgTradeSizeUsd24h
    avgTradeSizeUsd1w
    tradesChange5m
    tradesChange1h
    tradesChange4h
    tradesChange12h
    tradesChange24h
    tradesChange1w
    uniqueTraders5m
    uniqueTraders1h
    uniqueTraders4h
    uniqueTraders12h
    uniqueTraders24h
    uniqueTraders1w
    uniqueTradersChange5m
    uniqueTradersChange1h
    uniqueTradersChange4h
    uniqueTradersChange12h
    uniqueTradersChange24h
    uniqueTradersChange1w
    priceCompetitiveness
    volumeImbalance24h
    liquidityAsymmetry
    impliedProbabilitySum
    maxPriceRange5m
    maxPriceRange1h
    maxPriceRange4h
    maxPriceRange12h
    maxPriceRange24h
    maxPriceRange1w
    phraseScore
  }

  enum PredictionOutcomeIndex {
    outcome0
    outcome1
  }

  enum PredictionOutcomeRankingAttribute {
    bestBidUsd
    bestAskUsd
    spreadUsd
    lastPriceUsd
    bestBidCT
    bestAskCT
    spreadCT
    lastPriceCT
    liquidityUsd
    liquidityCT
    twoPercentAskDepthUsd
    twoPercentBidDepthUsd
    twoPercentAskDepthCT
    twoPercentBidDepthCT
    highPriceUsd5m
    highPriceUsd1h
    highPriceUsd4h
    highPriceUsd12h
    highPriceUsd24h
    highPriceUsd1w
    lowPriceUsd5m
    lowPriceUsd1h
    lowPriceUsd4h
    lowPriceUsd12h
    lowPriceUsd24h
    lowPriceUsd1w
    volumeUsd5m
    volumeUsd1h
    volumeUsd4h
    volumeUsd12h
    volumeUsd24h
    volumeUsd1w
    volumeChange5m
    volumeChange1h
    volumeChange4h
    volumeChange12h
    volumeChange24h
    volumeChange1w
    volumeShares5m
    volumeShares1h
    volumeShares4h
    volumeShares12h
    volumeShares24h
    volumeShares1w
    buyVolumeUsd5m
    buyVolumeUsd1h
    buyVolumeUsd4h
    buyVolumeUsd12h
    buyVolumeUsd24h
    buyVolumeUsd1w
    sellVolumeUsd5m
    sellVolumeUsd1h
    sellVolumeUsd4h
    sellVolumeUsd12h
    sellVolumeUsd24h
    sellVolumeUsd1w
    trades5m
    trades1h
    trades4h
    trades12h
    trades24h
    trades1w
    buys5m
    buys1h
    buys4h
    buys12h
    buys24h
    buys1w
    sells5m
    sells1h
    sells4h
    sells12h
    sells24h
    sells1w
    tradesChange5m
    tradesChange1h
    tradesChange4h
    tradesChange12h
    tradesChange24h
    tradesChange1w
    priceChange5m
    priceChange1h
    priceChange4h
    priceChange12h
    priceChange24h
    priceChange1w
    priceRange5m
    priceRange1h
    priceRange4h
    priceRange12h
    priceRange24h
    priceRange1w
  }

  enum RankingDirection {
    ASC
    DESC
  }

  input PredictionEventTopMarketsBarsInput {
    eventId: String!
    from: Int!
    to: Int!
    resolution: PredictionMarketBarsResolution!
    countback: Int
    limit: Int
    useLeaderboard: Boolean
    rankBy: PredictionMarketRankingAttribute
    rankByOutcome: PredictionOutcomeIndex
    rankByOutcomeAttribute: PredictionOutcomeRankingAttribute
    rankDirection: RankingDirection
    removeEmptyBars: Boolean
    marketIds: [String!]
  }
  ```
</div>

## Example Queries

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

Get trending markets ranked by outcome price change

```graphql theme={null}
{
  predictionEventTopMarketsBars(input: {
    eventId: "67284:Polymarket:0xc5d563a36ae78145c45a50134d48a1215220f80a:137"
    from: 1773347775
    to: 1773349275
    resolution: min15
    limit: 3
    rankByOutcome: outcome0
    rankByOutcomeAttribute: priceChange1h
    rankDirection: DESC
    removeEmptyBars: true
  }) {
    marketBars {
      marketId
      predictionMarket {
        question
        outcomeLabels
      }
      bars {
        t
        volumeUsd
        outcome0 {
          priceUsd {
            o
            h
            l
            c
          }
          liquidityUsd {
            c
          }
        }
      }
    }
  }
}
```

## Example Response

```json Example response (truncated) theme={null}
{
  "data": {
    "predictionEventTopMarketsBars": {
      "marketBars": [
        {
          "marketId": "0xdeb615a52cd114e5aa27d8344ae506a72bea81f6ed13f5915f050b615a193c20:Polymarket:0xc5d563a36ae78145c45a50134d48a1215220f80a:137",
          "predictionMarket": {
            "question": "Will the Fed decrease interest rates by 50+ bps after the March 2026 meeting?",
            "outcomeLabels": [
              "Yes",
              "No"
            ]
          },
          "bars": [
            {
              "t": 1773347400,
              "volumeUsd": "1291.363323",
              "outcome0": {
                "priceUsd": {
                  "o": "0.002",
                  "h": "0.002",
                  "l": "0.002",
                  "c": "0.002"
                },
                "liquidityUsd": {
                  "c": "7145187.310262"
                }
              }
            },
            {
              "t": 1773348300,
              "volumeUsd": "988.200516",
              "outcome0": {
                "priceUsd": {
                  "o": "0.002",
                  "h": "0.002",
                  "l": "0.002",
                  "c": "0.002"
                },
                "liquidityUsd": {
                  "c": "7138365.20336"
                }
              }
            },
            {
              "t": 1773349200,
              "volumeUsd": "703.948227",
              "outcome0": {
                "priceUsd": {
                  "o": "0.002",
                  "h": "0.002",
                  "l": "0.002",
                  "c": "0.002"
                },
                "liquidityUsd": {
                  "c": "7093679.819347"
                }
              }
            }
          ]
        },
        // ... 2 more markets
      ]
    }
  }
}
```

## Usage Guidelines

This query returns bar data for multiple top markets within a prediction event, combining event context with individual market time-series data. It's useful for comparing market performance, identifying trending markets, and analyzing multi-market events.

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`)
* **Batch market data**: Get bars for up to 10 markets in a single query
* **Flexible ranking**: Rank markets by volume, liquidity, trending score, or outcome-specific metrics
* **Complete market context**: Each response includes the full market object plus bar data
* **Efficient querying**: Better performance than making multiple individual [`predictionMarketBars`](/api-reference/queries/predictionmarketbars) calls
* **Time-series format**: Same OHLC bar structure as [`predictionMarketBars`](/api-reference/queries/predictionmarketbars)

Common use cases:

* Display multiple markets from an event on a dashboard
* Compare trading activity across related markets
* Identify the most active or trending markets within an event
* Build event overview pages with market-level granularity

## Troubleshooting Tips

<AccordionGroup>
  <Accordion title="Should I use rankBy or rankByOutcome + rankByOutcomeAttribute?">
    * Use `rankBy` for market-level metrics (e.g., `volumeUsd24h`, `liquidityUsd`, `uniqueTraders24h`)
    * Use `rankByOutcome` + `rankByOutcomeAttribute` for outcome-specific metrics (e.g., price changes, outcome-specific volume)

    You cannot use both at the same time. Choose based on whether you're ranking markets by overall activity or by specific outcome performance.
  </Accordion>

  <Accordion title="What happens if I specify marketIds?">
    When you provide `marketIds`, the ranking parameters are ignored and you'll get bars for exactly those markets. This is useful when you want specific markets but still benefit from the batch query performance. The limit parameter is also ignored in this case.
  </Accordion>

  <Accordion title="Why am I getting fewer than 'limit' markets?">
    Possible reasons:

    * The event has fewer markets than your limit
    * Some markets had no activity in the specified time range (when `removeEmptyBars: true`)
    * Some markets don't have the ranking attribute you specified (e.g., older markets may not have trending scores)

    Check the total number of markets in the event using the `predictionEvent` query.
  </Accordion>

  <Accordion title="How do trending scores work for ranking?">
    Trending scores (e.g., `trendingScore1h`, `trendingScore24h`) are composite metrics that consider:

    * Recent volume changes
    * Price movement velocity
    * Unique trader growth
    * Social engagement (where available)

    Higher scores indicate markets experiencing rapid increases in activity. Use these to surface "hot" markets.
  </Accordion>

  <Accordion title="What's the difference between rankDirection ASC and DESC?">
    * `DESC` (descending): Highest values first - use for "top" markets (e.g., highest volume, most liquid)
    * `ASC` (ascending): Lowest values first - use for "bottom" markets or when looking for lowest spreads, earliest closing times, etc.

    Most use cases want `DESC` to get the top/best markets.
  </Accordion>

  <Accordion title="Can I rank by outcome price but get both outcomes' data?">
    Yes! The ranking only determines which markets are returned. You can rank by `outcome0.priceChange1h` but still query full data for both `outcome0` and `outcome1` in your bars selection. The ranking criterion doesn't limit what data you receive.
  </Accordion>

  <Accordion title="How should I handle the max limit of 10 markets?">
    The 10-market limit balances comprehensive data with performance. If you need more markets:

    * Make multiple queries with different ranking criteria
    * Use pagination by explicitly specifying different `marketIds` in subsequent queries
    * Consider whether you truly need more than 10 markets for your UI/analysis

    Most dashboards and visualizations work well with 5-10 top markets.
  </Accordion>
</AccordionGroup>

### Related Recipes

* [Prediction Event Dashboard](/recipes/predictions/event-dashboard): Use multi-market bars for the probability comparison chart on an event page
* [Prediction Charts](/recipes/predictions/charts): Render multi-candidate probability lines and other chart types
