特色栏目

ASP源码

PHP源码

.NET源码

JSP源码

游戏频道
专题合集
关闭菜单
首页> AI教程> Polymarket 交易配置:自动化机器人设置 - Openclaw Skills

Polymarket 交易配置:自动化机器人设置 - Openclaw Skills

时间:2026-03-26 19:06:01 作者:互联网

什么是 Polymarket 交易配置?

Polymarket 交易配置是一个专门的技能,旨在简化为全球最大的预测市场构建和配置自动化交易机器人的复杂过程。它为开发者提供了一条结构化路径,用于集成 Polygon 网络、处理 USDC 代币授权以及与中央限价订单簿 (CLOB) API 进行身份验证。通过在 Openclaw Skills 生态系统中使用该技能,开发者可以快速从手动投柱转向高可靠性的程序化执行。

该技能专注于去中心化身份与中心化订单执行之间的关键桥梁。它确保代理浅包与签名密钥正确映射,API 凭据是安全派生而非硬编码,并且四个主要的 API 接口——Gamma、CLOB REST、Data 和 WebSockets——能够完美同步以进行实时交易操作。

下载入口:https://github.com/openclaw/skills/tree/main/skills/emsin44/polymarket-setup

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install polymarket-setup

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 polymarket-setup。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Polymarket 交易配置 应用场景

Polymarket 交易配置 工作原理
  1. 扫描本地环境中的现有 .env 文件和配置设置,以确定当前的设置状态。
  2. 建立 Polygon 网络的环境变量,包括 EOA 私钥和 Polymarket 代理地址。
  3. 安装核心 Python 技术栈,包括 py-clob-client、httpx 和 WebSocket 依赖项。
  4. 发起代币授权,允许 Polymarket 交易所合约与用户的 USDC 余额进行交互。
  5. 通过签名密钥以程序化方式派生 API 密钥、密钥和密码,以启用 CLOB 访问。
  6. 对所有 API 端点进行健康检查,确保代理可以获取市场信息、读取订单簿并跟踪持仓。
  7. 生成一个低额测试订单,以在不冒重大资金风险的情况下验证签名逻辑和执行流程。

Polymarket 交易配置 配置指南

要开始在 Openclaw Skills 中使用此技能,首先安装所需的 Python 包:

pip install "py-clob-client>=0.28.0" httpx "websocket-client>=1.9.0" orjson pandas python-dotenv

接下来,确保您的 .env 文件已填入 Polymarket 设置页面中的代理浅包详细信息:

POLYMARKET_PRIVATE_KEY=0xYourPrivateKey
POLYMARKET_PROXY_ADDRESS=0xYourProxyAddress
POLYMARKET_SIGNATURE_TYPE=2

Polymarket 交易配置 数据架构与分类体系

该技能管理环境变量和 API 数据的特定分类以维持状态。以下是使用的主要架构:

类型 用途
POLYMARKET_PRIVATE_KEY 字符串 (十六进制) 用于签署交易和订单的 EOA 密钥。
POLYMARKET_PROXY_ADDRESS 字符串 (地址) 资金和持仓所在的智能合约浅包地址。
POLYMARKET_API_KEY 字符串 用于 CLOB REST API 身份验证的派生凭据。
Signature Type 整数 在大多数程序化 Openclaw Skills 实现中标准化为 2。
clobTokenIds 数组 YES(索引 0)和 NO(索引 1)结果代币的标识符。
name: polymarket-setup
description: Set up automated trading on Polymarket. Covers wallet setup, token approvals, API authentication, market discovery, order placement, WebSocket feeds, and position management.
metadata:
  {
    "openclaw": {
      "requires": {
        "env": [
          "POLYMARKET_PRIVATE_KEY",
          "POLYMARKET_PUBLIC_ADDRESS",
          "POLYMARKET_PROXY_ADDRESS",
          "POLYMARKET_SIGNATURE_TYPE",
          "POLYMARKET_API_KEY",
          "POLYMARKET_API_SECRET",
          "POLYMARKET_API_PASSPHRASE"
        ],
        "optionalEnv": [
          "POLYMARKET_BUILDER_API_KEY",
          "POLYMARKET_BUILDER_SECRET",
          "POLYMARKET_BUILDER_PASSPHRASE"
        ]
      }
    }
  }

