> ## Documentation Index
> Fetch the complete documentation index at: https://docs.polymarket.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 概述

> 在 Polymarket CLOB 上交易

Polymarket 的 CLOB (Central Limit Order Book) 是一个混合去中心化交易系统——链下订单撮合与链上结算通过 [Exchange 合约](https://github.com/Polymarket/ctf-exchange/tree/main/src)实现([由 Chainsecurity 审计](https://github.com/Polymarket/ctf-exchange/blob/main/audit/ChainSecurity_Polymarket_Exchange_audit.pdf))。所有交易均为非托管式。订单是 [EIP-712](https://eips.ethereum.org/EIPS/eip-712) 签名消息,撮合后的交易在 Polygon 上原子化结算。运营方无法设定价格或执行未授权交易。

我们建议使用开源 SDK 客户端,它们可以处理订单签名、身份验证和提交:

<CardGroup cols={2}>
  <Card title="TypeScript Client" icon="github" href="https://github.com/Polymarket/clob-client-v2">
    <p className="font-mono text-[0.8rem]">
      npm install @polymarket/clob-client-v2 viem
    </p>
  </Card>

  <Card title="Python Client" icon="github" href="https://github.com/Polymarket/py-clob-client-v2">
    <p className="font-mono text-[0.8rem]">pip install py-clob-client-v2</p>
  </Card>
</CardGroup>

<Info>
  你也可以直接使用 REST API,但需要自己管理 [EIP-712
  订单签名](https://github.com/Polymarket/clob-client-v2/blob/main/src/signing/eip712.ts)
  和 [HMAC 身份验证头](https://github.com/Polymarket/clob-client-v2/blob/main/src/signing/hmac.ts)。
  请参阅下方的 [REST API 请求头](#rest-api-headers)。
</Info>

***

## 身份验证

CLOB 使用两级身份验证:

| 级别     | 方法                   | 用途           |
| ------ | -------------------- | ------------ |
| **L1** | EIP-712 签名(私钥)       | 创建或派生 API 凭证 |
| **L2** | HMAC-SHA256 (API 凭证) | 下单、撤单、查询交易   |

你需要使用私钥一次来派生 **L2 凭证**(API key、secret、passphrase),这些凭证用于验证所有后续的交易请求。

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { ClobClient } from "@polymarket/clob-client-v2";
  import { createWalletClient, http } from "viem";
  import { privateKeyToAccount } from "viem/accounts";

  const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
  const signer = createWalletClient({ account, transport: http() });

  // Derive L2 API credentials
  const tempClient = new ClobClient({ host: "https://clob.polymarket.com", chain: 137, signer });
  const apiCreds = await tempClient.createOrDeriveApiKey();
  ```

  ```python Python theme={null}
  from py_clob_client_v2 import ClobClient
  import os

  private_key = os.getenv("PRIVATE_KEY")

  # Derive L2 API credentials
  temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain_id=137)
  api_creds = temp_client.create_or_derive_api_key()
  ```
</CodeGroup>

***

## 签名类型

初始化交易客户端时,你必须指定钱包的**签名类型**和 **funder 地址**:

| 钱包类型             | ID  | 使用场景                                                         | Funder 地址            |
| ---------------- | --- | ------------------------------------------------------------ | -------------------- |
| **EOA**          | `0` | 独立钱包——你自己支付 gas 费(使用 POL 支付 gas)                             | 你的 EOA 钱包地址          |
| **POLY\_PROXY**  | `1` | 现有的 Polymarket 代理钱包流程                                        | 你的代理钱包地址             |
| **GNOSIS\_SAFE** | `2` | 现有的 Gnosis Safe 钱包流程                                         | 你的 Safe 钱包地址         |
| **POLY\_1271**   | `3` | 面向新 API 用户的 Deposit Wallet 流程。订单由所有者/会话签名者签名,并通过 ERC-1271 验证 | 你的 Deposit Wallet 地址 |

<Note>
  新 API 用户应使用签名类型 `3`(Deposit Wallet)。现有的 Proxy 和 Safe 用户
  不受影响,可以继续使用签名类型 `1` 和 `2`。类型 `0` 仅适用于独立的 EOA 钱包。
</Note>

### 初始化交易客户端

<CodeGroup>
  ```typescript TypeScript theme={null}
  const client = new ClobClient({
    host: "https://clob.polymarket.com",
    chain: 137,
    signer,
    creds: apiCreds,
    signatureType: 2, // GNOSIS_SAFE
    funderAddress: "0x...", // Your proxy wallet address
  });
  ```

  ```python Python theme={null}
  client = ClobClient(
      "https://clob.polymarket.com",
      key=private_key,
      chain_id=137,
      creds=api_creds,
      signature_type=2,  # GNOSIS_SAFE
      funder="0x..."  # Your proxy wallet address
  )
  ```
</CodeGroup>

***

## REST API 请求头

如果你直接使用 REST API (不通过 SDK),需要在每个请求中附加身份验证头。

**L1 请求头** — 用于创建或派生 API 凭证:

| 请求头              | 说明         |
| ---------------- | ---------- |
| `POLY_ADDRESS`   | 你的钱包地址     |
| `POLY_SIGNATURE` | EIP-712 签名 |
| `POLY_TIMESTAMP` | Unix 时间戳   |
| `POLY_NONCE`     | 请求随机数      |

**L2 请求头** — 用于所有交易操作(下单、撤单、查询):

| 请求头               | 说明                 |
| ----------------- | ------------------ |
| `POLY_ADDRESS`    | 你的钱包地址             |
| `POLY_SIGNATURE`  | 请求的 HMAC-SHA256 签名 |
| `POLY_TIMESTAMP`  | Unix 时间戳           |
| `POLY_API_KEY`    | 你的 API key         |
| `POLY_PASSPHRASE` | 你的 API passphrase  |

<Note>
  即使使用 L2 身份验证,创建订单的方法仍然需要用户的私钥来进行 EIP-712 订单载荷签名。
  L2 凭证用于验证请求本身,但订单必须由密钥签名。
</Note>

***

## 速率限制

CLOB 实施速率限制以确保系统稳定性:

| 范围                  | 限制                |
| ------------------- | ----------------- |
| 一般限制                | 每 10 秒 15,000 个请求 |
| `POST /order`       | 峰值 500/秒,持续 80/秒  |
| `POST /orders` (批量) | 峰值 150/秒,持续 35/秒  |
| `DELETE /order`     | 峰值 500/秒,持续 80/秒  |

超过这些限制将返回 HTTP `429`。请在客户端中实现指数退避。

***

## 服务器基础设施

CLOB 撮合引擎运行在以下区域：

* **主服务器**：eu-west-2
* **最近的非地区限制区域**：eu-west-1

<Tip>
  **可申请直接同地协作（co-location）。** 完成 [KYC/KYB
  表单](https://docs.google.com/forms/d/e/1FAIpQLSfY-3Dl3yxq8HKFjFad8YzKZmm0k3Gdg29HD6gL-K-AmI6KXw/viewform)的用户可以申请直接在 `eu-west-2`
  中进行同地协作，以获得到 Polymarket 主服务器的最低延迟。完整的地理可用性信息请参阅
  [地区限制](/api-reference/geoblock#server-infrastructure)。
</Tip>

***

## 本节内容

<CardGroup cols={2}>
  <Card title="快速开始" icon="bolt" href="/trading/quickstart">
    端到端完成你的第一笔订单
  </Card>

  <Card title="订单簿" icon="chart-bar" href="/trading/orderbook">
    读取订单簿、价格、价差和中间价
  </Card>

  <Card title="订单" icon="list-check" href="/trading/orders/create">
    订单类型、最小价格单位、创建、取消和查询订单
  </Card>

  <Card title="费用" icon="receipt" href="/trading/fees">
    费用结构、启用费用的市场以及做市商回扣
  </Card>

  <Card title="免 Gas 交易" icon="gas-pump" href="/trading/gasless">
    无需支付 gas 即可执行链上操作
  </Card>

  <Card title="CTF Tokens" icon="coins" href="/trading/ctf/overview">
    拆分、合并和赎回结果代币
  </Card>

  <Card title="跨链桥" icon="bridge" href="/trading/bridge/deposit">
    跨链存入和提取资金
  </Card>
</CardGroup>
