Real-time sentiment analysis and signal generation engine that aggregates social media, news, and market data into actionable Fear & Greed scores and trade signals.
Run the full pipeline with Docker Compose and see live sentiment scores, Fear & Greed index, and trade signals flowing through Kafka topics.
Reddit ──────> RedditProducer ──┐
├── raw_text_data ──> SentimentConsumer ──> analyzed_sentiment ──┐
NewsAPI ─────> NewsProducer ──┘ │
├── AggregatorConsumer ──> aggregated_metrics ──> SignalConsumer ──> trade_signals ──> LoggingSink
yFinance ────> MarketDataProducer ──> raw_market_data ──────────────────────────────────────────────┘
| Topic | Payload | Produced By | Consumed By |
|---|---|---|---|
raw_text_data |
Raw text from Reddit / News | RedditProducer, NewsProducer | SentimentConsumer |
raw_market_data |
Price + volume snapshots | MarketDataProducer | AggregatorConsumer |
analyzed_sentiment |
FinBERT sentiment score [-1, 1] | SentimentConsumer | AggregatorConsumer |
aggregated_metrics |
Fear & Greed Index (0–100) | AggregatorConsumer | SignalConsumer |
trade_signals |
BUY / SELL / HOLD with confidence | SignalConsumer | LoggingSink |
- FinBERT ONNX — sub-100ms sentiment analysis on CPU (batch of 32)
- Kafka streaming — decoupled producers/consumers, 1000+ messages/min
- Fear & Greed Index — weighted composite of sentiment, momentum, and velocity
- Signal strategies — contrarian buy/sell and trend following with confidence scores
- Multi-source — Reddit, NewsAPI, yFinance in a unified pipeline
- Configurable — YAML-based asset targets and keywords
| Layer | Technology |
|---|---|
| Language | Python 3.11+ |
| Streaming | Apache Kafka, Docker Compose |
| NLP | FinBERT (ProsusAI/finbert), ONNX Runtime |
| Data | yFinance, Reddit API, NewsAPI |
| Validation | Pydantic |
| Config | YAML (config/targets.yaml) |
| Packaging | Poetry |
- Python 3.11–3.14
- Docker & Docker Compose
- Poetry (recommended) or pip
# Clone & enter the project
git clone https://github.com/N-S8990/sentivo.git
cd sentivo
poetry shell
# Install dependencies
poetry install
# Configure API keys
cp .env.example .env
# Edit .env with your keys
# Start Kafka
docker compose up -d
# Run the full pipeline (tmux)
./scripts/run_all.sh# Docker services (Kafka + Zookeeper)
docker compose up
# Terminal 2 — producers
poetry run python src/sentivo/main.py producer reddit
poetry run python src/sentivo/main.py producer news
poetry run python src/sentivo/main.py producer market
# Terminal 3 — consumers
poetry run python src/sentivo/main.py consumer sentiment
poetry run python src/sentivo/main.py consumer aggregator
poetry run python src/sentivo/main.py consumer signal
poetry run python src/sentivo/main.py consumer loggerAdd these to .env:
REDDIT_CLIENT_ID,REDDIT_CLIENT_SECRET,REDDIT_USER_AGENT— Reddit AppNEWSAPI_API_KEY— NewsAPITWITTER_*— Optional, for Twitter/X data
Edit config/targets.yaml to define tracked assets:
assets:
- name: "Bitcoin"
ticker: "BTC-USD"
keywords: ["bitcoin", "btc"]
reddit_subreddits: ["bitcoin", "btc", "CryptoCurrency"]
news_queries: ["bitcoin", "crypto"]Uses FinBERT (ProsusAI/finbert) exported to ONNX with dynamic quantisation for CPU inference. Each batch of 32 texts processes in ~50ms.
Preprocessing pipeline:
- Lowercase normalisation
- URL / mention / ticker removal
- Whitespace cleanup
- LRU cache (10,000 entries)
Three weighted components:
| Component | Weight | Range |
|---|---|---|
| Sentiment score (5 min avg) | 50% | 0–100 |
| Price momentum (5 min Δ) | 30% | 0–100 |
| Sentiment velocity | 20% | 0–100 |
- Contrarian Buy — F&G < 20 + sentiment recovering → BUY (75% confidence)
- Contrarian Sell — F&G > 85 + price dipping → SELL (80% confidence)
- Trend Follow — F&G > 70 + strong sentiment + rising price → BUY (60% confidence)
src/sentivo/
├── main.py # CLI entry point
├── core/
│ ├── config.py # Env + YAML loader
│ ├── logging_config.py # stdout logging setup
│ └── kafka_client.py # Kafka producer/consumer factory
├── data_collectors/ # API wrappers (Reddit, News, Market, Twitter)
├── producers/ # Kafka producers (streaming & polling)
├── consumers/ # Kafka consumers (sentiment → aggregation → signal)
├── schemas/ # Pydantic message models
└── sentiment_analysis/ # FinBERT ONNX, preprocessor, test texts
- Throughput: 1,000+ messages/min across all Kafka topics
- Sentiment latency: <100 ms per batch of 32 texts (ONNX CPU)
- Signal latency: <500 ms from data ingestion to final signal
- Memory: ~2 GB with loaded FinBERT model
- CPU: ~40% on 4-core system at peak load
The Fear & Greed Index combines behavioural finance principles with real-time NLP:
- Sentiment score (50%) — 5-minute rolling average of FinBERT scores normalised to 0–100
- Price momentum (30%) — 5-minute percent change capped at ±5%
- Sentiment velocity (20%) — rate of change in 1-minute sentiment averages
Signals are generated when threshold combinations indicate statistically significant market conditions, inspired by classic behavioural finance literature (Shiller, Kahneman & Tversky).
MIT
Built by Nirav Sayanja · NIT Rourkela