in-solana by Supanode

Solana DEX Data: Getting Swap History

TL;DR

  • - DEX swap data lives in on-chain transaction logs — no single API serves it all
  • - Use Geyser gRPC to stream live swaps; use indexers or warehouses for historical data
  • - Decode swap instructions by program: each DEX has its own instruction format

Solana DEX swap data is not stored in a single queryable database. Each swap is a transaction on-chain, and extracting swap details requires decoding transaction instructions for each DEX program. This guide covers how to access both live and historical swap data.

Where swap data lives

Each DEX swap is one or more instructions in a Solana transaction. The key data points:

FieldWhere to find it
Token pairInstruction accounts (pool, mint addresses)
Amount in/outInstruction data or inner instruction transfers
PriceCalculated from amounts + decimals
TimestampBlock time of the slot
User walletTransaction signer
Pool/AMMInstruction accounts

Live swap monitoring

Geyser gRPC

Stream all transactions for a specific DEX program:

const stream = client.subscribe({
  transactions: {
    swaps: {
      accountInclude: [
        JUPITER_PROGRAM_ID,
        RAYDIUM_AMM_PROGRAM_ID,
        ORCA_WHIRLPOOL_PROGRAM_ID,
      ],
    },
  },
});

for await (const tx of stream) {
  const swap = parseSwapTransaction(tx);
  if (swap) {
    console.log(`${swap.tokenIn} → ${swap.tokenOut}: ${swap.amountIn} → ${swap.amountOut}`);
  }
}

WebSocket logsSubscribe

For lower-volume monitoring without Geyser:

connection.onLogs(
  new PublicKey(JUPITER_PROGRAM_ID),
  (logs) => {
    // Parse swap details from logs and inner instructions
  },
  "confirmed",
);

Parsing swap data by DEX

Jupiter

Jupiter is an aggregator that routes through multiple DEXes. A Jupiter swap transaction contains:

  • The Jupiter program’s route instruction.
  • Inner instructions for each hop (Raydium, Orca, etc.).
  • Token transfers showing amounts in and out.

Extract the first and last token transfer inner instructions to get the input and output amounts.

Raydium

Raydium AMM swap instructions contain the pool address, user token accounts, and amount fields in the instruction data. The pool account stores the token mints and reserves.

Orca Whirlpool

Orca Whirlpool uses concentrated liquidity. Swap instructions include the pool (Whirlpool) address, tick arrays, and token accounts. The instruction data contains the amount and sqrt price limit.

Historical swap data

Option 1: Build your own indexer

Geyser gRPC → Parser → Database (ClickHouse/PostgreSQL)
  1. Subscribe to transactions for target DEX programs.
  2. Decode each transaction’s swap instructions.
  3. Store structured data (pair, amounts, timestamp, user).
  4. Query via SQL.

Option 2: Use existing data services

Several services provide indexed DEX data:

ServiceData typeQuery method
BirdeyeAggregated DEX dataREST API
DexScreenerPair prices, volumeREST API
FlipsideHistorical analyticsSQL
Custom indexersRaw swap dataDepends on service

Option 3: Backfill from archive

For one-time historical analysis:

  1. Iterate through blocks using an archive RPC node.
  2. Filter transactions by program ID.
  3. Decode swap instructions from each transaction.
  4. Aggregate the results.

This is slow but requires no external services.

Data schema example

A minimal swap record for indexing:

CREATE TABLE swaps (
  signature TEXT PRIMARY KEY,
  slot BIGINT NOT NULL,
  block_time TIMESTAMP NOT NULL,
  dex TEXT NOT NULL,
  pool TEXT NOT NULL,
  signer TEXT NOT NULL,
  token_in TEXT NOT NULL,
  token_out TEXT NOT NULL,
  amount_in BIGINT NOT NULL,
  amount_out BIGINT NOT NULL,
  fee_amount BIGINT DEFAULT 0
);

Volume calculation

To calculate trading volume:

  1. Get token decimals from the mint account.
  2. Convert raw amounts to human-readable: amount / 10^decimals.
  3. Get USD price from an oracle or price API at the transaction’s timestamp.
  4. Volume = amount × price at that time.

FAQ

Can I get all Solana DEX volume from a single API? Not from the RPC. Aggregator services like Birdeye and DexScreener provide pre-computed volume data across multiple DEXes.

How much storage does swap data require? Solana processes millions of swap transactions per day. Storing raw swap data for all DEXes requires significant storage. For a single DEX or specific pairs, the volume is more manageable. Expect 10–100 GB per month depending on scope.

Can I get swap data without running infrastructure? Yes. Use existing data APIs (Birdeye, DexScreener, Flipside). These services have already done the indexing work.

How do I identify which DEX a swap went through? Check the program ID in the transaction’s instructions. Each DEX has a unique program ID. Jupiter swaps contain inner instructions that reveal which DEX was used for each hop.

Updated: