{"id":50850162,"url":"https://github.com/pallaoro/polymarket-ai-trading","last_synced_at":"2026-06-14T13:07:13.948Z","repository":{"id":363329840,"uuid":"1262854201","full_name":"pallaoro/polymarket-ai-trading","owner":"pallaoro","description":"Open-source AI trading bot for Polymarket prediction markets. Paper-trade live markets with mean-reversion signals, LLM gating, and Kelly sizing — React + Hono + Cloudflare D1. One-click deploy.","archived":false,"fork":false,"pushed_at":"2026-06-08T11:44:27.000Z","size":65,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-08T13:25:27.677Z","etag":null,"topics":["ai-trading","algorithmic-trading","clob","cloudflare-workers","hono","kelly-criterion","mean-reversion","openrouter","paper-trading","polymarket","prediction-markets","quant","react","self-hosted","trading-bot"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pallaoro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-08T11:39:41.000Z","updated_at":"2026-06-08T11:44:31.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/pallaoro/polymarket-ai-trading","commit_stats":null,"previous_names":["pallaoro/polymarket-ai-trading"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/pallaoro/polymarket-ai-trading","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pallaoro%2Fpolymarket-ai-trading","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pallaoro%2Fpolymarket-ai-trading/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pallaoro%2Fpolymarket-ai-trading/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pallaoro%2Fpolymarket-ai-trading/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pallaoro","download_url":"https://codeload.github.com/pallaoro/polymarket-ai-trading/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pallaoro%2Fpolymarket-ai-trading/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34322314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-14T02:00:07.365Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-trading","algorithmic-trading","clob","cloudflare-workers","hono","kelly-criterion","mean-reversion","openrouter","paper-trading","polymarket","prediction-markets","quant","react","self-hosted","trading-bot"],"created_at":"2026-06-14T13:07:11.068Z","updated_at":"2026-06-14T13:07:13.944Z","avatar_url":"https://github.com/pallaoro.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Polymarket AI Trader — Open-Source Prediction-Market Trading Bot\n\n[![Deploy with Clawnify](https://app.clawnify.com/deploy-button.svg)](https://app.clawnify.com/deploy?repo=pallaoro/polymarket-ai-trading)\n\nAn **open-source, self-hostable AI trading bot for [Polymarket](https://polymarket.com)** prediction markets. It pulls live markets from Polymarket's public **Gamma API**, scores market quality, generates **mean-reversion** signals (longshot-bias and favorite-fade), gates each idea through an LLM \"risk desk,\" sizes positions with the **Kelly criterion**, and tracks a full **paper-trading** P\u0026L ledger — built on **React + Hono + Cloudflare Workers + D1** and deployable in one click via [Clawnify](https://clawnify.com).\n\n\u003cimg width=\"1458\" height=\"938\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/5830bbef-a878-4851-99ec-d9b8889a5858\" /\u003e\n\n\u003e **Paper-trading by default — no wallet key, no real money, nothing to drain.** Most \"Polymarket trading bot\" repos ask you to paste a funded wallet private key into unaudited code. This one doesn't: it simulates against live prices, and live CLOB execution stays disabled behind an explicit, auditable seam. Trade the strategy, not your savings.\n\nUse it as a research desk for **algorithmic prediction-market trading**, a quant sandbox for **mean reversion and Kelly sizing**, or a starting point for your own Polymarket strategy.\n\n## Start here — pick your path\n\n| If you want to… | Do this |\n|---|---|\n| **Deploy a hosted version in one click** | Click **[Deploy with Clawnify](https://app.clawnify.com/deploy?repo=pallaoro/polymarket-ai-trading)** — your AI employee provisions it, wires the API keys, and gives you a live dashboard. No server, no Docker. |\n| **Run it locally** | `pnpm install \u0026\u0026 pnpm dev` → dashboard on `localhost:5173`. See [Local development](#local-development). |\n| **Understand the strategy** | Read [How it works](#how-it-works) — quality scoring, signals, AI gating, Kelly sizing. |\n| **Take it live (advanced)** | Read [Going live](#going-live-the-execution-seam) before flipping anything. Live trading is intentionally stubbed. |\n\n## Features\n\n- **Live Polymarket markets** — pulled from the public **Gamma API** (`gamma-api.polymarket.com`); no API key, no wallet, read-only.\n- **Market quality scoring (0–100, A–F)** — ranks markets by liquidity, spread tightness, 24h activity, and clarity, so the bot only trades deep, unambiguous markets.\n- **Mean-reversion signals** — two well-documented prediction-market edges: cheap-**longshot** value buys and **favorite-fade** (buy the underpriced NO on rich favorites). Thresholds fully configurable.\n- **AI gating** — a skeptical LLM \"risk desk\" approves or rejects every signal with a calibrated confidence, via **OpenRouter** (use any model: Claude, GPT, Gemini, Llama).\n- **Fractional-Kelly position sizing** — optimal-growth sizing scaled down for noisy edges, with hard per-position and total-exposure caps.\n- **Paper-trading ledger** — open positions, mark-to-market, automatic settlement on resolution, realized/unrealized P\u0026L, and win rate, persisted in **D1 (SQLite)**.\n- **One-click AI market analysis** — ask the model for fair value and a recommendation on any market.\n- **Agent-ready** — every action is an API route the Clawnify perimeter exposes to your AI employee, so an agent can run cycles, mark to market, and report P\u0026L on a schedule.\n\n## How it works\n\n```\nPolymarket Gamma API (live markets)\n        │\n        ▼\n Quality scoring  ──►  only A/B markets (deep, tight, active, clear)\n        │\n        ▼\n Mean-reversion signals  ──►  longshot YES  ·  favorite-fade NO\n        │\n        ▼\n AI risk-desk gate (OpenRouter)  ──►  take? + calibrated confidence\n        │\n        ▼\n Fractional-Kelly sizing  ──►  caps: per-position · total exposure · kill switch\n        │\n        ▼\n Executor (paper | live)  ──►  fill recorded in the D1 ledger\n        │\n        ▼\n Mark-to-market + settle on resolution  ──►  realized / unrealized P\u0026L\n```\n\nThe strategy concepts — favorite-longshot bias, mean reversion, Kelly sizing, market-quality filtering — come from decades of prediction-market and sports-betting research. The point isn't a guaranteed edge (there isn't one); it's a clean, legible framework you can study, tune, and extend.\n\n## Stack\n\n**React + Vite + Tailwind CSS** dashboard · **Hono** API on **Cloudflare Workers** · **D1 (SQLite)** ledger via `@clawnify/db` · **OpenRouter** for AI · public **Polymarket Gamma API** for data. Deploys to Workers for Platforms through [Clawnify](https://clawnify.com); no separate database, queue, or VM to run.\n\n## Configuration\n\nSecrets are injected by the Clawnify platform (added via the dashboard or CLI — **never** in `clawnify.json` or source).\n\n| Env | Required | Purpose |\n|---|---|---|\n| `OPENROUTER_API_KEY` | for AI features | LLM gating + market analysis; the quant strategy runs without it |\n| `POLYMARKET_MODEL` | optional | OpenRouter model id (default `anthropic/claude-sonnet-4`) |\n| `RELAYER_API_KEY` | yes | Polymarket relayer key for (future) live execution |\n| `RELAYER_API_KEY_ADDRESS` | yes | Wallet address paired with the relayer key |\n\nStrategy parameters — bankroll, Kelly fraction, position/exposure caps, signal thresholds, AI gating, kill switch — live in the in-app **Strategy** panel and persist to D1.\n\n## API\n\nAll routes sit behind the Clawnify perimeter (your dashboard and your AI employee reach them with injected identity).\n\n| Method | Path | Does |\n|---|---|---|\n| `GET` | `/api/markets?limit=` | live, quality-scored markets |\n| `GET` | `/api/signals` | current mean-reversion signals |\n| `GET` | `/api/stats` · `/api/positions` · `/api/trades` | portfolio + ledger |\n| `GET` · `PUT` | `/api/settings` | strategy configuration |\n| `POST` | `/api/cycle` | run one paper-trading cycle |\n| `POST` | `/api/mark` | mark open positions to market + settle resolved |\n| `POST` | `/api/positions/:id/close` | manually close a position |\n| `POST` | `/api/analyze` | AI fair-value analysis of a market |\n| `POST` | `/api/reset` | wipe the paper ledger |\n\n## Going live (the execution seam)\n\nEverything runs in **paper** mode. All execution flows through a single `Executor` interface (`src/server/lib/executor.ts`):\n\n- `PaperExecutor` fills instantly at the quoted price — no money moves.\n- `LiveExecutor` is a **guarded stub**. It refuses to run without `RELAYER_API_KEY` + `RELAYER_API_KEY_ADDRESS` and explicit live mode, and throws until the Polymarket CLOB relayer integration is implemented **and audited**. Switching a deployment to real trading is a change in one file — not a rewrite of the strategy — and is left as a deliberate, reviewable step.\n\n**This is not financial advice.** Prediction-market trading is risky; you can lose money. Paper-trade first, understand the strategy, and never run any trading bot against a wallet you can't afford to lose.\n\n## Local development\n\n```bash\npnpm install\npnpm dev          # applies schema.sql to a local D1, runs Vite + Wrangler\n```\n\nVite serves the dashboard on `:5173` and proxies `/api` to Wrangler on `:8787`. For AI features locally, add `OPENROUTER_API_KEY` to a gitignored `.dev.vars`. Requires **Node ≥ 22**.\n\n---\n\n*Open-source Polymarket trading bot · AI prediction-market trading · paper trading · mean reversion · Kelly criterion · quant research. For research and simulation — not financial advice.*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpallaoro%2Fpolymarket-ai-trading","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpallaoro%2Fpolymarket-ai-trading","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpallaoro%2Fpolymarket-ai-trading/lists"}