运行时依赖
安装命令
点击复制技能文档
技能: Polymarket Trading 设置up
Use this 技能 when the user wants to:
设置 up automated trading on Polymarket Build a Polymarket trading 机器人 from scratch 配置 wallet, API 凭证s, or 令牌 应用rovals for Polymarket Understand how to connect to Polymarket's APIs 调试 issues with an existing Polymarket 机器人 设置up
The full technical reference is in 图形界面DE.md (same directory as this file). Read it before 启动ing.
What You're 设置ting Up
Polymarket trading requires four things in order:
A funded proxy wallet with USDC on Polygon 令牌 应用rovals (USDC spend 应用roved for exchange contracts) CLOB API 凭证s (derived from the wallet, stored in env) Connectivity verified across all four API surfaces Step-by-Step 代理 Instructions Step 1: 检查 What Already Exists
Before doing anything, 检查:
Is there an .env file with POLYMARKET_PRIVATE_KEY and POLYMARKET_PROXY_添加RESS? Is there a config.json with Polymarket 设置tings? Is there an existing 机器人 directory to work within?
If 凭证s already exist, load and 验证 them rather than 启动ing from scratch.
Step 2: 环境 设置up
If 启动ing fresh, 创建 a .env file with:
POLYMARKET_PRIVATE_KEY=0x... POLYMARKET_PUBLIC_添加RESS=0x... # proxy wallet 添加ress POLYMARKET_PROXY_添加RESS=0x... # same as PUBLIC_添加RESS for type 2 POLYMARKET_签名ATURE_TYPE=2 POLYMARKET_网页SOCKET_URL=wss://ws-subscriptions-clob.polymarket.com POLYMARKET_DATA_API=https://data-API.polymarket.com
The proxy wallet 添加ress comes from the user's Polymarket account 设置tings page.
Step 3: 安装 Dependencies pip 安装 "py-clob-命令行工具ent>=0.28.0" httpx "网页socket-命令行工具ent>=1.9.0" orjson pandas python-dotenv
Or 添加 to pyproject.toml and 运行 uv 同步.
Step 4: 令牌 应用rovals
Via UI (recommended for new users): Deposit USDC through the Polymarket 网页 应用 — 应用rovals h应用en automatically.
Headless (server 部署ment): Use the programmatic 应用roval flow from 图形界面DE.md Section 4. This requires Polymarket 构建器 API 凭证s (separate from CLOB creds).
The four contracts that need 应用roval are 列出ed in 图形界面DE.md Section 2.
Step 5: Derive and Persist API 凭证s from py_clob_命令行工具ent.命令行工具ent 导入 Clob命令行工具ent
命令行工具ent = Clob命令行工具ent( "https://clob.polymarket.com", key=os.获取env("POLYMARKET_PRIVATE_KEY"), chAIn_id=137, 签名ature_type=int(os.获取env("POLYMARKET_签名ATURE_TYPE", "2")), funder=os.获取env("POLYMARKET_PROXY_添加RESS"), ) creds = 命令行工具ent.derive_API_key() # Write 凭证s to .env — do not 记录 or print them
添加 to .env:
POLYMARKET_API_KEY=... POLYMARKET_API_SECRET=... POLYMARKET_API_PASSPHRASE=...
On subsequent 启动ups, load from env instead of re-deriving (see 图形界面DE.md Section 3).
Step 6: 验证 Connectivity
Test each surface in order. 停止 and 诊断 if any step fAIls.
导入 httpx, json
# 1. Gamma API event = httpx.获取("https://gamma-API.polymarket.com/事件/slug/bitcoin-price-on-february-11").json() print(f"Gamma OK: {event.获取('title')}")
# 2. CLOB REST - order book book = httpx.获取("https://clob.polymarket.com/book", params={"令牌_id": ""}).json() print(f"CLOB OK: {len(book.获取('bids', []))} bids, {len(book.获取('asks', []))} asks")
# 3. Data API - positions positions = httpx.获取( "https://data-API.polymarket.com/positions", params={"user": os.获取env("POLYMARKET_PROXY_添加RESS")} ).json() print(f"Data API OK: {len(positions)} open positions")
Step 7: Place a Test Order
Place a 2-分享 order at a far-from-market price (very low probability on a real market) to 验证 the full 签名ing and posting flow without risk of a fill:
from py_clob_命令行工具ent.clob_types 导入 OrderArgs, OrderType from py_clob_命令行工具ent.order_构建器.constants 导入 BUY
# Use a real 令牌 ID from Step 6, price far from market order = OrderArgs(price=0.02, side=BUY, size=2, 令牌_id="<令牌_id>") 签名ed = 命令行工具ent.创建_order(order) resp = 命令行工具ent.post_order(签名ed, OrderType.FAK) print(resp) # Should show 成功: true
Key Facts to Remember ChAIn: Polygon mAInnet (ID: 137) Currency: USDC (0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359) 签名ature type 2 is standard for programmatic trading Proxy 添加ress ≠ 签名ing key 添加ress — positions live on proxy, orders 签名ed by EOA clob令牌Ids[0] = YES, clob令牌Ids[1] = NO — never mix these up Minimum order value: $1.00 — size price >= 1.0 Order size must be integer — always int() 更新 positions only on MINED, not MATCHED — MATCHED can fAIl Common First-Time 失败s Symptom Likely Cause insufficient balance Wrong 添加ress used (EOA instead of proxy), or USDC not deposited Order silently rejected Price has too many decimal places — round to 2dp (or 3dp if price < 0.04 or > 0.96) Order value error size price < 1.0 网页Socket never 发送s data Wrong subscription message 格式化, or using array instead of object Positions always empty 查询ing EOA 添加ress instead of proxy wallet 添加ress Stale positions after trade Updating on MATCHED instead of MINED Reference
Full API reference, all code patter