Implementation:24mlight A Share investment Agent get stock news
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Data_Engineering, Web_Scraping, Finance |
| Last Updated | 2026-10-10 14:00 GMT |
Overview
Concrete tool for fetching stock news with SQLite cache lookup, Tavily API search, deduplication, and cache write-back provided by the A_Share_investment_Agent repository.
Description
The get_stock_news function implements a multi-layer news fetching pipeline:
- Checks
stock_news_daily_cachein SQLite for cached news by symbol and date - If cache sufficient (>= max_news), returns cached slice immediately
- Otherwise builds a search query via
build_news_query() - Searches via
TavilyNewsSearch.search()with API key rotation - Merges new results with cache, deduplicates by title, sorts by time
- Writes combined list back to SQLite cache
- Returns up to max_news items
The companion function get_news_sentiment sends formatted news to an LLM for sentiment scoring.
Usage
Import when you need to:
- Fetch news articles for a stock with caching
- Get sentiment analysis from news content via LLM
Code Reference
Source Location
- Repository: A_Share_investment_Agent
- File: src/tools/news_crawler.py
- Lines: L70-217 (get_stock_news), L226-326 (get_news_sentiment)
Signature
def get_stock_news(
symbol: str,
max_news: int = 10,
date: str = None,
*,
agent_name: str | None = None,
trace_state: dict | None = None,
) -> list:
"""Fetch stock news with cache-first strategy."""
def get_news_sentiment(
news_list: list,
num_of_news: int = 5,
*,
symbol: str | None = None,
cache_date: str | None = None,
trace_state: dict | None = None,
agent_name: str | None = None,
) -> dict:
"""Analyze news sentiment via LLM, returning {score, signal, confidence, reasoning}."""
Import
from src.tools.news_crawler import get_stock_news, get_news_sentiment
I/O Contract
Inputs (get_stock_news)
| Name | Type | Required | Description |
|---|---|---|---|
| symbol | str | Yes | Stock code (6-digit) |
| max_news | int | No | Maximum news items (default: 10, cap: 50) |
| date | str | No | Cache date (YYYY-MM-DD) |
| agent_name | str | No | Agent name for query optimization |
| trace_state | dict | No | Trace state for LLM logging |
Outputs (get_stock_news)
| Name | Type | Description |
|---|---|---|
| return | list[dict] | News items with title, content, source, publish_time, search_time |
Outputs (get_news_sentiment)
| Name | Type | Description |
|---|---|---|
| return | dict | {score: float (-1 to 1), signal: str, confidence: float, reasoning: str} |
Usage Examples
Fetch News with Caching
from src.tools.news_crawler import get_stock_news
news = get_stock_news(
symbol="002848",
max_news=10,
date="2025-01-15",
agent_name="sentiment_agent",
trace_state=state,
)
print(f"Fetched {len(news)} news articles")
Analyze Sentiment
from src.tools.news_crawler import get_news_sentiment
result = get_news_sentiment(
news_list,
num_of_news=5,
symbol="002848",
cache_date="2025-01-15",
trace_state=state,
agent_name="sentiment_agent",
)
# result = {"score": 0.35, "signal": "bullish", "confidence": 0.7, "reasoning": "..."}
Related Pages
Implements Principle
- Principle:24mlight_A_Share_investment_Agent_News_Search_Pipeline
- Principle:24mlight_A_Share_investment_Agent_News_Sentiment_Analysis
Requires Environment
Uses Heuristics
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment