DEV Community

Cover image for I built a Python script that alerts me when Reddit is hyping a stock
Alexander Schneider
Alexander Schneider

Posted on

I built a Python script that alerts me when Reddit is hyping a stock

GameStop went from $20 to $480. AMC from $2 to $72. Palantir doubled in a week.

Every single one started the same way: a handful of Reddit posts in r/wallstreetbets that snowballed into thousands of mentions within hours. By the time CNBC reported on it, the move was already happening.

The pattern is always the same:

  1. A stock goes from ~5 mentions/day to 50+ mentions in a few hours
  2. Sentiment flips heavily bullish (70%+ positive)
  3. It spreads from one subreddit to multiple communities
  4. The buzz score explodes

What if you could detect step 1 automatically and get a Slack message before step 4 happens?

That's what we're building.

What we're building

A Python script that:

  • Checks Reddit sentiment data every hour
  • Detects stocks with unusual buzz spikes (momentum)
  • Filters for high bullish sentiment (not just noise)
  • Sends you a Slack/Discord/email alert

No machine learning. No complex setup. Just API calls and simple thresholds.

Setup

pip install requests
Enter fullscreen mode Exit fullscreen mode

You'll need a free API key from the Reddit Stock Sentiment API (250 requests/month, takes 30 seconds to sign up).

The detector โ€” 40 lines of Python

# reddit_hype_alert.py
import requests
import json
from datetime import datetime

API_KEY = "your_api_key_here"
BASE = "https://api.adanos.org/reddit/stocks/v1"
HEADERS = {"X-API-Key": API_KEY}

# --- Thresholds (tune these to your preference) ---
BUZZ_MIN = 40            # Minimum buzz score to consider
BULLISH_MIN = 55         # Minimum bullish percentage
TREND_FILTER = "rising"  # Only alert on rising stocks
SPREAD_MIN = 3           # Mentioned in at least N subreddits

def get_trending():
    """Fetch top 50 trending stocks from the last 24 hours."""
    r = requests.get(f"{BASE}/trending", headers=HEADERS,
                     params={"limit": 50, "days": 1})
    r.raise_for_status()
    return r.json()

def detect_hype(stocks):
    """Filter for stocks showing hype signals."""
    alerts = []
    for s in stocks:
        if (s["buzz_score"] >= BUZZ_MIN
            and s.get("bullish_pct", 0) >= BULLISH_MIN
            and s["trend"] == TREND_FILTER
            and s.get("subreddit_count", 0) >= SPREAD_MIN):
            alerts.append(s)
    return alerts

def format_alert(stock):
    """Format a single stock alert."""
    return (
        f"๐Ÿšจ ${stock['ticker']} โ€” {stock.get('company_name', 'Unknown')}\n"
        f"   Buzz: {stock['buzz_score']:.1f}/100 โ†‘ {stock['trend']}\n"
        f"   Mentions: {stock['mentions']} across {stock.get('subreddit_count', '?')} subreddits\n"
        f"   Sentiment: {stock.get('bullish_pct', '?')}% bullish\n"
    )

# --- Run ---
print(f"[{datetime.now():%H:%M}] Scanning Reddit trending stocks...")
stocks = get_trending()
hype_stocks = detect_hype(stocks)

if hype_stocks:
    print(f"\n๐Ÿ”ฅ {len(hype_stocks)} stocks showing hype signals:\n")
    for s in hype_stocks:
        print(format_alert(s))
else:
    print("No hype signals detected right now.")
Enter fullscreen mode Exit fullscreen mode

Run it:

$ python reddit_hype_alert.py

[14:30] Scanning Reddit trending stocks...

๐Ÿ”ฅ 3 stocks showing hype signals:

๐Ÿšจ $NVDA โ€” NVIDIA Corporation
   Buzz: 92.3/100 โ†‘ rising
   Mentions: 487 across 12 subreddits
   Sentiment: 72% bullish

๐Ÿšจ $PLTR โ€” Palantir Technologies Inc.
   Buzz: 78.1/100 โ†‘ rising
   Mentions: 198 across 8 subreddits
   Sentiment: 68% bullish

๐Ÿšจ $RKLB โ€” Rocket Lab USA, Inc.
   Buzz: 54.2/100 โ†‘ rising
   Mentions: 67 across 5 subreddits
   Sentiment: 81% bullish
