Price Index Algorithm
What it is
The Price Index is the engine behind the Crypto Price API. It turns DEX trades into one price per pool, blends the pools of a token into one token price per chain, and blends a currency's tokens across chains into one currency price. This page explains the three levels well enough to read the fields they produce. It does not describe the internal rules or their thresholds.
How to get it
The index is not a separate cube. Its outputs are the price and ranking fields on the Trading cubes, in queries, subscriptions and on the trading.prices Kafka topic.
| Level | Cube | One row is |
|---|---|---|
| Pool | Trading.Pairs | one pool on one market, for one interval |
| Token | Trading.Tokens | one token on one chain, all its pools blended |
| Currency | Trading.Currencies | one asset across chains, all its tokens blended |
| Group | Trades | Pairs | Tokens | Currencies |
|---|---|---|---|---|
Ranking { Position Weight } | yes | yes | yes | – |
RankingDetail { Verdict StaleMultiplier } | – | yes | yes | – |
Liquidity { Usd Source RealShare … } | – | yes (one pool) | yes (summed) | yes (summed) |
LeadingPool { MarketId PoolAddress QuoteTokenId } | – | – | yes | – |
Pairs filtered to Ranking: { Position: { eq: 1 } } returns the pool that leads a token's blend. See Getting the Most Accurate Token Price.
How it is derived
Pool: from trades to a price
- Orientation. One side of the pool is base, the other quote. Stablecoins and native tokens are preferred as quote, so a memecoin/WSOL pool prices the memecoin in WSOL. The rules are in Breaking Down Price Streams in Detail.
- Bad prints are dropped. Zero-amount trades, trades below the token's precision, and legs of a self-sandwich do not count. Trades of negligible USD value count toward volume but not price.
- The price is the pool's spot. Each trade is priced at what the pool's curve moved to, with the pool fee excluded where the venue reports it inside the input. Chart sites show the price the trader paid, fee included, so on a pool with a 1 % fee the two differ by about 1 % in the direction of the last trade. The trader's price is still on every
Trading.Tradesrow from itsAmounts. - Trades are averaged by size into one pool price per block. The candle open, high, low and close come from the individual trades.
- USD is the quote-denominated price times the quote currency's own index price. A pool whose quote has no USD price carries a price in quote tokens only.
Token: from pools to a price
Every pool where the token is base is a part of the token. Each part gets a weight, each part gets a verdict, and the token price is the average of the accepted parts' prices by weight.
- Weight is the pool's share of the token's liquidity, discounted for staleness. Liquidity is the measured reserve where the index can read it and an estimate otherwise (Liquidity fields). A pool that stops trading keeps its liquidity but loses weight the longer it stays quiet. This is
Ranking.Weight;Ranking.Positionorders the pools by it. - Verdict says what the blend did with the pool's price.
pricedis accepted as is.clampedis accepted but pulled toward the other pools.outlieris rejected, price and volume.ineligibleis a pool with too little money or history: its volume counts, its price does not.retiredis a launch curve the token has left.no_priceis a pool with nothing to price. This isRankingDetail.Verdict. - Launch curves. While a token trades only on its bonding curve, the curve is its price. Once it graduates to a real pool, the curve is retired for that token and never votes again, so its frozen price cannot drag the blend.
- One pool. A token with one pool has nothing to blend: that pool's price is the token's, at
Position1 andWeight1.
Currency: from tokens to a price
The same blend one level up. A non-stablecoin currency such as bid:bitcoin is made of its token representations across chains (WBTC, cbBTC and so on), each weighted by that token's liquidity. Ranking is not exposed on Currencies.
Stablecoins skip the trade-based path: their price comes from an external spot source. At currency level they carry no Liquidity and no Supply.
Which price to read
| Field | What it is | Use it for |
|---|---|---|
Price.Ohlc.Close | The last accepted trade of the interval. | Candles, charts, last traded price. |
Price.Average.Estimate | The valuation price: smoothed over recent short intervals, so one spike moves it a little and a sustained move captures it fully. | Market cap, portfolio value. MarketCap is Estimate × supply. |
Price.Average.Mean | Size-weighted mean of the interval's trades. | VWAP over the bar. |
PriceInUsd on Trading.Trades | That trade's own price times the quote token's USD rate. Not the blended token price. | Per-swap accounting, PnL. |
PoolPrice on Pairs | The pool curve's marginal quote after the last swap. | Routing, slippage. See PoolPrice fields. |
Fields
Ranking is exposed on Trades, Pairs and Tokens.
| Field | Type | Meaning |
|---|---|---|
Ranking.Position | Int | 1-based priority among the parts of a blend: the pool among a token's pools, or the token among a currency's tokens. Lower is higher priority. |
Ranking.Weight | Float | This part's share of the blend, in [0, 1]. Weights across a token's pools sum to 1. |
RankingDetail { Verdict StaleMultiplier }, LeadingPool and every Liquidity field are documented in Liquidity, RankingDetail and LeadingPool fields.
Examples
Which pools set a token's price?
Filter Pairs on Ranking.Position to keep only the top contributors (positions 1, 2 and 3 here). Weight is normally read, not filtered.
{
Trading {
Pairs(
where: {
Ranking: { Position: { in: [1, 2, 3] } }
Interval: { Time: { Duration: { eq: 3600 } } }
Block: { Time: { since_relative: { hours_ago: 1 } } }
}
limit: { count: 10 }
) {
Block {
Time(maximum: Block_Time)
}
Currency {
Id
}
Token {
Id
}
QuoteToken {
Id
}
Market {
Id
Protocol
Address
}
Price {
Ohlc {
Close
}
}
Ranking {
Position
Weight
}
Interval {
Time {
Start
End
}
}
}
}
}
Position: 1is the pool with the largest liquidity-weighted share, not the one with the most trades.- Add
Token: { Id: { is: "bid:solana:So11111111111111111111111111111111111111112" } }to see one token's pools and check that theirWeightvalues sum to about 1. - Add
RankingDetail { Verdict StaleMultiplier }to see why each pool got its rank.
Pitfalls
- Our close is not DEX Screener's close on high-fee pools. We publish the pool's spot; chart sites publish the price the trader paid, fee included.
Estimateis not the close. It is smoothed. UseOhlc.Closefor the last trade andEstimatefor valuation.- Rejected pools still have rows. An
outlierorineligiblepool keeps itsPairsrow andPosition. Filter onRankingDetail.Verdictfor the pools the price actually uses. - Do not apply
StaleMultiplieragain.Weightalready includes it. - History before 2026-10-19 is volume-weighted.
Liquidityfields are0on those rows andWeightfollows traded volume. Do not compare weights across the cutover. Volume.Quoteis not USD. It is the sum of quote-token amounts. UseVolume.Usd.
Related
Ready to run this in production?
Get an API key and run these queries in minutes, or talk to us about plans and enterprise delivery.