# 下載

機器可讀規格 + Postman 集合。自行產生 SDK，或匯入任何 HTTP 工具。

## OpenAPI 3.1 (REST)

公開 REST 規格 — **209 個路徑 / 240 個操作，涵蓋 21 個標籤群組**：Discovery、Builders、Apps、Attribution、Revenue、Orders、Auth、Subaccounts、Competitions、Composer、Weather、Liquidity、Data、Webhooks、Marketplace、Oracle、Sandbox、Audit、Portfolio、Copy trading、Provider Keys。稽核鏈（`/v1/audit/head`、`/root`、`/batches`、`/health`、`/anchor`）為公開且免驗證。管理員／團隊／結算端點存在於執行環境中，但刻意未包含在公開規格內。使用 [openapi-generator](https://openapi-generator.tech) 進行程式碼生成（支援 50 多種目標語言）。

| 格式 | 檔案 | 大小 | 用途 |
|---|---|---|---|
| YAML | [openapi.yaml](https://docs.predictasiax.com/downloads/openapi.yaml) | 273 KB | 人類可讀、易於比對 |
| JSON | [openapi.json](https://docs.predictasiax.com/downloads/openapi.json) | 388 KB | Redoc / Swagger UI / 程式碼產生工具 |

```
# Codegen Python client
openapi-generator generate -i https://docs.predictasiax.com/downloads/openapi.json -g python -o pax-python-client

# Codegen TypeScript axios client
openapi-generator generate -i https://docs.predictasiax.com/downloads/openapi.json -g typescript-axios -o pax-ts-client

# Codegen Go client
openapi-generator generate -i https://docs.predictasiax.com/downloads/openapi.json -g go -o pax-go-client
```

## AsyncAPI 2.6 (WebSocket)

WebSocket 規格 — **78 個伺服器訊息（Ev*）+ 7 個客戶端訊息（Cmd*：六個指令與一個 ping 保活）**，`components.messages` 中共 85 個。每個訊息都帶有 `x-access`：39 個 `public` 頻道、16 個 `account` 頻道（AUTH 後 SUBSCRIBE）、12 個 `push` 事件（傳送至你已驗證的 socket）以及 11 個 `control` 回應。客戶端指令：`AUTH` / `SUBSCRIBE` / `UNSUBSCRIBE` / `LOCALE` / `RFQ_SUBSCRIBE` / `RFQ_UNSUBSCRIBE`（這兩個 RFQ 動詞用於註冊 socket 以接收 request-for-quote 更新）。public 與 account 頻道清單與 live gateway ACL 一致。

| 格式 | 檔案 | 大小 | 用途 |
|---|---|---|---|
| YAML | [asyncapi.yaml](https://docs.predictasiax.com/downloads/asyncapi.yaml) | 50 KB | 人類可讀、易於比對 |
| JSON | [asyncapi.json](https://docs.predictasiax.com/downloads/asyncapi.json) | 73 KB | AsyncAPI Studio、codegen 工具 |

```
# Codegen Node.js WebSocket client from AsyncAPI
npm i -g @asyncapi/generator
ag https://docs.predictasiax.com/downloads/asyncapi.json @asyncapi/nodejs-ws-template -o pax-ws-client
```

## Postman Collection

PredictAsiaX 已[發布在 Postman 的 Public Workspace](https://www.postman.com/predictasiax-2938441/predictasiax-api)。將其 Fork 到你自己的 Postman workspace，當我們更新規格時，它會保持同步：

- **工作區**：`PredictAsiaX API` · 1 個集合 + 2 個環境（production + 沙盒）。
- **Fork**：登入 Postman → 開啟工作區 → 點擊 *Fork Collection*。
- **環境設定**：fork 後，編輯 `PAX Sandbox` 環境，並將 `apiKey` 設為你從 `POST /v1/sandbox-keys` 取得的 `sk_live_*`。

直接下載（供隔離環境 / 稽核檢視使用的鏡像）：

| 檔案 | 用途 | 大小 |
|---|---|---|
| [postman.json](https://docs.predictasiax.com/downloads/postman.json) | 集合 — 全部 239 個公開 REST 操作，含範例請求主體，由 openapi.json 產生；在環境中設定 `apiKey` | 486 KB |
| [pax-sandbox.postman_environment.json](https://docs.predictasiax.com/downloads/pax-sandbox.postman_environment.json) | 沙盒環境 — `baseUrl`、`apiKey`、HMAC 金鑰 | <1 KB |
| [pax-production.postman_environment.json](https://docs.predictasiax.com/downloads/pax-production.postman_environment.json) | 生產環境 — 結構相同，使用生產 URL | <1 KB |

### 匯入 Postman

1. 開啟 Postman → **Import**（左上角）。
2. 拖曳全部 3 個檔案（collection + 2 個 environments），或貼上 URL：
  ```
  https://docs.predictasiax.com/downloads/postman.json
  https://docs.predictasiax.com/downloads/pax-sandbox.postman_environment.json
  https://docs.predictasiax.com/downloads/pax-production.postman_environment.json
  ```
3. 右上角的環境選擇器 → 選擇 **PAX Sandbox**。
4. 環境分頁 → 填入 `apiKey` = 你的 `sk_live_*` 沙盒金鑰（來自 `POST /v1/sandbox-keys`，tier=sandbox）。儲存。
5. 開啟任何請求 → 點擊 **Send**。完成。

**Postman → cURL：**在 Postman 中設定好請求後，點擊**Code** 按鈕（請求面板右上角），即可複製等價的 cURL、Python、Node 或 Go 程式碼片段。

## MCP 伺服器

PredictAsiaX 已作為 `com.predictasiax/mcp` [發布在官方 MCP Registry](https://registry.modelcontextprotocol.io/v0/servers?search=predictasiax)。AI 代理應用程式（Claude Desktop、Cursor、Windsurf、自訂代理）可透過 MCP 客戶端註冊表搜尋發現該伺服器並直接連線：

| 欄位 | 值 |
|---|---|
| 註冊名稱 | `com.predictasiax/mcp` |
| 伺服器 URL | `https://mcp.predictasiax.com` |
| 傳輸 | SSE + 可串流 HTTP |
| 驗證 | Bearer `sk_live_*`（透過 `POST /v1/sandbox-keys` 自行簽發）；讀取公開資料（市場、訂單簿、手續費、文件）的 19 個工具無需憑證 |
| 工具 (46) | `market_search`、`market_get`、`market_orderbook`、`market_price_history`、`probability_movers`、`markets_top_volume`、`category_list`、`portfolio_read`、`portfolio_history`、`balance_get`、`positions_list`、`subaccount_list`、`place_order`、`cancel_order`、`cancel_all_orders`、`orders_open`、`orders_history`、`fee_estimate`、`mm_stipend_estimate`、`mm_stipend_history`、`liquidity_leaderboard`、`subaccount_create`、`subaccount_transfer`、`subaccount_close`、`composer_templates_list`、`composer_template_get`、`composer_proposal_submit`、`resolution_evidence`、`mm_quote_post`、`mm_quotes_list`、`rfq_create`、`rfq_accept`、`builder_me`、`builder_apps_list`、`builder_apikeys_list`、`tier_status`、`fee_ledger_read`、`webhook_endpoints_list`、`webhook_create`、`webhook_deliveries`、`access_request_create`、`access_request_status`、`docs_search`、`docs_read`、`sandbox_agent_examples`、`health` — 透過 `tools/list` 提供命名空間 `pax.*` |

## SDKs

提供原生 SDK。兩者皆指向 `https://api.predictasiax.com` 閘道（方法會附加 `/v1/…` 路徑），支援 Bearer 或 HMAC（`PAX-*` 標頭）驗證、離線稽核驗證器、寫入操作自動產生 `Idempotency-Key`，以及安全預設值（僅限 HTTPS、串流回應上限、CRLF 標頭防護、回應主體大小上限 10 MB）。

| 語言 | 套件 | 版本 | 安裝 |
|---|---|---|---|
| Python | `pax-api` | 3.3.2 LIVE | `pip install "pax-api>=3"` |
| TypeScript / JavaScript | `@predictasiax/api` | 3.4.1 LIVE | `npm i @predictasiax/api@3` |
| Go | 透過 OpenAPI 程式碼產生 | — | `oapi-codegen -package pax https://docs.predictasiax.com/downloads/openapi.yaml` |
| Rust | 透過 OpenAPI 程式碼產生 | — | `openapi-generator generate -g rust -i https://docs.predictasiax.com/downloads/openapi.json` |
| 其他 50+ 種語言 | 透過 OpenAPI 程式碼產生 | — | `openapi-generator generate -g <lang> -i https://docs.predictasiax.com/downloads/openapi.json` |

### TypeScript 快速入門

```
# npm i @predictasiax/api@3    (2.x cannot authenticate against the current gateway)
import { PaxClient } from '@predictasiax/api';

// 1. Public endpoints need no key; mint a sandbox key (api_key is shown once)
const pub = new PaxClient();
const minted = await pub.sandboxKeys.mint({ orgName: 'my-app' });

// 2. Use the key: Authorization: Bearer sk_live_...
//    (or { apiKey, keyId: 'api_...' } to HMAC-sign with PAX-* headers instead)
const pax = new PaxClient({ apiKey: minted.api_key });

for await (const market of pax.markets.list({ category: 'crypto' })) {
  console.log(market.id, market.title);
}

// Limit BUY of one outcome. Idempotency-Key and client_order_id are generated
// once per call and reused across retries.
const { data, requestId } = await pax.orders.place({
  marketId: 'hadjar-f1-2026', side: 'yes', price: '0.05', size: '20',
}).withResponse();
console.log('Order:', data, 'Request:', requestId);

// Price an order first (public, nothing placed), then wait for the fill and the settlement.
// Both waits read the result over REST and ride out 429, 5xx and network errors.
const q = await pub.markets.quote('hadjar-f1-2026', { side: 'yes', amount: 25 });
console.log(q.fill?.avg_price, q.fill?.fee_usdt, q.fill?.filled_all);
const { status, filledSize } = await pax.orders.waitForFill(data, { marketId: 'hadjar-f1-2026', timeoutMs: 30_000 });
const res = await pub.markets.waitForSettlement('hadjar-f1-2026');   // until status "settled"

// Offline audit verification
console.log((await pub.audit.verify(110841)).ok);

// WebSocket streaming
import { PaxWSClient } from '@predictasiax/api';
const ws = new PaxWSClient({ apiKey: minted.api_key, subscribeOnConnect: ['fast_tick', 'account'] });
ws.on('fast_tick', (e) => console.log(e));
await ws.connect();
```

### Python 快速入門

```
# pip install "pax-api>=3"    (2.x cannot authenticate against the current gateway)
from pax_api import PaxClient

# 1. Public endpoints need no key; mint a sandbox key (api_key is shown once)
key = PaxClient().mint_sandbox_key(org_name="my-app")["data"]["api_key"]

# 2. Use the key: Authorization: Bearer sk_live_...
#    (or PaxClient(api_key=key, key_id="api_...") to HMAC-sign instead)
pax = PaxClient(api_key=key)
print(pax.get_balance())

# 3. Limit BUY of one outcome; client_order_id + Idempotency-Key fixed across retries
order = pax.place_order(market_id="hadjar-f1-2026", side="yes", price="0.05", size="20")

# Price an order first (public, nothing placed), then wait for the fill and the settlement.
# Both waits read the result over REST and ride out 429, 5xx and connection errors.
q = PaxClient().quote("hadjar-f1-2026", side="yes", amount=25)["data"]
print(q["fill"])
r = pax.wait_for_fill(order, market_id="hadjar-f1-2026", timeout=30)   # r["status"], r["filled_size"]
res = PaxClient().wait_for_settlement("hadjar-f1-2026")                 # until status "settled"

# Offline audit verification
print(PaxClient().verify_audit_event(110841)["ok"])

# WebSocket streaming (multiplexed subscriptions, sequence# gap detection)
from pax_api import PaxWSClient
ws = PaxWSClient(api_key=key)
ws.on("fast_tick", lambda evt: print("tick:", evt))
ws.subscribe(["fast_tick", "orderbook", "account"])
ws.run_forever()
```

直接下載（供氣隙環境 / 稽核檢視使用的鏡像；與 PyPI 上的檔案相同）：[pax_api-3.3.2-py3-none-any.whl](https://docs.predictasiax.com/downloads/sdk/python/pax_api-3.3.2-py3-none-any.whl)（SHA-256 `6be3f9ad00533b540728239b7ec133dcbfe8d118b3f3269b027765b659077bc3`）· [pax_api-3.3.2.tar.gz](https://docs.predictasiax.com/downloads/sdk/python/pax_api-3.3.2.tar.gz)（SHA-256 `c4ef72a0dbbe155f9a0c7ffd458211bb5de7198d5952b88a5bfe219fe3437c3a`）。

## 模擬伺服器 (Prism)

針對 OpenAPI 規格啟動本地模擬伺服器，以進行離線開發：

```
npm i -g @stoplight/prism-cli
prism mock https://docs.predictasiax.com/downloads/openapi.json
# → mock server on http://localhost:4010
```

Prism 會根據 OpenAPI 範例產生模擬回應——非常適合在沙盒存取權限配置完成前，用於 CI 或客戶端開發。

Source: https://docs.predictasiax.com/zh-hant/downloads
