Solana Tracker LogoSolana Tracker
Swap
Developers
⌘K
Affiliate
All Resources
Stream a Live Solana Trade Tape over WebSocket
Data APITypeScriptJune 8, 20265 min read

Stream a Live Solana Trade Tape over WebSocket

Receive token swaps in real time over WebSocket, including side, wallet, amount and pool-scoped trade data.

  • data-api,
  • websocket,
  • trades,
  • datastream,
  • typescript
Solana Data API›

A live trade tape needs swaps, not just prices

Price WebSockets tell you where a token traded; a trade stream tells you who swapped, how much, and in which direction. Production apps backfill recent trades over REST, then open ds.subscribe.tx.token(mint) on the Datastream for live tape output.

What you need

  • Node.js 18+
  • Datastream key (Premium+)
  • REST API key (recommended, token context + backfill)

Step 1: Backfill context over REST

Before going live, fetch token metadata and the last few trades so your UI is not empty:

const info = await client.getTokenInfo(MINT);
const history = await client.getTokenTrades(MINT);
const recent = history.trades?.slice(0, 10) ?? [];

Step 2: Connect the Datastream

import WebSocket from 'ws';
(globalThis as any).WebSocket = WebSocket;
const { Datastream } = await import('@solana-tracker/data-api');

const ds = new Datastream({ wsUrl: `wss://datastream.solanatracker.io/${process.env.ST_DATASTREAM_KEY}` });
ds.on('disconnected', () => setTimeout(() => ds.connect(), 2000));
await ds.connect();

Step 3: Run a trade tape

Format each swap and track session stats (buy/sell count, volume):

const tape = { count: 0, buys: 0, sells: 0, volumeUsd: 0 };

ds.subscribe.tx.token(MINT).on((tx) => {
  tape.count++;
  if (tx.type === 'buy') tape.buys++;
  if (tx.type === 'sell') tape.sells++;
  tape.volumeUsd += tx.amountUsd ?? tx.volumeUsd ?? 0;
  console.log(tx.type ?? tx.side, tx.amountUsd ?? tx.volumeUsd, tx.wallet ?? tx.owner, tx.tx ?? tx.signature);
});

The GitHub example splits this into trade-tape.ts, format.ts, and index.ts.

Step 4: Pool-scoped trades (SOL pairs)

For SOL-quoted pairs, pool-level rooms avoid noise from unrelated routes:

ds.subscribe.tx.pool(MINT, POOL_ID).on((tx) => {
  console.log('Pool trade:', tx.type, tx.volumeUsd);
});

Price vs trades

| Feed | Room | Use when |

|------|------|----------|

| Price | subscribe.price.aggregated(mint) | Charts, tickers |

| Trades | subscribe.tx.token(mint) | Tape, flow analysis, alerts |

See the price WebSocket guide for aggregated quotes.

FAQ

Do I need REST polling too?

Fetch once at startup for context and backfill. The stream handles everything after that.

How many tokens can I stream?

Multiple concurrent subscriptions; watch your plan limits on the dashboard.

What if the connection drops?

Listen for disconnected and reconnect with backoff.

Related: Real-time price WebSocket -> · Solana Data API

Download the example

Clone the full runnable project on GitHub, npm install && npm start with your keys in .env. Or open it in StackBlitz to run in your browser (free). See the tutorial for step-by-step context.

View source on GitHub›Run in StackBlitz›

Runnable Node.js project — clone from GitHub, add keys to .env, then npm start. StackBlitz runs REST and Datastream examples in your browser for free.

Related Guides

Replace Solana Price Polling with a WebSocket Feed
Data API

Replace Solana Price Polling with a WebSocket Feed

Read more
Rank Solana Traders by PnL, Not Follower Count
Data API

Rank Solana Traders by PnL, Not Follower Count

Read more
Build a Solana Token Screener with Search Filters
Data API

Build a Solana Token Screener with Search Filters

Read more

Products

  • Data API
  • Pump.fun API
  • Solana RPC
  • Dedicated Nodes
  • Yellowstone gRPC
  • Raptor Swap API
  • Enterprise

Trading

  • Swap
  • Latest Tokens
  • Trending
  • Top Gainers
  • Memescope
  • Whale Watch
  • KOL Tracker

Tools

  • Wallet Tracker
  • Rugcheck
  • PnL Leaderboard
  • KOLScan
  • Axiom Leaderboard
  • Photon Leaderboard
  • Bloom Leaderboard
  • FOMO Leaderboard
  • GMGN Leaderboard
  • Pump.fun App Leaderboard
  • Terminal Leaderboard
  • Platform Compare
  • My Positions
  • Teams

Resources

  • Developer Guides
  • Blog
  • Documentation
  • API Reference
  • Status
  • Affiliate Program — 25% recurring, uncapped
Solana TrackerSolana Tracker© 2026
Terms of ServicePrivacy PolicyContact