get_cash_flow_data
Retrieve quarterly cash flow data for A-share stocks to analyze financial performance and liquidity metrics.
Instructions
Quarterly cash flow data.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| year | Yes | ||
| quarter | Yes | ||
| limit | No | ||
| format | No | markdown |
Implementation Reference
- src/tools/financial_reports.py:63-69 (handler)The primary MCP tool handler for 'get_cash_flow_data'. It is registered using @app.tool() decorator, performs error handling via run_tool_with_handling, and delegates to the use case fetch_cash_flow_data.@app.tool() def get_cash_flow_data(code: str, year: str, quarter: int, limit: int = 250, format: str = "markdown") -> str: """Quarterly cash flow data.""" return run_tool_with_handling( lambda: fetch_cash_flow_data(active_data_source, code=code, year=year, quarter=quarter, limit=limit, format=format), context=f"get_cash_flow_data:{code}:{year}Q{quarter}", )
- Helper use case function that validates inputs (year, quarter, format), fetches raw data from data_source, and formats it into a markdown table.def fetch_cash_flow_data(data_source: FinancialDataSource, *, code: str, year: str, quarter: int, limit: int, format: str) -> str: validate_year(year) validate_quarter(quarter) validate_output_format(format) df = data_source.get_cash_flow_data(code=code, year=year, quarter=quarter) return _format_financial_df(df, code=code, year=year, quarter=quarter, dataset="Cash Flow", format=format, limit=limit)
- src/data_source_interface.py:150-152 (schema)Abstract method definition in the data source interface, specifying the input parameters and return type for cash flow data retrieval.@abstractmethod def get_cash_flow_data(self, code: str, year: str, quarter: int) -> pd.DataFrame: pass
- src/baostock_data_source.py:429-431 (helper)Concrete implementation of get_cash_flow_data in Baostock data source, delegating to a shared _fetch_financial_data helper that calls the Baostock API.def get_cash_flow_data(self, code: str, year: str, quarter: int) -> pd.DataFrame: """Fetches quarterly cash flow data using Baostock.""" return _fetch_financial_data(bs.query_cash_flow_data, "Cash Flow", code, year, quarter)