get_recent_trading_range
Calculate date ranges for recent trading periods to analyze stock market data within specified timeframes.
Instructions
Return a date range string covering the recent N trading days.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | No |
Implementation Reference
- src/tools/date_utils.py:69-75 (handler)The 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.@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}", )
- mcp_server.py:56-56 (registration)The call to register_date_utils_tools, which includes the registration of the get_recent_trading_range tool via @app.tool() decorators.register_date_utils_tools(app, active_data_source)
- src/use_cases/date_utils.py:91-99 (helper)Core helper function implementing the logic to compute the recent trading range by fetching trading days and selecting the last N days.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]}"