previous_trading_day
Calculate the previous trading day for A-share market analysis by inputting any date to identify valid market days for historical data review and trading strategy planning.
Instructions
Get the previous trading day before the given date.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes |
Implementation Reference
- src/tools/date_utils.py:45-51 (handler)The MCP tool handler for 'previous_trading_day', decorated with @app.tool(). It wraps the use case function with error handling via run_tool_with_handling.@app.tool() def previous_trading_day(date: str) -> str: """Get the previous trading day before the given date.""" return run_tool_with_handling( lambda: uc_date.previous_trading_day(active_data_source, date=date), context=f"previous_trading_day:{date}", )
- mcp_server.py:56-56 (registration)Invocation of register_date_utils_tools which defines and registers the date utils tools, including 'previous_trading_day', to the FastMCP app.register_date_utils_tools(app, active_data_source)
- src/use_cases/date_utils.py:64-70 (helper)Core implementation of previous_trading_day logic: fetches trading days in a 31-day window before the given date and returns the most recent trading day prior to it.def previous_trading_day(data_source: FinancialDataSource, *, date: str) -> str: target = datetime.strptime(date, "%Y-%m-%d") start = (target - timedelta(days=31)).strftime("%Y-%m-%d") df = _fetch_trading_days(data_source, start_date=start, end_date=date) days = df[df["is_trading_day"] == "1"]["calendar_date"].tolist() prev = max([d for d in days if d < date], default=None) return prev or date