STOCKY TERMINAL - AI AGENTS & AUTOMATION ========================================= REPO: https://github.com/SirCharan/stocky-terminal LIVE: https://terminal.stockyai.xyz BLOG: https://terminal.stockyai.xyz/blog LICENSE: AGPL-3.0 OVERVIEW -------- Stocky Terminal is a real-time global market intelligence platform. It uses Groq AI (Llama 3.3 70B Versatile) as its primary intelligence engine, with chain-of-thought prompting, live market price injection, and Nifty-aware signal coherence filtering. The platform publishes automated daily market briefs (morning & evening) with AI trade signals, delivers them via email to 70+ subscribers, and is installable as a PWA with push notifications and offline support. CAPABILITIES ------------ - Real-time equity prices (NSE, BSE, global markets) - Gift Nifty (SGX Nifty) pre-market indicator via NSE India - Commodity tracking (gold, silver, crude oil, natural gas, copper) - Live forex rates (20+ currency pairs) - Cryptocurrency dashboard (25 coins via CoinGecko) - 30+ RSS news feeds with severity scoring and deduplication - AI-powered trade signal generation with confidence scores - Pre-cached AI insights refreshed every 15 minutes - Daily market briefs (morning 8AM IST, evening 8PM IST, Mon-Fri) - Email delivery to 70+ subscribers via Resend - 1-10 rating system for market briefs - Blog system with server-rendered HTML and PDF download - Geopolitical OSINT with conflict zone mapping (ACLED) - 27-layer interactive map (deck.gl + MapLibre) - Live earthquake (USGS), disaster (GDACS), fire (NASA FIRMS) tracking - Internet outage monitoring (Cloudflare Radar) - Social sharing (WhatsApp, Telegram, LinkedIn, X/Twitter) - 3-tier audio alert system - Universal fuzzy search with AI summaries - Installable PWA with service worker, offline mode, and push notifications - Chain-of-thought AI reasoning with live price injection - Signal confidence levels (high/medium/low) per affected asset - Nifty-aware coherence filtering (suppress contradicting stock signals) - 2-hour signal validation against live market prices - Macro asset signals (Gold, Crude Oil, USD/INR, etc.) with lower mention threshold PRODUCT SCREENSHOTS ------------------- Terminal Overview: https://terminal.stockyai.xyz/screenshots/terminal-overview.png Market Panel: https://terminal.stockyai.xyz/screenshots/market-panel.png News Panel: https://terminal.stockyai.xyz/screenshots/news-panel.png AI Trade Signals: https://terminal.stockyai.xyz/screenshots/ai-signals.png Interactive Map: https://terminal.stockyai.xyz/screenshots/map-layers.png Command Palette: https://terminal.stockyai.xyz/screenshots/command-palette.png Blog Page: https://terminal.stockyai.xyz/screenshots/blog-page.png CRAWLABLE PATHS --------------- / - Main terminal application /docs - Documentation index /docs/* - Individual documentation pages /blog - Blog listing (daily market briefs) /blog/* - Individual market brief posts /llms.txt - LLM summary documentation /llms-full.txt - Full LLM documentation /llm.md - LLM-optimized project reference /agents.md - AI agents documentation (markdown) /agents.txt - AI agents documentation (plaintext) /metadata.json - Schema.org structured metadata /.well-known/ai-plugin.json - OpenAI plugin discovery manifest /robots.txt - Crawler directives /sitemap.xml - XML sitemap API ENDPOINTS (25+) ------------------- POST /api/ai/summarize - AI summarization (Groq, JSON mode) POST /api/ai/insight - Single headline AI insight GET /api/ai/signals - Cached AI trade signals POST /api/ai/batch-insights - Batch AI insight generation GET /api/market/quotes - Yahoo Finance equity/commodity quotes GET /api/market/commodities - MCX commodity price data GET /api/market/forex - Live forex rates GET /api/market/gift-nifty - Gift Nifty (SGX Nifty) pre-market data GET /api/crypto/prices - CoinGecko cryptocurrency prices GET /api/rss-proxy - RSS feed proxy (30+ allowed domains) GET /api/x-feed/proxy - X/Twitter via Nitter proxy GET /api/news/aggregated - Aggregated news from all sources GET /api/data/acled - ACLED conflict event data GET /api/data/eia - US Energy Information Administration GET /api/data/fred - Federal Reserve economic data GET /api/data/gdacs - GDACS disaster alerts GET /api/data/firms - NASA FIRMS active fire data GET /api/data/cloudflare-outages - Internet outage tracking GET /api/blog - Blog listing (paginated) GET /api/blog/:slug - Individual blog post GET /api/rate - Brief rating submission POST /api/feedback - User feedback GET /api/sitemap - Dynamic XML sitemap GET /api/cron/daily-brief-v2 - Cron: generate daily market brief GET /api/cron/generate-insights - Cron: refresh AI insights cache POST /api/push/subscribe - Web Push subscription registration POST /api/push/send - Send push notification to subscribers GET /api/cron/validate-signals - Cron: validate signals against live prices GET /api/cron/aggregate-signals - Cron: hourly signal aggregation (time-weighted scoring) GET /api/market/options - Dhan options chain (Nifty, BankNifty, Sensex) with Greeks/OI/IV/PCR GET /api/auth/zerodha-callback - Zerodha Kite Connect OAuth callback GET /api/docs - Documentation index page GET /api/docs/:slug - Individual documentation page AI FUNCTIONS (src/services/summarization.ts) -------------------------------------------- 1. summarizeHeadlines(headlines) - Generates 3-4 sentence market brief from top news headlines - Input: Up to 15 headline strings - Output: Market analysis focused on global equity and commodity impact - Triggered by DataLoader.loadNews() when news items > 5 - Feeds: InsightsPanel 2. generateTradeSignal(headline) - Assesses market impact of a headline, returns structured signal - Output: JSON with impact, direction, affectedAssets, expectedMove, rationale, confidence (0-100) - Triggered for top 3 geopolitical/commodity/macro headlines - Feeds: HighImpactSignalsPanel 3. generateFEDImpact(title, type) - Assesses Federal Reserve event impact on global markets - Input: FED event title and type - Output: 2-3 sentences covering FII flows, currencies, commodities - Triggered by DataLoader.loadUSEvents() 4. summarizeXPosts(posts) - Generates sentiment summary from X/Twitter posts - Input: Up to 10 post text strings - Output: 2-3 sentence sentiment analysis - Triggered by DataLoader.loadXFeed() when posts > 3 - Feeds: XFeedPanel (AI Sentiment section) 5. generateSymbolAnalysis(symbol, price, changePercent) - Generates analysis for a specific stock/commodity/crypto - Output: 3-4 sentences with support/resistance and outlook - Triggered when user clicks a market row - Feeds: ChartDetailModal (AI Analysis section) 6. summarizeSearchResults(query, results) - Summarizes search results in market context - Triggered by CommandPalette after search completes - Feeds: CommandPalette (AI Summary section) AI INFRASTRUCTURE ----------------- Edge Function: api/ai/summarize.ts Endpoint: POST /api/ai/summarize Body: { prompt: string, model?: string } Response: { summary: string } Mode: JSON response format (response_format: json_object) Provider chain: 1. Groq API (primary) - GROQ_API_KEY env var Model: llama-3.3-70b-versatile (chain-of-thought, 1024 max tokens) 2. Ollama (fallback) - OLLAMA_URL env var 3. Graceful degradation - Returns empty string on failure Signal Validation: api/cron/validate-signals.ts Schedule: Every 2 hours - Reads ai:signals:latest from Redis - Fetches live prices via /api/market/quotes (Yahoo Finance) - Contradiction check: bullish + down >0.5% or bearish + up >0.5% - Strong move >1.5%: flip direction, reduce confidence by 15 - Weak contradiction 0.5-1.5%: remove signal - Preserves original updatedAt timestamp BLOG & DAILY BRIEF AUTOMATION ------------------------------ Cron Schedule: Morning brief: 30 2 * * 1-5 UTC (8:00 AM IST, Mon-Fri) Evening brief: 30 14 * * 1-5 UTC (8:00 PM IST, Mon-Fri) Pipeline (api/cron/daily-brief-v2.ts): 1. Fetch market data: Nifty 50, Sensex, Bank Nifty, 8 sector indices, Gift Nifty, 8 global indices, 5 commodities, 5 forex pairs, 5 cryptos 2. Fetch news: Top headlines from aggregated news endpoint 3. AI analysis: Groq generates market outlook, key movers, trade signals 4. Render HTML: Server-rendered blog post with tables, collapsible sections 5. Store in Redis: blog:post:{slug}, indexed in blog:posts sorted set 6. Send emails: Resend API to 70+ subscribers with personalized footers Email System (api/_lib/email.ts): - Strips collapsible sections and nav from email HTML - Appends footer: blog link, WhatsApp community link, 1-10 rating buttons - Batched at 2 emails/second (Resend free tier rate limit) - Subscriber list: api/_lib/subscribers.ts Rating System (api/rate.ts): - GET /api/rate?slug=...&score=...&email=... - Per-subscriber rating in Redis with 90-day TTL - Aggregated in sorted set blog:ratings:{slug} PRE-CACHED AI INSIGHTS ----------------------- Cron: api/cron/generate-insights.ts Schedule: */15 * * * * (every 15 minutes) - Fetches high-severity headlines from /api/news/aggregated - Generates batch AI insights via Groq - Caches results in Redis - Served via /api/ai/signals and /api/ai/insight Signal Aggregation: api/cron/aggregate-signals.ts Schedule: 30 * * * * (every hour at :30) - Re-aggregates cached insights into top-5 signals - Time-weighted sentiment scoring (12h lookback, exponential decay) - Correlation-aware amplification (21 asset pairs) - Nifty coherence filtering - Does NOT call LLM — uses pre-cached insights OPTIONS CHAIN ------------- Endpoint: api/market/options.ts GET /api/market/options?underlying=NIFTY&expiry=2026-03-27 - Fetches live options chain from Dhan API - Underlyings: NIFTY, BANKNIFTY, SENSEX, FINNIFTY, MIDCPNIFTY - Returns: full Greeks, OI, IV, PCR, ATM strike, max pain ZERODHA KITE CONNECT --------------------- Integration: api/_lib/zerodha.ts - Live NSE/BSE market prices via Zerodha broker API - OAuth flow via api/auth/zerodha-callback.ts - Automated daily token refresh via GitHub Actions - Tokens expire daily at 6 AM IST — refresh runs automatically NEWS INTELLIGENCE ----------------- Pipeline: src/services/rss.ts - 30+ RSS feeds from global financial sources - Relevance filtering (keyword keep/reject) - Severity scoring (critical/high/medium/low) - Source credibility tiers (T1-T4) - Affected asset detection (16 regex patterns) - Jaccard similarity deduplication (>0.6 threshold) - Category classification (india-market, commodity, macro, geopolitical, etc.) NOTIFICATION SYSTEM ------------------- Service: src/services/notifications.ts 3-Tier Audio Alerts (Web Audio API oscillators): - Critical: Alarm (saw wave, 880->440Hz, 1.5s) - High: Double beep (square wave, 660Hz, 0.6s) - Medium: Single ping (sine wave, 440Hz, 0.3s) EVENT STORE ----------- Service: src/services/event-store.ts IndexedDB-based persistent storage: - Up to 1000 events (auto-evicts oldest) - Query by date range, severity, category, country - Full-text search on title and description SEARCH INTELLIGENCE ------------------- Service: src/services/search-index.ts Fuzzy search across all terminal data (Cmd/Ctrl+K): - News items, market data, GeoEvents, map actions - Custom fuzzy matching algorithm - AI-powered result summarization DATA SOURCES ------------ Yahoo Finance - Equities, commodities, forex (NSE, BSE, MCX, global) NSE India - Gift Nifty / SGX Nifty (derivatives API) CoinGecko - 25 cryptocurrencies (BTC, ETH, SOL, etc.) Finnhub - US market data, company profiles Frankfurter - ECB exchange rates CurrencyFreaks - Forex rates (20+ pairs) Reuters - Tier 1 wire service (global news) Bloomberg - Tier 1 financial news AP - Tier 1 wire service CNBC, BBC, ET - Tier 2 major outlets ACLED - Armed conflict data USGS - Real-time earthquake data NASA EONET - Natural event data (fires, storms, volcanoes) NASA FIRMS - Active fire detection (global satellite data) GDACS - Global Disaster Alert and Coordination System Cloudflare Radar - Internet outage monitoring Open-Meteo - Weather and monsoon data FRED - Federal Reserve economic data EIA - US Energy Information Administration Zerodha Kite - Live NSE/BSE prices via broker API (automated daily token refresh) Dhan - Options chain data (Greeks, OI, IV, PCR, ATM strike, max pain) TECH STACK ---------- TypeScript - Strict mode, zero frameworks Vite - Build tool deck.gl - Map visualization (27+ layers) MapLibre GL JS - Base map renderer Groq API - AI (Llama 3.3 70B Versatile, chain-of-thought) Vercel - Edge Functions (30+ endpoints) + Cron (5 jobs) Upstash Redis - Blog storage, AI insight cache, ratings Resend - Email delivery (70+ subscribers) IndexedDB - Client-side event persistence Web Audio API - Oscillator-based audio alerts