stock_info
Retrieve stock information by symbol and market for A-shares, Hong Kong, and US stocks, providing basic data for investment analysis.
Instructions
根据股票代码和市场获取股票基本信息, 不支持加密货币
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | 股票代码 | |
| market | No | 股票市场,仅支持: sh(上证), sz(深证), hk(港股), us(美股), 不支持加密货币 | sh |
Implementation Reference
- mcp_aktools/__init__.py:44-69 (handler)The handler function for the 'stock_info' tool, decorated with @mcp.tool for registration. It retrieves stock basic information from akshare APIs for specified market and symbol, with caching, falling back to search if not found.@mcp.tool( title="获取股票信息", description="根据股票代码和市场获取股票基本信息, 不支持加密货币", ) def stock_info( symbol: str = field_symbol, market: str = field_market, ): markets = [ ["sh", ak.stock_individual_info_em], ["sz", ak.stock_individual_info_em], ["hk", ak.stock_hk_security_profile_em], ] for m in markets: if m[0] != market: continue all = ak_cache(m[1], symbol=symbol, ttl=43200) if all is None or all.empty: continue return all.to_string() info = ak_search(symbol, market) if info is not None: return info.to_string() return f"Not Found for {symbol}.{market}"
- mcp_aktools/__init__.py:20-21 (schema)Pydantic Field definitions used as input schema for the stock_info tool parameters: symbol and market.field_symbol = Field(description="股票代码") field_market = Field("sh", description="股票市场,仅支持: sh(上证), sz(深证), hk(港股), us(美股), 不支持加密货币")
- mcp_aktools/__init__.py:564-580 (helper)Helper function ak_cache used by stock_info to cache akshare API calls with TTL.def ak_cache(fun, *args, **kwargs) -> pd.DataFrame | None: key = kwargs.pop("key", None) if not key: key = f"{fun.__name__}-{args}-{kwargs}" ttl1 = kwargs.pop("ttl", 86400) ttl2 = kwargs.pop("ttl2", None) cache = CacheKey.init(key, ttl1, ttl2) all = cache.get() if all is None: try: _LOGGER.info("Request akshare: %s", [key, args, kwargs]) all = fun(*args, **kwargs) cache.set(all) except Exception as exc: _LOGGER.exception(str(exc)) return all
- mcp_aktools/__init__.py:65-69 (helper)Fallback to ak_search helper when direct stock info not found.info = ak_search(symbol, market) if info is not None: return info.to_string() return f"Not Found for {symbol}.{market}"