> 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/getting-started/error-codes/websocket-error-codes.md).

# WebSocket Error Codes

Business errors commonly arrive as JSON in a WS text frame: `{"code":506,"msg":"...","traceId":"..."}`. Errors use `traceId`; successful subscription acknowledgements use `trace`. Some rejections have a `Subscribe fail:` prefix, and some errors are plain text. Handle all of these forms.

**Do not interpret them with the REST `ret` table.** REST `508` means the symbol is missing; WS `508` means the API key expired. REST: [REST API Error Codes](/en-docs/getting-started/error-codes/rest-api-error-codes.md). Limits: [WebSocket Limitation](/en-docs/getting-started/api-limitation/websocket-limitation.md).

Subscribe acks `10001` / `10004` / `10007` with `msg=ok` only mean the frame was accepted. A wrong `business` for the symbol can still ack and then never push.

The welcome frame `{"code":200,"msg":"ws connect success"}` is **not** an error. `business=stock` may also send a plaintext greeting first.

### Subscribe rejections: prefixed, not bare JSON

Some subscription rejections arrive as a **text frame starting with `Subscribe fail:` followed by one space**. Running `JSON.parse` / `json.loads` on the whole frame throws. If your code silently drops frames it cannot parse, the symptom is "connected, subscribe sent, but no market data and no error at all".

Common shapes are shown below. The `stock` channel prefixes quota errors; `crypto` and `common` return bare JSON for `505` and `516`. Free-plan symbol-permission errors (`521`) use the prefix:

| Condition                                               | Frame                                                                                                             |
| ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| Symbols on this connection exceed the limit (505)       | `Subscribe fail: {"traceId":"...","code":505,"msg":"Single WS subscribe exceeds the limit 200"}`                  |
| Total symbols across connections exceed the limit (516) | `Subscribe fail: {"traceId":"...","code":516,"msg":"All WS subscribe exceeds the limit 6000"}`                    |
| `business` does not match the symbol type               | `Subscribe fail: Some product is not stock product like:BTCUSDT.Business stock can only subscribe stock products` |
| Market not included in your plan                        | `Subscribe fail: No access to the following market data:JP`                                                       |

Free-plan symbol-permission example:

```
Subscribe fail: {"traceId":"request-1","code":521,"msg":"No permission：<symbol>"}
```

Error JSON uses **`traceId`**. During market-data subscription, `521` means symbol permission is missing; its separate news-handshake meaning is listed below. If a request contains a symbol without permission, that entire subscription request is rejected.

Recommended handling:

1. Check whether the text starts with `Subscribe fail:`; if so, strip that prefix and the following space. Otherwise inspect the original text directly.
2. If the remainder starts with `{`, parse it as JSON and read `code` against the table below. Otherwise pass the whole remainder up as the error message.
3. **Do not resend the same subscribe as-is.** Wrong `business`, missing market or symbol entitlement (including 521), and 505 fail identically no matter how many times you retry. 516 may be retried with backoff, but retry frames also count against the 60 requests per minute budget (see [WebSocket Limitation](/en-docs/getting-started/api-limitation/websocket-limitation.md)) — unthrottled resends trigger `501`, the server closes the connection, the client reconnects, hits the limit again, and loops.

### Application codes

| code | Meaning                                                 | English `msg`                                          |
| ---- | ------------------------------------------------------- | ------------------------------------------------------ |
| 200  | Connected (welcome)                                     | ws connect success                                     |
| 500  | Server error                                            | server error                                           |
| 501  | Per-minute request limit (includes heartbeats, 60/min)  | Request frequency exceed the limit：%s times per minute |
| 502  | Daily request limit                                     | Request frequency for the day upper limit：%s           |
| 503  | Candlestick count exceeds the limit                     | Kline quantity exceeds the limit：%s                    |
| 504  | Order-book depth exceeds the limit                      | Orderbook depth exceeds the limit：%s                   |
| 505  | Symbols on this connection exceed the limit             | Single WS subscribe exceeds the limit %s               |
| 506  | Parameter error                                         | Param error：%s                                         |
| 507  | Required parameter missing                              | Param lost：%s                                          |
| 508  | API key permission expired                              | The apiKey permission has expired                      |
| 509  | API key invalid                                         | The apiKey is invalid                                  |
| 510  | API key empty                                           | The apiKey is empty                                    |
| 511  | API key blacklisted                                     | The apiKey is in the blacklist                         |
| 512  | WebSocket connection count exceeds the plan             | WebSocket connections exceeds the limit：%s             |
| 513  | Heartbeat timeout                                       | Websocket heartbeat timeout                            |
| 514  | Wrong WebSocket URL                                     | Websocket Url Wrong                                    |
| 515  | Payload is not JSON                                     | Param not json，request failed                          |
| 516  | Total symbols across connections exceed the limit       | All WS subscribe exceeds the limit %s                  |
| 521  | Free-plan symbol permission missing during subscription | No permission：%s                                       |

For malformed JSON, `crypto` and `common` can send the plain text `Param not json，request failed` without `code:515`. API-key expiry can also be reported as plain text before disconnection. Listed codes do not guarantee that every channel or stage sends that JSON form.

There is no `427`. Connection limits can surface as application `512`, news-handshake `521`, or gateway HTTP `429`; interpret them in context.

### Handshake extras

News / Korea / Taiwan ports may also return:

| code | Meaning                                                                                                      |
| ---- | ------------------------------------------------------------------------------------------------------------ |
| 517  | Handshake API key missing                                                                                    |
| 518  | API key does not exist                                                                                       |
| 519  | No permission (news entitlement; Korea subscribe permission)                                                 |
| 520  | Korea/Taiwan: suffix does not match the market (`.KS` / `.TW`); news: this key already has a news connection |
| 521  | News handshake: server connection cap                                                                        |

A key without news access may also fail the `/news` HTTP handshake with **401**.

### Gateway / CDN

| HTTP status | Meaning               |
| ----------- | --------------------- |
| 401         | Handshake auth failed |
| 404         | Path not found        |
| 429         | Gateway rate limit    |
| 499         | Client disconnect     |
| 524         | Origin timeout        |
