> ## 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.zh-Hant.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: 歷史估值記錄；每個元素是 `[時間, 指標值]`。
          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.