> ## 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.