Skip to content

vitwit/copy-trade-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Copy Trading Platform

A comprehensive copy-trading platform that monitors top DEX traders, tracks their performance, and automatically executes copy trades with built-in risk management.

πŸš€ Features

  • Real-time Trader Monitoring: Tracks top 5 traders from CoinMarketCap DEX data
  • Multi-Chain Support: Supports Solana and BSC (Binance Smart Chain)
  • Automated Copy Trading: Executes trades automatically with configurable parameters
  • Risk Management: Pauses underperforming traders automatically
  • Performance Analytics: Real-time P&L tracking and portfolio management
  • Blockchain Monitoring: Real-time transaction monitoring via WebSockets

πŸ—οΈ Architecture

Core Components

  1. Trader Discovery Service: Fetches and monitors top traders every 30 seconds
  2. Blockchain Monitor Service: Real-time transaction monitoring for tracked wallets
  3. Copy Trading Engine: Executes copy trades with risk management logic
  4. Performance Analytics: Tracks P&L and portfolio performance

Database Schema

  • traders - Tracked trader information and status
  • trader_trades - Original trader transactions
  • copy_trades - Our executed copy trades
  • portfolio_positions - Current holdings per trader
  • trader_performance - Aggregated performance metrics
  • system_metrics - Overall platform performance

πŸ› οΈ Installation

Prerequisites

  • Go 1.21+
  • PostgreSQL 15+
  • CoinMarketCap API key (optional)

Quick Start

  1. Clone and setup:

    git clone <repository>
    cd copy-trade-bot
    make setup
  2. Configure environment:

    cp .env.example .env
    # Edit .env with your configuration
  3. Start database:

    make db-up
  4. Install dependencies and build:

    make deps
    make build
  5. Run the application:

    make run

βš™οΈ Configuration

Edit the .env file with your settings:

# Database
DB_HOST=localhost
DB_PORT=5432
DB_USER=copy_trader
DB_PASSWORD=your_password
DB_NAME=copy_trade_db

# API Keys
COINMARKETCAP_API_KEY=your_cmc_api_key

# Blockchain RPC URLs
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
BSC_RPC_URL=https://bsc-dataseed.binance.org/

# Trading Configuration
MAX_POSITION_SIZE=10.0  # USDC per trade
MAX_SLIPPAGE=0.05       # 5% max slippage
TRADER_FETCH_INTERVAL=30 # seconds

🎯 Trading Logic

Buy Trades

  • Condition: Trader status = ACTIVE AND avg performance > 50%
  • Amount: Fixed 10 USDC per trade
  • Risk: Pause trader if avg portfolio performance drops below 50%

Sell Trades

  • Condition: Always copy (regardless of trader status)
  • Amount: Proportional to our current holdings
  • Execution: Immediate copy when detected

πŸ“Š Performance Monitoring

The platform continuously monitors:

  • Trader Performance: Win rate, P&L, volume metrics
  • Portfolio Values: Real-time position tracking and P&L
  • Risk Metrics: Automatic trader pausing based on performance
  • System Health: Database connectivity and service status

🚦 Risk Management

Automated Protections

  • Performance-based pausing: Traders paused if avg performance < 50%
  • Position limits: Max 10 USDC per trade, configurable per trader
  • Slippage protection: Configurable maximum slippage (default 5%)
  • Gas management: Dynamic gas estimation for optimal execution

Manual Controls

  • Pause/resume individual traders
  • Adjust position sizes and risk parameters
  • Emergency stop functionality

πŸ”§ Development

Available Commands

make help              # Show all available commands
make deps              # Download dependencies
make build             # Build the application
make run               # Run the application
make dev               # Run with hot reload
make test              # Run tests
make test-coverage     # Run tests with coverage
make check             # Run fmt, vet, and lint
make clean             # Clean build artifacts

Development Tools

Install recommended tools:

make install-tools

This installs:

  • air - Hot reload for development
  • golangci-lint - Code linting

Database Management

make db-up     # Start PostgreSQL container
make db-down   # Stop PostgreSQL container

πŸ“ Project Structure

copy-trade-bot/
β”œβ”€β”€ cmd/                    # Application entry points
β”‚   └── main.go
β”œβ”€β”€ internal/               # Private application code
β”‚   β”œβ”€β”€ config/            # Configuration management
β”‚   β”œβ”€β”€ db/                # Database connection and migrations
β”‚   β”œβ”€β”€ models/            # Database models
β”‚   └── services/          # Business logic services
β”œβ”€β”€ pkg/                   # Public library code
β”‚   β”œβ”€β”€ dex/               # DEX client implementations
β”‚   └── utils/             # Utility functions
β”œβ”€β”€ scripts/               # Database scripts and utilities
β”œβ”€β”€ docs/                  # Documentation
β”œβ”€β”€ .env.example           # Environment configuration template
β”œβ”€β”€ Makefile              # Build and development commands
└── README.md             # This file

πŸ”’ Security Considerations

  • Private Keys: Store securely, consider hardware wallets for production
  • API Keys: Rotate regularly and use environment variables
  • Database: Use SSL connections and proper access controls
  • Monitoring: Implement proper logging and alerting

πŸ“ˆ Analytics & Metrics

Platform Metrics

  • Total P&L across all traders
  • Success rate percentage
  • Average copy delay time
  • Volume traded per day

Per-Trader Metrics

  • Individual trader P&L
  • Win/loss ratios
  • Average hold times
  • Risk scores

Per-Token Metrics

  • Token performance across traders
  • Best/worst performing assets
  • Portfolio allocation

🚨 Monitoring & Alerts

The platform includes:

  • Health check endpoints
  • Database connectivity monitoring
  • Service status tracking
  • Error logging and reporting

⚠️ Disclaimers

  • High Risk: Copy trading involves significant financial risk
  • No Guarantees: Past performance does not guarantee future results
  • Due Diligence: Always verify trader performance before copying
  • Compliance: Ensure compliance with local trading regulations

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and quality checks: make check test
  5. Submit a pull request

πŸ“„ License

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

πŸ“ž Support

For issues and feature requests, please open an issue on GitHub.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors