In this recipe we’ll walk through building a prediction event detail page, the kind of page Polymarket and Kalshi center their UX around. An event like “2024 Presidential Election” contains multiple related markets (“Who wins?”, “Popular vote margin?”, “Which states flip?”).
We’ll combine multiple Codex endpoints to populate every section: event metadata, market probabilities, multi-market charts, aggregated activity, trade history, and market drill-downs.
We’ll combine multiple Codex endpoints to populate every section: event metadata, market probabilities, multi-market charts, aggregated activity, trade history, and market drill-downs.
Step 1: Event Metadata & Market List
For the examples below to work, you’ll need an ID of an event. You can get that by using filterPredictionEvents. Take the ouput of that and replace the
eventId value in the queries below.Unforunately, Prediction Markets are ever changing so it’s hard for us to hardcode an example like we can with tokens.detailedPredictionEventStats. This returns event metadata, the full list of markets, aggregated stats across time windows, and lifecycle information.Full event metadata with markets and stats
Full event metadata with markets and stats
This is the core call that populates the event header, market list sidebar, and summary stats. It gives you everything you need to render the top of the page in one request. Stats are available at multiple windows.
statsDay1 is shown above, but statsHour1, statsHour4, statsHour12, statsWeek1 follow the same structure.Step 2: Market Outcome Pricing
To show current probabilities (best ask price) for each market’s outcomes (the core of any prediction market UI), use
filterPredictionMarkets scoped to the event. This returns real-time bid/ask pricing, spread, liquidity depth, and volume for each outcome.Current outcome pricing for all markets in an event
Current outcome pricing for all markets in an event
- The
bestAskCTprice (in collateral token, e.g., USDC) represents the current implied probability (0.65 = 65% chance) - Ranking by outcome0’s
bestAskCTin DESC order puts the highest-probability outcomes at the top - You can also rank by market-level attributes like
volumeUsd24hortrendingScore24h - The spread (
bestAskCT - bestBidCT) indicates market efficiency - This is the data that powers the market list showing “Yes 65¢ / No 35¢” for each market
Step 3: Multi-Market Probability Chart
The signature visualization: a multi-line chart showing how probabilities for the top markets in an event have moved over time. Use
predictionEventTopMarketsBars.Top 5 markets by weekly volume
Top 5 markets by weekly volume
- Returns OHLC bars for the top N markets (up to 10) in a single request
rankBydetermines which markets are “top”. UsevolumeUsd1wfor most active, or rank by outcome attribute withrankByOutcome+rankByOutcomeAttribute- Plot
outcome0.priceCollateralToken.c(close price) for each market as a line to get the multi-candidate probability chart - You can also pass explicit
marketIdsinstead of using ranking to choose which markets to chart
Step 4: Event-Level Aggregated Charts
For charts showing aggregated activity across the entire event (total volume, liquidity, open interest over time), use
predictionEventBars.Event volume, liquidity, and open interest over time
Event volume, liquidity, and open interest over time
- This aggregates data across ALL markets in the event
- Use for volume bar charts, liquidity area charts, and open interest line charts
buyVolumeUsd/sellVolumeUsdbreakdown enables buy/sell pressure analysisuniqueTradersshows participation growth over time
Step 5: Trade Feed
Recent trades for an event
Recent trades for an event
- Returns trades across all markets in the event, sorted by most recent
- Each trade includes the
outcomeLabelandoutcomeIndexso you can show “Bought Yes @ $0.65” cursorenables pagination for loading more tradestraderIdcan be used to link to trader profiles- Can also query by
marketIdfor single-market trade feeds
Step 6: Single Market Drill-Down
When a user clicks on a specific market within the event, fetch detailed chart data and token holder information.
Single market OHLC chart with bid/ask
Single market OHLC chart with bid/ask
Outcome token holders
Outcome token holders
Getting the
tokenId: The tokenId is extracted from the outcomeIds array on the market object (returned in Step 1). Each outcomeId is a compound string like 46553455570564517989191023458705371521436514261892866503067981558938998232024:Polymarket:0xc5d563a36ae78145c45a50134d48a1215220f80a:137. The tokenId is just the first segment before the first colon (e.g., 46553455570564517989191023458705371521436514261892866503067981558938998232024).For a binary market, outcomeIds[0] is the “Yes” token and outcomeIds[1] is the “No” token. Query once per outcome to get holders for each side.- Market bars give per-outcome OHLC data for price, liquidity, bid, and ask, enabling candlestick charts and bid/ask spread visualization
- Token holders shows who holds the most of each outcome token, with their trader alias if available
- Token holder data is only available for Polymarket (on-chain ERC-1155 tokens on Polygon). Kalshi does not expose holder data.
Putting It All Together
Here’s the recommended data flow for an event dashboard: On page load (parallel queries):detailedPredictionEventStats: event metadata, market list, aggregated statsfilterPredictionMarkets(eventIds): current outcome pricing for all marketspredictionEventTopMarketsBars: multi-market probability chart datapredictionEventBars: event-level volume/liquidity charts
predictionTrades(eventId): trade feed
predictionMarketBars: when user clicks a specific marketpredictionTokenHolders: when user views holders tab
Check out the related endpoints in their respective API reference pages: