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

# 价格与订单簿数据

> 通过 Prediction API 查询公开订单簿、Token 价格、Ticker、批量价格与价格历史。

每个 Market Outcome 都由一个 Token 表示。先通过「发现市场」或「市场详情」获取 `outcomes[].token_id`，再使用 Token ID 查询价格和流动性数据。

本页接口均为公开市场数据接口，无需认证。生产环境 Base URL：

```text theme={null}
https://api.dexbuilder.com
```

## 订单簿

```bash cURL theme={null}
curl "https://api.dexbuilder.com/api/v4/prediction/tokens/<token_id>/order_book?depth=20"
```

`depth` 为可选查询参数，默认返回每侧最多 20 档，可指定 1–100 档；实际档位数以 `bids`、`asks` 为准。

```json Example theme={null}
{
  "token_id": "token-yes",
  "condition_id": "0xabc...",
  "timestamp": null,
  "hash": null,
  "bids": [{ "price": "0.48", "size": "100.00" }],
  "asks": [{ "price": "0.52", "size": "80.00" }],
  "min_order_size": null,
  "tick_size": null,
  "neg_risk": null,
  "last_trade_price": null
}
```

| 字段 | 说明 |
| - | - |
| `token_id` | Outcome Token ID |
| `condition_id` | Market Condition ID |
| `bids`、`asks` | 买卖深度，每档包含 decimal string 格式的 `price` 与 `size` |
| `timestamp` | 来源提供的订单簿快照时间，Unix 毫秒；无可靠来源时为 `null` |
| `hash` | 来源提供的完整快照 Hash；无可靠来源时为 `null` |
| `min_order_size`、`tick_size`、`neg_risk` | 市场交易参数；无值时为 `null` |
| `last_trade_price` | 最新成交价；无可用成交价时为 `null` |

`timestamp` 和 `hash` 不会用服务器响应时间或推测值填充。订单簿被 `depth` 截断时，`hash` 如有值仍对应来源的完整快照。

当前 API 没有批量 Order Book 接口，如需多个 Token 的订单簿，应分别请求。

## 最新 Token 价格

```bash cURL theme={null}
curl "https://api.dexbuilder.com/api/v4/prediction/tokens/<token_id>/price"
```

```json theme={null}
{
  "token_id": "token-yes",
  "price": "0.50",
  "side": "BUY",
  "timestamp": 1782753357257
}
```

`price` 表示该 Outcome Token 的最新成交价，不是最佳买价或卖价。没有可用成交记录时，`price` 为 `""`、`side` 为 `""`，`timestamp` 为 `null`。

## Token Ticker

```bash cURL theme={null}
curl "https://api.dexbuilder.com/api/v4/prediction/tokens/<token_id>/ticker"
```

```json theme={null}
{
  "token_id": "token-yes",
  "last_price": "0.50",
  "best_bid": "0.48",
  "best_ask": "0.52",
  "timestamp": 1782753357257
}
```

`last_price`、`best_bid`、`best_ask` 分别表示最新成交价、最佳买价和最佳卖价；任一数据不可用时，对应字段为 `null`。`timestamp` 是返回的有效价格数据中最新的来源时间；没有可靠时间时为 `null`，不是服务器响应时间。

## 批量 Token 价格

通过逗号分隔的 Token ID 查询，单次最多支持 100 个不同 Token：

```bash cURL theme={null}
curl "https://api.dexbuilder.com/api/v4/prediction/tokens/prices?token_ids=token-yes,token-no"
```

```json theme={null}
{
  "items": [
    { "token_id": "token-yes", "price": "0.50", "timestamp": 1782753357257 },
    { "token_id": "token-no", "price": "0.50", "timestamp": 1782753357257 }
  ]
}
```

不存在或当前不可见的 Token 会被忽略，返回顺序保持与请求中的有效 Token 顺序一致。

批量接口同样返回最新成交价。可见 Token 尚无可用成交记录时，该项的 `price` 为 `""`、`timestamp` 为 `null`。

## 价格历史

```bash cURL theme={null}
curl "https://api.dexbuilder.com/api/v4/prediction/tokens/<token_id>/price_history?interval=1h&from=1782666000000&to=1782752400000"
```

| 参数 | 说明 |
| - | - |
| `interval` | `5m`、`15m`、`1h`、`4h`、`1d` |
| `from` | 开始时间，Unix 毫秒 |
| `to` | 结束时间，Unix 毫秒 |

`interval`、`from`、`to` 均为必填参数。单次查询时间范围最多 14 天。响应中的 `t` 为 Unix 毫秒，`p` 为价格字符串。

```json theme={null}
{
  "history": [
    { "t": 1782666000000, "p": "0.485" },
    { "t": 1782669600000, "p": "0.500" }
  ]
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.