A Node.js tool for analyzing Solana wallet transactions to extract trade data, calculate profit/loss, and generate detailed CSV reports.
- Fetches and analyzes transaction history for any Solana wallet
- Calculates buy/sell trades with price per token
- Tracks realized P&L using FIFO (First-In-First-Out) accounting
- Calculates holding time for each trade
- Generates detailed trade logs and token summaries
- Adaptive retry logic with exponential backoff for rate limiting
- Node.js (v14 or higher)
- A Helius RPC API key (or other Solana RPC endpoint)
-
Clone this repository
-
Install dependencies:
npm install
-
Create a
.envfile in the project root:SOLANA_RPC_URL=https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY_HERE
Run the analyzer with a wallet address:
node analyzer_full_trades.js <WALLET_ADDRESS> [MAX_SIGNATURES]Analyze a wallet with default limit (2000 signatures):
node analyzer_full_trades.js qtMPaTvJrfU8YourWalletAddressHereAnalyze with custom signature limit:
node analyzer_full_trades.js qtMPaTvJrfU8YourWalletAddressHere 5000The tool generates two CSV files in the output/ directory:
Detailed trade-by-trade log with columns:
ts- Timestampsignature- Transaction signatureprogramIds- Programs involved in the transactionmint- Token mint addressside- Buy or selldelta_token- Token amount changedelta_sol- SOL amount changeprice_per_token- Calculated priceholding_time_sec- Time held before sellingrealized_pnl- Profit/loss for this tradecumulative_pnl- Running total P&Lwallet_token_balance_after- Balance after transaction
Aggregated statistics per token:
mint- Token mint addresstotal_buys- Number of buy transactionstotal_sells- Number of sell transactionsnet_tokens- Net token balance changevolume_in_tokens- Total tokens boughtvolume_out_tokens- Total tokens soldrealized_pnl- Total realized profit/losscumulative_pnl- Cumulative P&Lremaining_balance- Current token balance
- Fetch Signatures: Retrieves transaction signatures for the specified wallet
- Parse Transactions: Fetches and parses each transaction with retry logic
- Calculate Deltas: Determines token and SOL balance changes
- Track Lots: Uses FIFO accounting to match buys with sells
- Calculate P&L: Computes realized profit/loss and holding times
- Export Data: Writes detailed CSV reports
The tool includes adaptive retry logic with exponential backoff to handle:
- HTTP 429 (Too Many Requests) errors
- Transient network failures
- RPC endpoint rate limits
- Always use environment variables for sensitive data
- Keep your
.envfile in.gitignore - Rotate API keys if accidentally exposed
ISC
This tool is for informational purposes only. Always verify trade data and calculations independently. Not financial advice.