Solana copy trading bot that automatically mirrors wallet trades across Pump.fun, Raydium, Jupiter, Meteora, Orca, and other DEXs using Jito for fast execution.
Solana Copy Trading Bot
A fast Solana copy-trading bot leveraging Jito to mirror any transaction from a designated "copy" wallet. Supports all major DEXs (Pump.fun, Pump.fun AMM, Raydium, Meteora, Moonshot, Orca, Jupiter) and includes essential features for automated trading.
๐ Repository: https://github.com/bigmacman1129/solana-copy-trading-bot โญ Give this repo a star if you find it helpful!
Video Guide
- Watch this video to see the bot in action
Table of Contents
- Overview
- Features
- Prerequisites
- Installation
- Configuration
- Project Structure
- Usage
- Environment Variables Reference
- Links & Resources
- Community & Support
- Contributing
- License
Overview
This bot connects to CoinVera's WebSocket API to subscribe to trades of a specified wallet. It mirrors each buy/sell by submitting transactions via Jito. It tracks open positions in a local JSON database and can operate in either "COPY" or "SELLING" mode.
Features
- DEX Coverage: Pump.fun, Pump.fun AMM, Raydium, Meteora, Moonshot, Orca, Jupiter, and more.
- Jito Execution: Fast, low-latency transaction submission.
- Trade Modes:
- Multi-Buy Toggle: Enable/disable multiple buys per mint.
- Position Tracking: Persistent JSON storage for open/closed positions.
- Price Monitoring: Polls CoinVera HTTP API for TP/SL checks.
- Trailing Stop Loss: Dynamic stop loss that follows price movements upward, locking in profits while allowing for maximum upside.
- Emergency SELL: Liquidate all positions on startup if desired.
- Accurate Balances: Raw BigInt + decimals to avoid rounding errors.
- User-Friendly Logs: Clear, timestamped console output.
Prerequisites
- Node.js (v16+), npm
- Solana wallet private key (Base58) with sufficient SOL
- CoinVera API key for price data and WebSocket subscription
- Copy wallet public address whose trades will be mirrored
Installation
git clone https://github.com/bigmacman1129/solana-copy-trading-bot.git
cd solana-copy-trading-bot
npm install
mv .env.example .env
npm start
Configuration
Rename .env.example to .env and configure variables:
- SOLANA_RPC: Solana RPC URL (e.g. Jito RPC or mainnet-beta).
- PRIVATE_KEY: Base58 private key for signing.
- PUBLIC_KEY: Corresponding public key for balance checks.
- BOT_MODE:
COPYorSELLING. - COPY_WALLET: Wallet address to mirror.
- TRADE_TYPE:
EXACTorSAFE. - BUYAMOUNT, TAKEPROFIT, STOP_LOSS: Only for
SAFE. - ENABLEMULTIBUY:
trueorfalse. - SLIPPAGE, JITOTIP, JITOENGINE: Execution parameters.
- COINVERAAPI, PRICECHECK_DELAY: Price monitoring settings.
- ENABLETRAILINGSTOP, TRAILINGSTOPDISTANCE, TRAILINGSTOPACTIVATION: Trailing stop loss configuration.
Trailing Stop Loss
The trailing stop loss feature is an advanced risk management tool that automatically adjusts your stop loss upward as the price increases, helping lock in profits while allowing for continued upside potential. This dynamic approach maximizes your profit potential while protecting against significant reversals.
๐ How Trailing Stop Loss Works
Phase 1: Monitoring (Before Activation)
- Bot tracks the highest price reached since entry
- Trailing stop remains inactive until activation threshold is met
- Regular stop loss provides downside protection
- When profit reaches
TRAILINGSTOPACTIVATIONthreshold, trailing stop activates - Initial trailing stop price is set at
TRAILINGSTOPDISTANCEbelow current peak - Bot continues to track peak price movements
- As price rises to new peaks, trailing stop moves up proportionally
- Trailing stop price = Peak Price ร (1 -
TRAILINGSTOPDISTANCE/ 100) - Important: Trailing stop never moves down, only up
- When price drops to or below the trailing stop price, position is sold immediately
- Profit is locked in at the trailing stop level
๐ Integration with Existing Features
The bot checks exit conditions in this priority order:
- ๐ฏ Trailing Stop Loss (highest priority - if active)
- ๐ Take Profit (fixed percentage)
- ๐ Stop Loss (fixed percentage)
| Scenario | Entry | Peak | Current | Action | Result | |----------|-------|------|---------|--------|--------| | Trailing Stop Wins | $1.00 | $2.00 | $1.79 | Trailing Stop | Sell at $1.79 (+79%) | | Take Profit Wins | $1.00 | $1.45 | $1.50 | Take Profit | Sell at $1.50 (+50%) | | Stop Loss Protects | $1.00 | $1.15 | $0.80 | Stop Loss | Sell at $0.80 (-20%) |
โ๏ธ Configuration Options
# Enable/disable trailing stop loss
ENABLETRAILINGSTOP=true
Distance below peak price to maintain stop loss (percentage)
TRAILINGSTOPDISTANCE=10.0
Minimum profit before trailing stop activates (percentage)
TRAILINGSTOPACTIVATION=20.0
๐ฏ Configuration Strategies
Conservative Strategy (Risk-Averse)
ENABLETRAILINGSTOP=true TRAILINGSTOPDISTANCE=15.0 # Wider distance - less sensitive TRAILINGSTOPACTIVATION=30.0 # Higher activation - more selective TAKE_PROFIT=40.0 # Lower take profit - secure gains STOP_LOSS=15.0 # Tighter stop loss - limit losses
Aggressive Strategy (Maximum Profit)
ENABLETRAILINGSTOP=true TRAILINGSTOPDISTANCE=8.0 # Closer distance - more sensitive TRAILINGSTOPACTIVATION=15.0 # Lower activation - starts sooner TAKE_PROFIT=100.0 # Higher take profit - let winners run STOP_LOSS=25.0 # Wider stop loss - ride volatility
Balanced Strategy (Recommended)
ENABLETRAILINGSTOP=true TRAILINGSTOPDISTANCE=12.0 # Moderate distance TRAILINGSTOPACTIVATION=25.0 # Reasonable activation threshold TAKE_PROFIT=60.0 # Balanced take profit STOP_LOSS=20.0 # Standard stop loss
๐ Detailed Examples
Example 1: Successful Trailing Stop
Entry Price: $1.00 Config: TSL Distance=10%, TSL Activation=20%
Price Movement: $1.00 โ $1.10 (+10%) โ Tracking peak, TSL not active $1.10 โ $1.25 (+25%) โ TSL ACTIVATES, stop at $1.125 $1.25 โ $1.60 (+60%) โ TSL updates to $1.44 $1.60 โ $1.80 (+80%) โ TSL updates to $1.62 $1.80 โ $1.61 (+61%) โ TSL TRIGGERS, sells at $1.61
Result: +61% profit (vs +80% peak, -10.6% from peak)
Example 2: Take Profit Override
Entry Price: $1.00 Config: TSL Distance=10%, TSL Activation=20%, Take Profit=50%
Price Movement: $1.00 โ $1.25 (+25%) โ TSL activates, stop at $1.125 $1.25 โ $1.50 (+50%) โ TAKE PROFIT triggers immediately
Result: +50% profit (take profit overrides trailing stop)
Example 3: Stop Loss Protection
Entry Price: $1.00 Config: TSL Distance=10%, TSL Activation=20%, Stop Loss=15%
Price Movement: $1.00 โ $1.15 (+15%) โ TSL not active yet (below 20%) $1.15 โ $0.85 (-15%) โ STOP LOSS triggers
Result: -15% loss (regular stop loss protects before TSL activates)
๐จ Important Considerations
Market Volatility:
- High volatility may trigger trailing stops prematurely
- Consider wider
TRAILINGSTOPDISTANCEfor volatile tokens - Monitor and adjust based on market conditions
- Too low activation threshold: May activate on small pumps
- Too high activation threshold: May miss profit protection opportunities
- Recommended range: 15-30% depending on strategy
- Too tight distance: Frequent false triggers on normal volatility
- Too wide distance: May give back too much profit
- Recommended range: 8-15% depending on token behavior
๐งช Testing Your Configuration
Before going live, it's recommended to:
- Start with Conservative Settings: Use wider distances and higher activation thresholds
- Monitor Initial Trades: Watch how the trailing stop behaves with your token selections
- Adjust Based on Results: Fine-tune parameters based on actual performance
- Use Small Amounts: Test with smaller
BUY_AMOUNTinitially
๐ Performance Benefits
- Profit Maximization: Captures more upside than fixed take profit
- Risk Management: Protects against significant reversals
- Automated Execution: No manual intervention required
- Adaptive Strategy: Adjusts to market movements in real-time
๐ง Technical Implementation
- Storage: All trailing stop data persisted in
positions.json - Logging: Comprehensive logging with
[TSL]prefix for easy monitoring - Mode Support: Only available in
SAFEmode (notEXACTmode) - Performance: Minimal overhead, checked during regular price polling
.env.example for details and examples.
Project Structure
.
โโโ .env.example # Copy to .env and configure
โโโ data/
โ โโโ positions.json # Persisted position records
โโโ utils/
โ โโโ getTimestamp.js # ISO timestamp helper
โโโ src/
โโโ config.js # Loads and validates environment variables
โโโ logger.js # Timestamped console logger
โโโ storage.js # Reads/writes data/positions.json
โโโ dexMapper.js # Maps CoinVera DEX names to SolanaPortal codes
โโโ priceChecker.js # Fetches prices from CoinVera HTTP API
โโโ websocket.js # Subscribes to CoinVera WS, emits copyTrade events
โโโ tradeExecutor.js # Builds & submits SolanaPortal/Jito transactions
โโโ index.js # Main application logic and event loop
Usage
- Clone & install (see Installation).
- Rename
.env.exampleto.envand fill in values. - Run:
npm start
- BOT_MODE=SELLING: Liquidate all open positions and exit.
- BOT_MODE=COPY: Listen for copy-wallet trades and mirror them.
Environment Variables Reference
| Variable | Description | |---------------------|-----------------------------------------------------------------------------------------------| | SOLANA_RPC | RPC endpoint (mainnet-beta) | | PRIVATE_KEY | Base58 private key for signing transactions | | PUBLIC_KEY | Wallet public key for balance queries | | BOT_MODE | COPY (normal) or SELLING (liquidate & exit) | | COPY_WALLET | Wallet address to mirror | | TRADE_TYPE | EXACT or SAFE | | BUYAMOUNT | (If TRADETYPE=SAFE) SOL to spend per buy | | TAKEPROFIT | (If TRADETYPE=SAFE) TP percentage | | STOPLOSS | (If TRADETYPE=SAFE) SL percentage | | ENABLEMULTIBUY | true or false | | SLIPPAGE | Slippage tolerance (%) | | JITO_TIP | SOL tip per transaction to prioritize on Jito | | JITO_ENGINE | Jito RPC endpoint (e.g. https://tokyo.mainnet.block-engine.jito.wtf/api/v1/transactions) | | COINVERA_API | CoinVera HTTP API key (for price lookups & WS) | | PRICECHECKDELAY | Polling interval in ms for open-position price checks | | PREFERRED_DEX | Preferred DEX for trading. Options: "none" (system decides) or specific DEX: "auto", "pumpfun", "meteora", "raydium", "moonshot", "jupiter" | | ENABLETRAILINGSTOP | Enable trailing stop loss feature (true or false) | | TRAILINGSTOPDISTANCE | Distance below peak price to trail (%) | | TRAILINGSTOPACTIVATION | Minimum profit percentage before trailing starts (%) |
Links & Resources
- SolanaPortal Docs: https://docs.solanaportal.io
- CoinVera: https://www.coinvera.io
- Telegram Community: https://t.me/ahk782
Community & Support
- โญ Star the repo: https://github.com/bigmacman1129/solana-copy-trading-bot
- ๐ฌ Join our Telegram to request features or get help:
Contributing
- Fork the repository.
- Create a branch:
git checkout -b feature/new-feature. - Make changes & commit:
git commit -m "Add new feature". - Push & open a Pull Request.
License
Licensed under the MIT License.