get_all_stock
Fetch A-share stocks and indices with trading status for a specific date, returning results in a markdown table format.
Instructions
Fetch a list of all stocks (A-shares and indices) and their trading status for a date.
Args:
date: Optional. The date in 'YYYY-MM-DD' format. If None, uses the current date.
Returns:
Markdown table listing stock codes and trading status (1=trading, 0=suspended).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | ||
| limit | No | ||
| format | No | markdown |
Implementation Reference
- src/tools/market_overview.py:48-63 (handler)MCP tool handler for get_all_stock: decorated with @app.tool(), handles input parameters, logging, error handling via run_tool_with_handling, and delegates to fetch_all_stock use case.@app.tool() def get_all_stock(date: Optional[str] = None, limit: int = 250, format: str = "markdown") -> str: """ Fetch a list of all stocks (A-shares and indices) and their trading status for a date. Args: date: Optional. The date in 'YYYY-MM-DD' format. If None, uses the current date. Returns: Markdown table listing stock codes and trading status (1=trading, 0=suspended). """ logger.info(f"Tool 'get_all_stock' called for date={date or 'default'}") return run_tool_with_handling( lambda: fetch_all_stock(active_data_source, date=date, limit=limit, format=format), context=f"get_all_stock:{date or 'default'}", )
- mcp_server.py:54-54 (registration)Registration call for market overview tools, including get_all_stock, in the main MCP server setup.register_market_overview_tools(app, active_data_source)
- Use case helper fetch_all_stock: validates format, fetches data from data_source.get_all_stock, formats as markdown/json/csv table.def fetch_all_stock(data_source: FinancialDataSource, *, date: Optional[str], limit: int, format: str) -> str: validate_output_format(format) df = data_source.get_all_stock(date=date) meta = {"as_of": date or "default"} return format_table_output(df, format=format, max_rows=limit, meta=meta)
- src/baostock_data_source.py:622-663 (helper)Core data fetching implementation in BaostockDataSource.get_all_stock: queries Baostock API bs.query_all_stock(day=date), handles errors, returns DataFrame.def get_all_stock(self, date: Optional[str] = None) -> pd.DataFrame: """Fetches all stock list for a given date using Baostock.""" logger.info(f"Fetching all stock list for date={date or 'default'}") try: with baostock_login_context(): rs = bs.query_all_stock(day=date) if rs.error_code != '0': logger.error( f"Baostock API error (All Stock) for date {date}: {rs.error_msg} (code: {rs.error_code})") if "no record found" in rs.error_msg.lower() or rs.error_code == '10002': # Check if this applies raise NoDataFoundError( f"No stock data found for date {date}. Baostock msg: {rs.error_msg}") else: raise DataSourceError( f"Baostock API error fetching all stock list: {rs.error_msg} (code: {rs.error_code})") data_list = [] while rs.next(): data_list.append(rs.get_row_data()) if not data_list: logger.warning( f"No stock list returned for date {date} (empty result set).") raise NoDataFoundError( f"No stock list found for date {date} (empty result set).") result_df = pd.DataFrame(data_list, columns=rs.fields) logger.info( f"Retrieved {len(result_df)} stock records for date {date or 'default'}.") return result_df except (LoginError, NoDataFoundError, DataSourceError, ValueError) as e: logger.warning( f"Caught known error fetching all stock list for date {date}: {type(e).__name__}") raise e except Exception as e: logger.exception( f"Unexpected error fetching all stock list for date {date}: {e}") raise DataSourceError( f"Unexpected error fetching all stock list for date {date}: {e}")
- src/data_source_interface.py:93-96 (schema)Abstract method signature in FinancialDataSource interface defining the expected input/output for get_all_stock.@abstractmethod def get_all_stock(self, date: Optional[str] = None) -> pd.DataFrame: """Fetches list of all stocks and their trading status on a given date.""" pass