Overview

Accurate USD pricing is critical for PnL calculations. We use multiple data sources with fallback strategies to ensure reliable price data.

Price Sources

Source Type Usage Status
Jupiter Price API v3 Real-time Primary - current prices Active
Birdeye Historical OHLCV, historical snapshots Active
Helius DAS Metadata Token info, decimals Active
Jupiter Token List Static Token metadata fallback Active

Jupiter Price API v3

Primary source for real-time token prices.

Endpoint

GET https://api.jup.ag/price/v2?ids={mint1},{mint2}

Response

{
  "data": {
    "So11111111111111111111111111111111111111112": {
      "id": "So11111111111111111111111111111111111111112",
      "type": "derivedPrice",
      "price": "173.45"
    }
  },
  "timeTaken": 0.012
}

Usage in Code

import { getTokenPrices } from '@posit/parser/pricing';

const prices = await getTokenPrices([
  'So11111111111111111111111111111111111111112',  // SOL
  'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
]);

console.log(prices.SOL); // 173.45

Birdeye Historical

Used for historical price data and OHLCV charts.

Endpoint

GET https://public-api.birdeye.so/defi/history_price
  ?address={mint}
  &address_type=token
  &type=15m
  &time_from={unix_start}
  &time_to={unix_end}
Rate limits: Birdeye has strict rate limits. Cache aggressively and batch requests.

Price Estimation

For transactions where we don't have exact USD prices at the time of trade:

  1. Exact match: Price at transaction timestamp (preferred)
  2. Interpolation: Linear interpolation between nearest data points
  3. Nearest: Closest available price within 1 hour
  4. Estimated: Flagged as estimate, uses current price
Design principle: Estimates are flagged with Caution Amber (#C8861A) in the UI. Never present estimates as exact values.

Caching Strategy

Data Type Cache Duration
Current prices 30 seconds
Historical prices 24 hours
Token metadata 7 days

Handling Missing Prices

Some tokens (especially new pump.fun tokens) may not have price data: