Skip to main content

Overview

The Codex API offers two ways to get data: queries and subscriptions. Many endpoints have both a query and a subscription version that return the same data — the difference is how you receive it.
QuerySubscription
ProtocolHTTP (POST to https://graph.codex.io/graphql)WebSocket (wss://graph.codex.io/graphql)
How it worksYou request data, you get a responseYou subscribe once, data is pushed to you as it changes
Best forPage loads, historical data, one-time lookupsLive feeds, real-time dashboards, streaming updates
Billing1 request per query execution1 request per message received
Plan requirementAll plansGrowth or Enterprise

Which Should I Use?

Use a query when...

  • You need data once (e.g. loading a page, fetching a wallet’s history)
  • You need historical data (e.g. OHLCV bars from last week)
  • You need to paginate through large result sets (e.g. filtering tokens)
  • You’re on a Free plan
  • You need real-time updates (e.g. live price ticker, streaming trades)
  • You want data pushed to you instantly as it happens
  • You’re building a live dashboard or trading bot
  • You want to avoid polling the API repeatedly
A common pattern is to use a query to load initial data, then switch to a subscription to keep it updated in real-time.

Endpoint Mapping

The table below maps each subscription to its query equivalent. Both return the same data — the query fetches it on-demand, while the subscription streams updates as they happen.

Token Data

SubscriptionQuery EquivalentDescription
onPriceUpdatedgetTokenPricesPrice for a single token
onPricesUpdatedgetTokenPricesPrices for multiple tokens (up to 25)
onTokenBarsUpdatedgetTokenBarsToken-level OHLCV bars
onDetailedTokenStatsUpdatedgetDetailedTokenStatsDetailed token statistics
onTokenEventsCreatedgetTokenEventsSwap/trade events for a token
onTokenLifecycleEventsCreatedtokenLifecycleEventsToken lifecycle events (mint, burn, etc.)

Pair Data

SubscriptionQuery EquivalentDescription
onBarsUpdatedgetBarsPair-level OHLCV bars
onUnconfirmedBarsUpdatedgetBarsUnconfirmed pair bars (faster, pre-finalization)
onDetailedStatsUpdatedgetDetailedPairStatsDetailed pair statistics
onPairMetadataUpdatedpairMetadataPair metadata (volume, liquidity, supply)

Events

SubscriptionQuery EquivalentDescription
onEventsCreatedgetTokenEventsTrade events for a pair
onEventsCreatedByMakergetTokenEventsForMakerTrades by a specific wallet
onUnconfirmedEventsCreatedgetTokenEventsUnconfirmed events (faster, pre-finalization)
onEventLabelCreatedgetEventLabelsEvent labels (sandwich, front-run, etc.)

Balances & Holders

SubscriptionQuery EquivalentDescription
onHoldersUpdatedholdersToken holder list updates
onBalanceUpdatedbalancesWallet balance updates

Launchpads

SubscriptionQuery EquivalentDescription
onLaunchpadTokenEventfilterTokens (with launchpad filters)Individual launchpad token events
onLaunchpadTokenEventBatchfilterTokens (with launchpad filters)Batched launchpad token events