Autonomous AI Trading Agent for Prediction Markets
A production trading system that scans 2,000+ markets on Polymarket, runs multi-LLM analysis, detects cross-platform arbitrage, and executes trades with 5-layer risk management — all through a Discord interface.
16,000+ lines of Python. Built solo. Source is private.
Note: This is a showcase repository. The source code is private. This README documents the architecture, capabilities, and design decisions.
ASGARD is an autonomous prediction market trading agent. You interact with it through Discord slash commands. It scans markets, researches fundamentals, calculates edges, and manages a portfolio of positions with real money on the line.
It doesn't just give you picks. It tells you why, scores its own confidence, tracks whether it was right, and adjusts its strategy over time.
┌─────────────────────────────────────────────────────┐
│ DISCORD INTERFACE │
│ 13 slash commands · 4-tier permissions · embeds │
└──────────────────────┬──────────────────────────────┘
│
┌──────────────┼──────────────┐
▼ ▼ ▼
┌──────────────┐ ┌──────────┐ ┌──────────────┐
│ MARKET │ │ WEATHER │ │ NEWS │
│ SCANNER │ │ ENGINE │ │ VELOCITY │
│ │ │ │ │ │
│ 2000+ mkts │ │ NWS API │ │ 60s polling │
│ Firecrawl │ │ CDF calc │ │ Tavily+Claude│
│ gamma-api │ │ bracket │ │ dislocation │
│ keyword │ │ pricing │ │ detection │
└──────┬───────┘ └────┬─────┘ └──────┬───────┘
│ │ │
└──────────────┼──────────────┘
▼
┌──────────────────────────────┐
│ MULTI-LLM PIPELINE │
│ │
│ Stage 1: Ollama (local) │
│ → Pre-filter, classify │
│ → Cost: $0 per market │
│ │
│ Stage 2: Claude (cloud) │
│ → Deep analysis, scoring │
│ → Only high-signal markets │
│ │
│ Anti-hallucination guards │
│ Date verification │
│ Evidence requirements │
└──────────────┬───────────────┘
▼
┌──────────────────────────────┐
│ 5-LAYER RISK ENGINE │
│ │
│ 1. Circuit breaker │
│ 2. Position sizing │
│ 3. Stop loss / take profit │
│ 4. Volatility gate │
│ 5. Portfolio exposure cap │
└──────────────┬───────────────┘
▼
┌──────────────────────────────┐
│ ORDER EXECUTION │
│ │
│ Polymarket CLOB API │
│ Stale price guard (3%) │
│ Confirmation flow │
│ 30-second timeout │
└──────────────────────────────┘
Local Ollama (qwen2.5) pre-filters markets before Claude does deep analysis. 90% of markets get rejected at the cheap stage. Only high-signal opportunities reach the expensive model. Same cost optimization pattern used by production AI companies.
Episodic + semantic memory system. The bot remembers every market it scanned, every trade it made, every strategy that worked or failed. Temporal supersession chains ensure newer information overrides stale data. Built on SQLite with HNSW vector search.
Zero-cost edge detection using NWS (National Weather Service) forecasts. Pulls 7-day forecasts, calculates bracket probabilities using normal distribution CDF, identifies mispriced weather markets on Polymarket. No API costs — NWS data is free.
Background process polling breaking news every 60 seconds via Tavily. Detects news-price dislocations — when breaking news hasn't been priced into prediction markets yet. Keyword heuristic pre-filter, Claude verification gate.
Compares prices between Polymarket and Kalshi for the same event. When the price gap exceeds a threshold, it flags the opportunity. The Peru election trade was sourced this way — 13% price gap between platforms.
| Strategy | Description | Edge Source |
|---|---|---|
| XARB | Cross-platform arbitrage (Polymarket vs Kalshi) | Price divergence |
| THETA | Time decay plays with known catalysts | Calendar events |
| BIAS | Recency bias and anchoring exploitation | Behavioral economics |
| EXTREME VALUE | Base rate analysis on mispriced tails | Statistical |
| MOMENTUM | Geopolitical catalyst-driven momentum | News flow |
| WEATHER | NWS forecast-based edge on weather markets | Free data advantage |
| Command | Description |
|---|---|
/scan |
Scan markets by category with AI analysis |
/weather |
Run NWS weather engine on temperature markets |
/velocity |
Check breaking news velocity signals |
/picks |
Get AI-scored trading recommendations |
/analyze |
Deep-dive analysis on a specific market |
/live-trade |
Execute a real trade on Polymarket |
/paper-trade |
Execute a paper (simulated) trade |
/auto-trade |
Toggle autonomous trading mode |
/wallet |
Check Polymarket wallet balance |
/portfolio |
View open positions and P&L |
/pnl |
Detailed profit & loss breakdown |
/whales |
Track large-position whale activity |
/status |
System health and configuration |
Every trade passes through a 7-step validation before execution:
- Edge threshold — minimum required edge before entry
- Position limits — max size per trade, per tier
- Circuit breaker — blocks trading after consecutive losses
- Stale price guard — re-fetches price before execution, aborts on 3%+ drift
- Duplicate check — prevents opening the same position twice
- Exposure cap — maximum total portfolio exposure
- Credential verification — confirms wallet connectivity before every trade
| Metric | Value |
|---|---|
| Lines of Code | 16,000+ |
| Source Files | 16 |
| Discord Commands | 13 |
| Trading Strategies | 6 |
| Safety Checks | 7 |
| Markets Scanned | 2,000+ per run |
| Permission Tiers | 4 (Owner → Admin → Trader → Viewer) |
This system trades real money. The source code contains:
- Trading strategies and edge calculations
- Risk parameters and position sizing logic
- API integration details
- Memory architecture specifics
Making it public would eliminate the trading edge. The architecture and design decisions are shared here for portfolio purposes.
Karim Lukita — One-person product studio. SaaS platforms, trading bots, AI tools, games. Design to deployment, shipped fast.