get_latest_trading_date
Retrieve the most recent trading date for China's A-share market. Returns the current date if it's a trading day; otherwise, provides the last available trading date in 'YYYY-MM-DD' format.
Instructions
获取最近的交易日期。如果当天是交易日,则返回当天日期;否则返回最近的交易日。
Returns:
最近的交易日期,格式为'YYYY-MM-DD'。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/date_utils.py:25-59 (handler)The handler function for the 'get_latest_trading_date' tool. It queries the active data source for recent trading dates, filters valid trading days up to today, and returns the latest one in 'YYYY-MM-DD' format. Falls back to today if none found.def get_latest_trading_date() -> str: """ Get the latest trading date up to today. Returns: The latest trading date in 'YYYY-MM-DD' format. """ logger.info("Tool 'get_latest_trading_date' called") try: today = datetime.now().strftime("%Y-%m-%d") # Query within the current month (safe bound) start_date = (datetime.now().replace(day=1)).strftime("%Y-%m-%d") end_date = (datetime.now().replace(day=28)).strftime("%Y-%m-%d") df = active_data_source.get_trade_dates( 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 if latest_trading_date: logger.info("Latest trading date found: %s", latest_trading_date) return latest_trading_date else: logger.warning("No trading dates found before today, returning today's date") return today except Exception as e: logger.exception("Error determining latest trading date: %s", e) return datetime.now().strftime("%Y-%m-%d")
- mcp_server.py:56-56 (registration)The call to register_date_utils_tools, which defines and registers the get_latest_trading_date tool (among others) with the FastMCP app instance.register_date_utils_tools(app, active_data_source)
- mcp_server.py:18-18 (registration)Import of the register_date_utils_tools function used to register the date utilities tools including get_latest_trading_date.from src.tools.date_utils import register_date_utils_tools