Back to articles

I Mass-Built a Polymarket Trading Bot in 2 Weeks - Here's Every Tool That Powers It

Lunar · @LunarResearcher · Mar 23

View original post
I Mass-Built a Polymarket Trading Bot in 2 Weeks - Here's Every Tool That Powers It cover

Most trading bot tutorials show you the code. None of them show you the 30+ tools behind the code.

I spent 2 weeks building an automated Polymarket trading system. Not a toy. A real bot that scans 50+ markets, estimates probabilities with AI, calculates position sizes, and executes trades on-chain.

This is every tool, API, and library I used - and why.

Save this. You'll need it.

Here's the full breakdown:

Bookmark this before you start

Follow for daily alpha on Polymarket and AI trading

Join in my alpha channel with all bots: lunar alpha moves

The Stack at a Glance

Before we go deep - here's what the full system looks like:

Polymarket API pulls live markets. Claude analyzes them. 4 formulas decide what to trade and how much. The bot places orders on Polygon. A dashboard shows everything in real time.

30+ tools. ~$5/month to run. Let's break it down.

Layer 1 - Data & Market Access

Everything starts with data. If your bot can't read markets fast, nothing else matters.

1. Polymarket CLOB API (https://docs.polymarket.com/trading/overview) The core. Central Limit Order Book API gives you real-time prices, orderbook depth, and market metadata. REST + WebSocket. Free.

2. py-clob-client (https://github.com/Polymarket/py-clob-client) Official Python SDK for Polymarket's CLOB. Handles authentication, signing, order placement. Saved me weeks of writing raw API calls.

3. Polygon RPC - Alchemy (https://www.alchemy.com/polygon) Polymarket runs on Polygon. You need an RPC endpoint to check balances, approve tokens, and interact with smart contracts. Alchemy's free tier handles everything.

4. USDC.e on Polygon (https://polygonscan.com/token/0x2791bca1f2de4661ed88a30c99a7a9449aa84174) The settlement currency. Every trade on Polymarket is denominated in USDC.e. Bridge from Ethereum or buy directly on Polygon.

5. python-dotenv (https://pypi.org/project/python-dotenv/) Stores API keys, private keys, and config outside of code. Basic but critical - one leaked key and your funds are gone.

Layer 2 - The AI Brain

This is where most bots fail. They use hardcoded rules. Mine uses an LLM that actually reads and reasons.

6. Claude API - Anthropic (https://docs.anthropic.com/en/api/getting-started) The brain of the entire system. Claude analyzes each market question, considers base rates, recent news, and historical patterns. Returns a probability estimate + confidence level. I use claude-sonnet for speed and cost efficiency.

7. Structured JSON Prompts Not a tool - a technique. Claude returns {"probability": 0.XX, "confidence": "high/medium/low", "reasoning": "..."}. Strict JSON output means zero parsing errors.

8. httpx (https://www.python-httpx.org) Async HTTP client for Python. Faster than requests, supports connection pooling. When you're hitting Claude API 50+ times per scan cycle, speed matters.

9. Prompt Versioning I keep every prompt iteration in a /prompts folder with dates. v1 was garbage. v7 is what runs now. The difference between a 40% and 75% accuracy rate was 6 prompt rewrites.

Layer 3 - The Math Engine

AI gives you probabilities. Math tells you what to do with them.

10. Expected Value (EV)

If EV < 5% edge - skip. No exceptions. This single filter eliminates 90% of bad trades.

11. Kelly Criterion

Tells you exactly what % of your bankroll to bet. I use Quarter Kelly - aggressive enough to grow, conservative enough to survive.

12. Bayesian Updating

When news drops mid-trade, the bot updates its probability estimate instead of holding a stale opinion. Most traders can't do this. The bot does it in milliseconds.

13. Log Returns

Arithmetic returns lie. Log returns sum correctly. Every P&L calculation in the system uses log returns.

14. NumPy (https://numpy.org) Fast math. Log calculations, array operations, statistical functions. The backbone of every formula above.

Layer 4 - Execution

Knowing what to trade is half the job. Actually executing it on-chain without losing money to slippage and failed orders - that's the other half.

15. GTC Orders (Good Till Cancelled) Learned this the hard way. FOK (Fill or Kill) orders fail constantly on low-liquidity markets. GTC orders sit in the orderbook and wait. Higher fill rate, lower stress.

16. Balance Pre-Check Before every trade, the bot checks on-chain balance via RPC. No more "not enough balance" errors at 3 AM. Sounds obvious. Took me 4 failed trades to implement.

17. Position Tracker - SQLite (https://sqlite.org) Local database tracking every open position: entry price, size, market ID, timestamp. The bot knows exactly what it holds without querying the chain every time.

18. Slippage Protection Max 2% slippage on any order. If the orderbook is too thin - skip. Better to miss a trade than get filled at a terrible price.

19. web3.py (https://web3py.readthedocs.io) For direct blockchain interactions - token approvals, balance checks, contract calls. py-clob-client handles most trading, but some operations need raw web3.

Layer 5 - Monitoring & Alerts

A bot that runs without monitoring is a bot that loses money silently.

20. Telegram Bot - aiogram (https://github.com/aiogram/aiogram) Real-time notifications for every trade. Market scanned? Ping. Edge found? Ping. Order filled? Ping. Error? PING. I manage the entire bot from my phone.

21. Position Dashboard Built-in Telegram command: tap a button, see all open positions with P&L, current prices, and a "close" button for each one. No need to open a laptop.

22. Logging - Python logging (https://docs.python.org/3/library/logging.html) Every decision the bot makes is logged with timestamps. When something goes wrong at 4 AM, the log file is your detective. I use rotating file handlers so logs don't eat disk space.

23. Error Recovery The bot doesn't crash on errors. It catches exceptions, logs them, sends a Telegram alert, and continues scanning. Uptime > perfection.

Layer 6 - Infrastructure

Where does all this actually run?

24. Python 3.11+ (https://www.python.org) The entire bot is Python. Fast enough for this use case. Easy to iterate. Massive ecosystem.

25. asyncio (https://docs.python.org/3/library/asyncio.html) The bot is fully async. Scans markets, calls Claude, checks balances - all concurrently. A synchronous version would take 10x longer per cycle.

26. VPS (any cheap Linux box) I run it on a $5/month VPS. 1 vCPU, 1GB RAM. That's it. The bot uses maybe 100MB of memory.

27. systemd (https://systemd.io) Auto-restart on crash. Auto-start on boot. The bot has been running for weeks without manual intervention.

28. Git (https://git-scm.com) Version control. Every change tracked. Easy rollback when a new feature breaks something. If you're not using Git for your bot - you're gambling with your code too.

Layer 7 - Research & Development

The tools I used to figure out what to build in the first place.

29. Polymarket Leaderboard (https://polymarket.com/leaderboard) Studied the top wallets. What markets they trade, how often, what sizes. Reverse-engineering winners taught me more than any tutorial.

30. Polygonscan (https://polygonscan.com) On-chain explorer. I traced top trader transactions to understand their patterns. When they buy, at what prices, how they size positions.

31. Claude for development (https://claude.ai) I used Claude not just in the bot - but to help build the bot. Debugging code, optimizing prompts, researching market mechanics. The AI writes its own brain.

32. Perplexity (https://www.perplexity.ai) For real-time research during development. "How does Polymarket CLOB API handle partial fills?" - getting accurate, sourced answers saved hours of trial and error.

What I'd Do Differently

After 2 weeks and dozens of bugs, here's what I learned:

Start with paper trading. I jumped into real money too fast. Lost $12 on the first day to a bug that double-ordered. Build a simulation mode first.

Quarter Kelly, not Half Kelly. Half Kelly looks good on paper. In practice, the variance will make you panic-close winning positions. Quarter Kelly lets you sleep.

Don't trust the first Claude response. Early versions of my prompt returned wildly overconfident probabilities. The fix: force Claude to consider the base rate explicitly and penalize extreme confidence.

GTC > FOK. FOK orders get killed on thin orderbooks. GTC orders wait patiently. My fill rate went from 60% to 95% after switching.

Monitor everything. The first version had no alerts. I woke up to find the bot had been stuck on a single market for 6 hours because the API returned an unexpected format. Now everything pings Telegram.

The Numbers

The math is simple. The tools are free or cheap. The hard part is putting them all together and not blowing up your account while learning.

TL;DR

Bookmark this. The tools don't change - but your understanding of how to combine them gets sharper every time.

  • Copytrade my bot on Polymarket with me: https://t.me/KreoPolyBot
  • Profile bot: https://polymarket.com/@googoogaga23
  • Join in my alpha channel with all bots: lunar alpha moves
  • As soon as the article gets more than 10,000 bookmarks, I'll make the bot publicly available on GitHub