Skip to main content
Glama

get_stock_list

Retrieve a list of stocks within a specified sector using the MCP server XTQuantAI. Ideal for accessing trading data directly through AI integration.

Instructions

获取指定板块的股票列表

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sectorNo板块名称,例如 沪深A股沪深A股

Implementation Reference

  • The core asynchronous handler function for the 'get_stock_list' MCP tool. It ensures XTQuant data center is initialized, calls xtdata.get_stock_list_in_sector(sector), limits results to 50 stocks, and handles errors gracefully.
    async def get_stock_list(input: GetStockListInput) -> List[str]: """ 获取指定板块的股票列表 Args: sector: 板块名称,例如 "沪深A股" Returns: 股票代码列表 """ try: # 确保XTQuant数据中心已初始化 ensure_xtdc_initialized() if xtdata is None: return ["错误: xtdata模块未正确加载"] print(f"调用xtdata.get_stock_list_in_sector({input.sector})") stock_list = xtdata.get_stock_list_in_sector(input.sector) # 检查返回值 if stock_list is None or len(stock_list) == 0: return [f"未找到板块 {input.sector} 的股票列表"] # 只返回前50个股票代码 limited_list = stock_list[:50] if len(stock_list) > 50 else stock_list return limited_list except Exception as e: print(f"获取股票列表出错: {str(e)}") traceback.print_exc() return [f"错误: {str(e)}"]
  • Pydantic BaseModel defining the input schema for the get_stock_list tool, with a single optional 'sector' parameter defaulting to '沪深A股'.
    class GetStockListInput(BaseModel): sector: str = "沪深A股" # 默认为沪深A股
  • Tool registration in the MCP server's @server.list_tools() handler, specifying name, description, and inputSchema matching the GetStockListInput model.
    name="get_stock_list", description="获取指定板块的股票列表", inputSchema={ "type": "object", "properties": { "sector": { "type": "string", "description": "板块名称,例如 沪深A股", "default": "沪深A股" } } } ),
  • Dispatch logic in the MCP server's @server.call_tool() handler that parses arguments for 'get_stock_list', instantiates the input model, calls the handler function, and formats the response.
    elif name == "get_stock_list": sector = "沪深A股" if arguments and "sector" in arguments: sector = arguments["sector"] input_model = GetStockListInput(sector=sector) result = await get_stock_list(input_model) return [types.TextContent(type="text", text=json.dumps(result, ensure_ascii=False, indent=2))]
  • Mock implementation of xtdata.get_stock_list_in_sector used when the real xtquant module fails to import, providing fallback stock list data.
    def get_stock_list_in_sector(self, sector="沪深A股"): print(f"模拟调用get_stock_list_in_sector({sector})") return ["000001.SZ", "600519.SH", "300059.SZ"]

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