# 快速入门

5 分钟内下出你的第一笔预测市场订单。全部使用 curl——无需 SDK。

**以下所有 curl 命令均针对真实的线上 API 运行。**你将在第 1 步中铸造一个匿名沙盒密钥(耗时 30 秒，无需邮箱)。沙盒等级将单笔订单限制在 $10，每日限制在 $100，因此你输入的任何内容都不会动用真实资金。订单会经过与生产环境相同的验证和等级限制，然后在模拟中成交：密钥初始拥有 1,000 虚拟 USDT，且响应中带有 `is_simulated: true`。

## 步骤 1 — 生成沙盒密钥

公开接口，无需身份验证。速率限制为每个 IP 每天 1 次铸造 + 每个浏览器指纹每天 1 次。

```
curl -X POST https://api.predictasiax.com/v1/sandbox-keys \
  -H "Content-Type: application/json" \
  -d '{"org_name":"my-test"}'
```

响应 — 请立即复制 `sk`，仅显示一次：

```
{
  "data": {
    "sk":            "sk_live_7d40ce10_12b638913cadfbbd...",   // your bearer, shown ONCE
    "api_key_id":    "api_sbx_...",
    "builder_id":    "bld_sbx_...",
    "app_id":        "app_sbx_...",
    "tier":          "sandbox",
    "caps":          { "max_order_usdt": "10", "daily_notional_usdt": "100" },
    "expires_at_ms": 1789741484472,                            // 30 days out
    "sandbox_url":   "https://api.predictasiax.com",
    "docs_url":      "https://docs.predictasiax.com/getting-started",
    "upgrade_url":   "https://docs.predictasiax.com/request-access"
  },
  "meta": { "ts_ms": 1787149484561, "trace_id": "trc_..." }
}

# Save it:
export SK=sk_live_7d40ce10_12b638913cadfbbd...
```

如果沙盒密钥泄露，请使用该密钥本身进行吊销：`curl -X DELETE https://api.predictasiax.com/v1/keys/self -H "Authorization: Bearer $SK"`。

该密钥属于一个新创建的匿名 Builder，标记为 `tier=sandbox`，并在创建后 30 天过期。它是一个 `sk_live_` 前缀，在生产环境被接受——tier 标志将订单硬性限制为每单 $10 且每日名义金额 $100。

## 步骤 2 — 获取市场列表

市场是 predictasiax.com 上的实时市场。选择一个并保留其 `id` 用于下一步 (`MARKET_ID=...`):

```
curl "https://api.predictasiax.com/v1/markets?q=btc" \
  -H "Authorization: Bearer $SK"
```

响应 (已精简):

```
{
  "data": {
    "markets": [
      {
        "id":        "m_btc_150k_2026",
        "title":     "BTC > $150k by end of 2026",
        "category":  "crypto",
        "prices":    { "yes": "0.4200", "no": "0.5800" },
        "volume_usd":"12345.67",
        "status":    "open",
        "closes_at_ms": 1798700400000
      }
    ]
  }
}
```

## 步骤 3 — 下 $1 订单

以 $0.55 买入 2 份 `yes` 份额 = $1.10 名义金额 — 远低于沙盒 $10 上限。写入请求必须携带 `Idempotency-Key`，且必须符合 `[A-Za-z0-9_-]{8,128}`；使用相同值重试是安全的。

```
IDEM=$(uuidgen | tr -d '-' | cut -c1-24)
curl -X POST https://api.predictasiax.com/v1/orders \
  -H "Authorization: Bearer $SK" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: ${IDEM}" \
  -d '{
    "market_id":       "'"$MARKET_ID"'",
    "side":            "yes",
    "price":           "0.55",
    "size":            "2",
    "client_order_id": "cli-001"
  }'
```

**订单规则。** `size` 是普通十进制数，最多 6 位小数；`price` 范围是 0.0001–0.9999，最多 4 位小数（拒绝指数形式数字，如 `1e-7`）。在普通市场中，`limit` 和 `post_only` 价格必须位于 tick 网格上：0.04 到 0.96 之间步长为 0.01，低于 0.04 和高于 0.96 步长为 0.001；不在网格上的订单将被拒绝，返回 `rejectReason: invalid_tick` 及适用的 `tick`。订单名义金额 `size × price` 必须在 1 到 100,000 USDT 之间。不符合这些规则的订单返回 `400 INVALID_FIELD`、`BELOW_MIN_NOTIONAL` 或 `ABOVE_MAX_NOTIONAL`。

使用沙盒密钥时，订单将被模拟。若价格等于或高于市场当前价格，则按该价格成交；若低于当前价格，则挂单（`status: "open"`，金额保留在 `reserved_usdt` 中），并在价格达到你的限价时成交。此检查在你读取订单、持仓、余额或投资组合时触发：

```
{
  "data": {
    "order_id":           "sbx_ord_...",
    "client_order_id":    "cli-001",
    "market_id":          "...",
    "side":               "yes",
    "limit_price":        "0.55",
    "size":               2,
    "filled_size":        2,
    "status":             "filled",
    "fill_price":         "0.42",
    "fill_notional_usdt": "0.84",
    "reserved_usdt":      "0",
    "is_simulated":       true
  },
  "meta": { "trace_id": "...", "is_simulated": true }
}
```

如果虚拟余额不足以覆盖订单，则不会创建该订单：`{"data": {"ok": false, "status": "REJECTED", "reject_reason": "insufficient_balance", ...}}`。使用 `DELETE /v1/orders/{order_id}` 取消订单（预留资金将退回）。沙盒中的持仓按当前价格标记，且在市场结算时不进行结算。

