# 價格提醒

價格警示監控單一市場中單一結果的價格。當價格首次達到你的門檻值時，PAX 會向你的 webhook 端點發送已簽章的 `price.alert.triggered` 事件。警示屬於 Builder 帳戶。

## 開始之前

- 你的 Builder 帳戶的 API 金鑰，擁有 `builder:apps:write` 權限可建立及取消警報，並擁有 `builder:apps:read` 權限可列出它們。
- 一個 webhook 端點，其 `events` 包含 `price.alert.triggered`。使用 `POST /v1/webhooks` 建立一個，或使用 `PATCH /v1/webhooks/{id}` 將事件加入現有端點。按 [Webhook Signing](https://docs.predictasiax.com/zh-hant/webhook-signing) 所述驗證每一次交付。

警報會在該時刻是否已訂閱端點與否都會觸發，且只觸發一次。稍後新增的端點不會收到。

## 端點

| 方法與路徑 | 權限範圍 | 速率限制桶 |
|---|---|---|
| `POST /v1/price-alerts` | `builder:apps:write` | `webhooks:manage` |
| `GET /v1/price-alerts` | `builder:apps:read` | `markets:read` |
| `GET /v1/price-alerts/{id}` | `builder:apps:read` | `markets:read` |
| `DELETE /v1/price-alerts/{id}` | `builder:apps:write` | `webhooks:manage` |

桶與其每分鐘預算詳見 [Rate Limits](https://docs.predictasiax.com/zh-hant/rate-limits)。

## 建立提醒

```
curl -sX POST "https://api.predictasiax.com/v1/price-alerts" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"market_id":"fed-cut-3x-2026","outcome":"yes","condition":"above","price":"0.6","label":"breakout"}'
```

| 欄位 | 必要 | 規則 |
|---|---|---|
| `market_id` | 是 | 市場的 `id`，格式與 `GET /v1/markets` 回傳的一致。市場必須是開放狀態。 |
| `結果` | 否 (預設 `yes`) | 在二元結果市場中為 `yes` 或 `no`。在具有三個或更多結果的市場中，為該結果在市場結果清單中的 0 起始索引（0 到 31）。 |
| `條件` | 是 | `above`：當價格等於或高於 `price` 時觸發。`below`：當價格等於或低於時觸發。 |
| `price` | 是 | 介於 0 與 1 之間（不含端點），最多 4 位小數。字串（`"0.6"`）或數字。 |
| `label` | 否 | 你自己的文字，最多 100 個字元。會隨警報和事件一起回傳。 |

任何其他欄位都會被拒絕，並回傳 `400 VALIDATION_FAILED`。回應為 `201`，包含該警示以及建立時的結果價格：

```
{
  "ok": true,
  "data": {
    "alert": {
      "id": "pa_x7Kq2mVb9TzR4wLs",
      "market_id": "fed-cut-3x-2026",
      "outcome": "yes",
      "condition": "above",
      "price": "0.6000",
      "label": "breakout",
      "status": "active",
      "created_at_ms": 1796020000000,
      "triggered_at_ms": null,
      "triggered_price": null,
      "ended_at_ms": null
    },
    "current_price": "0.5500"
  }
}
```

在具有三個或更多結果的市場中，`outcome` 會以數字回傳。當該市場尚未有該結果的價格時，`current_price` 為 `null`。

## 當警報觸發時

- 比較的價格是該市場的結果價格 `GET /v1/markets` 所示。活躍的警報每 2 秒檢查一次。
- **一次性。** 在條件首次成立的檢查點，警報會變為 `triggered`，並附上 `triggered_price` 與 `triggered_at_ms`，同時在同一步驟中將 `price.alert.triggered` 事件加入佇列。警報絕不會觸發兩次。若要繼續監控，請建立新的警報。
- 如果你在建立提醒時條件已經成立，它會在下次檢查時觸發，通常在數秒內。
- 如果市場在警報觸發前已關閉或結算，警報將以 `expired` 結束，且不會送出任何事件。
- Builder 帳戶同時最多可持有 100 個 `active` 提醒。已觸發、已取消和已過期的提醒不計入。

### 事件

送達的 `data` 是提醒，格式與 `GET /v1/price-alerts/{id}` 回傳的一致，但狀態為 `triggered`。`event_id` 在每次重試時都相同，請用它來去重。

```
{
  "event_id": "pa_trig_pa_x7Kq2mVb9TzR4wLs",
  "event_type": "price.alert.triggered",
  "is_test_event": false,
  "created_at_ms": 1796022000000,
  "data": {
    "alert": {
      "id": "pa_x7Kq2mVb9TzR4wLs", "market_id": "fed-cut-3x-2026", "outcome": "yes",
      "condition": "above", "price": "0.6000", "label": "breakout", "status": "triggered",
      "created_at_ms": 1796020000000, "triggered_at_ms": 1796022000000,
      "triggered_price": "0.6100", "ended_at_ms": 1796022000000
    }
  }
}
```

送達、重試與死信的工作方式與其他事件相同：參見 [送達與重試](https://docs.predictasiax.com/zh-hant/webhook-signing#delivery).

## 列出並讀取警示

`GET /v1/price-alerts` 會傳回你的警示，依最新排序，格式為 `data.alerts[]`。查詢參數，皆為選填：

| 參數 | 值 |
|---|---|
| `狀態` | `active`、`triggered`、`cancelled` 或 `expired` |
| `market_id` | 僅限此市場的提醒 |
| `limit` | 1 到 200，預設 50 |

`GET /v1/price-alerts/{id}` 回傳一個警示為 `data.alert`。

## 取消提醒

`DELETE /v1/price-alerts/{id}` 會取消一個 `active` 警示。它會保留在你的清單中，狀態為 `cancelled`，並設定 `ended_at_ms`。已觸發、過期或已取消的警示會傳回 `409 STATE_CONFLICT`，警示內容位於 `error.details.alert`。

## 狀態

| 狀態 | 意義 |
|---|---|
| `啟用` | 正在檢查 |
| `已觸發` | 條件成立；事件已發送 |
| `cancelled` | 你已取消 |
| `expired` | 市場先結束或結算；沒有事件 |

## 錯誤

| HTTP | 代碼 | 時間 |
|---|---|---|
| 400 | `VALIDATION_FAILED` | 欄位違反上述規則、未知欄位，或市場不存在的結果 |
| 403 | `SCOPE_MISSING` | 該金鑰缺少權限範圍，或不屬於 Builder 帳戶 |
| 404 | `MARKET_NOT_FOUND` | 不存在該 `market_id` 對應的市場 |
| 404 | `NOT_FOUND` | 你的帳戶中沒有該 id 的提醒 |
| 409 | `STATE_CONFLICT` | 取消未啟動的警報 |
| 422 | `MARKET_CLOSED` | 市場未開放 |
| 422 | `PRICE_ALERT_LIMIT` | 你已經有 100 個啟用中的提醒 |
| 429 | `RATE_LIMITED` | 速率限制桶已用完；請在 `Retry-After` 之後重試 |

所有代碼都列在 [錯誤代碼](https://docs.predictasiax.com/zh-hant/errors) 中。

規格版本 2.7.82 · 最後更新 2026-12-03

Source: https://docs.predictasiax.com/zh-hant/price-alerts
