# K线获取

## 接口说明

注意：此包回包服务端对于整包进行libz压缩

## 请求-协议号：14012

### 数据格式:json

### 数据结构

#### data定义

| 字段                    | 名称     | 类型     | 必填项 | 说明                                                                                                                                                                                                                     |
| --------------------- | ------ | ------ | --- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| symbol\_id            | 产品ID   | uint64 | 是   |                                                                                                                                                                                                                        |
| trade\_type           | 交易类型   | uint32 | 是   | 1:全仓合约,2:逐仓合约,3:杠杆,5:现货,6:股票                                                                                                                                                                                           |
| trade\_mode           | 交易模式   | uint32 | 是   | 1:MM,2:蝴蝶MM,3:撮合,4:聚合                                                                                                                                                                                                  |
| kline\_type           | k线类型   | uint32 | 是   | 1分钟K，2为5分钟K，3为15分钟K，4为30分钟K，5为小时K，6为2小时K，7为4小时K，8为日K，9为周K，10为月K                                                                                                                                                        |
| kline\_timestamp\_end | 线结束时间戳 | uint64 | 否   | 单位秒                                                                                                                                                                                                                    |
| query\_kline\_num     | 查询K线数量 | uint32 | 是   | <p>kline\_timestamp\_end为0，query\_kline\_num不为0，查询当前最新的query\_kline\_num条K线（包含当前K线）<br>kline\_timestamp\_end不为0，query\_kline\_num不为0，查询从kline\_timestamp\_end开始往前的query\_kline\_num条K线<br>其他情况，该接口直接返回错误，表示查询业务不支持</p> |

### 请求示例

```json
{
    "cmd_id":14012,
    "seq_id":123,
    "ext":"3baaa938-f92c-4a74-a228-fd49d5e2f8bc-1678419657806",
    "data":{
        "symbol_id": 1,
        "trade_type": 1,
        "trade_mode": 0,
        "kline_type": 1,
        "kline_timestamp_end": 1605509068,
        "query_kline_num": 100,
    }
}
```

## 应答-协议号：14013

### 数据格式:json

### 数据结构

#### data定义

| 字段            | 名称    | 类型     | 说明                                                              |
| ------------- | ----- | ------ | --------------------------------------------------------------- |
| symbol\_id    | 产品ID  | uint64 |                                                                 |
| trade\_type   | 交易类型  | uint32 | 1:全仓合约,2:逐仓合约,3:杠杆,5:现货,6:股票                                    |
| trade\_mode   | 交易模式  | uint32 | 1:MM,2:蝴蝶MM,3:撮合,4:聚合                                           |
| kline\_type   | k线类型  | uint32 | 1分钟K，2为5分钟K，3为15分钟K，4为30分钟K，5为小时K，6为2小时K，7为4小时K，8为日K，9为周K，10为月K |
| price\_digits | 价格小数位 | uint32 |                                                                 |
| kline\_list   | K线列表  | array  | 具体格式见下面kline\_list定义                                            |

#### kline\_list定义

| 字段                   | 名称              | 类型     | 说明   |
| -------------------- | --------------- | ------ | ---- |
| timestamp            | 该K线的时间戳         | uint64 | 单位秒  |
| open\_price          | 该K线开盘价          | string |      |
| close\_price         | 该K线收盘价          | string |      |
| high\_price          | 该K线最高价          | string |      |
| low\_price           | 该K线最低价          | string |      |
| last\_tick\_time     | 该K线的最后一口tick的时间 | uint64 | 单位毫秒 |
| last\_tick\_seq      | 该K线的最后一口tick的序号 | uint64 |      |
| transactions\_number | 该K线成交数量         | string |      |

### 应答示例

```json
{
    "ret":200,
    "msg":"ok",
    "cmd_id":14013,
    "seq_id":123,
    "ext":"3baaa938-f92c-4a74-a228-fd49d5e2f8bc-1678419657806",
    "data":{
        "symbol_id": 1123,
        "trade_type": 1,
        "trade_mode": 0,
        "kline_type": 1,
        "price_digits": 2,
        "kline_list":[
            {
                "timestamp": 1605509068,
                "open_price": "651.12",
                "close_price": "623.12",
                "high_price": "674.12",
                "low_price": "619.12",
                "last_tick_time": 1605509068000001,
                "last_tick_seq": 1605509068000001,
                "transactions_number": "12345.6",
            },
        ]
    }    
}
```


---

# 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-cn.multimarkets.org/client-api/bao-jia-jie-kou/cha-xun-jie-kou/k-xian-huo-qu.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.
