Polymarket 量化交易自动化套件
简介
Polymarket交易自动化工具集,支持预测市场浏览、分仓交易执行、AI对冲发现及自动化风控(止盈/自动赎回),适合量化交易者与套利者,私钥环境变量存储存在安全风险。
原始描述
Trade on Polymarket via split + CLOB execution. Browse markets, track positions with P&L, discover hedges via LLM. Includes automation tools: live portfolio...
通过你的 Agent 添加
安装目录:polyclaw-pro/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
核心用法
PolyClaw 是一套面向 Polymarket 预测市场的全功能交易工具,基于 OpenClaw 框架开发。用户可通过 CLI 完成市场浏览、钱包管理、交易执行、持仓追踪等操作。核心交易流程采用"拆分+订单簿"机制:将 USDC.e 拆分为 YES/NO 代币对,保留目标方向持仓,通过 CLOB 卖出非目标方向代币以降低成本。技能还集成了 LLM 驱动的对冲发现功能,利用逻辑蕴含关系识别可相互对冲的市场组合。
自动化模块包含四项工具:实时持仓追踪(基于 Data API)、自动赎回(检测已结算市场并执行赎回)、纪律扫描器(20%止盈自动卖出)以及增强 API(为外部集成提供 JSON 接口)。
显著优点
功能完整度高是最大亮点,覆盖了预测市场交易的完整生命周期。对冲发现功能颇具创新性,通过 LLM 分析市场间的逻辑关系寻找覆盖组合,为用户提供结构化风险管理思路。自动化工具设计实用,特别是自动赎回和止盈扫描器,能减少手动操作负担。CLI 设计清晰,支持表格、JSON 等多种输出格式,便于脚本集成。技能明确披露了 CLOB Cloudflare 屏蔽问题,并提供代理+重试的解决方案,体现了对实际运营问题的认知。
潜在缺点与局限性
安全架构存在根本缺陷:私钥以明文环境变量存储,无加密或密钥管理服务集成,且多处硬编码钱包地址,灵活性受限。CLOB 交易依赖代理绕过 IP 封锁,增加了运营复杂度和成本。自动化交易功能缺乏足够的安全护栏,无交易限额、确认延迟或模拟模式,误配置可能导致资金损失。LLM 对冲发现依赖特定模型(Nemotron Nano),模型选择不当会产生虚假关联,功能可靠性存疑。代码中 subprocess 调用和硬编码路径反映出工程成熟度不足。
适合的目标群体
主要面向熟悉 DeFi 和预测市场的进阶用户,尤其是需要批量管理 Polymarket 持仓的交易者。自动化功能适合有明确策略纪律、能接受代码审计的技术型投资者。不适合加密货币新手或无法自行评估智能合约风险的用户。企业级或大额资金管理场景应谨慎考虑,当前安全架构不足以支撑高价值操作。
使用风险
资金安全层面:私钥环境变量存储存在泄露风险,建议仅用独立小额钱包。自动化交易模块可能因配置错误或市场异常导致非预期卖出。运营层面:CLOB 流动性不足或代理失效时交易可能失败,虽拆分操作不受影响,但资金效率会降低。外部 API 依赖(Polymarket、OpenRouter、Chainstack)任一节点的服务中断或策略变更都会影响功能。合规层面:预测市场监管存在不确定性,部分司法辖区可能限制相关活动。技术层面:T3 来源的个人开发者维护,长期更新和安全响应能力未经验证。
技能正文
name: polyclaw description: "Trade on Polymarket via split + CLOB execution. Browse markets, track positions with P&L, discover hedges via LLM. Includes automation tools: live portfolio tracking, auto-redeem, discipline scanner, and API bridge. Polygon/Web3." metadata: {"openclaw":{"emoji":"🦞","homepage":"https://polymarket.com","primaryEnv":"POLYCLAW_PRIVATE_KEY","requires":{"bins":["uv"],"env":["CHAINSTACK_NODE","POLYCLAW_PRIVATE_KEY"]},"install":[{"id":"uv-brew","kind":"brew","formula":"uv","bins":["uv"],"label":"Install uv (brew)"}]},"clawdbot":{"emoji":"🦞","homepage":"https://polymarket.com","primaryEnv":"POLYCLAW_PRIVATE_KEY","requires":{"bins":["uv"],"env":["CHAINSTACK_NODE","POLYCLAW_PRIVATE_KEY"]},"install":[{"id":"uv-brew","kind":"brew","formula":"uv","bins":["uv"],"label":"Install uv (brew)"}]}}
PolyClaw
Trading-enabled Polymarket skill for OpenClaw. Browse markets, manage wallets, execute trades, and track positions.
Features
- Market Browsing - Search and browse Polymarket prediction markets
- Wallet Management - Env-var based wallet configuration
- Trading - Buy YES/NO positions via split + CLOB execution
- Position Tracking - Track entry prices, current prices, and P&L
- Hedge Discovery - LLM-powered covering portfolio discovery via logical implications
Quick Start
First, install dependencies (from skill directory):
cd {baseDir}
uv sync
First-Time Setup (Required for Trading)
Before your first trade, set Polymarket contract approvals (one-time, costs ~0.01 POL in gas):
uv run python scripts/polyclaw.py wallet approve
This submits 6 approval transactions to Polygon. You only need to do this once per wallet.
Browse Markets
# Trending markets by volume
uv run python scripts/polyclaw.py markets trending
# Search markets
uv run python scripts/polyclaw.py markets search "election"
# Market details (returns full JSON with all fields)
uv run python scripts/polyclaw.py market <market_id>
Output options:
- Default output is a formatted table (good for display)
- Use
--fullflag for full question text without truncation - Use
--jsonflag viascripts/markets.py --json trendingfor structured JSON output
Wallet Management
# Check wallet status (address, balances)
uv run python scripts/polyclaw.py wallet status
# Set contract approvals (one-time)
uv run python scripts/polyclaw.py wallet approve
The wallet is configured via the POLYCLAW_PRIVATE_KEY environment variable.
Trading
# Buy YES position for $50
uv run python scripts/polyclaw.py buy <market_id> YES 50
# Buy NO position for $25
uv run python scripts/polyclaw.py buy <market_id> NO 25
Positions
# List all positions with P&L
uv run python scripts/polyclaw.py positions
Hedge Discovery
Find covering portfolios - pairs of market positions that hedge each other via contrapositive logic.
# Scan trending markets for hedges
uv run python scripts/polyclaw.py hedge scan
# Scan markets matching a query
uv run python scripts/polyclaw.py hedge scan --query "election"
# Analyze specific markets for hedging relationship
uv run python scripts/polyclaw.py hedge analyze <market_id_1> <market_id_2>
Output options:
- Default output is a formatted table showing Tier, Coverage, Cost, Target, and Cover
- Use
--jsonflag for structured JSON output - Use
--min-coverage 0.90to filter by minimum coverage (default 0.85) - Use
--tier 1to filter by tier (1=best, default 2)
Coverage tiers:
- 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): <85% - speculative (filtered by default)
LLM model: Uses nvidia/nemotron-nano-9b-v2:free via OpenRouter. Model selection matters — some models find spurious correlations while others (like DeepSeek R1) have output format issues. Override with --model <model_id> if needed.
Automation Tools
Portfolio Live Tracking
Real-time position tracking via Polymarket Data API. Groups positions by (slug, outcome) and displays YES/NO side, current value, and P&L with cost basis from portfolio.json.
uv run python portfolio_live.py
- Fetches live on-chain positions from
data-api.polymarket.com - Shows outcome side (YES/NO), current price, and unrealized P&L
- No web3 dependency — uses REST API only
Auto Redeem
Automatically detects and redeems settled (resolved) markets. Checks payoutDenominator on-chain via the CTF contract. When a market resolves, submits a redeemPositions transaction through the NegRiskAdapter.
# Manual run
cd {baseDir} && source .env && .venv/bin/python3 auto_redeem_check.py
# Cron (every 15 minutes)
*/15 * * * * cd /path/to/polyclaw && source .env && .venv/bin/python3 auto_redeem_check.py >> /var/log/polyclaw-redeem.log 2>&1
- Requires
web3(use.venv/bin/python3, not system python) - Tracks redeemed positions in
redeem_state.jsonto avoid duplicates - Needs
CHAINSTACK_NODEandPOLYCLAW_PRIVATE_KEYenv vars
Discipline Scanner
Automated take-profit scanner. Sells positions that are up 20%+ with slippage protection. Configurable via cfo_params.json (DISCIPLINE_TP_PCT key).
# Manual run
cd {baseDir} && export $(grep -v "^#" .env | xargs) && .venv/bin/python3 discipline_scanner.py
# Cron (every 30 minutes)
*/30 * * * * cd /path/to/polyclaw && export $(grep -v "^#" .env | xargs) && .venv/bin/python3 discipline_scanner.py >> /var/log/polyclaw-discipline.log 2>&1
- Skips positions worth less than $1
- Take-profit threshold defaults to 20% (configurable)
Enhanced API (polyclaw_api.py)
CLI bridge for external integrations (e.g., Wells TG Bot via SSH). Provides structured JSON output for programmatic use.
python3 polyclaw_api.py portfolio # All open positions with live prices (JSON)
python3 polyclaw_api.py summary # Text summary of portfolio
python3 polyclaw_api.py balance # CLOB + on-chain wallet balance
python3 polyclaw_api.py risk # Current risk rules
python3 polyclaw_api.py risk_check <usd> <slug> <channel> # Pre-trade risk check
python3 polyclaw_api.py swap auto # Swap all non-USDC.e to USDC.e
python3 polyclaw_api.py swap status # Show token balances
portfoliois the recommended command for live position data (reads Data API, not local DB)balancerequiresweb3— use.venv/bin/python3summaryreads local DB and can be stale — preferportfoliofor accuracy
Security
For the MVP, the private key is stored in an environment variable for simplicity and Claude Code compatibility.
Security Warning: Keep only small amounts in this wallet. Withdraw regularly to a secure wallet.
Environment Variables
| Variable | Required | Description |
|---|---|---|
CHAINSTACK_NODE |
Yes (trading) | Polygon RPC URL |
OPENROUTER_API_KEY |
Yes (hedge) | OpenRouter API key for LLM hedge discovery |
POLYCLAW_PRIVATE_KEY |
Yes (trading) | EVM private key (hex, with or without 0x prefix) |
HTTPS_PROXY |
Recommended | Rotating residential proxy for CLOB (e.g., IPRoyal) |
CLOB_MAX_RETRIES |
No | Max CLOB retries with IP rotation (default: 5) |
Security Warning: Keep only small amounts in this wallet. Withdraw regularly to a secure wallet. The private key in an env var is convenient for automation but less secure than encrypted storage.
Trading Flow
- Split Position - USDC.e is split into YES + NO tokens via CTF contract
- Sell Unwanted - The unwanted side is sold via CLOB order book
- Result - You hold the wanted position, recovered partial cost from selling unwanted
Example: Buy YES at $0.70
- 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: $0.73)
Polymarket Contracts (Polygon Mainnet)
- USDC.e:
0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 - CTF (Conditional Tokens):
0x4D97DCd97eC945f40cF65F87097ACe5EA0476045 - CTF Exchange:
0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E
Dependencies
Install with uv (from skill directory):
cd {baseDir}
uv sync
Limitations
- Trading requires wallet approval setup (one-time)
- CLOB sells may fail if liquidity is insufficient
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:
export HTTPS_PROXY="http://user:pass@geo.iproyal.com:12321"
export CLOB_MAX_RETRIES=10 # Default is 5
With this setup, CLOB orders typically succeed within 5-10 retries as the proxy rotates through IPs until finding an unblocked one.
Alternative workarounds:
- Use
--skip-sell— Keep both YES and NO tokens, sell manually on polymarket.com - No proxy — Split still works; only CLOB sell is affected
If CLOB fails after all retries, your split still succeeded. The output tells you how many tokens to sell manually.
Troubleshooting
"No wallet available"
Set the POLYCLAW_PRIVATE_KEY environment variable:
export POLYCLAW_PRIVATE_KEY="0x..."
"Insufficient USDC.e"
Check balance with uv run python scripts/polyclaw.py wallet status. You need USDC.e (bridged USDC) on Polygon.
"CLOB order failed"
The CLOB sell may fail due to:
- Insufficient liquidity at the sell price
- IP blocked by Cloudflare (try proxy)
Your split still succeeded - you have the tokens, just couldn't sell unwanted side.
"Approvals not set"
First trade requires contract approvals. Run:
uv run python scripts/polyclaw.py wallet approve
License
MIT
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。