Skip to main content
Glama

get_instrument_detail

Retrieve detailed information for a specific stock using its code, with options to fetch complete data fields, powered by XTQuantAI’s integration with quantitative trading platforms.

Instructions

获取指定股票的详细信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes股票代码,例如 000001.SZ
iscompleteNo是否获取全部字段,默认为False

Implementation Reference

  • The primary handler function for the 'get_instrument_detail' tool. It validates input, initializes XTQuant if needed, calls xtdata.get_instrument_detail, formats the result into a serializable dict, and handles errors.
    async def get_instrument_detail(input: GetInstrumentDetailInput) -> Dict[str, Any]:
        """
        获取指定股票的详细信息
        
        Args:
            code: 股票代码,例如 "000001.SZ"
            iscomplete: 是否获取全部字段,默认为False
            
        Returns:
            股票详细信息
        """
        try:
            # 确保XTQuant数据中心已初始化
            ensure_xtdc_initialized()
            
            if xtdata is None:
                return {"error": "xtdata模块未正确加载"}
                
            print(f"调用xtdata.get_instrument_detail({input.code}, {input.iscomplete})")
            # 直接使用用户输入的股票代码,不做任何格式处理
            detail = xtdata.get_instrument_detail(input.code, input.iscomplete)
            
            # 处理返回值为None的情况
            if detail is None:
                return {"message": f"未找到股票代码 {input.code} 的详细信息"}
                
            # 将结果转换为可序列化的字典
            result = {}
            for key, value in detail.items():
                if isinstance(value, (str, int, float, bool, type(None))):
                    result[key] = value
                else:
                    result[key] = str(value)
            
            return result
        except Exception as e:
            print(f"获取股票详情出错: {str(e)}")
            traceback.print_exc()
            return {"error": str(e)}
  • Pydantic model defining the input schema for the tool, with required 'code' string and optional 'iscomplete' boolean.
    class GetInstrumentDetailInput(BaseModel):
        code: str  # 股票代码,例如 "000001.SZ"
        iscomplete: bool = False  # 是否获取全部字段,默认为False
  • Tool registration in the list_tools handler, defining name, description, and JSON schema matching the Pydantic input model.
    types.Tool(
        name="get_instrument_detail",
        description="获取指定股票的详细信息",
        inputSchema={
            "type": "object",
            "properties": {
                "code": {
                    "type": "string",
                    "description": "股票代码,例如 000001.SZ"
                },
                "iscomplete": {
                    "type": "boolean",
                    "description": "是否获取全部字段,默认为False",
                    "default": False
                }
            },
            "required": ["code"]
        }
    ),
  • Dispatch logic in the @server.call_tool() handler that parses arguments, creates input model, calls the tool handler, and returns JSON response.
    elif name == "get_instrument_detail":
        if not arguments or "code" not in arguments:
            return [types.TextContent(type="text", text="错误: 缺少必要参数 'code'")]
        
        code = arguments["code"]
        # 从参数中获取iscomplete,如果不存在则默认为False
        iscomplete = False
        if arguments and "iscomplete" in arguments:
            # 确保iscomplete是布尔值
            if isinstance(arguments["iscomplete"], bool):
                iscomplete = arguments["iscomplete"]
            elif isinstance(arguments["iscomplete"], str):
                iscomplete = arguments["iscomplete"].lower() == "true"
        
        input_model = GetInstrumentDetailInput(code=code, iscomplete=iscomplete)
        result = await get_instrument_detail(input_model)
        return [types.TextContent(type="text", text=json.dumps(result, ensure_ascii=False, indent=2))]
  • Mock implementation of get_instrument_detail in MockXtdata class used when real xtquant import fails.
    def get_instrument_detail(self, code, iscomplete=False):
        print(f"模拟调用get_instrument_detail({code}, {iscomplete})")
        return {"code": code, "name": "模拟股票", "price": 100.0}
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. The description only states what the tool does ('获取指定股票的详细信息'), but doesn't disclose any behavioral traits such as whether it's a read-only operation, potential rate limits, authentication requirements, error handling, or what '详细信息' (detailed information) specifically includes. For a tool with no annotation coverage, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise ('获取指定股票的详细信息') - a single sentence that directly states the tool's purpose without any fluff. It's front-loaded and every word earns its place, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what '详细信息' (detailed information) includes, how the data is returned, or any behavioral aspects. For a tool that presumably returns complex stock data, the description should provide more context about the nature and scope of the information retrieved.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds no parameter semantics beyond what the input schema provides. The schema has 100% description coverage, with clear documentation for both parameters ('code' and 'iscomplete'), including examples and defaults. Since schema coverage is high (>80%), the baseline score is 3, as the description doesn't need to compensate but also adds no extra value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '获取指定股票的详细信息' (Get detailed information for a specified stock). It uses a specific verb ('获取' - get) and resource ('股票详细信息' - stock detailed information). However, it doesn't differentiate from sibling tools like get_history_market_data or get_latest_market_data, which also retrieve stock-related data.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like get_history_market_data or get_latest_market_data, nor does it explain what makes this tool unique (e.g., comprehensive vs. historical vs. real-time data). The only implied usage is when detailed stock information is needed, but this is too vague for effective tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dfkai/xtquantai'

If you have feedback or need assistance with the MCP directory API, please join our Discord server