# 实时K线（Candles）取消订阅

## API说明

展示如何在不断开Websocket连接的情况下，**全量取消**或者**只取消一部分**产品订阅           &#x20;

## 请求频率

同一个Websocket连接，所有的请求（订阅、取消订阅、心跳）限制为**1分钟60次**，如果超出请求频率限制将会自动断连。如果断连次数过多被系统判定为恶意请求将会封禁apikey。请在使用过程中注意调用逻辑。

## 错误码说明

参考[Websocket错误码说明](/getting-started/error-codes/websocket.md)

## 接口地址

请参考[Websocket订阅地址](/websocket-api/endpoints.md)

## 请求（协议号：11002）

```json
{
    "code": 11002,
    "trace": "423afec425004bd8a5e02e1ba5f9b2b0",
    "data": {
        "codes": "BTCUSDT",
        "klineTypes": "1,2,4"
    }
}
```

***解释：入参data或者codes、***&#x6B;lineType&#x73;***可以为null或者空。***

***如果获取不到codes的值，会进行全量取消，也就是说如果订阅了100个产品对的成交明细都会清除订阅数据，不会再进行推送；如果传了codes值，会根据所传的产品单独清除订阅数据，不会影响其他产品的数据推送***

***如果获取不到klineTypes的值，会清除所需产品的所有Kline类型（1分钟至1年k）；如果传了klineTypes值，会根据所传的k线类型清除对应的类型数据推送***

***例如：假设订阅了产品A、B的1分钟k和5分钟k，入参codes="A"，klineTypes="1"，则只会取消产品A的1分钟k线推送，不会影响产品A的5分钟k推送以及产品B的1分钟和5分钟k推送***

| 参数名           | 类型      | 必填 | 描述                  | 示例值                                |
| ------------- | ------- | -- | ------------------- | ---------------------------------- |
| `code`        | Integer | 是  | 请求的协议号              | 实时K线取消订阅协议号：`11002`                |
| `trace`       | String  | 是  | 可追溯ID（随机字符串）        | `423afec425004bd8a5e02e1ba5f9b2b0` |
| `data`        | JSON    | 否  | 取消订阅数据              |                                    |
| `＜codes`      | String  | 否  | 取消订阅产品，多个用逗号分隔      | `BTCUSDT`                          |
| `＜klineTypes` | String  | 否  | 取消订阅产品的k线类型，多个用逗号分隔 | 1,2                                |

## 应答（协议号：11010）

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

| 字段名     | 类型      | 必填 | 描述          | 示例值                                |
| ------- | ------- | -- | ----------- | ---------------------------------- |
| `code`  | Integer | 是  | 响应协议号       | 取消订阅实时k线响应协议号：`11010`              |
| `trace` | String  | 是  | 订阅传入参数可追溯id | `423afec425004bd8a5e02e1ba5f9b2b0` |
| `msg`   | String  | 是  | 响应          | `ok`                               |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.infoway.io/websocket-api/unsubscribe/trade-subscribe-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
