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

# 获取历史 K 线

> 按 `start` 和 `end` 日期范围查询，或按 `count` 加可选的 `forward` 和 `datetime` 偏移查询。



## OpenAPI

````yaml /cn/api-reference/openapi.json get /api/market-data/quote/{symbol}/history_candlestick
openapi: 3.1.0
info:
  title: Financial Context
  version: 1.0.0
  description: >-
    Financial Context 提供经过认证、按量计费的只读美股市场数据访问。可通过 `/api/market-data/*` 端点，针对
    `.US` 标的和 `US` 市场筛选条件访问行情、K 线、市场日历、基本面、新闻、选股器和相关分析。
servers:
  - url: https://openapi.fcontext.com
    description: 生产环境
security:
  - ApiKeyHeader: []
  - BearerAuth: []
tags:
  - name: 行情
    description: 行情、K 线、交易日、深度、经纪队列和其他市场数据端点。
  - name: 内容
    description: 证券内容：新闻和话题。
  - name: 市场
    description: 市场状态、交易日历、异常活动和排行。
  - name: 日历
    description: 财务事件日历。
  - name: 基本面
    description: 基本面、分析师评级、估值、股东和交易披露。
  - name: 选股器
    description: 选股策略、筛选条件和指标。
paths:
  /api/market-data/quote/{symbol}/history_candlestick:
    get:
      tags:
        - 行情
      summary: 获取历史 K 线
      description: 按 `start` 和 `end` 日期范围查询，或按 `count` 加可选的 `forward` 和 `datetime` 偏移查询。
      parameters:
        - name: symbol
          in: path
          required: true
          schema:
            type: string
          example: AAPL.US
        - name: period
          in: query
          required: false
          description: >-
            K 线周期，默认 `day`。支持 `1m`、`5m`、`15m`、`30m`、`1h`、`day`、`week`、`month` 和
            `year`。
          schema:
            type: string
            default: day
          example: day
        - name: adjust
          in: query
          required: false
          description: 复权类型：`none` 表示不复权（默认），`forward` 表示前复权数据。
          schema:
            type: string
          example: none
        - $ref: '#/components/parameters/AdjustTypeQuery'
        - name: session
          in: query
          required: false
          description: 交易时段：`intraday` 表示常规交易时段（默认），`all` 表示所有交易时段。
          schema:
            type: string
          example: intraday
        - $ref: '#/components/parameters/TradeSessionsQuery'
        - name: start
          in: query
          required: false
          description: 日期范围模式的开始日期 `YYYY-MM-DD`。
          schema:
            type: string
            format: date
        - name: end
          in: query
          required: false
          description: 日期范围模式的结束日期 `YYYY-MM-DD`。
          schema:
            type: string
            format: date
        - name: count
          in: query
          required: false
          description: 偏移模式下要返回的记录数。
          schema:
            type: integer
            minimum: 1
          example: 100
        - name: forward
          in: query
          required: false
          description: 向前查询：`true`（默认）或 `false`。
          schema:
            type: boolean
            default: true
        - name: datetime
          in: query
          required: false
          description: 开始时间，格式为 `YYYY-MM-DD HH:MM:SS`。
          schema:
            type: string
      responses:
        '200':
          description: 历史 K 线列表
          content:
            application/json:
              schema:
                type: object
                properties:
                  quote:
                    type: array
                    items:
                      $ref: '#/components/schemas/Candlestick'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          description: 需要付费的 Financial Context 方案或剩余数据请求额度。
        '403':
          description: 该凭证无权访问 Financial Context 市场数据。
components:
  parameters:
    AdjustTypeQuery:
      name: adjust_type
      in: query
      required: false
      description: '`adjust` 的兼容别名：`0` 表示不复权，`1` 表示前复权数据。'
      schema:
        type: integer
        enum:
          - 0
          - 1
      example: 0
    TradeSessionsQuery:
      name: trade_sessions
      in: query
      required: false
      description: '`session` 的兼容别名：`0` 表示常规交易时段，`1` 表示所有交易时段。'
      schema:
        type: integer
        enum:
          - 0
          - 1
      example: 0
  schemas:
    Candlestick:
      type: object
      description: K 线数据点。
      additionalProperties: true
      properties:
        close:
          type: string
          description: 收盘价，以字符串表示以保留小数精度。
        open:
          type: string
          description: 开盘价，以字符串表示以保留小数精度。
        low:
          type: string
          description: 最低价，以字符串表示以保留小数精度。
        high:
          type: string
          description: 最高价，以字符串表示以保留小数精度。
        volume:
          type: string
          description: 成交量。
        turnover:
          type: string
          description: 成交额，以字符串表示以保留小数精度。
        timestamp:
          type: string
          format: date-time
          description: 数据时间戳。
    Error:
      type: object
      description: 标准错误响应。
      additionalProperties: true
      properties:
        error:
          type: string
          description: 可读错误消息。
  responses:
    BadRequest:
      description: 请求参数无效。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: 缺少或使用了无效的 Financial Context 凭证。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 'Unauthorized: missing API key'
  securitySchemes:
    ApiKeyHeader:
      type: apiKey
      in: header
      name: x-api-key
      description: '在账户设置中生成的 Financial Context key。请以 `x-api-key: <key>` 形式发送。'
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: OAuth access token
      description: >-
        面向具有 `market_data` scope 的 Financial Context CLI、MCP 或 agent 客户端的 OAuth
        bearer token。

````