Skip to content

WisdomAyo/Solana-Bot

Repository files navigation

🚀 Solana Trading Bot

A professional-grade automated trading bot for the Solana ecosystem that discovers newly launched tokens via Twitter, executes trades with technical analysis, and manages risk with capital preservation.

Python 3.10+ License: MIT Solana


✨ Features

Token Discovery

  • Twitter Real-Time Streaming - Monitors Twitter for new Solana token launches and announcements
  • Smart Extraction - Automatically extracts and validates Solana token addresses from tweets
  • Event Classification - Categorizes mentions as launches, announcements, or general mentions

Security Analysis

  • RugCheck Integration - Analyzes tokens for rug-pull risk factors
  • Birdeye API - Checks for honeypot indicators and freeze authority
  • Composite Scoring - Combines multiple data sources for comprehensive safety assessment
  • Liquidity Validation - Ensures minimum liquidity requirements before trading

Technical Analysis

  • RSI (Relative Strength Index) - Identifies overbought/oversold conditions
  • MACD - Detects trend momentum and crossovers
  • EMA Crossovers - Tracks short/medium/long-term moving average alignments
  • Volume Analysis - Confirms signals with volume validation
  • Re-Entry Detection - Identifies opportunities to re-enter after pullbacks

Trade Execution

  • Jupiter DEX Integration - Executes swaps through Jupiter V6 API
  • Slippage Protection - Configurable slippage tolerance
  • Priority Fees - Adjustable transaction priority
  • Paper Trading Mode - Test strategies without risking real funds

Risk Management

  • Stop-Loss - Fixed percentage stop-loss protection
  • Trailing Stop - Dynamic stop that follows price upward after reaching targets
  • Take Profit - Automatic profit-taking at 2x (100% gain) or custom targets
  • Capital Preservation - Locks initial capital after reaching 200% profit threshold
  • Circuit Breaker - Emergency shutdown on excessive daily losses or consecutive losing trades

📋 Prerequisites

  • Python 3.10 or higher
  • Solana Wallet with SOL for trading
  • API Keys:
    • Twitter API v2 (Elevated access required)
    • Birdeye API
    • Solana RPC endpoint (recommended: Helius, QuickNode)

🛠️ Installation

1. Clone the Repository

git clone https://github.com/yourusername/solana-trading-bot.git
cd solana-trading-bot

2. Create Virtual Environment

python -m venv venv

# Windows
venv\Scripts\activate

# Linux/Mac
source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Configure Environment

# Copy the example environment file
cp .env.example .env

# Edit .env with your credentials
notepad .env  # Windows
nano .env     # Linux/Mac

⚙️ Configuration

Edit your .env file with the following required settings:

Required API Keys

# Solana Configuration
SOLANA_PRIVATE_KEY=your_base58_private_key
SOLANA_RPC_URL=https://your-rpc-endpoint.com

# Twitter API v2
TWITTER_BEARER_TOKEN=your_twitter_bearer_token

# Birdeye API
BIRDEYE_API_KEY=your_birdeye_api_key

Trading Parameters

# Capital Settings
INITIAL_CAPITAL_SOL=1.0
MAX_TRADE_AMOUNT_SOL=0.1

# Risk Settings
STOP_LOSS_PERCENT=15
TAKE_PROFIT_MULTIPLIER=2.0
MAX_SLIPPAGE_PERCENT=5.0

# Risk Management
MAX_DAILY_LOSS_SOL=0.5
MAX_CONSECUTIVE_LOSSES=3
CAPITAL_PRESERVE_THRESHOLD=200

# Mode: 'paper' for simulation, 'live' for real trading
TRADING_MODE=paper

Security Thresholds

MIN_RUGCHECK_SCORE=60
MIN_LIQUIDITY_USD=10000
MAX_TOP_HOLDER_PERCENT=20

🚀 Usage

Paper Trading (Recommended for Testing)

python main.py --mode paper

Live Trading

⚠️ Warning: Live trading involves real financial risk. Start with small amounts.

