Implementation:24mlight A Share investment Agent market data agent
| Knowledge Sources | |
|---|---|
| Domains | Finance, Data_Engineering |
| Last Updated | 2026-10-10 14:00 GMT |
Overview
Concrete tool for gathering and preprocessing A-share market data (price history, financial metrics, statements, market snapshot) provided by the A_Share_investment_Agent repository.
Description
The market_data_agent function is the entry point of the LangGraph analysis workflow. It collects all data required by downstream analysis agents: OHLCV price history via AkShare, financial metrics (ROE, margins, growth, P/E, P/B, P/S), financial statements (balance sheet, income statement, cash flow), and an LLM-generated market snapshot. It handles date normalization (defaulting to yesterday, capping at yesterday), validates data integrity, and gracefully degrades when individual data sources fail.
Usage
Import and use this function when you need to:
- Gather all market data for a stock before running analysis agents
- Serve as the entry node in a LangGraph workflow
This function is decorated with @agent_endpoint("market_data", "市场数据收集...") for automatic monitoring.
Code Reference
Source Location
- Repository: A_Share_investment_Agent
- File: src/agents/market_data.py
- Lines: L17-135
Signature
@agent_endpoint("market_data", "市场数据收集,负责获取股价历史、财务指标和市场信息")
def market_data_agent(state: AgentState) -> dict:
"""Responsible for gathering and preprocessing market data"""
...
Import
from src.agents.market_data import market_data_agent
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| state | AgentState | Yes | LangGraph shared state with data["ticker"], data["start_date"], data["end_date"], data["portfolio"], metadata["show_reasoning"] |
Outputs
| Name | Type | Description |
|---|---|---|
| data["prices"] | list[dict] | OHLCV price records (list of dicts) |
| data["financial_metrics"] | dict | Financial indicators (ROE, margins, growth, ratios) |
| data["financial_line_items"] | dict | Financial statements (balance sheet, income, cash flow) |
| data["market_cap"] | float | Market capitalization |
| data["market_data"] | dict | Market data including volume, 52-week range |
| data["start_date"] | str | Normalized start date (YYYY-MM-DD) |
| data["end_date"] | str | Normalized end date (YYYY-MM-DD, capped at yesterday) |
Usage Examples
Basic Usage in LangGraph
from src.agents.market_data import market_data_agent
from src.main import app
# The agent is invoked as part of the LangGraph workflow
initial_state = {
"messages": [],
"data": {
"ticker": "002848",
"portfolio": {"cash": 100000.0, "stock": 0},
"start_date": None, # Auto: 1 year before end_date
"end_date": None, # Auto: yesterday
},
"metadata": {
"show_reasoning": True,
"run_id": "test-run-001",
}
}
# market_data_agent runs as the entry point of the compiled graph
final_state = app.invoke(initial_state)
Sub-calls
The agent calls these functions internally:
get_price_history(ticker, start_date, end_date)— fetches OHLCV dataget_market_snapshot(ticker, trace_state, agent_name, as_of_date)— LLM market snapshotget_financial_metrics(ticker, trace_state, as_of_date, snapshot)— financial indicatorsget_financial_statements(ticker, as_of_date)— financial statementsget_market_data(ticker, trace_state, as_of_date, snapshot)— market cap and volume