get_cni_index_hist
Retrieve daily historical market data for Chinese stock indices by specifying index code and date range, with output in multiple formats including JSON, CSV, and Excel.
Instructions
获取指定指数的日频率历史行情数据
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | 指数代码 (例如: '399005') | |
| start_date | Yes | 开始日期,格式为 YYYYMMDD (例如: '20230114') | |
| end_date | Yes | 结束日期,格式为 YYYYMMDD (例如: '20240114') | |
| output_format | No | 输出数据格式: json, csv, xml, excel, markdown, html。默认: markdown | markdown |
Implementation Reference
- src/china_stock_mcp/server.py:1003-1005 (registration)Registers the 'get_cni_index_hist' tool with MCP, providing the tool name and description.@mcp.tool( name="get_cni_index_hist", description="获取指定指数的日频率历史行情数据" )
- Defines the input schema with Pydantic Field descriptions for parameters: symbol (index code), start_date, end_date (YYYYMMDD), output_format (default markdown).symbol: Annotated[str, Field(description="指数代码 (例如: '399005')")], start_date: Annotated[str, Field(description="开始日期,格式为 YYYYMMDD (例如: '20230114')")], end_date: Annotated[str, Field(description="结束日期,格式为 YYYYMMDD (例如: '20240114')")], output_format: Annotated[ Literal["json", "csv", "xml", "excel", "markdown", "html"], Field(description="输出数据格式: json, csv, xml, excel, markdown, html。默认: markdown"), ] = "markdown"
- src/china_stock_mcp/server.py:1006-1019 (handler)The main handler function that executes the tool: fetches daily historical quote data for the given CNI index using akshare's index_hist_cni, handles empty DataFrame, and returns formatted output via _format_dataframe_output.def get_cni_index_hist( symbol: Annotated[str, Field(description="指数代码 (例如: '399005')")], start_date: Annotated[str, Field(description="开始日期,格式为 YYYYMMDD (例如: '20230114')")], end_date: Annotated[str, Field(description="结束日期,格式为 YYYYMMDD (例如: '20240114')")], output_format: Annotated[ Literal["json", "csv", "xml", "excel", "markdown", "html"], Field(description="输出数据格式: json, csv, xml, excel, markdown, html。默认: markdown"), ] = "markdown" ) -> str: """获取指定指数的日频率历史行情数据.""" df = ak.index_hist_cni(symbol=symbol, start_date=start_date, end_date=end_date) if df.empty: df = pd.DataFrame() return _format_dataframe_output(df, output_format)