get_last_n_trading_days
Retrieve recent trading dates for China's A-share market to analyze market activity, schedule transactions, or calculate time-based metrics.
Instructions
Return the last N trading dates.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | No |
Implementation Reference
- src/use_cases/date_utils.py:82-89 (handler)Core implementation of get_last_n_trading_days: fetches trading days data and returns the last N dates as a comma-separated string.def get_last_n_trading_days(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() return ", ".join(trading_days[-days:]) if trading_days else ""
- src/tools/date_utils.py:61-67 (registration)Registers the MCP tool 'get_last_n_trading_days' with @app.tool(), defining input schema (days: int=5) and delegating to the use case via run_tool_with_handling.@app.tool() def get_last_n_trading_days(days: int = 5) -> str: """Return the last N trading dates.""" return run_tool_with_handling( lambda: uc_date.get_last_n_trading_days(active_data_source, days=days), context=f"get_last_n_trading_days:{days}", )