> ## 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.

# 历史估值

> 查询市盈率（PE）按日或按月的历史数值。

## 套餐权限

| 套餐 | 可用 |
| - | :-: |
| 免费版 | ❌ |
| 基础版 | ❌ |
| 专业版 | ✅ |
| 全量套餐（A 股、港股、美股） | ✅ |
| 企业版 | ✅ |

## 注意事项

* `points` 中每个元素为 `[时间, 指标值]`，不是带字段名的对象；时间是带时区信息的 RFC 3339 字符串。
* 未指定日期范围时，`daily` 默认查询最近一年，`monthly` 默认查询最近五年。查询范围内没有记录时返回 HTTP 404、错误码 `40405`，不是成功的空数组。

## 支持的市场

| 市场 | 示例 |
| - | - |
| 美股 | AAPL.US |
| 港股 | 700.HK |
| A股 | 600519.SH |

## 请求参数

| 参数 | 是否必须 | 说明 |
| - | :-: | - |
| `symbol` | 是 | 股票代码 |
| `type` | 否 | 产品类型，当前支持 `stock` |
| `granularity` | 否 | `daily` 或 `monthly`，默认 `daily` |
| `from` | 否 | 起始日期，格式 `YYYY-MM-DD` |
| `to` | 否 | 结束日期，格式 `YYYY-MM-DD` |

## 请求示例

```bash theme={null}
curl -H "X-API-Key: YOUR_API_KEY" \
  "https://api.tickdb.ai/v1/fundamentals/valuation/ts?symbol=AAPL&type=stock&granularity=monthly"
```

## 返回字段说明

以下列出 `data` 中的字段；外层 `code=0` 表示成功。

| 字段 | 说明 |
| - | - |
| symbol | 股票代码。 |
| metric | 估值指标，当前为 `PE`（市盈率）。 |
| granularity | 时间粒度：日度或月度。 |
| from | 查询范围起始日期，格式 `YYYY-MM-DD`。 |
| to | 查询范围结束日期，格式 `YYYY-MM-DD`。 |
| points | 历史估值记录；每个元素是 `[时间, 指标值]`。 |
| └─ \[0] | RFC 3339 日期时间字符串，包含时区信息。 |
| └─ \[1] | 对应指标值，可以是字符串、数值或 `null`。 |

返回市盈率（PE）在查询时间范围内的日度或月度历史数值。


## OpenAPI

````yaml openapi.yaml GET /v1/fundamentals/valuation/ts
openapi: 3.1.0
info:
  title: TickDB API
  description: TickDB 统一实时行情数据 API，提供 REST 和 WebSocket 接入。
  version: 1.0.3
  contact:
    email: support@tickdb.ai
servers:
  - url: https://api.tickdb.ai
    description: 生产环境
security:
  - ApiKeyAuth: []
paths:
  /v1/fundamentals/valuation/ts:
    get:
      tags:
        - fundamentals-valuation-industry
      summary: 历史估值
      description: 查询市盈率（PE）按日或按月的历史数值。
      operationId: getFundamentalsValuationTimeSeries
      parameters:
        - $ref: '#/components/parameters/SymbolQuery'
        - $ref: '#/components/parameters/TypeQuery'
        - $ref: '#/components/parameters/GranularityQuery'
        - $ref: '#/components/parameters/ValuationFromQuery'
        - $ref: '#/components/parameters/ValuationToQuery'
      responses:
        '200':
          $ref: '#/components/responses/ValuationTimeSeriesResponse'
        default:
          $ref: '#/components/responses/ErrorResponse'