Skill: Polymarket Trading Setup

Use this skill when the user wants to:

The full technical reference is in GUIDE.md (same directory as this file). Read it before starting.


What You're Setting Up

Polymarket trading requires four things in order:

  1. A funded proxy wallet with USDC on Polygon
  2. Token approvals (USDC spend approved for exchange contracts)
  3. CLOB API credentials (derived from the wallet, stored in env)
  4. Connectivity verified across all four API surfaces

Step-by-Step Agent Instructions

Step 1: Check What Already Exists

Before doing anything, check:

If credentials already exist, load and validate them rather than starting from scratch.

Step 2: Environment Setup

If starting fresh, create a .env file with:

POLYMARKET_PRIVATE_KEY=0x...
POLYMARKET_PUBLIC_ADDRESS=0x...     # proxy wallet address
POLYMARKET_PROXY_ADDRESS=0x...      # same as PUBLIC_ADDRESS for type 2
POLYMARKET_SIGNATURE_TYPE=2
POLYMARKET_WEBSOCKET_URL=wss://ws-subscriptions-clob.polymarket.com
POLYMARKET_DATA_API=https://data-api.polymarket.com

The proxy wallet address comes from the user's Polymarket account settings page.

Step 3: Install Dependencies

pip install "py-clob-client>=0.28.0" httpx "websocket-client>=1.9.0" orjson pandas python-dotenv

Or add to pyproject.toml and run uv sync.

Step 4: Token Approvals

Via UI (recommended for new users): Deposit USDC through the Polymarket web app — approvals happen automatically.

Headless (server deployment): Use the programmatic approval flow from GUIDE.md Section 4. This requires Polymarket Builder API credentials (separate from CLOB creds).

The four contracts that need approval are listed in GUIDE.md Section 2.

Step 5: Derive and Persist API Credentials

from py_clob_client.client import ClobClient

client = ClobClient(
    "https://clob.polymarket.com",
    key=os.getenv("POLYMARKET_PRIVATE_KEY"),
    chain_id=137,
    signature_type=int(os.getenv("POLYMARKET_SIGNATURE_TYPE", "2")),
    funder=os.getenv("POLYMARKET_PROXY_ADDRESS"),
)
creds = client.derive_api_key()
# Write credentials to .env — do not log or print them

Add to .env:

POLYMARKET_API_KEY=...
POLYMARKET_API_SECRET=...
POLYMARKET_API_PASSPHRASE=...

On subsequent startups, load from env instead of re-deriving (see GUIDE.md Section 3).

Step 6: Verify Connectivity

Test each surface in order. Stop and diagnose if any step fails.

import httpx, json

# 1. Gamma API
event = httpx.get("https://gamma-api.polymarket.com/events/slug/bitcoin-price-on-february-11").json()
print(f"Gamma OK: {event.get('title')}")

# 2. CLOB REST - order book
book = httpx.get("https://clob.polymarket.com/book", params={"token_id": ""}).json()
print(f"CLOB OK: {len(book.get('bids', []))} bids, {len(book.get('asks', []))} asks")

# 3. Data API - positions
positions = httpx.get(
    "https://data-api.polymarket.com/positions",
    params={"user": os.getenv("POLYMARKET_PROXY_ADDRESS")}
).json()
print(f"Data API OK: {len(positions)} open positions")

Step 7: Place a Test Order

Place a 2-share order at a far-from-market price (very low probability on a real market) to verify the full signing and posting flow without risk of a fill:

from py_clob_client.clob_types import OrderArgs, OrderType
from py_clob_client.order_builder.constants import BUY

# Use a real token ID from Step 6, price far from market
order = OrderArgs(price=0.02, side=BUY, size=2, token_id="")
signed = client.create_order(order)
resp = client.post_order(signed, OrderType.FAK)
print(resp)  # Should show success: true

Key Facts to Remember


Common First-Time Failures

Symptom Likely Cause
insufficient balance Wrong address 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
WebSocket never sends data Wrong subscription message format, or using array instead of object
Positions always empty Querying EOA address instead of proxy wallet address
Stale positions after trade Updating on MATCHED instead of MINED

Reference

Full API reference, all code patterns, and detailed explanations: GUIDE.md (same directory).

相关文章

热门文章

猜你喜欢

返回顶部