AgentSkillsCN

polymarket

完整的Polymarket CLOB集成手册。涵盖认证(L1/L2、构建者头、HMAC签名)、订单下单(GTC/GTD/FOK/FAK、批量、仅限挂单、心跳)、市场数据(Gamma API、Data API、订单簿)、WebSocket流式传输(市场/用户/体育频道)、CTF操作(拆分、合并、赎回、负风险)、桥接(存款、取款、多链),以及免Gas交易(中继客户端、订单归属)。适用于构建AI代理、自主做市商、预测市场UI,或任何与Polymarket CLOB API集成的应用场景。

SKILL.md
--- frontmatter
name: polymarket
description: Complete Polymarket CLOB integration playbook. Covers authentication (L1/L2, builder headers, HMAC signing), order placement (GTC/GTD/FOK/FAK, batch, post-only, heartbeat), market data (Gamma API, Data API, orderbook), WebSocket streaming (market/user/sports channels), CTF operations (split, merge, redeem, neg risk), bridge (deposits, withdrawals, multi-chain), and gasless transactions (relayer client, order attribution). Use when building AI agents, autonomous market makers, prediction market UIs, or any application integrating with Polymarket's CLOB API.

Polymarket CLOB Skill

What this Skill is for

Use this Skill when the user asks for:

  • Polymarket API authentication (L1/L2, API keys, HMAC signing)
  • Placing orders (limit, market, GTC, GTD, FOK, FAK, batch)
  • Reading orderbook data (prices, spreads, midpoints, depth)
  • Market data fetching (events, markets, by slug, by tag, pagination)
  • WebSocket subscriptions (market channel, user channel, sports)
  • CTF operations (split, merge, redeem positions)
  • Negative risk markets (multi-outcome, conversion, augmented neg risk)
  • Bridge operations (deposits, withdrawals, multi-chain)
  • Gasless transactions (relayer client, order attribution)
  • Builder program integration (order attribution, API keys)
  • Polymarket SDK usage (TypeScript @polymarket/clob-client, Python py-clob-client)

API Configuration

APIBase URLAuthPurpose
CLOBhttps://clob.polymarket.comL2 for trade endpointsOrderbook, prices, order submission
Gamma / Datahttps://gamma-api.polymarket.comNoneEvents, markets, search
Data APIhttps://data-api.polymarket.comNoneTrades, positions, user data
WebSocket (Market)wss://ws-subscriptions-clob.polymarket.com/ws/marketNoneReal-time orderbook
WebSocket (User)wss://ws-subscriptions-clob.polymarket.com/ws/userAPI creds in messageTrade/order updates
WebSocket (Sports)wss://sports-api.polymarket.com/wsNoneLive scores
Relayerhttps://relayer-v2.polymarket.com/Builder headersGasless transactions
Bridgehttps://bridge.polymarket.comNoneDeposits/withdrawals

Contract Addresses (Polygon)

ContractAddress
USDC (USDC.e)0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174
CTF (Conditional Tokens)0x4D97DCd97eC945f40cF65F87097ACe5EA0476045
CTF Exchange0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E
Neg Risk CTF Exchange0xC5d563A36AE78145C45a50134d48A1215220f80a
Neg Risk Adapter0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296

Client Setup

TypeScript

typescript
import { ClobClient, Side, OrderType } from "@polymarket/clob-client";
import { Wallet } from "ethers"; // v5.8.0

const HOST = "https://clob.polymarket.com";
const CHAIN_ID = 137;
const signer = new Wallet(process.env.PRIVATE_KEY);

// Step 1: L1 — derive API credentials
const tempClient = new ClobClient(HOST, CHAIN_ID, signer);
const apiCreds = await tempClient.createOrDeriveApiKey();

// Step 2: L2 — init trading client
const client = new ClobClient(
  HOST,
  CHAIN_ID,
  signer,
  apiCreds,
  2,                // signatureType: 0=EOA, 1=POLY_PROXY, 2=GNOSIS_SAFE
  "FUNDER_ADDRESS"  // proxy wallet address from polymarket.com/settings
);

Python

python
from py_clob_client.client import ClobClient
import os

host = "https://clob.polymarket.com"
chain_id = 137
pk = os.getenv("PRIVATE_KEY")

# Step 1: L1 — derive API credentials
temp_client = ClobClient(host, key=pk, chain_id=chain_id)
api_creds = temp_client.create_or_derive_api_creds()

# Step 2: L2 — init trading client
client = ClobClient(
    host,
    key=pk,
    chain_id=chain_id,
    creds=api_creds,
    signature_type=2,  # 0=EOA, 1=POLY_PROXY, 2=GNOSIS_SAFE
    funder="FUNDER_ADDRESS",
)

Quick Reference: Order Types

TypeBehaviorUse Case
GTCRests on book until filled or cancelledDefault limit orders
GTDActive until expiration (UTC seconds). Min = now + 60 + NAuto-expire before events
FOKFill entirely immediately or cancelAll-or-nothing market orders
FAKFill what's available, cancel restPartial-fill market orders
  • FOK/FAK BUY: amount = dollar amount to spend
  • FOK/FAK SELL: amount = number of shares to sell
  • Post-only: GTC/GTD only — rejected if would cross spread

Quick Reference: Signature Types

TypeValueDescription
EOA0Standard wallet. Funder = EOA address. Needs POL for gas.
POLY_PROXY1Magic Link proxy wallet. User exported PK from Polymarket.com.
GNOSIS_SAFE2Gnosis Safe multisig proxy. Most common for new integrations.

Core Pattern: Place an Order

TypeScript

typescript
const response = await client.createAndPostOrder(
  {
    tokenID: "TOKEN_ID",
    price: 0.50,
    size: 10,
    side: Side.BUY,
  },
  {
    tickSize: "0.01",  // from client.getTickSize(tokenID) or market object
    negRisk: false,    // from client.getNegRisk(tokenID) or market object
  },
  OrderType.GTC
);
console.log(response.orderID, response.status);

Python

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

response = client.create_and_post_order(
    OrderArgs(token_id="TOKEN_ID", price=0.50, size=10, side=BUY),
    options={"tick_size": "0.01", "neg_risk": False},
    order_type=OrderType.GTC,
)
print(response["orderID"], response["status"])

Core Pattern: Read Orderbook

TypeScript

typescript
// No auth needed
const readClient = new ClobClient("https://clob.polymarket.com", 137);
const book = await readClient.getOrderBook("TOKEN_ID");
console.log("Best bid:", book.bids[0], "Best ask:", book.asks[0]);

const mid = await readClient.getMidpoint("TOKEN_ID");
const spread = await readClient.getSpread("TOKEN_ID");

Python

python
read_client = ClobClient("https://clob.polymarket.com", chain_id=137)
book = read_client.get_order_book("TOKEN_ID")
mid = read_client.get_midpoint("TOKEN_ID")
spread = read_client.get_spread("TOKEN_ID")

Core Pattern: WebSocket Subscribe

typescript
const ws = new WebSocket("wss://ws-subscriptions-clob.polymarket.com/ws/market");

ws.onopen = () => {
  ws.send(JSON.stringify({
    type: "market",
    assets_ids: ["TOKEN_ID"],
    custom_feature_enabled: true,
  }));
  // Send PING every 10s to keep alive
  setInterval(() => ws.send("PING"), 10_000);
};

ws.onmessage = (event) => {
  if (event.data === "PONG") return;
  const msg = JSON.parse(event.data);
  // msg.event_type: "book" | "price_change" | "last_trade_price" | "tick_size_change" | "best_bid_ask" | "new_market" | "market_resolved"
};

Progressive Disclosure (read when needed)