Skip to content

JRBlitz/polymarket-copytrader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Polymarket Copytrader Pro

A high-performance copy trading system for Polymarket that can process thousands of trades per second with minimal latency and maximum reliability.

πŸš€ Features

High-Performance Architecture

  • Real-time WebSocket connections for instant trade detection
  • Batch processing with configurable batch sizes (1-100 trades)
  • Concurrent execution with up to 50 simultaneous trades
  • Multi-level caching for optimal performance
  • Event-driven architecture for scalable processing

Advanced Trading Features

  • Smart slippage management with configurable limits
  • Multiple execution modes: percentage-based or fixed-size copying
  • Real-time performance monitoring with detailed metrics
  • Automatic retry mechanisms with exponential backoff
  • Circuit breaker patterns for fault tolerance

Professional UI

  • Real-time dashboards showing trade activity and performance
  • Advanced configuration options with preset profiles
  • Comprehensive logging with different log levels
  • Performance analytics with success rates and execution times
  • Import/export settings for easy configuration management

πŸ—οΈ Architecture Overview

The system is built with a modern, scalable architecture that separates concerns and optimizes for performance:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend UI   β”‚    β”‚  Backend Engine  β”‚    β”‚  External APIs  β”‚
β”‚   (React/TS)    │◄──►│  (Node.js/TS)    │◄──►│  (Polymarket)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
         └──────────────►│   WebSocket     β”‚β—„β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚   Manager       β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Components

  1. WebSocket Manager: Handles real-time connections to Polymarket
  2. Batch Processor: Groups trades for efficient processing
  3. Concurrent Executor: Manages parallel trade execution
  4. Cache Manager: Multi-level caching for optimal performance
  5. Performance Monitor: Real-time metrics and analytics

πŸ“Š Performance Benchmarks

Target Metrics

  • Throughput: 10,000+ trades/second
  • Latency: < 10ms end-to-end
  • Uptime: 99.99% availability
  • Scalability: Linear scaling with resources

Optimization Strategies

  • Memory Management: Object pooling, memory mapping
  • Network Optimization: Connection pooling, compression
  • CPU Optimization: SIMD instructions, worker threads
  • I/O Optimization: Async I/O, batch operations

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • npm 8+
  • Polymarket account with API access

Installation

  1. Clone the repository

    git clone https://github.com/JRBlitz/polymarket-copytrader.git
    cd polymarket-copytrader
  2. Install dependencies

    npm install
  3. Configure environment

    cp .env.example .env
    # Edit .env with your Polymarket API credentials
  4. Start the development server

    npm run dev
  5. Start the backend (in another terminal)

    npm run dev:backend

Production Build

# Build frontend and backend
npm run build
npm run build:backend

# Start production server
npm run start:backend

βš™οΈ Configuration

Trading Parameters

Parameter Description Range Default
copyFactor Copy size as percentage of original 0-500% 100%
maxSlippageBps Maximum price deviation in basis points 10-1000 100
batchSize Number of trades to process together 1-100 50
maxConcurrentTrades Maximum simultaneous executions 1-50 10
pollIntervalMs Polling frequency (fallback mode) 5000-60000 15000

Performance Presets

Safe Mode

  • Copy Factor: 80%
  • Max Slippage: 0.5%
  • Poll Interval: 20 seconds
  • Batch Size: 3
  • Concurrency: 1

Balanced Mode

  • Copy Factor: 100%
  • Max Slippage: 1.0%
  • Poll Interval: 15 seconds
  • Batch Size: 5
  • Concurrency: 3

Fast Mode

  • Copy Factor: 120%
  • Max Slippage: 2.0%
  • Poll Interval: 8 seconds
  • Batch Size: 8
  • Concurrency: 5

Ultra Mode

  • Copy Factor: 150%
  • Max Slippage: 3.0%
  • Poll Interval: 5 seconds
  • Batch Size: 12
  • Concurrency: 8

πŸ”§ Advanced Configuration

WebSocket vs Polling

The system can operate in two modes:

  1. WebSocket Mode (Recommended)

    • Real-time trade detection
    • Minimal latency
    • Automatic reconnection
    • Message queuing during disconnections
  2. Polling Mode (Fallback)

    • Configurable intervals
    • Reliable but higher latency
    • Better for unstable connections

Batch Processing

// Configure batch processing
const config = {
  batchSize: 50,           // Process 50 trades together
  maxWaitTime: 50,         // Wait max 50ms for batch to fill
  maxConcurrentTrades: 10  // Execute 10 trades simultaneously
}

Caching Strategy

// Multi-level caching configuration
const cacheConfig = {
  l1Cache: { max: 10000 },  // In-memory cache
  l2Cache: { max: 50000 },  // Redis cache
  ttl: 300000               // 5 minutes TTL
}

πŸ“ˆ Monitoring & Analytics

Real-Time Metrics

  • Total Trades: Number of completed copy trades
  • Success Rate: Percentage of successful executions
  • Average Execution Time: Mean time to execute trades
  • Total Volume: Cumulative volume of copied trades
  • Trades Per Second: Current processing rate

Performance Dashboard

The UI provides real-time insights into:

  • Trade execution status
  • System performance metrics
  • Error rates and types
  • Network connectivity status
  • Cache hit rates

πŸ›‘οΈ Security & Safety

Security Features

  • Private key encryption with secure storage
  • API key management with automatic rotation
  • Rate limiting to prevent abuse
  • Input validation and sanitization
  • Secure WebSocket connections

Safety Measures

  • Dry-run mode for testing without real trades
  • Slippage protection to prevent bad executions
  • Circuit breakers to stop trading on errors
  • Automatic stop-loss mechanisms
  • Trade size limits to prevent excessive exposure

πŸ” Troubleshooting

Common Issues

  1. WebSocket Connection Failed

    • Check network connectivity
    • Verify API credentials
    • Check firewall settings
  2. High Latency

    • Reduce batch size
    • Increase concurrency
    • Check network performance
  3. Memory Issues

    • Reduce cache sizes
    • Lower batch sizes
    • Monitor memory usage

Debug Mode

Enable debug logging:

DEBUG=* npm run dev:backend

Performance Tuning

For optimal performance:

  1. Use WebSocket mode when possible
  2. Adjust batch sizes based on your hardware
  3. Monitor memory and CPU usage
  4. Use appropriate concurrency levels

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“„ License

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

⚠️ Disclaimer

This software is for educational and research purposes. Trading cryptocurrencies involves substantial risk and may result in the loss of your invested capital. You should carefully consider whether trading is suitable for you in light of your financial condition, investment objectives, and risk tolerance.

πŸ†˜ Support

πŸ™ Acknowledgments

  • Polymarket team for their excellent API
  • Open source community for the amazing tools
  • Contributors and beta testers

Built with ❀️ for the DeFi community

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors