Skip to main content
PnL V2 Datastream is available on Premium, Business, and Enterprise plans.
Connect to wss://datastream.solanatracker.io/{apiKey} with your Data API key.
The PnL V2 Datastream pushes live trade and balance updates directly to your WebSocket client. Instead of polling the REST API, subscribe to a room and receive updates the moment they happen.
Plain terms: PnL means profit and loss. Realized PnL is from tokens already sold. Unrealized PnL is paper profit or loss on tokens still held. Cost basis is what the wallet paid for the current position.

Room Types

There are three rooms, each serving a different use case:
PnL rooms emit tradeUpdate on every fill and balanceUpdate on balance changes. They also emit priceUpdate events, but less frequently. Think of priceUpdate as a catch-up message for quiet positions, not as a fast price feed. For the fastest unrealized PnL ticks, pair PnL rooms with a price stream.

Connecting


Room: pnl:{wallet}:{token}

Subscribe to a specific token position in a wallet. You’ll receive two message types: tradeUpdate — fires whenever a buy or sell is executed:
balanceUpdate — fires when the position value changes due to price movement (no new trade):

Subscribe example


Room: pnl:{wallet}

Subscribe to all token positions for a wallet at once. Emits the same tradeUpdate and balanceUpdate messages as above, but for every token the wallet interacts with — you don’t need to know the token addresses in advance.
Use pnl:{wallet} when building a live portfolio dashboard — you only need one room subscription per wallet.

Room: pnl:{wallet}:summary

Receive the wallet’s total PnL summary whenever the aggregate changes. This room returns wallet-level totals, not individual positions.

Fastest Live Unrealized PnL — Combining Rooms

PnL rooms give you the official cost basis, FIFO realized PnL, and balance changes when a trade lands. FIFO means “first in, first out”: older buys are matched to sells first. PnL rooms are not designed to be a tick-by-tick price feed. priceUpdate events are throttled and only fill in for positions that have gone quiet for a while. For a real-time portfolio UI where the unrealized PnL number updates on every price tick, combine the PnL room with a price stream: Use the PnL room as the source of truth for currentBalance and holdingCostBasis, and recompute unrealizedPnl = (currentBalance × livePrice) − holdingCostBasis whenever a price tick arrives.

Example: live unrealized PnL on a single position

Example: live unrealized PnL across an entire wallet

Subscribe to pnl:{wallet} for trade and balance updates on every position, then dynamically subscribe to a price room for each token the wallet holds.
Price streams can update often. In production, batch UI updates or throttle logs so every price tick does not flood your console or browser.
Which price room?
  • price:aggregated:{token} — recommended default. Cross-pool median price; smoother and more accurate when a token trades on multiple pools.
  • price-by-token:{token} — primary-pool price. Slightly lower latency for memecoins or anything that effectively trades on a single pool.

priceUpdate payload (PnL room)

PnL rooms emit priceUpdate as a backstop when a position’s quote hasn’t moved in a while. Treat it as a periodic refresh, not a real-time feed:

Unsubscribing

Leave any room by sending a leave message:

Choosing the Right Room

Use pnl:{wallet}:{token}. Lowest noise — only fires for that token.
Use pnl:{wallet}. One subscription covers all positions. You get token-level detail on every update.
Use pnl:{wallet}:summary. It returns aggregated wallet-level PnL totals without per-token position rows.
Combine pnl:{wallet} (or pnl:{wallet}:{token}) with price:aggregated:{token} or price-by-token:{token}. PnL rooms own the cost basis and balance; price rooms drive the live tick. See Combining Rooms.
Yes. Send multiple join messages. Each room operates independently.

PnL V2 Overview

Core PnL V2 concepts, endpoints, and how wallet indexing works.

Live Prices & Charts

price:aggregated and price-by-token rooms — pair these with PnL for live unrealized PnL.

Wallet Analysis

Analyze wallet PnL, positions, trade timing, and exposure with the REST API.

Wallet Tracking

Combine live wallet activity with PnL streams for a real-time portfolio dashboard.