> ## 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.

# 撮合引擎重启

> 维护窗口、重启处理以及重启后的 post-only 模式

Polymarket 撮合引擎会重启以进行维护和升级。本页介绍如何检测和处理停机、重启后的 post-only 阶段以及如何获取变更的提前通知。

***

## 公告

撮合引擎变更——计划重启、更新和维护窗口——会在发生**之前**在以下渠道公告：

<CardGroup cols={2}>
  <Card title="Telegram" icon="telegram" href="https://t.me/polytradingapis">
    加入 Polymarket Trading APIs 频道获取实时公告。
  </Card>

  <Card title="Discord" icon="discord" href="https://discord.com/channels/710897173927297116/1473553279421255803">
    加入 Polymarket Discord 的 #trading-apis 频道。
  </Card>
</CardGroup>

公告通常包括**变更内容**、**计划时间**和**预计停机窗口**。目标是尽可能提前约 2 天通知。

***

## 处理 HTTP 425

在重启窗口期间，CLOB API 在所有订单相关端点上返回 **HTTP 425（Too Early）**。这告诉你的客户端撮合引擎正在重启，很快会恢复。

每次重启后，撮合引擎都会进入 **2 分钟的 post-only 模式**。在此期间，取消请求会被接受，新订单必须设置 `postOnly: true`；非 post-only 订单会被拒绝。

### 建议的重试策略

<Steps>
  <Step title="检测 425">
    当收到 HTTP `425` 响应时，撮合引擎正在重启。不要将其视为永久错误。
  </Step>

  <Step title="退避并重试">
    等待并使用指数退避重试。从 1-2 秒开始，每次重试增加间隔。
  </Step>

  <Step title="处理 post-only 模式">
    一旦不再收到 `425` 响应，引擎已恢复在线，但仍会保持 2 分钟的 post-only 模式。在此期间，只接受取消请求和设置了 `postOnly: true` 的订单。
  </Step>
</Steps>

### 代码示例

检查 CLOB API 响应的 HTTP 状态码，在收到 `425` 时重试：

<CodeGroup>
  ```typescript TypeScript theme={null}
  const CLOB_HOST = "https://clob.polymarket.com";

  async function postWithRetry(path: string, body: any, headers: Record<string, string>) {
    const MAX_RETRIES = 10;
    let delay = 1000;

    for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
      const response = await fetch(`${CLOB_HOST}${path}`, {
        method: "POST",
        headers: { "Content-Type": "application/json", ...headers },
        body: JSON.stringify(body),
      });

      if (response.status === 425) {
        console.log(`Engine restarting, retrying in ${delay / 1000}s...`);
        await new Promise((r) => setTimeout(r, delay));
        delay = Math.min(delay * 2, 30000);
        continue;
      }

      return response;
    }
    throw new Error("Engine restart exceeded maximum retry attempts");
  }
  ```

  ```python Python theme={null}
  import time
  import requests

  CLOB_HOST = "https://clob.polymarket.com"

  def post_with_retry(path, body, headers, max_retries=10):
      delay = 1

      for attempt in range(max_retries):
          response = requests.post(
              f"{CLOB_HOST}{path}",
              json=body,
              headers=headers,
          )

          if response.status_code == 425:
              print(f"Engine restarting, retrying in {delay}s...")
              time.sleep(delay)
              delay = min(delay * 2, 30)
              continue

          return response

      raise Exception("Engine restart exceeded maximum retry attempts")
  ```
</CodeGroup>

***

## 受限交易模式

在受限交易模式下，`POST /order` 和 `POST /orders` 的下单行为会发生变化。除非交易被完全禁用，取消端点仍会接受取消请求。

### 仅取消模式

在仅取消模式下，新订单会被拒绝，但取消请求仍会被接受。

`POST /order` 和 `POST /orders` 返回 `503`：

```json theme={null}
{
  "error": "Trading is currently cancel-only. New orders are not accepted, but cancels are allowed."
}
```

### Post-Only 模式

每次重启后，撮合引擎都会进入 **2 分钟的 post-only 模式**。取消请求会被接受，新订单必须设置 `postOnly: true`。非 post-only 订单会被拒绝。

`POST /order` 返回 `503`，并在响应体和 `Retry-After` HTTP header 中提供重试延迟：

```json theme={null}
{
  "error": "post-only mode: only post-only orders and cancels are allowed",
  "code": "post_only_mode",
  "retry_after_seconds": 79
}
```

`POST /orders` 会对批量请求中的每个非 post-only 订单返回单独的错误：

```json theme={null}
[
  {
    "errorMsg": "post-only mode: only post-only orders and cancels are allowed",
    "orderID": "",
    "takingAmount": "",
    "makingAmount": "",
    "status": "",
    "success": true
  },
  {
    "errorMsg": "post-only mode: only post-only orders and cancels are allowed",
    "orderID": "",
    "takingAmount": "",
    "makingAmount": "",
    "status": "",
    "success": true
  }
]
```

收到任一受限模式响应时，不要原样重试同一个非 post-only 订单。你可以取消现有订单、在提供重试延迟时等待后再重试，或使用 `postOnly: true` 重新提交符合条件的 maker 订单。

***

## 最佳实践

* **订阅公告渠道** — 在重启发生前获得通知，以便做好准备
* **优雅处理 425** — 将其视为临时状况而非错误；你的重试逻辑应自动恢复
* **处理下单端点的 503 模式响应** — 仅取消和 post-only 响应需要调整订单流程，而不是盲目重试
* **避免激进重试** — 引擎需要时间重新加载订单簿；快速重试不会加快速度，反而可能在引擎恢复后触发速率限制
* **记录重启事件** — 跟踪客户端遇到 425 的时间，与公告的维护窗口进行关联
