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

# 歷史營收構成

> 展示歷史報告期按業務或地區劃分的收入金額和占比。

## 套餐權限

| 套餐 | 可用 |
| - | :-: |
| 免費版 | ❌ |
| 基礎版 | ❌ |
| 專業版 | ✅ |
| 全量套餐（A 股、港股、美股） | ✅ |
| 企業版 | ✅ |

## 注意事項

* 可查詢的歷史報告期因公司而異；沒有匹配數據時可能返回結構化 `404`。

## 支持的市場

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

## 請求參數

| 參數 | 是否必須 | 說明 |
| - | :-: | - |
| `symbol` | 是 | 股票代碼 |
| `type` | 否 | 產品類型，當前支持 `stock` |
| `category` | 否 | 營收構成維度：`business` 按業務；`regional` 按地區。不傳返回全部可用維度。 |
| `report` | 否 | 報告周期：`qf` 季度報告、`saf` 半年度報告、`af` 年度報告 |
| `limit` | 否 | 返回條數，默認 200，范圍 `1–1000` |

## 請求示例

```bash theme={null}
curl -H "X-API-Key: YOUR_API_KEY" \
  "https://api.tickdb.ai/v1/fundamentals/segments/history?symbol=AAPL&type=stock&category=business&limit=200"
```

## 返回字段說明

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

| 字段 | 說明 |
| - | - |
| symbol | 股票代碼。 |
| report | 請求指定的報告周期；`qf` 季度報告、`saf` 半年度報告、`af` 年度報告，未指定時可為 null。 |
| segments | 歷史報告期的營收構成明細。 |
| └─ segment\_name | 業務類別或地區名稱。 |
| └─ category | 該記錄所屬維度：`business` 按業務，`regional` 按地區。 |
| └─ value | 該業務類別或地區的收入金額。 |
| └─ total\_revenue | 該報告期總收入。 |
| └─ percent | 該業務類別或地區收入占當期總收入的百分比，例如 `79.74` 表示 79.74%。 |
| └─ currency | 金額幣種。 |
| └─ report | 該記錄的報告周期：`qf` 季度報告、`saf` 半年度報告、`af` 年度報告。 |
| └─ period\_start | 周期開始日期，格式 `YYYY-MM-DD`。 |
| └─ period\_end | 周期結束日期，格式 `YYYY-MM-DD`。 |

每條明細對應一個報告期的業務類別或地區。篩選條件沒有匹配數據時可能返回結構化 `404`。


## OpenAPI

````yaml openapi.zh-Hant.yaml GET /v1/fundamentals/segments/history
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/segments/history:
    get:
      tags:
        - fundamentals-financials
      summary: 歷史營收構成
      description: 展示歷史報告期按業務或地區劃分的收入金額和占比。
      operationId: getFundamentalsSegmentsHistory
      parameters:
        - $ref: '#/components/parameters/SymbolQuery'
        - $ref: '#/components/parameters/TypeQuery'
        - $ref: '#/components/parameters/SegmentCategoryQuery'
        - $ref: '#/components/parameters/ReportQuery'
        - $ref: '#/components/parameters/SegmentLimitQuery'
      responses:
        '200':
          $ref: '#/components/responses/SegmentsResponse'
        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`
    SegmentCategoryQuery:
      name: category
      in: query
      required: false
      schema:
        type: string
        enum:
          - business
          - regional
      description: 營收構成維度：`business` 按業務；`regional` 按地區。不傳返回全部可用維度。
    ReportQuery:
      name: report
      in: query
      required: false
      schema:
        type: string
        examples:
          - qf
          - saf
          - af
      description: 報告周期：`qf` 季度報告、`saf` 半年度報告、`af` 年度報告
    SegmentLimitQuery:
      name: limit
      in: query
      required: false
      schema:
        type: integer
        minimum: 1
        maximum: 1000
        default: 200
      description: 返回條數，默認 200，范圍 `1–1000`
  responses:
    SegmentsResponse:
      description: 歷史營收構成回應。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SegmentsEnvelope'
    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:
    SegmentsEnvelope:
      allOf:
        - $ref: '#/components/schemas/SuccessEnvelope'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/SegmentsData'
    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`。
    SegmentsData:
      type: object
      required:
        - symbol
        - segments
      properties:
        symbol:
          type: string
          description: 股票代碼。
        report:
          type:
            - string
            - 'null'
          description: 請求指定的報告周期；`qf` 季度報告、`saf` 半年度報告、`af` 年度報告，未指定時可為 null。
        segments:
          type: array
          description: 歷史報告期的營收構成明細。
          items:
            $ref: '#/components/schemas/SegmentItem'
      additionalProperties: true
    SegmentItem:
      type: object
      required:
        - report
        - category
        - segment_name
        - period_start
        - period_end
        - value
      properties:
        report:
          type: string
          description: 報告周期：`qf` 季度報告、`saf` 半年度報告、`af` 年度報告。
        category:
          type: string
          description: 該記錄所屬維度：`business` 按業務，`regional` 按地區。
        segment_name:
          type: string
          description: 業務類別或地區名稱。
        period_start:
          type: string
          format: date
          description: 周期開始日期，格式 `YYYY-MM-DD`。
        period_end:
          type: string
          format: date
          description: 周期結束日期，格式 `YYYY-MM-DD`。
        total_revenue:
          type:
            - string
            - number
            - 'null'
          description: 該報告期總收入。
        currency:
          type:
            - string
            - 'null'
          description: 金額幣種。
        percent:
          type:
            - string
            - number
            - 'null'
          description: 該業務類別或地區收入占當期總收入的百分比，例如 `79.74` 表示 79.74%。
        value:
          type:
            - string
            - number
            - 'null'
          description: 該業務類別或地區的收入金額。
      additionalProperties: true
  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.