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.
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.
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].textStep 3: Track sentiment over time
Daily log for trend analysis.
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.
# 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/dayPython Example
# 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/moJavaScript Example
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
Daily stock sentiment tracker: Reddit mentions per ticker, LLM sentiment scoring, JSONL trend log. Legal API-based approach.