get_all_symbols_by_industry
Retrieve stock symbols from Vietnam's market filtered by industry sector, with options for JSON or DataFrame output formats.
Instructions
Get all symbols from stock market
Args:
industry: str = None (if None, return all symbols)
output_format: Literal['json', 'dataframe'] = 'json'
Returns:
pd.DataFrame or jsonInput Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| industry | No | ||
| output_format | No | json |
Implementation Reference
- src/vnstock_mcp/server.py:333-361 (handler)The handler function for the 'get_all_symbols_by_industry' tool. It retrieves all symbols grouped by industries using VCIListing.symbols_by_industries(), optionally filters by a specific industry code across ICB code columns, and returns the result in JSON or DataFrame format. The @server.tool() decorator registers this function as an MCP tool.
@server.tool() def get_all_symbols_by_industry( industry: str = None, output_format: Literal["json", "dataframe"] = "json" ): """ Get all symbols from stock market Args: industry: str = None (if None, return all symbols) output_format: Literal['json', 'dataframe'] = 'json' Returns: pd.DataFrame or json """ listing = VCIListing() df = listing.symbols_by_industries() if industry: codes = ["icb_code1", "icb_code2", "icb_code3", "icb_code4"] masks = [] for col in codes: if col in df.columns: masks.append(df[col].astype(str) == industry) if masks: mask = masks[0] for m in masks[1:]: mask = mask | m df = df[mask] if output_format == "json": return df.to_json(orient="records", force_ascii=False) else: return df