> For the complete documentation index, see [llms.txt](https://docs.infoway.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.infoway.io/en-docs/websocket/heartbeat.md).

# Heartbeat

### Overview

Market-data clients must send application heartbeats using `10010`, recommended every **30 seconds**. On the `stock`, `crypto`, and `common` channels, more than **60 seconds** without a valid `10010` causes the connection to close on a subsequent heartbeat check.

A WebSocket protocol Ping can receive a Pong, but it does not replace `10010` on these channels. Receiving market data or sending subscription requests also does not replace the application heartbeat.

`ack` is optional:

* Omit or `0`: keepalive only; the server does not reply.
* `ack=1` (top-level or `data.ack`): the server replies with `10011`. **`10011` is not an error.** It confirms receipt of the heartbeat. If both locations contain `ack`, the top-level value takes precedence.

Heartbeats count toward the 60 frames/minute cap. See [WebSocket Limitation](/en-docs/getting-started/api-limitation/websocket-limitation.md).

### Rate limits

Subscribe + unsubscribe + heartbeat on one connection: **60 per minute** ([WebSocket Limitation](/en-docs/getting-started/api-limitation/websocket-limitation.md)). Over the limit the socket is closed. Repeated abuse may suspend the API key.

### Error codes

See [WebSocket Error Codes](/en-docs/getting-started/error-codes/websocket-error-codes.md). Timeout is `513`.

### Address

See [Endpoints](/en-docs/getting-started/endpoints.md).

### Request (protocol 10010)

```json
{
    "code": 10010,
    "trace": "423afec425004bd8a5e02e1ba5f9b2b0"
}
```

When a reply is needed:

```json
{
    "code": 10010,
    "trace": "423afec425004bd8a5e02e1ba5f9b2b0",
    "ack": 1
}
```

| Field   | Type    | Required | Description                 | Example                            |
| ------- | ------- | -------- | --------------------------- | ---------------------------------- |
| `code`  | Integer | Yes      | Heartbeat `10010`           | `10010`                            |
| `trace` | String  | Yes      | Trace id                    | `423afec425004bd8a5e02e1ba5f9b2b0` |
| `ack`   | Integer | No       | `1` requests a confirmation | `1`                                |

### Reply (protocol 10011, only when ack=1)

```json
{
    "code": 10011,
    "trace": "423afec425004bd8a5e02e1ba5f9b2b0",
    "msg": "ok"
}
```

| Field   | Type    | Description                 | Example                            |
| ------- | ------- | --------------------------- | ---------------------------------- |
| `code`  | Integer | Heartbeat ack, not an error | `10011`                            |
| `trace` | String  | Echo of the request         | `423afec425004bd8a5e02e1ba5f9b2b0` |
| `msg`   | String  | `ok`                        | `ok`                               |