components:
  parameters:
    SymbolQuery:
      name: symbol
      in: query
      required: true
      schema:
        type: string
        examples:
          - AAPL
          - '700'
          - '600519'
          - AAPL.US
          - 700.HK
          - 600519.SH
      description: 股票代码
    TypeQuery:
      name: type
      in: query
      required: false
      schema:
        type: string
        enum:
          - stock
      description: 产品类型，当前支持 `stock`
    GranularityQuery:
      name: granularity
      in: query
      required: false
      schema:
        type: string
        enum:
          - daily
          - monthly
        default: daily
      description: '`daily` 或 `monthly`，默认 `daily`'
    ValuationFromQuery:
      name: from
      in: query
      required: false
      schema:
        type: string
        format: date
      description: 起始日期，格式 `YYYY-MM-DD`
    ValuationToQuery:
      name: to
      in: query
      required: false
      schema:
        type: string
        format: date
      description: 结束日期，格式 `YYYY-MM-DD`
  responses:
    ValuationTimeSeriesResponse:
      description: 历史估值响应。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ValuationTimeSeriesEnvelope'
    ErrorResponse:
      description: >-
        错误响应。常见 HTTP 状态包括
        400（参数错误）、401（鉴权失败）、403（权限或配额限制）、404（无匹配数据）、429（请求频率限制）和 503（服务暂不可用）。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
          examples:
            missingAPIKey:
              summary: 缺少 API Key
              value:
                code: '1002'
                message: API key is required. Provide via X-API-Key header
                error: '1002'
            missingKind:
              summary: 缺少必填参数
              value:
                code: 40001
                message: kind is required
                data: null
            endpointForbidden:
              summary: API Key 无权访问该接口
              value:
                code: 3009
                message: This endpoint is not allowed for your API key
                data: null
            marketForbidden:
              summary: API Key 未开放该市场
              value:
                code: 3010
                message: Fundamentals market not allowed for your API key
                data:
                  market: US
            noAvailableSource:
              summary: 数据暂不可用
              value:
                code: 5003
                message: Data is temporarily unavailable
                data: null
            notFound:
              summary: 无匹配数据
              value:
                code: 40404
                message: shareholder detail not found
                data: null
            businessNoData:
              summary: 查询条件无有效业务数据
              value:
                code: 40405
                message: valuation time series not found
                data: null
  schemas:
    ValuationTimeSeriesEnvelope:
      allOf:
        - $ref: '#/components/schemas/SuccessEnvelope'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/ValuationTimeSeriesData'
    ErrorEnvelope:
      type: object
      required:
        - code
        - message
      properties:
        code:
          description: TickDB API 业务错误码；可能为整数或字符串，客户端应归一化为字符串后比较。
          oneOf:
            - type: integer
            - type: string
        message:
          type: string
          description: 错误说明。
        error:
          type: string
          description: 兼容错误标识；仅部分错误响应返回。
        data:
          description: 可选的错误上下文；可能为 null、对象或数组。
          oneOf:
            - type: 'null'
            - type: object
              additionalProperties: true
            - type: array
              items: {}
    SuccessEnvelope:
      type: object
      required:
        - code
        - data
      properties:
        code:
          type: integer
          const: 0
          description: 业务状态码，成功为 0。
    ValuationTimeSeriesData:
      type: object
      required:
        - symbol
        - metric
        - granularity
        - from
        - to
        - points
      properties:
        symbol:
          type: string
          description: 标准化股票代码。
        metric:
          type: string
          enum:
            - PE
          description: 估值指标，当前固定为 PE（市盈率）。
        granularity:
          type: string
          enum:
            - daily
            - monthly
          description: 历史估值记录的时间粒度。
        from:
          type: string
          format: date
          description: 查询范围的起始日期，格式 YYYY-MM-DD。
        to:
          type: string
          format: date
          description: 查询范围的结束日期，格式 YYYY-MM-DD。
        points:
          type: array
          description: 历史估值记录，每项为 [RFC 3339 日期时间字符串, 指标值]。
          items:
            $ref: '#/components/schemas/MetricPoint'
      additionalProperties: true
    MetricPoint:
      type: array
      minItems: 2
      maxItems: 2
      prefixItems:
        - type: string
          format: date-time
          description: RFC 3339 日期时间字符串，包含时区信息。
        - type:
            - string
            - number
            - 'null'
          description: 指标值。
      items: false
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.