What if your portfolio dashboard could think?
Here's a stat that should bother any developer who invests: the S&P 500 and Nasdaq can sit flat for weeks (recently hovering around 738 and 705 index points), yet the average retail investor still checks prices manually 14 times a day. That's roughly 5,000 context switches a year to learn nothing changed.
Flat markets are a data problem, not a willpower problem. So let's solve it like engineers: build an automated pipeline that ingests market data, reasons about it with an LLM, and only pings you when something actually deserves attention.
In this article we'll wire up a market-monitoring workflow using n8n (open-source automation), a market data API, and GPT-4 for signal interpretation.
The architecture
Cron (every 15m)
→ HTTP Request (fetch quotes)
→ Function (compute deltas + volatility)
→ IF (threshold breached?)
→ GPT-4 (summarize + classify)
→ Slack / Email notify
The key design principle: push computation to the edge, push judgment to the LLM, push noise to /dev/null. We don't ask GPT-4 "should I check the market?" — that's expensive and slow. We let deterministic code gate the call.
Step 1: Pull the data
Most market APIs (Alpha Vantage, Finnhub, Polygon) expose a simple REST quote endpoint. In an n8n HTTP Request node:
GET https://finnhub.io/api/v1/quote?symbol=SPY&token={{$env.FINNHUB_KEY}}
Returns something like:
{ "c": 738.12, "pc": 737.95, "h": 739.40, "l": 736.10 }
c = current, pc = previous close. Everything we need to detect movement.
Step 2: Compute the signal (deterministic, cheap)
This is plain JS inside an n8n Function node — no AI required for arithmetic:
javascript
const { c, pc, h, l } = $input.first().json;
const pctChange = ((c - pc) / pc) * 100;
const intradayRange = ((h - l) / pc) * 100;
// Stable market = tight range AND small move.
// We only escalate to GPT-4 when it's NOT stable.
const isNoteworthy = Math.abs(pctChange) > 0.75 || intradayRange > 1.5;
return [{
json: { pctChange: +pctChange.toFixed(2), intradayRange: +intradayRange.toFixed(2), isNoteworthy }
}];
An IF node then routes on isNoteworthy. On a flat day, the workflow stops here — zero LLM cost.
Step 3: Let GPT-4 interpret, not just report
When the threshold is breached, we hand the numbers to GPT-4 with a tightly scoped prompt. The trick is forcing structured output so downstream nodes stay deterministic:
javascript
const payload = {
model: "gpt-4",
response_format: { type: "json_object" },
messages: [
{ role: "system", content: "You are a market signal classifier. Reply ONLY with JSON: {severity, oneLiner}. severity is low|medium|high." },
{ role: "user", content: SPY moved ${$json.pctChange}% with a ${$json.intradayRange}% intraday range. Classify it. }
]
};
Note what we're not doing: we never let the model invent prices or give financial advice. It classifies the delta we computed. The deterministic layer owns the facts; the LLM owns the language.
Step 4: Notify with context
Pipe the classified result into a Slack node, gated again so only medium/high severity reaches your phone:
🔴 SPY +1.2% (range 1.8%) — "Breakout above prior close on widening range; watch for continuation."
Why this beats a dumb price alert
Classic threshold alerts fire on every wiggle and you learn to ignore them — alert fatigue is just unfiltered data. By inserting an LLM classification step behind a deterministic gate, you get human-readable triage without paying for an API call on every quiet tick.
The same pattern generalizes far beyond finance: log monitoring, CI failure triage, on-call paging. Cheap code decides whether; the LLM decides what it means.
Practical takeaways
-
Gate your LLM calls. Never let GPT-4 do arithmetic or polling logic — that's what
Math.abs()is for. Use it only where judgment adds value. -
Force structured output (
response_format: json_object) so the automation downstream stays deterministic and testable. - Tier your notifications by severity so the pipeline fights alert fatigue instead of causing it.
- Keep facts and language separate. Computed values are the source of truth; the model only narrates them — this also keeps you clear of giving automated financial advice.
- Run it on a cron, not a loop. A 15-minute n8n schedule is plenty for non-day-traders and keeps API quotas happy.
Clone the workflow, swap SPY for your watchlist, and reclaim those 5,000 context switches. Stable markets are boring — let your automation be bored for you.
Want the done-for-you AI automation templates from this post? Get the NSST AI toolkit.
Top comments (0)