The /api/events/trigger endpoint allows you to manually trigger market events that will run the full analysis pipeline and generate personalized newsletters and content drafts.
POST /api/events/trigger
| Parameter | Type | Default | Description |
|---|---|---|---|
user_id |
string | "demo-user" |
User ID for personalization. Use "all" to generate newsletters for all users in the database. |
persona |
string | "buffett" |
Investment persona: buffett, trump, burry, or all |
{
"ticker": "NVDA",
"event_type": "price_drop",
"change_pct": 11.1,
"timeframe": "2h",
"threshold": -10.0,
"price_at_trigger": 145.32
}| Field | Type | Required | Description |
|---|---|---|---|
ticker |
string | Yes | Stock ticker symbol (e.g., "NVDA", "AAPL") |
event_type |
string | Yes | Type of event: price_drop, price_spike, or volume_surge |
change_pct |
float | Yes | Percentage change that triggered the event |
timeframe |
string | No | Time window for the event (default: "2h") |
threshold |
float | No | Threshold value (auto-calculated if not provided) |
price_at_trigger |
float | No | Stock price at trigger time |
{
"event_id": "550e8400-e29b-41d4-a716-446655440000",
"task_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "processing"
}The newsletter generation behavior depends on the user_id parameter:
Generates newsletter only for the specified user.
curl -X POST "http://localhost:8000/api/events/trigger?user_id=demo-user&persona=buffett" \
-H "Content-Type: application/json" \
-d '{
"ticker": "NVDA",
"event_type": "price_drop",
"change_pct": 11.1,
"timeframe": "2h"
}'Result: Newsletter created for demo-user only.
Generates newsletter only for that specific user.
curl -X POST "http://localhost:8000/api/events/trigger?user_id=28ccec92-6473-4af6-9e24-6d1f9768700b&persona=buffett" \
-H "Content-Type: application/json" \
-d '{
"ticker": "NVDA",
"event_type": "price_drop",
"change_pct": 11.1,
"timeframe": "2h"
}'Result: Newsletter created for user 28ccec92-6473-4af6-9e24-6d1f9768700b only.
Generates newsletters for all users in the database.
curl -X POST "http://localhost:8000/api/events/trigger?user_id=all&persona=buffett" \
-H "Content-Type: application/json" \
-d '{
"ticker": "NVDA",
"event_type": "price_drop",
"change_pct": 11.1,
"timeframe": "2h"
}'Result: Newsletters created for every user in the users table.
- Market Event Creation: A record is created in the
market_eventstable with statusdetected - Status Update: Event status changes to
processing - Analysis Pipeline: The LangGraph analysis pipeline runs with 4 nodes:
- Anomaly Detection: Validates the market event
- News Correlation: Fetches and correlates relevant news
- Behavioral Coaching: Generates personalized coaching advice
- Content Generation: Creates social media content drafts
- Content Drafts: Platform-specific content saved to
content_draftstable - Newsletter Generation: Personalized newsletters saved to
user_newsletterstable (based onuser_idparameter) - Status Update: Event status changes to
completed(orfailedif error occurs)
The pipeline broadcasts real-time progress via WebSocket at ws://localhost:8000/ws:
analysis_started: Pipeline beginsnode_started: Individual node begins processingnode_completed: Individual node finishesanalysis_complete: Full pipeline completes
market_events: Event record and statuscontent_drafts: Social media content (Twitter, LinkedIn, etc.)user_newsletters: Personalized newsletter entries
- Newsletters are only generated if
is_anomalyistruein the analysis result - The
force_anomalyflag is set totruefor manual triggers to ensure the pipeline runs - Content drafts are always saved, regardless of anomaly detection
- The analysis is personalized based on the
user_idparameter (affects coaching advice) - The pipeline runs asynchronously in the background
If the pipeline fails:
- Event status is set to
failed - Error details are stored in
market_events.metadata.error - Check server logs for detailed stack traces
curl "http://localhost:8000/api/events/{event_id}"Returns event details plus linked content drafts and newsletters.
curl "http://localhost:8000/api/events?limit=20&status=completed"Query parameters:
status: Filter by status (detected,processing,completed,failed)ticker: Filter by ticker symbollimit: Max results (default: 20, max: 50)