Skip to content

QuantAlpha-0RG/wallet-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solana Wallet Trade Analyzer

A Node.js tool for analyzing Solana wallet transactions to extract trade data, calculate profit/loss, and generate detailed CSV reports.

Features

  • 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

Prerequisites

  • Node.js (v14 or higher)
  • A Helius RPC API key (or other Solana RPC endpoint)

Installation

  1. Clone this repository

  2. Install dependencies:

    npm install
  3. Create a .env file in the project root:

    SOLANA_RPC_URL=https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY_HERE
    

Usage

Run the analyzer with a wallet address:

node analyzer_full_trades.js <WALLET_ADDRESS> [MAX_SIGNATURES]

Examples

Analyze a wallet with default limit (2000 signatures):

node analyzer_full_trades.js qtMPaTvJrfU8YourWalletAddressHere

Analyze with custom signature limit:

node analyzer_full_trades.js qtMPaTvJrfU8YourWalletAddressHere 5000

Output

The tool generates two CSV files in the output/ directory:

1. all_trades_long.csv

Detailed trade-by-trade log with columns:

  • ts - Timestamp
  • signature - Transaction signature
  • programIds - Programs involved in the transaction
  • mint - Token mint address
  • side - Buy or sell
  • delta_token - Token amount change
  • delta_sol - SOL amount change
  • price_per_token - Calculated price
  • holding_time_sec - Time held before selling
  • realized_pnl - Profit/loss for this trade
  • cumulative_pnl - Running total P&L
  • wallet_token_balance_after - Balance after transaction

2. summary_by_token.csv

Aggregated statistics per token:

  • mint - Token mint address
  • total_buys - Number of buy transactions
  • total_sells - Number of sell transactions
  • net_tokens - Net token balance change
  • volume_in_tokens - Total tokens bought
  • volume_out_tokens - Total tokens sold
  • realized_pnl - Total realized profit/loss
  • cumulative_pnl - Cumulative P&L
  • remaining_balance - Current token balance

How It Works

  1. Fetch Signatures: Retrieves transaction signatures for the specified wallet
  2. Parse Transactions: Fetches and parses each transaction with retry logic
  3. Calculate Deltas: Determines token and SOL balance changes
  4. Track Lots: Uses FIFO accounting to match buys with sells
  5. Calculate P&L: Computes realized profit/loss and holding times
  6. Export Data: Writes detailed CSV reports

Rate Limiting

The tool includes adaptive retry logic with exponential backoff to handle:

  • HTTP 429 (Too Many Requests) errors
  • Transient network failures
  • RPC endpoint rate limits

Security Notes

⚠️ Important: Never commit your API keys to version control!

  • Always use environment variables for sensitive data
  • Keep your .env file in .gitignore
  • Rotate API keys if accidentally exposed

License

ISC

Disclaimer

This tool is for informational purposes only. Always verify trade data and calculations independently. Not financial advice.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors