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

# 消息协议

> 了解事件合约 WebSocket 的请求、ACK、推送和订阅格式。

消息使用 JSON。请求中的 `t` 必须与服务端时间相差不超过 60 秒，`id` 必须是字符串或整数。

## 订阅

```json theme={null}
{
  "t": 1720000000123,
  "id": "req-1",
  "op": "subscribe",
  "ch": "ec.depth",
  "payload": {
    "items": [
      {
        "token_id": "ge_token-yes",
        "level": 20
      }
    ]
  }
}
```

取消订阅时使用相同的频道和 payload，并将 `op` 设置为 `unsubscribe`。私有频道还需要 `auth`；私有频道支持 `{"all": true}`，公共频道必须使用 `items`。

## ACK

成功：

```json theme={null}
{
  "t": 1720000000124,
  "id": "req-1",
  "trace_id": "trace-1",
  "op": "subscribe",
  "ch": "ec.depth",
  "err": null,
  "result": {
    "status": "success"
  }
}
```

失败：

```json theme={null}
{
  "t": 1720000000124,
  "id": "req-1",
  "trace_id": "trace-1",
  "op": "subscribe",
  "ch": "ec.depth",
  "err": {
    "code": 2,
    "msg": "invalid depth item"
  },
  "result": {
    "status": "fail"
  }
}
```

## 快照和更新

缓存的初始数据使用 `type: "snapshot"`，后续事件使用 `type: "update"`。消息包含 `ch`、`err: null` 和频道对应的 `result`。

单次请求最多 100 个订阅项，单连接最多 10,000 个订阅。重连后需要重新订阅；私有频道应通过 REST 接口恢复账户当前状态。


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