Enter fullscreen mode Exit fullscreen mode

That third one โ€” $RKLB with 67 mentions but 81% bullish across 5 subreddits โ€” that's exactly the kind of early signal you want to catch. It's not yet on CNBC, but Reddit is already talking.

Add Slack notifications

Turn it into a real alert system with one function:

import os

SLACK_WEBHOOK = os.environ.get("SLACK_WEBHOOK_URL")

def send_slack_alert(hype_stocks):
    """Send hype alerts to Slack."""
    if not SLACK_WEBHOOK:
        return

    blocks = [{"type": "header", "text": {
        "type": "plain_text",
        "text": f"๐Ÿ”ฅ {len(hype_stocks)} Reddit Hype Alert{'s' if len(hype_stocks) > 1 else ''}"
    }}]

    for s in hype_stocks[:5]:
        blocks.append({"type": "section", "text": {"type": "mrkdwn", "text":
            f"*${s['ticker']}* โ€” {s.get('company_name', '')}\n"
            f"Buzz `{s['buzz_score']:.1f}` ยท {s['mentions']} mentions ยท "
            f"{s.get('bullish_pct', '?')}% bullish ยท {s.get('subreddit_count', '?')} subreddits"
        }})

    requests.post(SLACK_WEBHOOK, json={"blocks": blocks})

# Update the run section:
if hype_stocks:
    send_slack_alert(hype_stocks)
Enter fullscreen mode Exit fullscreen mode

Want an AI explanation of WHY it's trending?

The API has an /explain endpoint that uses an LLM to summarize what Reddit is actually saying:

def get_explanation(ticker):
    """Get AI-generated explanation of why a stock is trending."""
    r = requests.get(f"{BASE}/stock/{ticker}/explain", headers=HEADERS)
    if r.status_code == 200:
        return r.json().get("explanation", "")
    return None

# Add to your alert:
for s in hype_stocks:
    explanation = get_explanation(s["ticker"])
    if explanation:
        print(f"   ๐Ÿ’ก Why: {explanation}")
Enter fullscreen mode Exit fullscreen mode

Output:

๐Ÿšจ $RKLB โ€” Rocket Lab USA, Inc.
   Buzz: 54.2/100 โ†‘ rising
   Mentions: 67 across 5 subreddits
   Sentiment: 81% bullish
   ๐Ÿ’ก Why: Rocket Lab trending after successful Neutron rocket test and new
   NASA contract announcement. Retail investors bullish on space sector growth.
Enter fullscreen mode Exit fullscreen mode

Now you're not just seeing that something is trending โ€” you know why.

Run it every hour with cron

# Edit crontab
crontab -e

# Add this line (runs every hour during market hours, Mon-Fri)
0 9-16 * * 1-5 cd /path/to/script && python reddit_hype_alert.py >> alerts.log 2>&1
Enter fullscreen mode Exit fullscreen mode

Or if you prefer GitHub Actions, Docker, or a cloud function โ€” the script is stateless, so it runs anywhere.

Tuning the thresholds

The default thresholds are conservative. Here's how to adjust them:

Signal Conservative Aggressive What it catches
BUZZ_MIN 40 20 Lower = more alerts, earlier signals
BULLISH_MIN 55 40 Lower = includes mixed-sentiment stocks
SPREAD_MIN 3 1 Lower = catches single-subreddit hype
TREND_FILTER "rising" Remove filter Also catches "stable" momentum

Start conservative. If you're getting 0-1 alerts per day, lower the thresholds. If you're getting 10+, raise them.

What I'd build next

  • Cross-platform validation: Check if the same stock is also trending on X/Twitter. Stocks hyped on both platforms have stronger signals.
  • Historical backtesting: Use the 90-day history (paid tier) to backtest which threshold combos would have caught past rallies.
  • Portfolio watchlist: Only alert on stocks you already own or are watching, using the /v1/stock/{ticker} endpoint.
  • Discord bot: Same logic, but posts to a Discord channel for your trading group.

Full code

The complete script is ~60 lines. It uses 2 API calls per run (trending + explain for each alert), so the free tier (250 requests/month) easily covers running it several times per day.


Built by Adanos Software in Berlin. The API tracks 12,000+ tickers across 50+ subreddits, updated hourly.

Top comments (0)