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

# Index Constituents

> Get list of stocks that are constituents of a specific index. Returns stock symbols and market areas for all constituent stocks of the given index

## 查询指数成分股

**URL:** `/v1/stock/index-constituents`\
**方法:** `POST`\
**描述:** 根据指数代码查询指数成分股列表。

### 请求参数

| 参数名    | 类型     | 必填 | 描述   |
| ------ | ------ | -- | ---- |
| symbol | string | 是  | 指数代码 |

### 响应参数

| 参数名     | 类型      | 描述       |
| ------- | ------- | -------- |
| status  | integer | HTTP 状态码 |
| code    | integer | 业务状态码    |
| message | string  | 响应消息     |
| data    | object  | 响应数据     |

#### data 对象结构

| 参数名   | 类型    | 描述    |
| ----- | ----- | ----- |
| items | array | 成分股列表 |

#### 成分股对象结构

| 参数名    | 类型     | 描述   |
| ------ | ------ | ---- |
| market | string | 股票市场 |
| symbol | string | 股票代码 |

### 示例代码

#### cURL 示例

```bash theme={null}
curl -X POST "https://api.reportify.cn/v1/stock/index-constituents" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "symbol": "000300"
  }'
```

#### Python 示例

```python theme={null}
import requests

url = "https://api.reportify.cn/v1/stock/index-constituents"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}
data = {
    "symbol": "000300"
}

response = requests.post(url, headers=headers, json=data)
result = response.json()

print(f"状态码: {result['status']}")
print(f"成分股数量: {len(result['data']['items'])}")

for item in result['data']['items'][:5]:  # 打印前5个
    print(f"市场: {item['market']}, 代码: {item['symbol']}")
```

#### TypeScript 示例

```typescript theme={null}
const response = await fetch('https://api.reportify.cn/v1/stock/index-constituents', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    symbol: '000300'
  })
});

const result = await response.json();
console.log(`成分股数量: ${result.data.items.length}`);
```

### 响应示例

#### 成功响应

```json theme={null}
{
  "status": 200,
  "code": 0,
  "message": "",
  "data": {
    "items": [
      {
        "market": "cn",
        "symbol": "000001"
      },
      {
        "market": "cn",
        "symbol": "000002"
      },
      {
        "market": "cn",
        "symbol": "000063"
      }
    ]
  }
}
```

#### 成功响应（无数据）

```json theme={null}
{
  "status": 200,
  "code": 0,
  "message": "",
  "data": {
    "items": []
  }
}
```

### 常用指数代码

| 指数代码   | 指数名称  |
| ------ | ----- |
| 000300 | 沪深300 |
| 000016 | 上证50  |
| 000905 | 中证500 |
| 399006 | 创业板指  |
| 399001 | 深证成指  |
| 000001 | 上证指数  |

### 注意事项

* **symbol 参数**：指数代码，如沪深300的代码为 `000300`
* **空响应**：如果 `data.items` 为空数组，说明没有找到该指数的成分股数据
* **市场标识**：返回的 `market` 字段表示成分股所在市场（cn、hk、us）


## OpenAPI

````yaml POST /v1/stock/index-constituents
openapi: 3.1.0
info:
  title: Reportify API
  version: 1.0.0
  description: API documentation for Reportify's document management and search services.
servers:
  - url: https://api.reportify.cn
    description: Production server
security:
  - BearerAuth: []
paths:
  /v1/stock/index-constituents:
    post:
      tags:
        - openapi-stock-tools
      summary: Index Constituents
      description: >-
        Get list of stocks that are constituents of a specific index. Returns
        stock symbols and market areas for all constituent stocks of the given
        index
      operationId: index_constituents_reportify_api_v1_stock_index_constituents_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IndexConstituentsInput'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StockAPIResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - BearerAuth: []
components:
  schemas:
    IndexConstituentsInput:
      properties:
        symbol:
          type: string
          title: Symbol
          description: Index symbol
          example: '000300'
      type: object
      required:
        - symbol
      title: IndexConstituentsInput
      description: Input schema for index constituents query
    StockAPIResponse:
      properties:
        status:
          type: integer
          title: Status
          description: HTTP status code
        code:
          type: integer
          title: Code
          description: Response code (0 for success)
        message:
          type: string
          title: Message
          description: Response message
        data:
          type: object
          title: Data
          description: Response data (structure varies by endpoint)
      type: object
      title: StockAPIResponse
      description: Generic response wrapper from stock API
    ErrorResponse:
      properties:
        status:
          type: integer
          title: Status
          description: HTTP status code
        code:
          type: integer
          title: Code
          description: Error code
        message:
          type: string
          title: Message
          description: Error message
      type: object
      title: ErrorResponse
      description: Standard error response
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Enter your Bearer token

````