DEV Community

NevoSayNevo
NevoSayNevo

Posted on

How I Built a Polymarket AFK Trading Bot That Runs While I Sleep

The goal was simple: fully autonomous trading on Polymarket 5/15-min BTC markets with zero manual intervention.

Architecture: Three Specialized Agents

Instead of one monolithic script, I split the system into three independent agents:

1. Analyst Agent (Claude 3.5 Sonnet via Anthropic API)

  • Ingests real-time market data + news + sentiment
  • Outputs: calibrated probability, confidence score (0–1), and trade recommendation
  • Uses structured prompting with historical resolution context

2. Executor Agent

  • Monitors Analyst output via Redis pub/sub
  • Validates edge: model_prob - market_prob > threshold (after fees)
  • Executes via viem directly on Polygon Conditional Tokens contract
  • IOC orders with pre-execution best-ask revalidation

3. Coder Agent (Optional OpenAI Codex / Claude Code)

  • Auto-fixes bugs, improves prompts, and patches strategies based on performance logs

Core Technical Flow

// Simplified decision loop
const signal = await analyst.getSignal(marketId);

if (signal.edge > 0.07 && signal.confidence > 0.75 && timeLeft < 90) {
    await executor.placeTrade({
        side: signal.direction,
        amount: calculateKelly(signal.edge),
        marketId
    });
}
Enter fullscreen mode Exit fullscreen mode

Key Production Features

  • Redis for inter-agent communication and state persistence
  • Telegram notifications for every executed trade
  • Daily drawdown circuit breaker
  • Automatic strategy performance logging + retraining loop
  • Non-custodial: limited USDC spending approval

The bot now runs 24/7, trades only high-conviction edges in the final minutes of each round, and consistently delivers profit while I sleep.

The real breakthrough wasn’t fancy ML — it was clean agent separation, reliable execution infrastructure, and strict risk rules.

If you have more questions, please feel free to contact me at any time: https://t.me/NevoSayNev0

Top comments (0)