python main.py --mode live

Command Line Options

python main.py --help

Options:
  --mode {live,paper}  Trading mode (default: paper)
  --capital FLOAT      Override initial capital in SOL
  --debug              Enable debug logging

📊 Trading Strategy

Entry Criteria

A buy signal is generated when:

  1. Token passes security checks (RugCheck score ≥ 60)
  2. RSI is between 30-70 (not overbought/oversold)
  3. MACD shows bullish crossover or positive momentum
  4. Volume is above average
  5. Price is above 20 EMA

Exit Criteria

Condition Action
Price ≥ 2x entry Take profit (sell all)
Price ≤ -15% from entry Stop-loss (sell all)
Price drops 10% from peak (after 2x) Trailing stop (sell all)

Capital Preservation

After reaching 200% total profit:

  • Original capital is locked and protected
  • Bot continues trading only with profits
  • Maximum 10% of available profits per trade

📁 Project Structure

Solana-Bot/
├── main.py                 # Entry point
├── requirements.txt        # Dependencies
├── .env.example           # Configuration template
│
├── config/
│   └── settings.py        # Pydantic configuration
│
├── solana_client/
│   ├── wallet.py          # Keypair & balance management
│   └── jupiter.py         # Jupiter DEX integration
│
├── discovery/
│   ├── twitter_stream.py  # Twitter API v2 streaming
│   └── token_extractor.py # Address validation
│
├── security/
│   ├── rugcheck_client.py # RugCheck API
│   ├── birdeye_client.py  # Birdeye API
│   └── analyzer.py        # Composite security analysis
│
├── analysis/
│   ├── indicators.py      # RSI, MACD, EMA
│   └── signals.py         # Signal generation
│
├── trading/
│   ├── executor.py        # Trade execution
│   └── position_manager.py# Position tracking
│
├── risk/
│   ├── stop_loss.py       # Stop-loss logic
│   ├── capital_manager.py # Capital preservation
│   └── circuit_breaker.py # Emergency shutdown
│
├── bot/
│   └── orchestrator.py    # Main coordinator
│
├── database/
│   └── models.py          # SQLAlchemy models
│
└── tests/
    ├── test_indicators.py # TA tests
    └── test_risk.py       # Risk management tests

🧪 Testing

Run All Tests

pytest tests/ -v

Run with Coverage

pytest tests/ -v --cov=. --cov-report=html

Test Specific Module

pytest tests/test_indicators.py -v
pytest tests/test_risk.py -v

📈 Monitoring

Log Files

Logs are stored in the ./logs/ directory:

  • bot_YYYY-MM-DD.log - General bot activity
  • trades_YYYY-MM-DD.log - Trade-specific logs
  • errors.log - Error tracking

Log Levels

Set via LOG_LEVEL in .env:

  • DEBUG - Verbose output
  • INFO - Standard operation
  • WARNING - Warnings only
  • ERROR - Errors only

🔒 Security Best Practices

  1. Never share your private key - Keep .env file secure
  2. Use a dedicated wallet - Don't use your main wallet
  3. Start with paper trading - Validate strategy before live trading
  4. Set conservative limits - Use small position sizes initially
  5. Monitor actively - Don't leave unattended during initial runs
  6. Use private RPC - Avoid public endpoints for trading

⚠️ Disclaimer

This software is for educational purposes only.

Trading cryptocurrencies, especially newly launched tokens, carries significant financial risk. You could lose some or all of your investment. The developers are not responsible for any financial losses incurred from using this software.

  • Past performance does not guarantee future results
  • Newly launched tokens are extremely volatile and risky
  • Always do your own research before trading
  • Only invest what you can afford to lose

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


🙏 Acknowledgments


📞 Support

For issues and feature requests, please use the GitHub Issues page.


Built with ❤️ for the Solana ecosystem

About

Build a profit-making trading bot on the Solana ecosystem that trades newly launched tokens discovered via Twitter, with technical analysis, risk management, and capital preservation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages