A swap-only tape cannot show when liquidity enters or leaves a pool. SDK 0.5.0 adds opt-in liquidity history and live subscriptions so you can display swaps, LP additions, and LP removals without pretending they share the same amount fields.
Select a history mode
The new history methods accept events: 'trades', 'liquidity', or 'all'. Existing getTokenTrades calls retain their swaps-only behavior. Use a new history method when adding an All / Swaps / Liquidity control to a product.
Run the Node.js example
Use Node.js 24 LTS and keep the API credentials on your server. Create an empty directory, then install:
npm init -y
npm install @solana-tracker/[email protected]
npm install --save-dev tsx typescript @types/node
Save the TypeScript block as index.mts. Put ST_API_KEY in an uncommitted .env file. Streaming examples also need ST_DATASTREAM_URL, the full private WebSocket URL from your Data API dashboard. REST and streaming access depend on your plan.
node --env-file=.env --import tsx index.mts
import { Client } from '@solana-tracker/data-api';
const apiKey = process.env.ST_API_KEY;
if (!apiKey) throw new Error('Set ST_API_KEY');
const client = new Client({ apiKey });
const mint = process.env.TOKEN_MINT ?? 'So11111111111111111111111111111111111111112';
const options = { events: 'all', enrich: 'identity', limit: 100,
sortDirection: 'DESC' } as const;
const page = await client.getTokenTradeHistory(mint, options);
for (const event of page.trades) {
switch (event.type) {
case 'buy':
case 'sell':
console.log('Swap:', event.amount, event.priceUsd);
break;
case 'add_liquidity':
case 'remove_liquidity':
console.log('LP action:', event.pool, event.tokens);
break;
}
}
if (page.hasNextPage && page.nextCursor != null) {
const next = await client.getTokenTradeHistory(mint, {
...options, cursor: page.nextCursor,
});
console.log('Next page:', next.trades.length);
}
The array is named trades even for liquidity and mixed modes. limit accepts 1–500 rows. Keep cursor values unchanged: liquidity and mixed feeds use opaque strings, while swaps use timestamp cursors. Do not parse a string cursor as a date or discard a numeric zero with a truthiness check.
Preserve exact LP amounts
Each liquidity token has string amount and amountRaw values. Store those strings or use decimal/integer arithmetic. Converting a large raw amount to JavaScript Number can silently round it.
amountBasis distinguishes transfer observations from principal accounting. Transfer amounts can be gross of Token-2022 withholding; principal amounts separate the position amount from fees or internal reallocations. Optional fee and transferred-amount fields carry additional context.
An LP row has no swap price, swap volume, or PnL field. Keep the token units visible. If you calculate a USD estimate, identify the price source and observation time, and label it as a derived estimate.
Add live liquidity to a separate process
Save the next block as stream.mts, set ST_DATASTREAM_URL, and run it with the same Node command used above, replacing the filename.
import { Datastream } from '@solana-tracker/data-api';
const wsUrl = process.env.ST_DATASTREAM_URL;
if (!wsUrl) throw new Error('Set ST_DATASTREAM_URL from your dashboard');
const ds = new Datastream({ wsUrl });
ds.on('error', () => console.error('Datastream connection error'));
process.once('SIGINT', () => ds.disconnect());
const mint = process.env.TOKEN_MINT ?? 'So11111111111111111111111111111111111111112';
ds.subscribe.liquidity.token(mint, { enriched: true }).on((event) => {
console.log(event.type, event.tokens, event.identity);
});
Use token, pool, wallet, token+pool, or token+pool+wallet scope according to the screen. A combined live feed also needs a swap subscription. Choose scopes that minimize overlapping delivery.
Reconcile instead of assuming exactly-once delivery
Live LP events are provisional at processed commitment. There are no rollback notifications. After reconnecting, load REST history for the affected window and reconcile it; live and historical timestamps can differ.
Do not deduplicate LP activity by signature alone, or even by signature plus pool plus wallet. Several distinct actions can share those fields. When the available event identity cannot distinguish live observations reliably, replace a bounded window from REST rather than collapsing valid actions.
Identity is current enrichment, not a historical identity snapshot. Partial enriched notifications do not receive a later correction automatically.
FAQ
Will existing trade subscriptions start sending LP events?
No. Existing transaction rooms remain swaps-only.
Can LP amounts be summed into trade volume?
No. They are token-unit position actions, not swap USD volume.
Does removing liquidity prove a rug?
No. It can reflect ordinary position management. Inspect pool depth and context before interpreting it.