get_month_end_trading_dates
Retrieve month-end trading dates for A-share markets in a specified year to support financial analysis and reporting.
Instructions
Return month-end trading dates for a given year.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| year | Yes |
Implementation Reference
- src/tools/date_utils.py:77-83 (handler)MCP tool handler function for 'get_month_end_trading_dates'. It wraps the use case execution with error handling via run_tool_with_handling.
@app.tool() def get_month_end_trading_dates(year: int) -> str: """Return month-end trading dates for a given year.""" return run_tool_with_handling( lambda: uc_date.get_month_end_trading_dates(active_data_source, year=year), context=f"get_month_end_trading_dates:{year}", ) - src/use_cases/date_utils.py:102-113 (helper)Core helper function implementing the logic to fetch the last trading day of each month for a given year using the financial data source.
def get_month_end_trading_dates(data_source: FinancialDataSource, *, year: int) -> str: results = [] for month in range(1, 13): last_day = calendar.monthrange(year, month)[1] start_date = datetime(year, month, last_day - 7).strftime("%Y-%m-%d") end_date = datetime(year, month, last_day).strftime("%Y-%m-%d") df = _fetch_trading_days(data_source, start_date=start_date, end_date=end_date) trading_days = df[df["is_trading_day"] == "1"]["calendar_date"].tolist() if trading_days: results.append(trading_days[-1]) return ", ".join(results) - mcp_server.py:56-56 (registration)Invocation of register_date_utils_tools which registers the date utility tools, including 'get_month_end_trading_dates', to the FastMCP app.
register_date_utils_tools(app, active_data_source)