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

# 公共頻道

> 訂閱事件合約公開成交、深度、BBO、價格和市場狀態。

公共頻道無需認證。

**連線位址**

```text theme={null}
wss://broker.dexbuilder.com/ws/dex-builder/event-contracts
```

## 訂閱

```json theme={null}
{
  "t": 1720000000123,
  "id": "sub-1",
  "op": "subscribe",
  "ch": "ec.trades",
  "payload": {
    "items": [
      {
        "condition_id": "ge_condition-1"
      }
    ]
  }
}
```

伺服器會先回傳 ACK。有快取狀態的頻道可能回傳 `snapshot`；`trades` 頻道只推送 `update`。後續訊息使用 `type: "update"`。

## `ec.trades`

使用 `condition_id` 訂閱。

**回應範例**

```json theme={null}
{
  "t": 1720000000124,
  "trace_id": "trace-1",
  "type": "update",
  "ch": "ec.trades",
  "err": null,
  "result": {
    "condition_id": "ge_condition-1",
    "token_id": "ge_token-yes",
    "outcome": "Yes",
    "side": "BUY",
    "px": "0.45",
    "qty": "10",
    "ts": 1720000000123
  }
}
```

## `ec.depth`

使用 `token_id` 和 `level` 訂閱，支援 5、10、20、50。回傳的是完整訂單簿，而非增量資料。

**回應範例**

```json theme={null}
{
  "t": 1720000000124,
  "trace_id": "trace-1",
  "type": "snapshot",
  "ch": "ec.depth",
  "err": null,
  "result": {
    "token_id": "ge_token-yes",
    "level": 20,
    "full": true,
    "bids": [
      ["0.44", "100"]
    ],
    "asks": [
      ["0.46", "80"]
    ],
    "hash": "book-hash",
    "ts": 1720000000123
  }
}
```

## `ec.bbo`

使用 `token_id` 訂閱。

**回應範例**

```json theme={null}
{
  "t": 1720000000124,
  "trace_id": "trace-1",
  "type": "update",
  "ch": "ec.bbo",
  "err": null,
  "result": {
    "condition_id": "ge_condition-1",
    "token_id": "ge_token-yes",
    "bid_px": "0.44",
    "ask_px": "0.46",
    "last_px": "0.45",
    "ts": 1720000000123
  }
}
```

## `ec.status`

使用 `market_id` 訂閱。

**回應範例**

```json theme={null}
{
  "t": 1720000000124,
  "trace_id": "trace-1",
  "type": "update",
  "ch": "ec.status",
  "err": null,
  "result": {
    "market_id": "ge_market-1",
    "condition_id": "ge_condition-1",
    "slug": "example-market",
    "status": "ACTIVE",
    "closed": false,
    "accepting_orders": true,
    "outcomes": [
      {
        "name": "Yes",
        "token_id": "ge_token-yes",
        "px": "0.45"
      },
      {
        "name": "No",
        "token_id": "ge_token-no",
        "px": "0.55"
      }
    ],
    "ts": 1720000000123
  }
}
```

## `ec.cpi`

使用 `symbol` 和 `interval` 訂閱。

**回應範例**

```json theme={null}
{
  "t": 1720000000124,
  "trace_id": "trace-1",
  "type": "update",
  "ch": "ec.cpi",
  "err": null,
  "result": {
    "symbol": "btcusdt",
    "interval": "1m",
    "price": "100000.10",
    "price_timestamp": "1720000000123",
    "ts": 1720000000123
  }
}
```

## `ec.candlestick`

使用 `symbol` 和 `interval` 訂閱。

**回應範例**

```json theme={null}
{
  "t": 1720000000124,
  "trace_id": "trace-1",
  "type": "update",
  "ch": "ec.candlestick",
  "err": null,
  "result": {
    "symbol": "btcusdt",
    "interval": "1m",
    "t": 1720000000,
    "o": "100000.00",
    "h": "100010.00",
    "l": "99990.00",
    "c": "100005.00",
    "v": "0",
    "closed": false
  }
}
```

快取的 K 線快照包含 `symbol`、`interval` 和 `history`。

## `ec.oc_price`

使用 `slug` 或 `market_id` 訂閱。已設定的幣價時間窗也可以使用 `symbol` 和 `interval`。

**回應範例**

```json theme={null}
{
  "t": 1720000000124,
  "trace_id": "trace-1",
  "type": "update",
  "ch": "ec.oc_price",
  "err": null,
  "result": {
    "slug": "bitcoin-up-or-down",
    "price_to_beat": "100000.00",
    "final_price": "100120.00"
  }
}
```

除非欄位明確標示為秒，否則時間戳均為 Unix 毫秒時間戳。


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