AI-powered trading advisor that reads the market mood and tells you what to do with your money.
SentXStock is an autonomous sentiment-driven trading agent that monitors real-time news and social media, analyzes market sentiment using a 3-tier AI pipeline, and generates actionable buy/sell/hold recommendations for a mock portfolio.
No manual stock picking. The AI reads 100+ news articles & social posts, judges the market mood, adjusts risk, and tells you exactly what to trade.
| Feature | Description |
|---|---|
| π€ 3-Tier AI Pipeline | FinBERT (local ML) β Gemini (LLM) β VADER (fallback) |
| π° Real-Time News | Finnhub + NewsAPI (80,000+ sources) |
| π¬ Social Media Analysis | Reddit (r/wallstreetbets, r/stocks, r/investing) |
| π Mock Portfolio | Virtual portfolio with live Yahoo Finance prices |
| βοΈ Dynamic Risk Engine | Auto-adjusts risk level based on market sentiment |
| π Order Drafting | BUY / SELL / HOLD recommendations with AI reasoning |
| π¬ AI Chatbot | Ask questions like "Should I buy Tesla?" β get data-backed answers |
| π API Key Rotation | Multiple Gemini keys with auto-rotation on quota limits |
| π― User Interaction | Custom tickers, portfolio size, and risk preference |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STREAMLIT FRONTEND β
β ββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββββ β
β β Sentiment β β Portfolio β β AI Chatbot β β
β β Gauge β β Pie Chart β β "Should I buy TSLA?" β β
β ββββββββ¬βββββββ ββββββββ¬ββββββββ ββββββββββββ¬ββββββββββββββ β
βββββββββββΌββββββββββββββββΌβββββββββββββββββββββΌββββββββββββββββ
β β β
βββββββββββββββββΌβββββββββββββββββββββ
β
βββββββΌββββββ
β api.py β β Unified API Layer
βββββββ¬ββββββ
β
βββββββββββββββββΌββββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββ βββββββββββββ ββββββββββββββββ
β Data Layer β β Sentiment β β Portfolio β
β (Fetchers) β β (3-Tier) β β (Risk+Orders)β
βββββββββββββββ βββββββββββββ ββββββββββββββββ
News/Social Posts (100+ items)
β
βΌ
βββββββββββββββ
β FinBERT β β Tier 1: Local ML model (FREE, unlimited)
β (Primary) β Handles ~90% of headlines with high confidence
ββββββββ¬βββββββ
β
Confident? ββYesβββ Use FinBERT result
β
No (ambiguous)
β
βΌ
βββββββββββββββ
β Gemini β β Tier 2: LLM (nuanced understanding)
β (Premium) β Only called for ~10% of items
ββββββββ¬βββββββ
β
Available? ββYesβββ Use Gemini result
β
No (quota hit)
β
βΌ
βββββββββββββββ
β VADER β β Tier 3: Rule-based fallback (always works)
β (Fallback) β
βββββββββββββββ
SentXStock/
βββ api.py # Unified API for Streamlit frontend
βββ main.py # CLI entry point
βββ requirements.txt # Python dependencies
βββ .env.example # Environment variables template
β
βββ agent/ # Core agent logic
β βββ agent.py # Trading agent orchestrator (5-step pipeline)
β βββ chatbot.py # AI chatbot for user questions
β
βββ config/ # Configuration
β βββ config.py # API keys, thresholds, model settings
β
βββ data/ # Data fetching layer
β βββ realtime_news.py # Finnhub + NewsAPI news fetchers
β βββ realtime_social.py # Reddit social media fetcher
β βββ scraper.py # BeautifulSoup web scraper
β βββ mock_news.py # Mock news data for demo
β βββ mock_social.py # Mock social data for demo
β
βββ sentiment/ # Sentiment analysis engine
β βββ analyzer.py # Main analyzer (3-tier pipeline)
β βββ finbert.py # FinBERT local ML model
β βββ scorer.py # VADER scoring + aggregation
β βββ prompts.py # LLM prompt templates
β
βββ portfolio/ # Portfolio management
β βββ portfolio.py # Portfolio manager (holdings, live prices)
β βββ risk.py # Risk engine (dynamic risk adjustment)
β βββ orders.py # Order drafter (BUY/SELL/HOLD logic)
β
βββ streamlit_app.py # Streamlit entry point (run this)
βββ st_pages/ # Streamlit page modules
βββ dashboard.py # Sentiment dashboard + orders
βββ chat.py # AI chatbot page
βββ settings.py # Tickers, portfolio & risk config
- Python 3.11+
- Git
- Free API keys (see below)
git clone https://github.com/RajendharAre/SentXStock.git
cd SentXStockpip install -r requirements.txtNote: First run will download FinBERT model (~438MB). This is cached locally and loads instantly on subsequent runs.
Copy the example env file and add your keys:
cp .env.example .envEdit .env:
# Multiple Gemini keys (comma-separated) for auto-rotation
GEMINI_API_KEYS=your_key_1,your_key_2
# Finnhub (financial news)
FINNHUB_API_KEY=your_finnhub_key
# NewsAPI (80,000+ news sources)
NEWSAPI_KEY=your_newsapi_key| API | Free Tier | Sign Up |
|---|---|---|
| Gemini | 1,500 req/day (2.0-flash) | ai.google.dev |
| Finnhub | 60 req/min | finnhub.io |
| NewsAPI | 100 req/day | newsapi.org |
# Real-time mode (uses live news + social data)
python main.py --output results.json
# Mock mode (uses demo data β great for testing)
python main.py --mock --output results.json
# Custom tickers
python main.py --tickers AAPL,TSLA,NVDA --output results.jsonstreamlit run streamlit_app.py| Section | What it Shows |
|---|---|
| Market Sentiment Gauge | Overall sentiment score (-1.0 to +1.0) with Bullish/Neutral/Bearish indicator |
| Risk Level Display | Current risk: High / Medium / Low with dynamic adjustment |
| Order Recommendations | BUY / SELL / HOLD cards with AI reasoning |
| Portfolio Pie Chart | Equity / Bonds / Cash allocation breakdown |
| News Feed | Headlines color-coded: π’ Bullish, π΄ Bearish, βͺ Neutral |
| AI Chatbot | Ask trading questions, get data-backed answers |
| User Settings | Custom tickers, investment amount, risk preference |
The Streamlit frontend uses api.py β the unified API layer:
from api import TradingAPI
api = TradingAPI()
# ββ User Setup ββ
api.set_user_tickers(["AAPL", "TSLA", "NVDA"])
api.set_user_portfolio(cash=50000, risk="Moderate")
# ββ Run Analysis ββ
result = api.run_analysis() # Real-time
result = api.run_analysis(use_mock=True) # Mock data
# ββ AI Chatbot ββ
response = api.chat("Should I buy Tesla?")
print(response["answer"])
# ββ Ticker Deep Dive ββ
ticker_data = api.analyze_ticker("AAPL")
# ββ Dashboard Data (everything in one call) ββ
dashboard = api.get_dashboard_data(){
"timestamp": "2026-02-27 15:33:33",
"overall_sentiment": "Neutral",
"sentiment_score": -0.0838,
"risk_adjustment": "Maintain Medium risk β sentiment supports current allocation",
"new_risk_level": "Medium",
"portfolio_action": "Maintain balanced allocation with selective adjustments",
"orders": [
{
"action": "SELL",
"asset": "AAPL",
"reason": "Risk trim on AAPL β strong negative sentiment (score: -0.67)"
},
{
"action": "BUY",
"asset": "GOOGL",
"reason": "Opportunistic buy on GOOGL β strong positive sentiment (score: 0.92)"
}
],
"analysis_details": {
"total_items_analyzed": 122,
"bullish_count": 28,
"bearish_count": 46,
"neutral_count": 48
},
"portfolio_snapshot": {
"total_value": 114834.90,
"equity_pct": 51.74,
"bonds_pct": 4.72,
"cash_pct": 43.54,
"risk_level": "Medium"
}
}| Component | Technology |
|---|---|
| Language | Python 3.11+ |
| ML Model | FinBERT (ProsusAI/finbert) β financial sentiment BERT |
| LLM | Google Gemini 2.0-flash |
| NLP Fallback | VADER Sentiment |
| Web Scraping | BeautifulSoup4 |
| News APIs | Finnhub, NewsAPI |
| Social Data | Reddit JSON API |
| Stock Prices | Yahoo Finance (yfinance) |
| Frontend | Streamlit |
| Deep Learning | PyTorch + HuggingFace Transformers |
- Fetches 50+ news headlines from Finnhub (general + company-specific)
- Fetches 35+ headlines from NewsAPI (business + technology)
- Scrapes 24+ posts from Reddit (wallstreetbets, stocks, investing)
- Deduplicates overlapping headlines across sources
- FinBERT (primary): Local BERT model fine-tuned on financial text. Processes all 100+ items in ~2 seconds. Handles ~90% with high confidence.
- Gemini (premium): Only called for ambiguous items (~10%). Provides nuanced understanding.
- VADER (fallback): Rule-based scorer. Always available, no API limits.
| Sentiment Score | Risk Level | Allocation |
|---|---|---|
| > 0.5 | High (aggressive) | 70% equity, 15% bonds, 15% cash |
| -0.3 to 0.5 | Medium (balanced) | 50% equity, 30% bonds, 20% cash |
| < -0.3 | Low (defensive) | 25% equity, 35% bonds, 40% cash |
The agent generates BUY/SELL/HOLD orders based on:
- Individual ticker sentiment scores
- Overall market mood
- Current portfolio allocation vs target
- Risk level recommendations
Users can ask natural language questions. The chatbot:
- Injects real-time sentiment data into the prompt
- Uses Gemini for conversational responses
- Falls back to template-based answers if Gemini is unavailable
SentXStock supports multiple Gemini API keys with automatic rotation:
GEMINI_API_KEYS=key1,key2,key3,key4,key5- When one key hits the daily quota β automatically rotates to the next
- All keys exhausted β falls back to FinBERT + VADER (no interruption)
- Each free-tier key provides 1,500 requests/day on gemini-2.0-flash
This project is built for the NAAC Hackathon 2026.
- Backend & AI Pipeline β Sentiment analysis, portfolio engine, API layer
- Frontend β Streamlit dashboard, visualizations, user interface
Built with β€οΈ for the NAAC Hackathon 2026