> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tickdb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 歷史 K 線

> 獲取已結束時間週期的歷史 K 線數據。

## 注意事項

* 本接口返回已結束週期的歷史K線數據，數據已固定不會變化
* 適用於策略回測、技術指標計算、數據歸檔存儲
* 若需獲取當前週期內正在更新的K線，請使用實時K線：`/v1/market/kline/latest`

## 支持的市場

**外匯**、**貴金屬**、**指數**、**美股**、**港股**、**A股**、**中國期貨**、**加密貨幣**

示例：

* 外匯：EURUSD、GBPUSD、USDJPY
* 貴金屬：XAUUSD、XAGUSD
* 指數：SPX、NDX、DJI
* 美股：AAPL.US、TSLA.US、MSFT.US
* 港股：700.HK、9988.HK、3690.HK
* A股：600519.SH、000001.SZ、920186.BJ
* 中國期貨：BU2609、IC2606、AP8888
* 加密貨幣：BTCUSDT、ETHUSDT、ADAUSDT

## 請求參數

| 參數名         | 是否必須 | 描述                                                                                                       |
| ----------- | ---- | -------------------------------------------------------------------------------------------------------- |
| symbol      | 是    | 交易產品代碼                                                                                                   |
| interval    | 是    | K線週期，可選值：1m, 5m, 15m, 30m, 1h, 2h, 4h, 1d, 1w, 1M                                                        |
| limit       | 否    | 返回記錄數，默認100，最大1000                                                                                       |
| start\_time | 否    | 開始時間戳（毫秒）                                                                                                |
| end\_time   | 否    | 結束時間戳（毫秒）                                                                                                |
| type        | 否    | 產品類型，可選。代碼無歧義時無需傳遞；若返回 `AMBIGUOUS_SYMBOL` 錯誤，按提示傳入對應值即可。可選值：`stock`、`indices`、`crypto`、`forex`、`futures` |

## 返回字段說明

| 字段                | 說明          |
| ----------------- | ----------- |
| symbol            | 交易產品        |
| type              | 產品類型        |
| interval          | K線週期        |
| klines            | K線數據數組      |
| └─ time           | K線時間戳（毫秒）   |
| └─ open           | 開盤價         |
| └─ high           | 最高價         |
| └─ low            | 最低價         |
| └─ close          | 收盤價         |
| └─ volume         | 成交量         |
| └─ quote\_volume  | 成交額，期貨通常不返回 |
| └─ open\_interest | 持倉量，僅期貨返回   |


## OpenAPI

````yaml GET /v1/market/kline
openapi: 3.0.0
info:
  title: TickDB API
  description: >-
    Unified real-time market data API — one connection for Forex, indices, US
    stocks, HK stocks, A-shares, China futures, and Crypto via REST and
    WebSocket.
  version: 1.0.2
  contact:
    email: support@tickdb.ai
servers:
  - url: https://api.tickdb.ai
    description: Production server
security:
  - ApiKeyAuth: []
paths:
  /v1/market/kline:
    get:
      summary: K-line (Candlestick) Data
      description: Get historical candlestick data for a symbol
      parameters:
        - name: symbol
          in: query
          required: true
          description: Trading symbol
          schema:
            type: string
            default: 700.HK
            example: 700.HK
        - name: interval
          in: query
          required: true
          description: K-line interval
          schema:
            type: string
            enum:
              - 1m
              - 5m
              - 15m
              - 30m
              - 1h
              - 2h
              - 4h
              - 1d
              - 1w
              - 1M
            default: 1h
            example: 1h
        - name: limit
          in: query
          required: false
          description: Number of records (default 100, max 1000)
          schema:
            type: integer
            minimum: 1
            maximum: 1000
            example: 100
        - name: start_time
          in: query
          required: false
          description: Start timestamp in milliseconds
          schema:
            type: integer
            example: 1703123456789
        - name: end_time
          in: query
          required: false
          description: End timestamp in milliseconds
          schema:
            type: integer
            example: 1703209856789
        - name: type
          in: query
          required: false
          description: >-
            Symbol type, optional. Not required when the symbol is unambiguous;
            if the API returns an AMBIGUOUS_SYMBOL error, pass the value as
            indicated
          schema:
            type: string
            enum:
              - stock
              - indices
              - crypto
              - forex
              - futures
            example: stock
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                    example: 0
                  message:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      symbol:
                        type: string
                        example: 700.HK
                      type:
                        type: string
                        enum:
                          - stock
                          - indices
                          - crypto
                          - forex
                          - futures
                      interval:
                        type: string
                        example: 1h
                      klines:
                        type: array
                        items:
                          type: object
                          properties:
                            time:
                              type: integer
                            open:
                              type: string
                            high:
                              type: string
                            low:
                              type: string
                            close:
                              type: string
                            volume:
                              type: string
                            quote_volume:
                              type: string
                              description: Trading amount; normally omitted for futures
                            open_interest:
                              type: string
                              description: Open interest; returned for futures
                        example:
                          - time: 1773291600000
                            open: '545.5'
                            high: '546.5'
                            low: '541.5'
                            close: '543.5'
                            volume: '1549300'
                            quote_volume: '842560983.33'
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key

````