A real-time Solana wallet monitoring and copy trading bot built with Python and FastAPI.
- Real-time Monitoring: Monitors multiple Solana wallets simultaneously using WebSocket connections
- Transaction Detection: Uses
logsSubscribeto detect new transactions in real-time - Copy Trading: Automatically copies SOL transfers, SPL token transfers, and program interactions
- Parallel Processing: Monitors all wallets concurrently using asyncio
- Error Handling: Robust error handling with automatic reconnection
- Comprehensive Logging: Detailed logging for debugging and monitoring
- REST API: FastAPI-based API for bot management and monitoring
- Wallet Monitoring: The bot connects to Solana mainnet via WebSocket and subscribes to logs for each target wallet
- Transaction Detection: When a new transaction is detected, the bot fetches full transaction details using
getTransaction - Transaction Analysis: The bot parses the transaction to determine if it's a SOL transfer, SPL token transfer, or program interaction
- Copy Execution: For supported transaction types, the bot reconstructs an equivalent transaction for your wallet and sends it immediately
- SOL Transfers: Basic SOL transfers between wallets
- SPL Token Transfers: Token transfers using the SPL Token Program
- Raydium Swaps: Automated market maker swaps (placeholder implementation)
-
Clone the repository:
git clone https://github.com/aleriado/Solana-Trading-Bot.git cd solana-trading-bot -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment:
cp .env.example .env # Edit .env with your configuration
Edit the .env file with your configuration:
# Your wallet configuration BOT_WALLET_ADDRESS=your_wallet_address BOT_PRIVATE_KEY=your_private_key # Wallets to monitor TARGET_WALLETS=wallet1,wallet2,wallet3 # Trading settings COPY_SOL_TRANSFERS=true COPY_SPL_TRANSFERS=true COPY_RAYDIUM_SWAPS=true MAX_TRANSACTION_AMOUNT=1.0 MIN_TRANSACTION_AMOUNT=0.001# Development mode python -m app.main # Production mode uvicorn app.main:app --host 0.0.0.0 --port 8000The bot provides a REST API for management:
GET /- Basic informationGET /health- Health checkGET /api/v1/status- Bot status and statisticsPOST /api/v1/start- Start the botPOST /api/v1/stop- Stop the botGET /api/v1/wallets- List monitored walletsPOST /api/v1/wallets- Add a wallet to monitorPUT /api/v1/wallets/{address}- Update wallet configurationDELETE /api/v1/wallets/{address}- Remove wallet from monitoringGET /api/v1/transactions- Get transaction historyGET /api/v1/stats- Get trading statisticsGET /api/v1/bot/balance- Get bot wallet balance
# Start the bot curl -X POST http://localhost:8000/api/v1/start # Check status curl http://localhost:8000/api/v1/status # Add a wallet to monitor curl -X POST http://localhost:8000/api/v1/wallets \ -H "Content-Type: application/json" \ -d '{"address": "wallet_address", "enabled": true}' # Get transaction history curl http://localhost:8000/api/v1/transactions?limit=50solana-trading-bot/ ├── app/ │ ├── __init__.py │ ├── main.py # FastAPI application │ ├── config.py # Configuration settings │ ├── models/ │ │ ├── __init__.py │ │ └── schemas.py # Pydantic models │ ├── core/ │ │ ├── __init__.py │ │ ├── solana_client.py # Solana blockchain client │ │ └── bot_manager.py # Bot management logic │ └── api/ │ ├── __init__.py │ └── endpoints.py # API endpoints ├── requirements.txt # Python dependencies ├── .env.example # Environment configuration template └── README.md # This file - Private Key Security: Store private keys securely and never commit them to version control
- Testnet First: Test thoroughly on Solana testnet before using on mainnet
- Amount Limits: Set appropriate limits to prevent large losses
- Monitoring: Monitor the bot's performance and logs regularly
- Backup: Keep backups of your wallet and configuration
pytestThe project follows Python best practices with type hints and async/await patterns.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is for educational purposes. Use at your own risk.
This software is provided "as is" without warranty. Trading cryptocurrencies involves risk, and you should never invest more than you can afford to lose. The authors are not responsible for any financial losses.