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

# WebSocket 订单频道 - 快照、实时订单更新与恢复

> 在 Apexium API WebSocket 上跟踪您账户的订单：登录后的快照、每次变化一条消息，以及重连后用 sinceEventId 恢复。

`orders` 频道发送您 API 密钥所属账户的订单：登录后立即发送一份快照，之后订单每次变化都发送完整的订单。

## 快照

紧接在 `login_ok` 之后，您会收到：

```json theme={null}
{
  "channel": "orders",
  "type": "snapshot",
  "payload": { "eventId": 48213, "orders": [ { "id": "…", "version": 3, "…": "…" } ] },
  "ts": 1791413359090,
  "seq": 1
}
```

`orders` 包含每个进行中的订单，以及过去 24 小时内发生过变化的每个订单。每个订单的结构与 [`GET /v1/orders/{id}`](https://docs.apexiumbet.com/zh/api-reference/overview#订单) 相同。

## 变化

订单每次变化都会再次发送完整的订单：

```json theme={null}
{
  "channel": "orders",
  "type": "order",
  "payload": { "eventId": 48214, "order": { "id": "…", "version": 4, "status": "FILLED", "…": "…" } },
  "ts": 1791413359512,
  "seq": 2
}
```

变化是指让订单或其某个注单发生改变的任何事情：成交、拒绝、撤单、到期、结算或更正。

对于每个订单 `id`，保留 `version` 最高的订单，忽略 version 更低或相同的订单：同一个 version 可能到达两次。

## 恢复

`eventId` 用于恢复。请保存您收到的最高 `eventId`，包括快照中的那个。重连时，用它登录：

```json theme={null}
{ "type": "login", "apiKey": "apx_live_…", "receiveType": "zstd", "channels": ["orders"], "sinceEventId": 48214 }
```

* **在窗口内。** 错过的变化最多 1 000 个，且最早的一个不超过 10 分钟：发生过变化的订单会以 `order` 消息发送，之后是实时变化。不会发送快照。
* **在窗口外。** 您会收到 `{ "type": "snapshot_required", "reason": "resume_window_exceeded", "channels": ["orders"] }`，然后是一份新快照。请用它替换您持有的内容。

不带 `sinceEventId` 的登录总是从快照开始。

## 不订阅该频道时

在 `channels` 中列出频道但不含 `orders` 的登录不会收到这些内容。不带 `channels` 的登录覆盖所有频道，包括 `orders`。


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