get_recent_trading_range
Calculate date ranges for recent trading periods to analyze A-share market data, supporting historical price queries and financial analysis.
Instructions
Return a date range string covering the recent N trading days.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | No |
Implementation Reference
- src/tools/date_utils.py:69-75 (handler)MCP tool handler for get_recent_trading_range. It is decorated with @app.tool() and delegates execution to the use case layer via run_tool_with_handling for error handling and logging.
@app.tool() def get_recent_trading_range(days: int = 5) -> str: """Return a date range string covering the recent N trading days.""" return run_tool_with_handling( lambda: uc_date.get_recent_trading_range(active_data_source, days=days), context=f"get_recent_trading_range:{days}", ) - src/use_cases/date_utils.py:91-99 (helper)Core implementation logic for computing the recent trading range. Fetches trading days from data source and formats the date range string.
def get_recent_trading_range(data_source: FinancialDataSource, *, days: int) -> str: today = datetime.now() start = (today - timedelta(days=days * 2)).strftime("%Y-%m-%d") end = today.strftime("%Y-%m-%d") df = _fetch_trading_days(data_source, start_date=start, end_date=end) trading_days = df[df["is_trading_day"] == "1"]["calendar_date"].tolist() if not trading_days: return "" return f"{trading_days[-days]} 至 {trading_days[-1]}" if len(trading_days) >= days else f"{trading_days[0]} 至 {trading_days[-1]}" - mcp_server.py:56-56 (registration)Invocation of the register_date_utils_tools function in the main MCP server setup, which registers the get_recent_trading_range tool among others.
register_date_utils_tools(app, active_data_source)