get_latest_trading_date
Retrieve the most recent stock market trading date for China's A-share market to ensure accurate financial data analysis and reporting.
Instructions
Get the latest trading date up to today.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/date_utils.py:20-26 (handler)MCP tool handler function for 'get_latest_trading_date'. Logs the invocation and delegates execution to the use case layer via run_tool_with_handling.def get_latest_trading_date() -> str: """Get the latest trading date up to today.""" logger.info("Tool 'get_latest_trading_date' called") return run_tool_with_handling( lambda: uc_date.get_latest_trading_date(active_data_source), context="get_latest_trading_date", )
- src/use_cases/date_utils.py:15-25 (helper)Core helper function implementing the logic to fetch recent trading days from the data source and determine the latest trading date up to today.def get_latest_trading_date(data_source: FinancialDataSource) -> str: today = datetime.now().strftime("%Y-%m-%d") start_date = datetime.now().replace(day=1).strftime("%Y-%m-%d") end_date = datetime.now().replace(day=28).strftime("%Y-%m-%d") df = _fetch_trading_days(data_source, start_date=start_date, end_date=end_date) valid_trading_days = df[df["is_trading_day"] == "1"]["calendar_date"].tolist() latest_trading_date = None for dstr in valid_trading_days: if dstr <= today and (latest_trading_date is None or dstr > latest_trading_date): latest_trading_date = dstr return latest_trading_date or today
- mcp_server.py:56-56 (registration)Invocation of the registration function that defines and registers the 'get_latest_trading_date' tool (among others) to the FastMCP app.register_date_utils_tools(app, active_data_source)