> ## 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 股、港股、美股） | ✅ |
| 企業版 | ✅ |

## 注意事項

* `industry_counter_id` 可從行業指標排行獲取；不同市場的行業節點不能混用。
* `market` 不區分大小寫，文檔中的市場代碼統一使用大寫形式。

## 支持的市場

| 市場 | 示例 |
| - | - |
| 美股 | US |
| 港股 | HK |
| A股 | CN |

## 請求參數

| 參數 | 是否必須 | 說明 |
| - | :-: | - |
| `market` | 是 | 市場代碼：`US` 美股、`HK` 港股、`CN` A股 |
| `industry_counter_id` | 是 | 行業節點 ID，可從行業指標排行接口獲取 |

## 請求示例

```bash theme={null}
curl -H "X-API-Key: YOUR_API_KEY" \
  "https://api.tickdb.ai/v1/fundamentals/industries/tree?market=US&industry_counter_id=BK%2FUS%2FIN00260"
```

## 返回字段說明

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

| 字段 | 說明 |
| - | - |
| market | 查詢市場。 |
| industry\_counter\_id | 行業節點 ID。 |
| top | 所屬頂層行業分類。 |
| └─ name | 頂層行業名稱。 |
| └─ market | 頂層行業市場。 |
| chain | 當前行業及其下級分類組成的層級結構。 |
| └─ name | 節點名稱。 |
| └─ counter\_id | 行業節點 ID。 |
| └─ level | 節點層級。 |
| └─ parent\_code | 父節點代碼。 |
| └─ market | 所屬市場。 |
| └─ stock\_num | 股票數量。 |
| └─ chg | 變動值。 |
| └─ ytd\_chg | 年初至今變動值。 |
| └─ symbol | 節點關聯代碼。 |
| └─ sharelist\_id | 股票列表 ID。 |
| └─ next | 下級行業分類列表；元素遞歸使用相同節點結構。 |

返回指定行業的頂層歸屬、當前分類和下級分類，便于查看行業分類關系。


## OpenAPI

````yaml openapi.zh-Hant.yaml GET /v1/fundamentals/industries/tree
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/industries/tree:
    get:
      tags:
        - fundamentals-valuation-industry
      summary: 行業分類層級
      description: 查詢指定行業所屬的頂層分類及下級行業分類。
      operationId: getFundamentalsIndustriesTree
      parameters:
        - $ref: '#/components/parameters/RequiredMarketQuery'
        - $ref: '#/components/parameters/IndustryCounterIDQuery'
      responses:
        '200':
          $ref: '#/components/responses/IndustriesTreeResponse'
        default:
          $ref: '#/components/responses/ErrorResponse'
components:
  parameters:
    RequiredMarketQuery:
      name: market
      in: query
      required: true
      schema:
        type: string
        enum:
          - US
          - HK
          - CN
      description: 市場代碼：`US` 美股、`HK` 港股、`CN` A股
    IndustryCounterIDQuery:
      name: industry_counter_id
      in: query
      required: true
      schema:
        type: string
      description: 行業節點 ID，可從行業指標排行介面獲取
  responses:
    IndustriesTreeResponse:
      description: 行業分類層級回應。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/IndustriesTreeEnvelope'
    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:
    IndustriesTreeEnvelope:
      allOf:
        - $ref: '#/components/schemas/SuccessEnvelope'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/IndustriesTreeData'
    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`。
    IndustriesTreeData:
      type: object
      required:
        - market
        - industry_counter_id
        - top
        - chain
      properties:
        market:
          type: string
          description: 查詢市場。
        industry_counter_id:
          type: string
          description: 行業節點 ID。
        top:
          $ref: '#/components/schemas/IndustryTop'
        chain:
          $ref: '#/components/schemas/IndustryChainNode'
      additionalProperties: true
    IndustryTop:
      type: object
      required:
        - name
        - market
      properties:
        name:
          type: string
          description: 頂層行業名稱。
        market:
          type: string
          description: 查詢市場。
      additionalProperties: false
    IndustryChainNode:
      type: object
      required:
        - name
        - level
        - market
        - counter_id
        - next
      properties:
        name:
          type: string
          description: 行業名稱。
        level:
          type: integer
          description: 節點層級。
        market:
          type: string
          description: 查詢市場。
        counter_id:
          type: string
          description: 行業節點 ID。
        parent_code:
          type: string
          description: 父節點代碼。
        sharelist_id:
          type: string
          description: 股票列表 ID。
        symbol:
          type: string
          description: 節點關聯代碼。
        stock_num:
          type: integer
          minimum: 0
          description: 股票數量。
        chg:
          type:
            - string
            - number
            - 'null'
          description: 變動值。
        ytd_chg:
          type:
            - string
            - number
            - 'null'
          description: 年初至今變動值。
        next:
          type: array
          description: 下級行業分類列表；元素遞歸使用相同節點結構。
          items:
            $ref: '#/components/schemas/IndustryChainNode'
      additionalProperties: 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.