对于具有余额的生产密钥，成交会返回订单及其手续费拆分（示意——确切的 `splits` 块由 PAX 自适应手续费曲线在成交时于服务端推导）：

```
{
  "data": {
    "order": {
      "order_id":     "ord_...",
      "status":       "filled",
      "filled_size":  "2",
      "fill_price":   "0.4200",
      "created_at_ms":1787149484561
    },
    "fee": {
      "taker_fee_bps":   20,                // PAF centre at 50/50, floor 8, ceiling 25
      "fee_total":       "0.001680",        // 20 bps of $0.84 notional
      "splits": {
        "acquisition_builder": "0.000000",  // unfilled → absorbed by platform_net
        "execution_builder":   "0.000000",  // 0 bps — builders earn their builder fee instead
        "operator":            "0.000000",  // 0 bps — PAX is the only operator; carried in platform_net
        "market_creator":      "0.000000",  // unfilled → absorbed by platform_net
        "mm_stipend_pool":     "0.000420",  // 5 bps — funds LQF-scored MM stipends
        "lp":                  "0.000168",  // 2 bps — pooled LP holder distribution
        "platform_net":        "0.001092"   // 10 bps residual + 3 (mc absorbed)
      },
      "attribution": {
        "execution_builder_id":   "sb_d5b09d2a...",   // your builder
        "acquisition_builder_id": null,
        "operator_id":            "op_pax_v3",
        "market_creator_id":      null,
        "builder_tier":           "trade_capped",
        "unfilled_roles":         ["acquisition_builder","market_creator"]
      }
    }
  }
}
```

`splits` 块通过 7 方 PAF 拆分（acquisition_builder / execution_builder / operator / market_creator / mm_stipend_pool / lp / platform_net）在平台账本上写入幂等的 `financial_event` 行。未分配的归因角色由 `platform_net` 吸收，以保护收入。**自适应 Taker 手续费**：`feeBps = clamp(PAF_BASE_BPS · 4 · p · (1−p), PAF_FLOOR_BPS, PAF_CEILING_BPS)`，基础值 20，下限 8，上限 25 —— 在 50/50 附近达到峰值，在极端情况下降低。完整模型和分桶比例见 [手续费架构](https://docs.predictasiax.com/zh-hans/fee-architecture)。

## 步骤 4 — 超出上限的请求 (查看等级上限的实际表现)

尝试一个超过 $10 的订单：

```
IDEM=$(uuidgen | tr -d '-' | cut -c1-24)
curl -X POST https://api.predictasiax.com/v1/orders \
  -H "Authorization: Bearer $SK" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: ${IDEM}" \
  -d '{
    "market_id":"'"$MARKET_ID"'",
    "side":"yes","price":"0.50","size":"100",
    "client_order_id":"too-big"
  }'
```

响应 — 429 `TIER_LIMIT_EXCEEDED`：

```
{
  "error": {
    "code":    "TIER_LIMIT_EXCEEDED",
    "message": "order notional 50.00 exceeds tier max_order_usdt 10",
    "details": { "tier": "sandbox", "cap": "10" }
  }
}
```

要解除限制并进行真实交易，请获取生产密钥（[申请访问](https://docs.predictasiax.com/zh-hans/request-access)，无需审核）并路由交易量——它会自动升级。当 30 天归因交易量达到 $1,000 时，`trade_capped`（$100/订单，$1k/天）解锁；达到 $50,000 时，`trade_full`（无限制）解锁。无需升级请求，无需人工步骤——参见 [速率限制 → 提升等级](https://docs.predictasiax.com/zh-hans/rate-limits#upgrade)。

## 第 5 步 — 读取你的投资组合

```
curl "https://api.predictasiax.com/v1/portfolio" \
  -H "Authorization: Bearer $SK"
```

返回你的持仓，并重新计算标记价格 (即时计算未实现盈亏)。

## 步骤 6 — 撤销订单

两种等效形式——在你的客户端中选择更简洁的一种：

```
# Canonical
curl -X DELETE https://api.predictasiax.com/v1/orders/ord_... \
  -H "Authorization: Bearer $SK"

# Alias (useful when your HTTP client can't send DELETE)
curl -X POST https://api.predictasiax.com/v1/orders/ord_.../cancel \
  -H "Authorization: Bearer $SK"
```

已成交订单返回 `STATE_CONFLICT`（无法取消已成交订单）；未成交订单状态变更为 `cancelled`。

## 后续步骤

- [身份验证指南](https://docs.predictasiax.com/zh-hans/auth) — Bearer sk_live_* + OAuth 2.1
- [REST API 参考](https://docs.predictasiax.com/openapi) — 完整模式 + 验证器接口
- [WebSocket API 参考](https://docs.predictasiax.com/asyncapi) — 事件目录
- [错误代码](https://docs.predictasiax.com/zh-hans/errors) — 优雅地处理失败
- [速率限制](https://docs.predictasiax.com/zh-hans/rate-limits) — 各权限范围的预算，在所有等级中保持一致
- [手续费架构](https://docs.predictasiax.com/zh-hans/fee-architecture) — PAF + LQF + 7 方分成
- [FAQ](https://docs.predictasiax.com/zh-hans/faq)
- [下载](https://docs.predictasiax.com/zh-hans/downloads) — OpenAPI / AsyncAPI 规范 + Postman 集合

**准备上线生产环境？** 主机和基础 URL 相同 — `https://api.predictasiax.com/v1`。提交 [申请访问权限](https://docs.predictasiax.com/zh-hans/request-access) 可将你的 Builder 从 `sandbox` 迁移至 `trade_capped` 或 `trade_full` 等级。无需切换环境或轮换密钥。

Source: https://docs.predictasiax.com/zh-hans/getting-started
