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}

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