- This Python-based OpenClaw skill enables Claude Code to browse, trade, and manage Polymarket prediction market positions on Polygon.
- Trading uses a split + CLOB execution strategy: split USDC.e into YES/NO tokens via the CTF contract, then sell the unwanted side on the CLOB order book.
- LLM-powered hedge discovery finds covering portfolios via contrapositive logic—pairs of market positions that hedge each other.
- The skill tracks positions with entry prices, current prices, and profit/loss calculations.
Run Polygon nodes on Chainstack
You can run global or regional Polygon nodes with Chainstack for fast and reliable RPC access.Start for free and get your app to production levels immediately. No credit card required. You can sign up with your GitHub, X, Google, or Microsoft account.Overview
The skill interacts with Polymarket’s contracts on Polygon mainnet and the CLOB (Central Limit Order Book) API. The core Polymarket contracts are:- USDC.e —
0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174— the bridged USDC used for trading - CTF (Conditional Tokens) —
0x4D97DCd97eC945f40cF65F87097ACe5EA0476045— the conditional token framework that creates outcome tokens - CTF Exchange —
0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E— the exchange contract for splitting and merging positions
- Split — USDC.e is split into YES + NO tokens via the CTF contract
- Sell unwanted — the unwanted side is sold on the CLOB order book
- Result — you hold the wanted position, having recovered partial cost from selling the unwanted side
- Split $100 USDC.e → 100 YES + 100 NO tokens
- Sell 100 NO tokens at ~$0.30 → recover ~$27 USDC.e
- Net cost: ~$73 for 100 YES tokens (entry price: $0.73)
Prerequisites
- Chainstack account with a Polygon node deployed
- Python 3.11+ with uv package manager
- A wallet with USDC.e on Polygon (for trading)
- OpenRouter API key (for hedge discovery)
Dependencies
Install dependencies using uv:Environment setup
Set the required environment variables:Implementation
The skill consists of five core modules:- Markets module — browse and search Polymarket markets
- Wallet module — manage wallet status and contract approvals
- Trading module — execute buy orders via split + CLOB
- Positions module — track positions with P&L calculations
- Hedge module — discover hedging opportunities via LLM analysis
First-time setup
Before trading, set Polymarket contract approvals (one-time, costs ~0.01 POL in gas):Markets module
The markets module fetches data from the Polymarket API:- Default output is a formatted table
- Use
--fullfor full question text without truncation - Use
--jsonfor structured JSON output (useful for agent parsing)
Wallet module
The wallet module manages wallet status and approvals:POLYCLAW_PRIVATE_KEY environment variable, supporting hex format with or without the 0x prefix.
Trading module
The trading module executes buy orders using the split + CLOB strategy:- Fetch market data and validate the position side
- Split USDC.e into YES + NO tokens via CTF contract
- Sell the unwanted tokens on the CLOB order book
- Record the position with entry price
If the CLOB sell fails (due to liquidity or IP blocking), your split still succeeded. You can sell the unwanted tokens manually on polymarket.com or use the
--skip-sell flag to keep both sides.Positions module
The positions module tracks all positions with profit/loss calculations:- Market question and position side (YES/NO)
- Entry price and current price
- Position size and current value
- Profit/loss in USD and percentage
Hedge module
The hedge module uses LLM analysis to find covering portfolios—pairs of market positions that hedge each other via contrapositive logic.- Tier 1 (HIGH): 95%+ coverage — near-arbitrage opportunities
- Tier 2 (GOOD): 90-95% — strong hedges
- Tier 3 (MODERATE): 85-90% — decent but noticeable risk
- Tier 4 (LOW): less than 85% — speculative (filtered by default)
- If “X wins election” implies “Y loses election”, then YES on X + NO on Y forms a covering portfolio
- The contrapositive also holds: NO on X + YES on Y forms another hedge
The hedge scanner uses
nvidia/nemotron-nano-9b-v2:free via OpenRouter by default. Model selection matters—some models find spurious correlations while others have output format issues. Override with --model <model_id> if needed.Example prompts
Once installed, you can use natural language prompts with Claude Code:Browse trending markets
Get market details
Check wallet status
Execute a trade
Discover hedges
Hedge scanning takes a few minutes. The skill fetches open markets and sends pairs to the LLM for logical implication analysis.
Check positions
Full trading flow
- “What’s trending on Polymarket?” — get market IDs
- “Run hedge scan limit 10” — wait for LLM analysis
- Review hedge opportunities with coverage tiers
- “Buy $25 YES on market abc123” — take position on target market
- “Buy $25 NO on market xyz789” — take position on covering market
- “Show my PolyClaw positions” — verify entries and track P&L
Configuration options
| Variable | Required | Description |
|---|---|---|
CHAINSTACK_NODE | Yes (trading) | Polygon RPC URL |
POLYCLAW_PRIVATE_KEY | Yes (trading) | EVM private key (hex, with or without 0x prefix) |
OPENROUTER_API_KEY | Yes (hedge) | OpenRouter API key for LLM hedge discovery |
HTTPS_PROXY | Recommended | Rotating residential proxy for CLOB (e.g., IPRoyal) |
CLOB_MAX_RETRIES | No | Max CLOB retries with IP rotation (default: 5) |
CLOB Cloudflare blocking
Polymarket’s CLOB API uses Cloudflare protection that blocks POST requests from many IPs, including datacenter IPs and some residential ISPs. This affects the “sell unwanted tokens” step. Solution: Residential proxy with retry logic The recommended setup uses a rotating residential proxy (e.g., IPRoyal, BrightData). The CLOB client automatically retries with new IPs until one works:- Use
--skip-sell— keep both YES and NO tokens, sell manually on polymarket.com - No proxy — split still works; only CLOB sell is affected
Troubleshooting
”No wallet available”
Set thePOLYCLAW_PRIVATE_KEY environment variable:
“Insufficient USDC.e”
Check balance withuv run python scripts/polyclaw.py wallet status. You need USDC.e (bridged USDC) on Polygon, not native USDC.
”CLOB order failed”
The CLOB sell may fail due to:- Insufficient liquidity at the sell price
- IP blocked by Cloudflare (try residential proxy)
