Solana Tracker LogoSolana Tracker
Swap
Developers
⌘K
Affiliate
All Resources
Replace Solana Price Polling with a WebSocket Feed
Data APITypeScriptMay 31, 20262 min read

Replace Solana Price Polling with a WebSocket Feed

Stream live Solana token prices over WebSocket with Datastream instead of polling REST endpoints on an interval.

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

Price polling is always late

REST polling for prices is wasteful: you keep asking even when nothing changed, and you're always one interval behind. A WebSocket pushes updates the moment a trade happens. A Datastream price subscription pushes the quote when the market moves, which is the behavior price tickers and bots actually need.

What you need

  • Node.js 18+
  • A Solana Tracker API key (free) and Datastream key (Premium+, same dashboard), WebSocket Datastream starts on Premium

Step 1: Connect

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('connected', () => console.log('Live'));
ds.connect();

Step 2: Subscribe to a token's price

ds.subscribe.price.aggregated(MINT_ADDRESS).on((update) => {
  console.log(update.token, update.aggregated.median, update.aggregated.median);
});

Step 3: Track multiple tokens

const priceState = new Map<string, number>();
const mints = [MINT_A, MINT_B, MINT_C];
for (const mint of mints) {
  ds.subscribe.price.aggregated(mint).on(u => priceState.set(u.token, u.aggregated.median));
}

Step 4: Reconnect when the feed drops

ds.on('disconnected', () => {
  setTimeout(() => ds.connect(), 1000);
});

Tip: combine the WebSocket feed with a one-off REST call (/tokens/{mint}) at startup, so your dashboard shows an initial value immediately and then moves live.

FAQ

Why WebSocket instead of REST?

You get updates push-based within milliseconds, without the rate-limit waste of constant polling.

How many tokens can I subscribe to at once?

Multiple; the Datastream supports many concurrent subscriptions with unlimited messages on the right tier.

What if the connection drops?

Catch the disconnected event and reconnect with a short backoff, as in step 4.

Related: Get a Solana token price (REST) -> · 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

Stream a Live Solana Trade Tape over WebSocket
Data API

Stream a Live Solana Trade Tape over WebSocket

Read more
Get Solana Token Prices Without Running an Indexer
Data API

Get Solana Token Prices Without Running an Indexer

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

Rank Solana Traders by PnL, Not Follower Count

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
  • My Positions
  • Teams

Resources

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