# 下载

机器可读规范 + Postman 集合。自行生成 SDK，或导入任何 HTTP 工具。

## OpenAPI 3.1 (REST)

公开 REST 规范 — **21 个标签组，共 209 个路径 / 240 个操作**：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 频道列表与实时网关 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 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 集合

PredictAsiaX 已[发布在 Postman 的 Public Workspace 中](https://www.postman.com/predictasiax-2938441/predictasiax-api)。将其 Fork 到你自己的 Postman workspace 中，随着我们更新 spec，它会保持同步：

- **工作区**: `PredictAsiaX API` · 1 个集合 + 2 个环境 (production + sandbox)。
- **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` |
| 前往 | 通过 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-hans/downloads
