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:
| Field | Where to find it |
|---|---|
| Token pair | Instruction accounts (pool, mint addresses) |
| Amount in/out | Instruction data or inner instruction transfers |
| Price | Calculated from amounts + decimals |
| Timestamp | Block time of the slot |
| User wallet | Transaction signer |
| Pool/AMM | Instruction 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)
- Subscribe to transactions for target DEX programs.
- Decode each transaction’s swap instructions.
- Store structured data (pair, amounts, timestamp, user).
- Query via SQL.
Option 2: Use existing data services
Several services provide indexed DEX data:
| Service | Data type | Query method |
|---|---|---|
| Birdeye | Aggregated DEX data | REST API |
| DexScreener | Pair prices, volume | REST API |
| Flipside | Historical analytics | SQL |
| Custom indexers | Raw swap data | Depends on service |
Option 3: Backfill from archive
For one-time historical analysis:
- Iterate through blocks using an archive RPC node.
- Filter transactions by program ID.
- Decode swap instructions from each transaction.
- 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:
- Get token decimals from the mint account.
- Convert raw amounts to human-readable:
amount / 10^decimals. - Get USD price from an oracle or price API at the transaction’s timestamp.
- 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.
Sources
Updated: