polymarket-paper-trader
AGENTS.md431 starsChanged 2 months agoMITView on GitHub
Contribution and PR rules: CONTRIBUTING.md; security reports: SECURITY.md. See CLAUDE.md for the detailed module map of the root pm_trader package. Paper-trading simulator for Polymarket, built for AI agents (Python 3.10+, SQLite, Click CLI, MCP SDK 2.x). Public repo, actively maintained; the product ships to PyPI/ClawHub/MCP. Four independent packages: the root polymarket-paper-trader (pm_trader/), benchmark/ (pm_benchmark/), leaderboard-client/ (pm_leaderboard_client/), and leaderboard-server/ (server/, depends on the root package and the client). Work on one package at a time; each has its own tests and…
- Reads credentials
- Installs packages
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository3 other files it gives its agents.
- benchmark/CLAUDE.mdCLAUDE.md
- CLAUDE.mdCLAUDE.md
- polymarket-paper-traderSkill
The file
We split this AGENTS.md into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 15
Read first: CLAUDE.md (architecture, conventions, testing rules), pyproject.toml.
- Distinctive: line 41
All trading is paper/simulated, but price and order-book reads are real public API calls.
- Distinctive: line 49
Prefer the existing helpers and JSON envelope conventions over new patterns.
- Distinctive: line 107
When a documented example and the wire disagree, probe the real endpoint first and record the outcome in the CHANGELOG entry — several of …
- Distinctive: line 123
Verify the tag live on PyPI and ClawHub before announcing.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
polymarket-paper-trader — agent guide
Contribution and PR rules: CONTRIBUTING.md; security reports: SECURITY.md.
See CLAUDE.md for the detailed module map of the root pm_trader package.
Purpose
Paper-trading simulator for Polymarket, built for AI agents (Python 3.10+, SQLite, Click CLI, MCP SDK 2.x). Public repo, actively maintained; the product ships to PyPI/ClawHub/MCP.
Orient
git status --short,git branch --show-current,git worktree list,gh pr list --state open.- Read first: CLAUDE.md (architecture, conventions, testing rules),
pyproject.toml.
Layout
Four independent packages: the root polymarket-paper-trader (pm_trader/), benchmark/
(pm_benchmark/), leaderboard-client/ (pm_leaderboard_client/), and leaderboard-server/
(server/, depends on the root package and the client). Work on one package at a time; each
has its own tests and 100% coverage gate.
Setup
make setup creates .venv and installs all four packages editable with dev extras:
pip install -e ".[dev]" -e "benchmark[dev]" -e "leaderboard-client[dev]" -e "leaderboard-server[dev]".
Requires Python 3.10+ and pip.
Check
make check runs, per package, the coverage gate CI enforces on Python 3.13
(.github/workflows/test.yml + toolkit.yml): pytest tests/ -x -q -m "not live" with
--cov-fail-under=100. CI additionally runs the suites on Python 3.10-3.12.
Narrow variant: run the same pytest command inside the one package directory you touched.
Boundaries
live-marked tests hit the real Polymarket Gamma/CLOB APIs.make checkexcludes them; run them only deliberately (tests/test_e2e_live.py -m live), never as part of the gate.- All trading is paper/simulated, but price and order-book reads are real public API calls.
- Public repo: never commit secrets, tokens, or
.envfiles; no private endpoints or links.
Done
- Branch per change -> PR; keep changes atomic: one logical change per commit.
- New code ships with tests in the same change, with a real oracle; 100% coverage is required.
make checkgreen locally; CI green before merge; receipts (commands + output) in PR body.- Prefer the existing helpers and JSON envelope conventions over new patterns.
Project state (2026-09-25)
Current release: v0.4.5 (PyPI + ClawHub + GitHub Releases, all latest). The client is
aligned with the current official API surface (Gamma keyset pagination, CLOB market data,
Data API v2 price history) and the fee simulation follows the official per-match curve.
Live e2e tests run weekly on CI (live.yml) and include bias assertions: simulated fills
must land inside the band the market actually quoted, and fees must equal the official
curve — the simulator's fidelity is tested, not assumed.
Recent history (details in CHANGELOG.md): v0.3.0 official fee curve ·
v0.3.1 tradability gates + partial-fill lifecycle · v0.3.2 cash reservation + per-level
fees · v0.3.3 keyset pagination · v0.3.4 Data API v2 get_price_history + bias tests
(closes #16) · README purpose-first rewrite · v0.4.0 MCP SDK 2.x (serialized tool calls,
real serverInfo.version) + pm-trader strategy + doc-drift guards · v0.4.1 agent-runtime
integrations (Claude Code plugin, Gemini CLI extension, docs/integrations.md), MCP carries
the skill (trading_playbook prompt/resource), streamable-HTTP transport (no
backtest/pk_battle over HTTP), Dockerfile, Jev strategy, outsider install gate ·
v0.4.2 fee-basis and cost-basis fixes, account-path and backtest hardening, MCP error
envelopes, leaderboard /ready · v0.4.3 audit fixes: atomic trade and resolution writes,
limit-order validation, GTD UTC expiry, leaderboard-server order identity and upstream errors ·
v0.4.4 UMA-status resolution, atomic limit fills, uncapped analytics, backtest mark-to-market,
atomic leaderboard trades, honest-red arena CI · v0.4.5 resolved-only benchmark alpha, arena
min-n ranking, resolution-aware analytics, shared-db cash safety, hashed leaderboard API keys.
Verified upstream contract facts (live-probed; the docs disagree)
Trust the wire, not the docs examples — every item below was established by probing the live API after the documented example failed:
GET /midpoint(CLOB) returns{"mid": "<string>"}— the docs schema saysmid_price. Parsemid, coerce withfloat().GET /markets/keyset(Gamma) rejects the docs' snake_caseorderexamples (volume_num) with 422; the wire accepts camelCasevolumeNum/liquidityNum.- Gamma
/marketsignorestag_slug— resolve slugs to ids via/tags/slug/{slug}. Gamma also defaultsclosed=false, so closed markets need aclosed=trueretry. - Gamma sends booleans as strings (
"false");bool("false")isTrue. Use the string-aware_to_boolin parsers. GET /clob-markets/{condition_id}(CLOB) returns abbreviated keys:c(condition),t(tokens, each{t, o}),mos,mts,mbf,tbf,fd(fee schedule{r, e, to}); newer additive keys (gst,r,rfqe,itode,ibce,oas) are ignored.GET /v2/prices-history(Data API v2) acceptstoken_id/tokenId,start,end,interval(1m|1h|6h|1d|1w|max|all),bucket_seconds/bucketSeconds,as_of/asOf,limit,cursor. Envelope{data: [...], pagination: {limit, offset, has_more, next_cursor}}; a documented miss isdata: null; points are oldest-first. The v1fidelityparameter does not exist on v2. The cursor's page size wins over alimitsent alongside it.- Resolution (Gamma): there is no explicit winner field (
winningOutcomeetc. do not exist). A settled market hasclosed: true,umaResolutionStatus: "resolved"andoutcomePricesof exactly"0"/"1"; before settlement the status is e.g."proposed", so a closing price alone is not a resolution. - Fees:
fee = C × feeRate × p × (1-p)per match, rounded to 5 decimals (minimum charge 0.00001), taker-only — makers are never charged. Rates come from each market'sfeeScheduleon the wire (never hardcode category rates); zero-fee categories (e.g. geopolitics) carryfeesEnabled: falseand nofeeScheduleat all.
When a documented example and the wire disagree, probe the real endpoint first and record the outcome in the CHANGELOG entry — several of the facts above exist precisely because a docs example was wrong.
Conventions and pitfalls
- Version pins live in
pyproject.toml,server.json(two places),.claude-plugin/plugin.json,gemini-extension.json, and BOTHskill/polymarket-paper-trader/SKILL.mdcopies (they must be identical —test_metaenforces it, and the changelog heading must match the installed version; reinstall withpip install -e . --no-depsafter a bump so dist-info catches up). - Release policy: patch releases are routine; any minor/major bump is an owner decision.
Releases: bump pins → promote
[Unreleased]in the CHANGELOG → PR → green CI → tagvX.Y.Zon the merged main commit →publish.yml(tests → tag/version match + outsider smoke on the built wheel → PyPI → ClawHub, GitHub Release, andverify-pypire-running the smoke against the published package).make outsiderruns the same smoke locally. Verify the tag live on PyPI and ClawHub before announcing. - The benchmark harness is a separate install (
polymarket-benchmark);pm-trader benchmark runreplays trading strategies and only imports modules from theexamples.andtests.test_benchmark.prefixes (allowlist inpm_trader/benchmark.py). pm-trader benchmark(strategy replay) andpolymarket-benchmark run(model eval) are different things — keep the distinction in docs and code.- Tests that hit the live APIs are marked
liveand skip cleanly without network; the full live suite is CI-only (live.yml), not part of the default run.
Open items (product backlog, uncontroversial starts)
- Expose the eval harness through
pm-trader(subcommand or pip extra) instead of a separate editable install.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

