Skip to content

Commit e55d12a

Browse files
committed
Added wallet balance tracking
1 parent 824b766 commit e55d12a

File tree

5 files changed

+135
-38
lines changed

5 files changed

+135
-38
lines changed

README.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ Official JavaScript/TypeScript client for the [Solana Tracker Data API](https://
1111
- Real-time data streaming via WebSocket (Datastream)
1212
- Built-in error handling with specific error types
1313
- Compatible with both Node.js and browser environments
14-
- **NEW**: Snipers and insiders tracking via WebSocket
14+
- **NEW**: Snipers and insiders tracking via WebSocket
15+
- **NEW**: Enhanced error details for better debugging
16+
- **NEW**: Subscribe to Wallet Balance updates
17+
- Support for all pool types including launchpad and meteora curve pools (Shows which platform token is released on, Moonshot, Bonk, Jupiter Studio etc)
1518

1619
## Installation
1720

@@ -129,6 +132,21 @@ dataStream.subscribe.insiders(tokenAddress).on((insiderUpdate) => {
129132
console.log(`Percentage: ${insiderUpdate.percentage.toFixed(2)}%`);
130133
console.log(`Total insiders hold: ${insiderUpdate.totalInsiderPercentage.toFixed(2)}%`);
131134
});
135+
136+
// Example 9: NEW - Monitor wallet balance changes
137+
const walletAddress = 'YourWalletAddressHere';
138+
139+
// Watch all token balance changes for a wallet
140+
dataStream.subscribe.tx.wallet(walletAddress).balance().on((balanceUpdate) => {
141+
console.log(`Balance update for wallet ${balanceUpdate.wallet}`);
142+
console.log(`Token: ${balanceUpdate.token}`);
143+
console.log(`New balance: ${balanceUpdate.amount}`);
144+
});
145+
146+
// Watch specific token balance for a wallet
147+
dataStream.subscribe.tx.wallet(walletAddress).tokenBalance('tokenMint').on((balanceUpdate) => {
148+
console.log(`Token balance changed to: ${balanceUpdate.amount}`);
149+
});
132150
```
133151

134152
Available subscription methods:
@@ -147,7 +165,10 @@ dataStream.subscribe.price.pool(poolId); // Pool price
147165
// Transactions
148166
dataStream.subscribe.tx.token(tokenAddress); // Token transactions
149167
dataStream.subscribe.tx.pool(tokenAddress, poolId); // Pool transactions
150-
dataStream.subscribe.tx.wallet(walletAddress); // Wallet transactions
168+
dataStream.subscribe.tx.wallet(walletAddress); // Wallet transactions (deprecated: use .transactions())
169+
dataStream.subscribe.tx.wallet(walletAddress).transactions(); // Wallet transactions (new)
170+
dataStream.subscribe.tx.wallet(walletAddress).balance(); // All token balance changes
171+
dataStream.subscribe.tx.wallet(walletAddress).tokenBalance(tokenAddress); // Specific token balance
151172

152173
// Pump.fun stages
153174
dataStream.subscribe.graduating(); // Graduating tokens
@@ -434,13 +455,14 @@ try {
434455

435456
#### New Features:
436457
1. **Snipers and Insiders Tracking**: Monitor wallets that are identified as snipers or insiders for any token via WebSocket subscriptions
437-
2. **Enhanced Error Handling**: Error responses now include detailed error information from the API when available
438-
3. **Subscription Endpoint**: New endpoint to get subscription details including plan, credits, and billing information
439-
4. **Updated Type Definitions**:
458+
2. **Wallet Balance Tracking**: Real-time monitoring of token balance changes for any wallet via WebSocket
459+
3. **Enhanced Error Handling**: Error responses now include detailed error information from the API when available
460+
4. **Subscription Endpoint**: New endpoint to get subscription details including plan, credits, and billing information
461+
5. **Updated Type Definitions**:
440462
- Added `volume24h` field to transaction statistics
441463
- Enhanced `TokenRisk` interface with detailed snipers/insiders data
442464
- Added `MultiTokensResponse` for the `/tokens/multi` endpoint
443-
- Updated `Launchpad` and `MeteoraCurve` interfaces for finding the specific platform a token launched on (letsbonk.fun, moonshot etc.)
465+
- Updated `Launchpad` and `MeteoraCurve` interfaces for pool-specific data (Shows which platform token is released on, Moonshot, Bonk, Jupiter Studio etc)
444466
- Added `SubscriptionResponse` for subscription information
445467

446468
#### Type Updates:
@@ -465,6 +487,13 @@ interface SniperInsiderUpdate {
465487
totalInsiderPercentage: number;
466488
}
467489

490+
// NEW: Wallet balance update structure
491+
interface WalletBalanceUpdate {
492+
wallet: string;
493+
token: string;
494+
amount: number;
495+
}
496+
468497
// UPDATED: Risk structure now includes detailed snipers/insiders
469498
interface TokenRisk {
470499
snipers: {
@@ -528,6 +557,8 @@ dataStream.on(`price:${tokenAddress}`, (data) => console.log('Price update:', da
528557
dataStream.on(`price:${poolAddress}`, (data) => console.log('Price update:', data));
529558
dataStream.on(`transaction:${tokenAddress}`, (data) => console.log('New transaction:', data));
530559
dataStream.on(`wallet:${walletAddress}`, (data) => console.log('Wallet transaction:', data));
560+
dataStream.on(`wallet:${walletAddress}:balance`, (data) => console.log('Wallet balance update:', data)); // NEW
561+
dataStream.on(`wallet:${walletAddress}:${tokenAddress}:balance`, (data) => console.log('Token balance update:', data)); // NEW
531562
dataStream.on('graduating', (data) => console.log('Graduating token:', data));
532563
dataStream.on('graduated', (data) => console.log('Graduated token:', data));
533564
dataStream.on(`metadata:${tokenAddress}`, (data) => console.log('Metadata update:', data));

examples/datastream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ const subscribeToPoolTransactions = (
222222

223223
// Subscribe to transactions for a specific wallet
224224
const subscribeToWalletTransactions = (walletAddress: string = WALLET_ADDRESS) => {
225-
const subscription = dataStream.subscribe.tx.wallet(walletAddress).on((data) => {
225+
const subscription = dataStream.subscribe.tx.wallet(walletAddress).transactions().on((data) => {
226226
console.log(`Wallet ${data.type.toUpperCase()} transaction`);
227227
console.log(`Transaction ID: ${data.tx}`);
228228
console.log(`Amount: ${data.amount}`);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@solana-tracker/data-api",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "Official Solana Tracker Data API client for accessing Solana Data",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",

src/datastream.ts

Lines changed: 90 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EventEmitter } from 'events';
22
import "./websocket-polyfill";
3-
import { TokenInfo, PoolInfo, TokenEvents, TokenRisk } from './interfaces';
3+
import { TokenInfo, PoolInfo, TokenEvents, TokenRisk, WalletBalanceUpdate } from './interfaces';
44

55
/**
66
* Room types for the WebSocket data stream
@@ -235,41 +235,101 @@ class PriceSubscriptions {
235235
}
236236
}
237237

238+
239+
240+
// 3. If you need TypeScript types for better IDE support
241+
interface WalletSubscriptionMethods {
242+
/**
243+
* @deprecated Use .transactions().on() instead
244+
*/
245+
on(callback: (data: WalletTransaction) => void): {
246+
unsubscribe: () => void;
247+
};
248+
room: string;
249+
transactions(): SubscribeResponse<WalletTransaction>;
250+
balance(): SubscribeResponse<WalletBalanceUpdate>;
251+
tokenBalance(tokenAddress: string): SubscribeResponse<WalletBalanceUpdate>;
252+
}
238253
/**
239254
* Transaction-related subscription methods
240255
*/
241256
class TransactionSubscriptions {
242-
private ds: Datastream;
243-
244-
constructor(datastream: Datastream) {
245-
this.ds = datastream;
246-
}
247-
248-
/**
249-
* Subscribe to transactions for a token across all pools
250-
* @param tokenAddress The token address
251-
*/
252-
token(tokenAddress: string): SubscribeResponse<TokenTransaction> {
253-
return this.ds._subscribe<TokenTransaction>(`transaction:${tokenAddress}`);
254-
}
257+
private ds: Datastream;
258+
259+
constructor(datastream: Datastream) {
260+
this.ds = datastream;
261+
}
262+
263+
/**
264+
* Subscribe to transactions for a token across all pools
265+
* @param tokenAddress The token address
266+
*/
267+
token(tokenAddress: string): SubscribeResponse<TokenTransaction> {
268+
return this.ds._subscribe<TokenTransaction>(`transaction:${tokenAddress}`);
269+
}
270+
271+
/**
272+
* Subscribe to transactions for a specific token and pool
273+
* @param tokenAddress The token address
274+
* @param poolId The pool address
275+
*/
276+
pool(tokenAddress: string, poolId: string): SubscribeResponse<TokenTransaction> {
277+
return this.ds._subscribe<TokenTransaction>(`transaction:${tokenAddress}:${poolId}`);
278+
}
279+
280+
/**
281+
* Subscribe to wallet-related events (transactions and balance updates)
282+
*
283+
* @example
284+
* // For transactions:
285+
* datastream.subscribe.tx.wallet('address').transactions().on(callback)
286+
*
287+
* // For all balance updates:
288+
* datastream.subscribe.tx.wallet('address').balance().on(callback)
289+
*
290+
* // For specific token balance:
291+
* datastream.subscribe.tx.wallet('address').tokenBalance('token').on(callback)
292+
*
293+
* // Legacy (deprecated):
294+
* datastream.subscribe.tx.wallet('address').on(callback)
295+
*
296+
* @param walletAddress The wallet address
297+
*/
298+
wallet(walletAddress: string): WalletSubscriptionMethods {
299+
const ds = this.ds;
300+
301+
// Create the base subscription
302+
const baseSubscription = ds._subscribe<WalletTransaction>(`wallet:${walletAddress}`);
303+
304+
// Add the new methods to the subscription object
305+
const enhancedSubscription = {
306+
...baseSubscription,
307+
308+
// Keep the original on method but mark it as deprecated
309+
on: (callback: (data: WalletTransaction) => void) => {
310+
311+
return baseSubscription.on(callback);
312+
},
313+
314+
// New methods
315+
transactions: () => {
316+
return ds._subscribe<WalletTransaction>(`wallet:${walletAddress}`);
317+
},
318+
319+
balance: () => {
320+
return ds._subscribe<WalletBalanceUpdate>(`wallet:${walletAddress}:balance`);
321+
},
322+
323+
tokenBalance: (tokenAddress: string) => {
324+
return ds._subscribe<WalletBalanceUpdate>(`wallet:${walletAddress}:${tokenAddress}:balance`);
325+
}
326+
};
327+
328+
return enhancedSubscription;
329+
}
330+
}
255331

256-
/**
257-
* Subscribe to transactions for a specific token and pool
258-
* @param tokenAddress The token address
259-
* @param poolId The pool address
260-
*/
261-
pool(tokenAddress: string, poolId: string): SubscribeResponse<TokenTransaction> {
262-
return this.ds._subscribe<TokenTransaction>(`transaction:${tokenAddress}:${poolId}`);
263-
}
264332

265-
/**
266-
* Subscribe to transactions for a specific wallet
267-
* @param walletAddress The wallet address
268-
*/
269-
wallet(walletAddress: string): SubscribeResponse<WalletTransaction> {
270-
return this.ds._subscribe<WalletTransaction>(`wallet:${walletAddress}`);
271-
}
272-
}
273333

274334
/**
275335
* WebSocket service for real-time data streaming from Solana Tracker

src/interfaces.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,4 +711,10 @@ export interface SubscriptionResponse {
711711
plan: string;
712712
next_billing_date: string;
713713
status: string;
714+
}
715+
716+
export interface WalletBalanceUpdate {
717+
wallet: string;
718+
token: string;
719+
amount: number;
714720
}

0 commit comments

Comments
 (0)