Inspiration
StrikeLab's AI tutor already helps students understand options pricing — Socratic hints, code review, passage re-explanation, all running on Groq. For this hackathon we wanted the AI to do more than explain: we wanted it to act. So we built a paper-trading sandbox where one AI surface turns a plain-English market view into a real, structured trade, and a second explains the risk of whatever you end up holding.
What it does
The Sandbox gives every signed-in StrikeLab user $100,000 in simulated cash to trade stocks, calls, and puts across ~90 real tickers, with two connected AI features:
1. AI Trade Idea Generator. Type a market thesis in plain English — "I think NVDA runs into earnings but I want limited risk" — and Groq (Llama 3.3 70B, JSON mode) returns a strict, structured trade: ticker, asset type, side, strike, expiry, and a position size scaled to the account. The server validates every field — the ticker must match the real watchlist, asset type and side must be valid enums, strike and expiry get clamped to sane ranges — before the client ever autofills the order ticket. A hallucinated or malformed response is rejected outright rather than silently corrupting a trade.
2. AI Trade Coach. On any position — proposed or already open — click for a short, streamed explanation of its risk/reward: moneyness, position sizing relative to the account, time-decay exposure. Same Groq infrastructure as the idea generator, but streaming mode instead of JSON mode, because a half-arrived structured object is useless but a half-arrived sentence still reads fine.
Both features share the exact quota system that already governs StrikeLab's lesson tutor, hint generator, and code reviewer — so a new AI surface didn't mean a new way to blow the AI budget.
Underneath both: options are priced by a hand-ported TypeScript Black-Scholes engine (the same math the lessons teach), and stocks move on a seeded geometric Brownian motion walk — fully simulated, no external market-data dependency.
How we built it
- Structured generation:
completeGroqJson, an existing shared helper, requests Groq'sjson_objectresponse format. We treat the model's output as untrusted input — every field is validated and clamped server-side (ticker existence, enum membership, numeric bounds) before it reaches the client. - Streaming generation:
streamGroqChattransforms Groq's SSE stream into plain UTF-8 text the client appends directly into state — the same pattern already used by the lesson tutor, code reviewer, and passage explainer. - Quota: both new AI actions (
sandboxTradeIdea,sandboxInsight) plug into the existing per-user daily action budget (consumeAiQuota), so cost stays bounded without inventing a parallel rate-limiter. - Data layer: three new Supabase tables (
sandbox_accounts,sandbox_positions,sandbox_trades), row-level-security scoped toauth.uid(), backing three trade-execution API routes independent of the AI routes. - Pricing: Black-Scholes ported from the Playground's Python reference implementation to TypeScript, verified against textbook values (S=K=100, T=1, r=5%, σ=20% → call ≈ $10.4506, put ≈ $5.5735, matched to 4 decimal places).
Challenges we ran into
- Trusting the model's output. An LLM returning a ticker that doesn't exist, a negative quantity, or a strike three orders of magnitude off isn't a hypothetical — it's the default failure mode of JSON-mode generation. Every field from the trade-idea endpoint gets validated against the real watchlist and clamped to sane bounds before it can touch a trade; a bad response fails loudly with an error message, not silently with a broken order.
- Two Groq call patterns in one feature. Deciding when structured JSON mode is right (trade generation, where a half-object is useless) versus streaming (trade explanation, where partial output is still valuable) shaped both routes' design from the start.
- Verifying without a screenshot. Every AI response — structured and streamed — was verified against production by reading actual network responses, not by eyeballing a rendered panel.
Accomplishments that we're proud of
- A genuinely two-sided AI loop — generation and explanation — sharing one quota system and one Groq client, not two disconnected integrations.
- Server-side validation that treats LLM output the way you'd treat any other untrusted client input, not as ground truth.
- Both features shipped, merged, and verified live on production the same day they were designed.
What we learned
Structured LLM output is only as trustworthy as the validation layer behind it — the interesting engineering problem in an "AI trade generator" isn't the prompt, it's deciding what happens when the model gets it wrong.
What's next
- Multi-turn refinement: let a student push back on a generated idea ("what if I want less risk?") instead of regenerating from scratch.
- A portfolio-level AI summary aggregating risk across all open positions, not just one at a time.
- Real market data as an opt-in "hard mode" once the simulated mode has proven the UX out.
Built With
- css
- extjs
- groq
- javascript
- llama
- node.js
- postgresql
- react
- recharts
- supabase
- typescript
- vercel

Log in or sign up for Devpost to join the conversation.