Skip to content

alastrat/polytrader

Repository files navigation

Polymarket AI Trading Bot

AI-powered trading bot for Polymarket prediction markets with strategy backtesting, live deployment, risk management, and automated profit extraction.

Features

  • Multi-Strategy Portfolio: Run multiple strategies simultaneously
  • Paper & Live Trading: Test strategies before deploying real capital
  • AI-Powered Analysis: Claude integration for market analysis
  • Risk Management: Position sizing, drawdown limits, circuit breakers
  • Automated Profit Extraction: Weekly profit calculation and withdrawal
  • Real-time Monitoring: Dashboard and Telegram/Discord alerts

Quick Start

Prerequisites

  • Python 3.11+
  • Docker & Docker Compose
  • Poetry (Python package manager)

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/polymarket-bot.git
cd polymarket-bot
  1. Copy environment file and configure:
cp .env.example .env
# Edit .env with your configuration
  1. Start services:
make init  # Installs dependencies, starts Docker, runs migrations
  1. Start the development server:
make dev

The API will be available at http://localhost:8000

Configuration

Required environment variables:

# Wallet (REQUIRED for trading)
WALLET_PRIVATE_KEY=0x...
WALLET_ADDRESS=0x...

# Database
DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/polymarket_bot
REDIS_URL=redis://localhost:6379/0

# AI (optional, for market analysis)
ANTHROPIC_API_KEY=sk-ant-...

Architecture

polymarket-bot/
├── src/
│   ├── api/           # FastAPI routes
│   ├── core/          # Orchestrator, scheduler
│   ├── strategies/    # Trading strategies
│   ├── trading/       # Execution engine
│   ├── risk/          # Risk management
│   ├── ai/            # LLM integration
│   ├── integrations/  # Polymarket client
│   ├── profit/        # P&L tracking
│   └── db/            # Database models
├── tasks/             # Celery background tasks
├── tests/             # Test suite
└── alembic/           # Database migrations

Usage

Create a Bot

curl -X POST http://localhost:8000/api/v1/bots \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My Trading Bot",
    "initial_capital": 10,
    "wallet_address": "0x...",
    "mode": "paper"
  }'

Add a Strategy

curl -X POST http://localhost:8000/api/v1/strategies \
  -H "Content-Type: application/json" \
  -d '{
    "bot_id": "your-bot-id",
    "name": "Momentum Strategy",
    "type": "momentum",
    "allocation_pct": 50,
    "parameters": {
      "fast_ma_period": 6,
      "slow_ma_period": 24
    }
  }'

Start Trading

curl -X POST http://localhost:8000/api/v1/bots/{bot_id}/start

Available Strategies

Strategy Type Description
Momentum momentum Trend-following using moving average crossovers
Mean Reversion mean_reversion Counter-trend using Bollinger Bands and RSI
Sentiment sentiment News-based trading signals

API Endpoints

Endpoint Method Description
/api/v1/bots GET List all bots
/api/v1/bots POST Create a new bot
/api/v1/bots/{id}/start POST Start a bot
/api/v1/bots/{id}/stop POST Stop a bot
/api/v1/strategies GET List strategies
/api/v1/strategies POST Create strategy
/api/v1/markets GET List markets
/api/v1/positions GET List positions
/api/v1/analytics/bots/{id}/performance GET Get performance

Development

Running Tests

make test

Linting & Formatting

make lint
make format

Database Migrations

# Create a new migration
make migrate-create

# Apply migrations
make migrate

Celery Workers

# Start worker
make worker

# Start beat scheduler
make beat

Risk Warnings

  • This is experimental software. Use at your own risk.
  • Start with small amounts ($10) to test.
  • Polymarket has US restrictions. Ensure compliance.
  • Smart contract risk exists for all funds.
  • Never share your private keys.

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •