> 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/getting-started/api-protocols-and-response-formats.md).

# 请求协议以及响应格式

包括HTTP请求以及WEBSOCKET请求

### 1. HTTP

#### 1.1 请求方法

**不是**所有 HTTP 接口都是 GET。

| 类型                       | 方法     | 说明                                        |
| ------------------------ | ------ | ----------------------------------------- |
| 成交明细、盘口、基础信息、套餐、财务 / 基本面 | `GET`  | 参数在 Path / Query                          |
| 历史 / 实时 K 线 v2           | `POST` | 路径 `/{market}/v2/batch_kline`，Body 为 JSON |

月归档下载同样使用 `POST` + JSON Body：`/kline/archive/download`，详见 [K 线月归档下载](/rest-api/http-endpoints/post-kline-archive-download.md)。

请求头固定带 API Key：

| Header   | 必填 | 说明                      |
| -------- | -- | ----------------------- |
| `apiKey` | 是  | 套餐 API Key。也接受 `apikey` |

#### 1.2 响应格式

```json
{
    "ret": 200,
    "msg": "success",
    "traceId": "698f920a-c53b-401c-bfac-4ea46b9b8f12",
    "data": []
}
```

| 字段        | 说明                                                               |
| --------- | ---------------------------------------------------------------- |
| `ret`     | 业务码。`200` 成功，其他见 [HTTP错误码](/getting-started/error-codes/http.md) |
| `msg`     | 状态说明，例如 `success`                                                |
| `traceId` | 系统生成的唯一追踪 ID（不是 `tradeId`）                                       |
| `data`    | 业务数据，结构随接口变化                                                     |

行情失败常见 **HTTP 200 + `ret=5xx`**。请先读 `ret` / `msg`，不要只看 HTTP 状态。

### 2. WebSocket

行情共用：

```
wss://data.infoway.io/ws?business={stock|crypto|common|japan|india|korea|taiwan}&apikey=<key>
```

用 `business` 区分市场，不是多套 Host。

新闻是独立地址，不带 `business`：

```
wss://data.infoway.io/news?apikey=<key>
```

连上后 `business=stock` 可能先收到纯文本欢迎语，再收到 `{"code":200,"msg":"ws connect success"}`。`200` 表示连接成功。

数字币和 `common` 通道的订阅失败可能是 `Subscribe fail:` 前缀加 JSON。客户端应先识别文本类型/前缀，再解析 JSON；连接成功不等于订阅成功。

心跳、订阅限制见 [WebSocket限制](/getting-started/api-limitation/websocket.md) 与 [心跳机制](/websocket-api/heartbeat.md)。地址见 [行情地址说明](/getting-started/api-endpoints.md)。HTTP 频率见 [HTTP接口限制](/getting-started/api-limitation/http.md)。
