Skip to content

LgrappaG/PolymarketAgent

🧠 Polymarket AI Agent

⚠️ DISCLAIMER: This is a TEST/DEMO PROJECT

This is research and educational software demonstrating autonomous AI trading concepts. NOT suitable for production use or real financial trading. Use for learning and testing only. No warranty provided.

An autonomous trading agent for Polymarket prediction markets, powered by Claude AI and multi-source data analysis.

Status: πŸš€ MVP Phase (Foundation & Configuration) - Educational/Test Purpose


πŸ“‹ Features

Current Phase (MVP)

  • βœ… Project structure & configuration management
  • βœ… Claude Tool-Use integration (decision engine)
  • πŸ”„ Multi-source data collection (Polls, Sports, Crypto, News)
  • πŸ”„ Semi-autonomous execution with confidence thresholds
  • πŸ”„ Memory system for trade history & performance tracking

Roadmap

  • Phase 2: Full data collectors for all market categories
  • Phase 3: Real-time Polymarket API integration
  • Phase 4: Advanced risk management (Kelly Criterion)
  • Phase 5: Backtesting framework

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  DATA LAYER (Collectors)                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ Polls (FiveThirtyEight)                   β”‚
β”‚ β€’ Sports (ESPN)                             β”‚
β”‚ β€’ Crypto (Binance, Whale Alert)             β”‚
β”‚ β€’ News (NewsAPI, Twitter/X)                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  CLAUDE DECISION ENGINE (Tool-Use)          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ Sentiment Analysis                        β”‚
β”‚ β€’ Expected Value Calculation                β”‚
β”‚ β€’ Risk Management                           β”‚
β”‚ β€’ Arbitrage Detection                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  EXECUTION (Semi-Autonomous)                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ IF confidence > 75% + size < $50:           β”‚
β”‚   β†’ AUTO-EXECUTE                            β”‚
β”‚ IF 60-75% confidence:                       β”‚
β”‚   β†’ QUEUE FOR APPROVAL                      β”‚
β”‚ ELSE:                                        β”‚
β”‚   β†’ HUMAN REVIEW                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  MEMORY (Tracking & Performance)            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ Trade History                             β”‚
β”‚ β€’ Win Rate by Category                      β”‚
β”‚ β€’ Claude Calibration                        β”‚
β”‚ β€’ Risk Metrics                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

1. Clone & Setup

cd PolymarketAgent
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt

2. Configure Credentials

cp .env.example .env.local
# Edit .env.local with your API keys:
# - ANTHROPIC_API_KEY (Claude)
# - POLYMARKET credentials
# - WALLET address & PRIVATE_KEY
# - Data source APIs (NewsAPI, Twitter, etc.)

3. Run Agent

python -m src.main

πŸ”‘ API Keys Required

Must-Have

Recommended

  • Twitter/X API v2: $100/month (Essential tier) for tweet analysis
  • FiveThirtyEight: Free polls (read-only)
  • ESPN API: Free sports data

Optional (Arbitrage)

  • Pinnacle: Bookmaker odds API ($200-500/month)

πŸ“Š Market Categories & Strategies

Category Strategy Target ROI Risk
Politics Polling + sentiment +3-5% / week 🟒 Low
Sports Historical + injuries +5-10% / week 🟑 Medium
Crypto Arbitrage + news +2-4% / week πŸ”΄ High
Arbitrage Cross-market spreads +1-2% / week 🟒 Low

🧠 Decision Engine (Claude Tool-Use)

The agent uses Claude's tool-use capability to:

  1. Sentiment Analysis - Extract market signals from news/tweets
  2. Expected Value Calc - Compare market odds vs. model probability
  3. Risk Calculator - Determine position size (Kelly Criterion)
  4. Arbitrage Detection - Spot cross-market inefficiencies

Example decision flow:

Market: "Will Bitcoin exceed $50k by April 2026?"
Current odds: 0.38 (38% probability)
Claude thinks: 42% probability (based on data)
Edge: +4.2%
Confidence: 82%
Decision: BUY 0.38 odds (underpriced)
Position Size: $100 (1% of balance)

πŸ“ Configuration

Key settings in .env.local:

# Risk Parameters
INITIAL_BALANCE=500                 # Starting USDC
MAX_POSITION_SIZE=0.02             # 2% per trade
MIN_CONFIDENCE_AUTO=0.75           # Auto-execute threshold
MIN_CONFIDENCE_APPROVAL=0.60       # Needs human review

# Execution Mode
EXECUTION_MODE=APPROVAL  # PAPER | APPROVAL | AUTO

See .env.example for all options.


πŸ“‚ Project Structure

polymarket-agent/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.py              # Entry point
β”‚   β”œβ”€β”€ config.py            # Configuration & constants
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   β”œβ”€β”€ collectors/      # Market data sources
β”‚   β”‚   └── datastore.py     # Data caching
β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”œβ”€β”€ claude_agent.py  # Decision engine (Tool-Use)
β”‚   β”‚   └── tools/           # Claude tools
β”‚   β”œβ”€β”€ execution/
β”‚   β”‚   β”œβ”€β”€ executor.py      # Trade executor
β”‚   β”‚   β”œβ”€β”€ polymarket_client.py
β”‚   β”‚   └── approval_queue.py
β”‚   └── memory/
β”‚       β”œβ”€β”€ trades_history.py
β”‚       └── performance_tracker.py
β”œβ”€β”€ tests/
β”œβ”€β”€ logs/
β”œβ”€β”€ .env.local              # Your secrets (GITIGNORE)
β”œβ”€β”€ .env.example            # Template
└── requirements.txt

πŸ”’ Security Notes

⚠️ CRITICAL SECURITY & DISCLAIMER:

  • This is NOT production software. This is a proof-of-concept for educational purposes only.
  • Real financial risk: Do not use with real money, real private keys, or production accounts.
  • For production deployment, you would need:
    • Hardware security module (HSM) for key management
    • Professional security audit
    • Compliance review (securities regulation)
    • Institutional-grade monitoring & alerting
    • Insurance & liability coverage
  • Never commit .env.local (private key stored here!)
  • Use .env.example as template only
  • Test in PAPER mode first (simulated trades)

πŸ’‘ Best Practices (For Learning):

  • Start in PAPER mode (simulation only)
  • Graduate to APPROVAL (human review of each trade)
  • Only then move to AUTO (fully automatic)
  • Never use real credentials or significant amounts while learning

πŸ“Š Performance Tracking

Agent logs all trades to memory/:

  • trades_history.json - All trades with PnL
  • category_performance.json - Win rate by market type
  • claude_calibration.json - Confidence accuracy metrics
# View performance
python -c "from src.memory import PerformanceTracker; \
           p = PerformanceTracker(); p.print_summary()"

πŸ§ͺ Testing

pytest tests/ -v
pytest tests/ --cov=src  # Coverage report

🀝 Contributing

Current contributors: 1 Focus area: Core agent loop & Claude integration


πŸ“œ License

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

All use is strictly for educational and testing purposes only.


🎯 Next Steps

  1. βœ… Phase 1 (NOW): Configure & validate API connections
  2. πŸ”„ Phase 2: Build data collectors
  3. πŸ”„ Phase 3: Claude decision engine
  4. πŸ”„ Phase 4: Trade execution
  5. πŸ”„ Phase 5: Memory & performance tracking

Let's get this agent trading! πŸš€

About

IDE AI Agent trades for profit (for test purposes only)

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages