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

# API 速率限制

> 了解 Polymarket API 的速率限制和節流機制

<Callout type="success">
  還沒有帳號？[點擊這裡註冊 Polymarket](https://polymarket.com/?r=2026VIP) 並完成入金，才能用錢包私鑰為訂單籤名、實際成交。
</Callout>

<Warning>
  **法律合規提醒**：在使用 Polymarket 服務或 API 前，請確認您所在地區的法律規定。Polymarket 目前不支援比利時、法國、新加坡、泰國、中國大陸等地區，政策可能隨時變化。
</Warning>

所有速率限制均使用 Cloudflare 的節流系統執行。當您超過任何端點的最大配置速率時，請求將被節流而不是立即拒絕。

## 速率限制工作原理

* **節流**：超過限制的請求會被延遲/排隊，而不是被丟棄
* **突發允許**：某些端點允許短時間內超過持續速率的突發
* **時間窗口**：限制基於滑動時間窗口重置（例如，每 10 秒，每分鐘）

## 通用速率限制

| 端點      | 限制             | 說明            |
| ------- | -------------- | ------------- |
| 通用速率限制  | 15000 請求 / 10秒 | 超過最大配置速率時節流請求 |
| "OK" 端點 | 100 請求 / 10秒   | 超過最大配置速率時節流請求 |

## Data API 速率限制

| 端點       | 限制          | 說明            |
| -------- | ----------- | ------------- |
| Data API | 50 請求 / 10秒 | 超過最大配置速率時節流請求 |

## GAMMA API 速率限制

| 端點        | 限制          | 說明            |
| --------- | ----------- | ------------- |
| GAMMA API | 50 請求 / 10秒 | 超過最大配置速率時節流請求 |

## CLOB API 速率限制

### 通用 CLOB 端點

| 端點      | 限制             | 說明            |
| ------- | -------------- | ------------- |
| CLOB 通用 | 15000 請求 / 10秒 | 超過最大配置速率時節流請求 |

### CLOB 市場數據

| 端點            | 限制           | 說明            |
| ------------- | ------------ | ------------- |
| GET /markets  | 100 請求 / 10秒 | 超過最大配置速率時節流請求 |
| GET /book     | 100 請求 / 10秒 | 超過最大配置速率時節流請求 |
| GET /midpoint | 100 請求 / 10秒 | 超過最大配置速率時節流請求 |
| GET /price    | 100 請求 / 10秒 | 超過最大配置速率時節流請求 |
| GET /spread   | 100 請求 / 10秒 | 超過最大配置速率時節流請求 |

### CLOB 帳本端點

| 端點            | 限制           | 說明            |
| ------------- | ------------ | ------------- |
| GET /balances | 100 請求 / 10秒 | 超過最大配置速率時節流請求 |

### CLOB 市場與定價

| 端點             | 限制           | 說明            |
| -------------- | ------------ | ------------- |
| GET /tick-size | 100 請求 / 10秒 | 超過最大配置速率時節流請求 |
| GET /neg-risk  | 100 請求 / 10秒 | 超過最大配置速率時節流請求 |

### CLOB 認證

| 端點            | 限制           | 說明            |
| ------------- | ------------ | ------------- |
| CLOB API Keys | 100 請求 / 10秒 | 超過最大配置速率時節流請求 |

### CLOB 交易端點

這些是最關鍵的端點，具有更嚴格的限制：

| 端點                           | 限制                     | 說明                     |
| ---------------------------- | ---------------------- | ---------------------- |
| POST /order                  | 3500 請求 / 10秒 (500/秒)  | **突發** - 超過最大配置速率時節流請求 |
| POST /order                  | 36000 請求 / 10分鐘 (60/秒) | 超過最大配置速率時節流請求          |
| DELETE /order                | 3000 請求 / 10秒 (300/秒)  | **突發** - 超過最大配置速率時節流請求 |
| DELETE /order                | 30000 請求 / 10分鐘 (50/秒) | 超過最大配置速率時節流請求          |
| POST /orders                 | 1000 請求 / 10秒 (100/秒)  | **突發** - 超過最大配置速率時節流請求 |
| POST /orders                 | 15000 請求 / 10分鐘 (25/秒) | 超過最大配置速率時節流請求          |
| DELETE /orders               | 1000 請求 / 10秒 (100/秒)  | **突發** - 超過最大配置速率時節流請求 |
| DELETE /orders               | 15000 請求 / 10分鐘 (25/秒) | 超過最大配置速率時節流請求          |
| DELETE /cancel-all           | 250 請求 / 10秒 (25/秒)    | **突發** - 超過最大配置速率時節流請求 |
| DELETE /cancel-all           | 6000 請求 / 10分鐘 (10/秒)  | 超過最大配置速率時節流請求          |
| DELETE /cancel-market-orders | 1000 請求 / 10秒 (100/秒)  | **突發** - 超過最大配置速率時節流請求 |
| DELETE /cancel-market-orders | 1500 請求 / 10分鐘 (25/秒)  | 超過最大配置速率時節流請求          |

## 其他 API 速率限制

| 端點              | 限制           | 說明            |
| --------------- | ------------ | ------------- |
| RELAYER /submit | 25 請求 / 1分鐘  | 超過最大配置速率時節流請求 |
| User PNL API    | 200 請求 / 10秒 | 超過最大配置速率時節流請求 |

## 最佳實踐

<Callout type="warning">
  為避免速率限制：

  1. **實施指數退避**：如果收到速率限制錯誤，等待後再重試
  2. **批量請求**：儘可能使用批量端點（如 POST /orders）而不是多個單獨請求
  3. **使用 WebSocket**：對於實時數據，使用 WebSocket 連接而不是輪詢
  4. **緩存數據**：緩存不經常變化的數據，如市場信息
  5. **監控使用情況**：跟蹤您的 API 使用情況，避免接近限制
</Callout>

## 處理速率限制錯誤

當您達到速率限制時，API 將返回 HTTP 429 狀態碼。響應將包含以下頭部：

```
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1234567890
```

示例錯誤處理：

```python theme={null}
import time
from py_clob_client.exceptions import RateLimitError

def make_request_with_retry(func, max_retries=3):
    for attempt in range(max_retries):
        try:
            return func()
        except RateLimitError as e:
            if attempt == max_retries - 1:
                raise
            wait_time = 2 ** attempt  # 指數退避
            print(f"速率限制，等待 {wait_time} 秒...")
            time.sleep(wait_time)
```

TypeScript 示例：

```typescript theme={null}
async function makeRequestWithRetry(
  func: () => Promise<any>,
  maxRetries: number = 3
): Promise<any> {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      return await func();
    } catch (error: any) {
      if (error.response?.status !== 429 || attempt === maxRetries - 1) {
        throw error;
      }
      const waitTime = Math.pow(2, attempt) * 1000;
      console.log(`速率限制，等待 ${waitTime}ms...`);
      await new Promise(resolve => setTimeout(resolve, waitTime));
    }
  }
}
```

## 下一步

<CardGroup cols={2}>
  <Card title="端點列表" icon="list" href="/api-tutorial/endpoints">
    查看所有可用的 API 端點
  </Card>

  <Card title="WebSocket" icon="bolt" href="/api-tutorial/websocket/overview">
    使用 WebSocket 獲取實時數據
  </Card>

  <Card title="第一筆訂單" icon="rocket" href="/api-tutorial/first-order">
    學習如何下第一筆訂單
  </Card>

  <Card title="CLOB 介紹" icon="book" href="/api-tutorial/clob/introduction">
    了解中央限價訂單簿
  </Card>
</CardGroup>
