Why Real-Time and Historical Onchain Data Need Different Designs
If you’re building a trading interface, wallet, or analytics product, you don’t just need “onchain data.”
You need two different products:
- A real-time onchain data API for live prices, charts, and notifications with sub-second latency.
- A historical onchain data API for backtesting, long-range analytics, compliance, and reporting.
Trying to serve both from the same naive pipeline leads to one of two failures:
- Fast but incomplete data that can’t support analytics or audits.
- Accurate but slow data that can’t power trading or high-traffic consumer apps.
Codex is built around this split: a low-latency blockchain data API for live use cases, paired with enriched historical data models for analytics, all exposed in a unified GraphQL-style interface.
This article breaks down:
- What makes real-time vs. historical onchain data fundamentally different.
- How Codex models both (tokens, bars, holders, prediction markets).
- Practical integration patterns for charting, monitoring, and backtesting alongside live trading UX.
Real-Time vs. Historical Onchain Data: Key Differences
1. Latency vs. Completeness
For real-time trading experiences, latency is king:
- You care about sub-second updates from new blocks and mempool events.
- You need ordered, reorg-aware streaming, not just “eventually correct” data.
- You’re optimizing API hot paths that sit directly behind charts and order controls.
For historical analytics, completeness is king:
- You need full history (months/years) across tokens, pools, and chains.
- You want stable, documented schemas that won’t break queries or dashboards.
- You care about precomputed aggregates (OHLCV, holders, liquidity, TVL-like stats) rather than raw logs.
Codex’s own docs reflect this split:
getTokenPricesis explicitly optimized for speed, not deepest historical accuracy.getDetailedPairStatsis the recommended source for historical price and volume correctness.
2. Streaming vs. Query Workflows
Real-time workflows rely on:
- Subscriptions/WebSockets for onchain data streaming.
- Event-driven handlers that update UI state, trigger alerts, or run bots.
- Clear semantics around confirmed vs. processed updates.
Historical workflows rely on:
- Query APIs that can fetch large time windows in a single call.
- Batch jobs / ETL that feed internal warehouses and models.
- Deterministic, replayable access to the full event history.
Most leading providers now converge on this hybrid model. Codex formalizes it as Queries vs. Subscriptions in its docs.
3. Data Modeling and Enrichment
Raw blockchain logs are not directly usable for either side:
- Trading UIs need token-centric and market-centric objects (bars, prices, holders, wallets).
- Analytics needs normalized models that survive protocol upgrades and contract differences.
That’s why the strongest vendors — including Codex, Covalent, Dune, and others — position themselves as data-model companies, not just indexers. Codex, for example, exposes:
- Tokens: metadata, scam filtering, launch data across 70M+ assets.
- Bars (OHLCV): per pair or aggregated across pools, in USD and native.
- Holders and wallets: transfer-driven holder counts, wallet stats, and performance.
- Prediction markets: events, markets, trades, trader analytics across Polymarket, Kalshi (beta).
Codex’s Architecture: One API, Two Modes (Real-Time + Historical)
Codex indexes:
- 80+ networks
- 70M+ tokens
- 700M+ wallets
- 27B+ historical events
It then exposes that via:
- Query endpoints for historical onchain data (tokens, bars, holders, prediction analytics).
- Subscription endpoints for real-time onchain data streaming (bars, prices, events).
At a high level, Codex:
- Backfills history chain by chain.
- Streams live blocks/events with sub-second freshness.
- Handles reorgs and reconciles confirmed vs. processed states.
- Normalizes into stable schemas, so your app doesn’t care which DEX/AMM or market protocol emitted the underlying events.
This separation lets you design your product around clear data contracts:
- Use queries when you care about completeness and consistent snapshots.
- Use subscriptions when you care about speed and live UX.
Designing APIs for Live Trading & Monitoring
To build the best real-time crypto data API experience into your product, you need:
- Streaming charts
- Live price updates
- Real-time alerts and monitoring
Codex provides a pattern for this.
Live Charts: getBars + onBarsUpdated
Codex treats charting as a two-step workflow:
Initial history fetch
- Use
getBarsfor a specific pair/market. - Up to 1,500 datapoints per request.
- Sub-1-minute resolutions available for the last 24 hours.
- Use
Live updates
- Subscribe to
onBarsUpdated. - Receives multi-resolution OHLCV updates with:
- Price in USD and native token.
volume,buyVolume,sellVolume.- Trading-flow metrics like
buyers,sellers.
- Updates emitted on each onchain swap event.
- Subscribe to
For token-level charts across all pools, use getTokenBars instead of pair-level getBars — this yields liquidity-weighted charts suitable for consumer-friendly token pages.
Real-Time Prices: getTokenPrices + Subscriptions
For hot-path price data behind trading UIs:
- Use
getTokenPricesfor:- Real-time prices in USD and native.
- Fast responses optimized for UX.
- For maximum accuracy across longer timeframes:
- Use
getDetailedPairStatsorgetTokenBarsfor deeper analytics.
- Use
This follows Codex’s design rule: separate speed from completeness.
Wallet and Holder Monitoring
Monitoring whales, LPs, or user portfolios in real time requires:
- Fast reads on current balances and positions.
- Accurate modeling of holder counts and wallet histories.
Codex offers:
holdersfor accurate holder counts per token:- Updated on every transfer.
- Returns up to 200 holders per request.
filterTokenWalletsfor trading stats per wallet, not just balances:- Useful for leaderboards, trader performance, and social trading views.
For streaming address-level changes, you can combine these with event subscriptions to drive dashboards and alerts.
Real-Time Prediction Market Data
Prediction markets are particularly sensitive to latency and correctness.
Codex’s prediction market API (beta) covers Polymarket and Kalshi with:
- Events and markets (
filterPredictionEvents,filterPredictionMarkets). - Real-time trades and price changes.
- Trader analytics (open holdings, performance).
Key models:
predictionTraderHoldingsfor current open positions:- Fully accurate and updated as trades settle onchain (Polymarket) or via Kalshi’s WebSocket.
- Ideal for live portfolio views.
predictionTraderMarketsStatsfor historical performance:- Available from ~Feb 2026 onward.
- Use for PnL history, win rates, and advanced analytics.
This makes Codex one of the first prediction market API providers designed for trading-grade apps, not just dashboards.
Designing APIs for Historical Analytics & Backtesting
Historical onchain data is the backbone of:
- Quant models and backtesting.
- Risk/treasury analytics.
- Regulatory or internal reporting.
- Long-range charting and cohort analysis.
Historical Prices & Liquidity: getDetailedPairStats and getTokenBars
For backtesting and research, you want the most accurate historical figures, even if the query is heavier.
Codex recommends:
getDetailedPairStatswhen you need:- Precise historical price and volume per market.
- Deep liquidity stats per pool.
- TVL-like figures and volume distribution.
getTokenBarswhen you need:- Token-level, liquidity-weighted bars across all pools.
- Cross-pool charts for a token’s global price history.
These endpoints are designed for analytics, not hot-path UX, so they’re allowed to be heavier and more comprehensive.
Historical Holders & Wallet Stats
Historical holder data powers:
- Token distribution analytics.
- Whale monitoring and concentration risk.
- Growth KPIs (e.g., unique wallets over time).
Codex models holders by tracking every token transfer:
holdersgives you a point-in-time view.- For longitudinal analysis, you can:
- Periodically snapshot
holdersinto your own warehouse, or - Use Codex’s broader wallet and transaction queries to rebuild historical trajectories.
- Periodically snapshot
Historical Prediction Market Analytics
For prediction markets, you often care more about long-term edge than short-term prices.
Codex’s prediction endpoints enable:
- Strategy backtesting using historical trades and market prices.
- Trader-level performance analytics using
predictionTraderMarketsStats. - Event-level analytics (e.g., volumes, open interest) over time.
When combined with your own labeling (market category, political vs. sports, etc.), you can generate rich performance reports for different strategies and segments.
Charting, Backtesting, Monitoring: Practical Integration Patterns
Here’s how product and engineering teams can combine real-time and historical APIs to power complete experiences.
1. Trading-Terminal Style Charting
Goal: Fast, trading-grade charts with historical depth.
Pattern:
- On load:
- Call
getBars(orgetTokenBars) for historical OHLCV.
- Call
- After render:
- Subscribe to
onBarsUpdatedfor the same pair/token.
- Subscribe to
- For time-range changes:
- Re-call
getBarswith new resolution/window.
- Re-call
Result: Charting and analytics backed by historical onchain data with real-time streaming updates.
2. Portfolio & Wallet Views
Goal: Accurate balances and PnL with responsive UX.
Pattern:
- Use Codex token and wallet endpoints for:
- Current balances and positions.
- Real-time token prices via
getTokenPrices.
- For deeper analytics (e.g., time-weighted returns):
- Pull historical prices with
getTokenBarsorgetDetailedPairStats. - Store periodic snapshots for fast local analytics.
- Pull historical prices with
3. Backtesting Engines
Goal: Quant-grade historical datasets for strategy research.
Pattern:
- Use Codex’s historical bar and stats endpoints to:
- Download OHLCV history for target markets.
- Fetch liquidity and volume metrics per pair/token.
- Join with your internal signals (orderflow, off-chain data).
- Run models locally or in your data warehouse.
Because Codex has 80+ networks and 70M+ tokens, you can backtest across long-tail assets and launchpad tokens, not just majors.
4. Monitoring & Alerting Pipelines
Goal: Real-time monitoring of markets, wallets, or prediction markets.
Pattern:
- Subscribe to:
onBarsUpdatedfor volatility and volume spikes.- Relevant token/market or prediction-market streams.
- Define alert rules (e.g., % change in price, volume thresholds, whale movements).
- Log events into your warehouse and join with historical metrics for context.
For most consumer apps, Codex recommends using filtered data (e.g., statsType: FILTERED in filterTokens) to exclude MEV noise and get cleaner charting.
Why a Unified Data Model Matters
One of the biggest risks in onchain products is stitching together multiple providers:
- One provider for RPC and logs.
- Another for prices.
- Another for holders and NFTs.
- Another for prediction markets.
This increases:
- Latency (more network hops).
- Complexity (more schemas and failure modes).
- Inconsistency (mismatched prices, missing data in long-tail tokens).
Codex’s position is simple:
We index the chain so you don’t have to.
By normalizing raw onchain events into a single, trading-ready API, Codex lets you:
- Consolidate vendors.
- Reduce infra and AWS costs (Sudoswap reports >$50k annual savings and 60% faster load times).
- Ship features faster with fewer low-level data concerns.
For teams building high-traffic trading apps, that’s often the difference between a brittle MVP and infrastructure-grade reliability.
How to Evaluate Onchain Data APIs for Both Real-Time and Historical Needs
When choosing the best onchain data provider for trading and analytics, evaluate across both axes.
Real-Time Checklist
- End-to-end latency: Can they reliably deliver sub-second updates?
- Streaming options: Do they support WebSockets/subscriptions with clear semantics?
- Reorg handling: How do they handle chain reorgs and eventual consistency?
- Throughput: Can they handle hundreds of req/sec and WebSocket connections (Codex Growth: 300 req/sec, 500 burst, 300 WS connections)?
Historical Checklist
- Coverage: How many chains, tokens, wallets, and events are indexed?
- Depth: Can you get years of OHLCV and liquidity data, not just days?
- Data models: Are tokens, trades, wallets, and markets normalized and documented?
- Analytics specialization: Are there dedicated endpoints for backtesting-grade stats, not just raw logs?
Unified Experience
- Single API for both streaming and queries?
- Consistent identifiers across real-time and historical endpoints?
- Documentation and recipes that map directly to your use cases (charts, backtesting, prediction markets)?
Codex’s design — trading-ready token & prediction market data in one API — is aimed squarely at these requirements.



