This page explains how to connect Claude AI agents (via Anthropic API) to automatically generate new stock analysis articles for Alpha Stocks Insight. Agents pull real-time data from public APIs, synthesize it into original analysis, and write it to the articles JSON file.
Required to run Claude agents. Create an account and generate an API key. Recommended model: claude-opus-4-6 for analysis quality, claude-haiku-4-5-20251001 for speed/cost.
Excellent for stock quotes + news sentiment. Free tier: 25 calls/day (sufficient for daily article generation).
ALPHA_VANTAGE_API_KEY=your_key_here
Store all API keys in a .env.local file (never commit to git).
Step 2: Agent System Prompt Template
Use this system prompt when creating your Claude agent. It instructs Claude to generate articles in the correct format for this site:
You are a financial news analyst for Alpha Stocks Insight.
Your task: Generate a professional stock analysis article.
INPUT: You will receive:
- A stock ticker (e.g., NASDAQ:NVDA)
- Recent news headlines and data for that stock
- Today's date
OUTPUT: Return a JSON object matching this exact schema:
{
"id": <next_available_integer>,
"slug": "<kebab-case-title>",
"title": "<compelling headline, 60-100 chars>",
"author": "<one of: Marcus Chen, Sarah Mitchell, James Rivera, Emma Thornton, David Park, Lisa Wang, Robert Kim, Michael Torres>",
"authorBio": "<one-sentence bio for the author>",
"date": "<e.g., April 20, 2026>",
"time": "<e.g., 9:42 AM ET>",
"dateISO": "<ISO 8601 datetime>",
"teaser": "<2-3 sentence summary, 150-200 chars>",
"content": "<FULL article in Markdown, 600-1200 words, with ## headers>",
"tickers": [{"exchange": "NASDAQ", "symbol": "NVDA"}],
"category": "<one of: Earnings Preview, Earnings, Stock Analysis, Technology, Semiconductors, Cloud Computing, AI & Technology, Big Tech, Government & Defense, AI Infrastructure>",
"featured": false,
"readTime": "<X min read>",
"tags": ["tag1", "tag2", "tag3"]
}
RULES:
- Content must include sections: analysis, key metrics, risks, conclusion
- Always end content with: "*This analysis is for informational purposes only.*"
- Use factual, measured language — not hype
- Include specific numbers and data points from the provided news
- Do NOT invent financial figures — only use what was provided
- Do NOT provide a buy/sell recommendation
Step 3: Agent Script (Node.js / Python)
Create a script that: (1) reads your ticker list, (2) fetches news from Finnhub, (3) calls Claude to generate the article, (4) appends it to articles.json. Run it via a cron job or GitHub Action for automated daily publishing.
# agents/generate_articles.py
import json, os, datetime, httpx
import anthropic
client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
finnhub_key = os.environ["FINNHUB_API_KEY"]
# 1. Load ticker list
with open("data/tickers.json") as f:
tickers = json.load(f)
# 2. Load existing articles (to get next ID)
with open("data/articles.json") as f:
articles = json.load(f)
next_id = max(a["id"] for a in articles) + 1
# 3. For each ticker, fetch news + generate article
for ticker in tickers[:3]: # limit to 3 per run
sym = ticker["symbol"]
# Fetch latest news from Finnhub
url = f"https://finnhub.io/api/v1/company-news?symbol={sym}&from={datetime.date.today()}&to={datetime.date.today()}&token={finnhub_key}"
news = httpx.get(url).json()[:5] # top 5 headlines
news_text = "\n".join([f"- {n['headline']}: {n['summary'][:200]}" for n in news])
# 4. Call Claude to generate article
msg = client.messages.create(
model="claude-opus-4-6",
max_tokens=2000,
system=SYSTEM_PROMPT, # paste the prompt from Step 2
messages=[{
"role": "user",
"content": f"Generate an article for {ticker['exchange']}:{sym}\n\nRecent news:\n{news_text}\n\nToday: {datetime.date.today()}"
}]
)
# 5. Parse and append article
article = json.loads(msg.content[0].text)
article["id"] = next_id
next_id += 1
articles.insert(0, article)
# 6. Save updated articles.json
with open("data/articles.json", "w") as f:
json.dump(articles, f, indent=2)
print(f"Generated {len(tickers[:3])} new articles.")
Note: All AI-generated articles must include the standard disclaimer (already included in the article page component). Review article output occasionally to ensure quality and factual accuracy. Never use generated financial figures that are not grounded in real data sources.
Important Legal Disclaimer: This is for informational purposes only and is not financial, investment, or tax advice. Past performance is no guarantee of future results. We are not licensed advisors. For Swiss residents: This does not constitute a public offer under FINSA. For EU residents: Not MiFID II compliant advice. For US residents: Not SEC-registered advice. Always consult a qualified professional. Investing involves risk of loss.