Tutorial

How to Build a Reddit Stock Sentiment Tracker

Build a stock sentiment tracker using Reddit data via Scavio's API. Track mentions, scores, and sentiment for any ticker.

An r/redditstock post covered the Reddit vs Anthropic/SerpAI/Oxylabs lawsuits — highlighting that Reddit data is contested territory. This tutorial builds a legal, API-based stock sentiment tracker using Scavio's Reddit endpoint.

Prerequisites

  • Scavio API key
  • Python 3.8+
  • LLM API key for sentiment scoring

Walkthrough

Step 1: Search Reddit for ticker mentions

Use Scavio's Reddit endpoint for structured thread data.

Python
import requests, os
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}

def reddit_sentiment(ticker):
    return requests.post('https://api.scavio.dev/api/v1/search',
        headers=H,
        json={'platform': 'reddit', 'query': f'{ticker} stock',
              'sort': 'new', 'time_range': 'day'}).json()

Step 2: Score sentiment with LLM

Feed thread titles and top comments to an LLM.

Python
from anthropic import Anthropic
client = Anthropic()

def score_sentiment(threads):
    titles = '\n'.join([t['title'] for t in threads[:20]])
    return client.messages.create(model='claude-sonnet-4-6', max_tokens=100,
        messages=[{'role': 'user', 'content': f'Rate overall sentiment for this stock ticker (bullish/neutral/bearish) based on these Reddit thread titles. One word answer + confidence 1-10.\n\n{titles}'}]).content[0].text

Step 3: Track sentiment over time

Daily log for trend analysis.

Python
import json, datetime
def log_sentiment(ticker, sentiment, thread_count):
    with open(f'sentiment/{ticker}.jsonl', 'a') as f:
        f.write(json.dumps({'date': str(datetime.date.today()),
            'ticker': ticker, 'sentiment': sentiment,
            'thread_count': thread_count}) + '\n')

Step 4: Schedule daily runs

Cron job for daily sentiment tracking.

Bash
# crontab: 0 18 * * 1-5 python sentiment_tracker.py
# Runs at market close (6 PM) on weekdays
# Tracks 10 tickers: 10 × 2 credits = $0.10/day

Python Example

Python
# Legal approach: Scavio's Reddit endpoint returns structured data
# via API, not scraping. No ToS violation risk.
# 10 tickers × 2 credits/call × 20 trading days = 400 credits/mo = $2/mo

JavaScript Example

JavaScript
const reddit = await fetch('https://api.scavio.dev/api/v1/search', {
  method: 'POST', headers: {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'},
  body: JSON.stringify({platform: 'reddit', query: `${ticker} stock`, sort: 'new'})
});

Expected Output

JSON
Daily stock sentiment tracker: Reddit mentions per ticker, LLM sentiment scoring, JSONL trend log. Legal API-based approach.

Related Tutorials

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Scavio API key. Python 3.8+. LLM API key for sentiment scoring. A Scavio API key gives you 500 free credits per month.

Yes. The free tier includes 500 credits per month, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Start Building

Build a stock sentiment tracker using Reddit data via Scavio's API. Track mentions, scores, and sentiment for any ticker.