DEV Community

Joe Vezzani
Joe Vezzani

Posted on

I Built a Tariff Impact Tracker That Shows What the Internet Actually Thinks

Tariffs are dominating the news cycle right now. But the headlines only tell you what journalists think. What does the actual internet think?

I built a quick tracker that pulls real-time social data on tariffs -- volume, sentiment, top posts, which platforms are driving the conversation -- using LunarCrush's API. It processes 50M+ social posts per hour across X, Reddit, TikTok, YouTube, Instagram, and 10K+ news sources.

Here's what I found and how to build it yourself.

GitHub repo: JoeVezzani/tariff-tracker

What we're building

A simple Node.js script that:

  • Tracks social volume and sentiment for any keyword (tariffs, trade war, specific companies)
  • Compares how different platforms feel about the same topic
  • Finds the most viral posts driving the conversation
  • Runs on a cron to alert you when sentiment shifts

Setup (2 minutes)

mkdir tariff-tracker && cd tariff-tracker
npm init -y
Enter fullscreen mode Exit fullscreen mode

Grab an API key at lunarcrush.com/developers.

Pull the data

const API_KEY = process.env.LUNARCRUSH_API_KEY;

async function getTopicData(keyword) {
  const res = await fetch(
    `https://lunarcrush.com/api4/public/topic/${encodeURIComponent(keyword)}/v1`,
    { headers: { Authorization: `Bearer ${API_KEY}` } }
  );
  return res.json();
}

async function getTopicPosts(keyword) {
  const res = await fetch(
    `https://lunarcrush.com/api4/public/topic/${encodeURIComponent(keyword)}/posts/v1`,
    { headers: { Authorization: `Bearer ${API_KEY}` } }
  );
  return res.json();
}

async function main() {
  const topic = await getTopicData("tariffs");

  console.log(`\nšŸ“Š TARIFFS - Social Intelligence Report`);
  console.log(`${"=".repeat(50)}`);
  console.log(`Total posts (24h):    ${topic.data?.num_posts?.toLocaleString()}`);
  console.log(`Total engagements:    ${topic.data?.interactions?.toLocaleString()}`);
  console.log(`Sentiment:            ${topic.data?.sentiment}% bullish`);
  console.log(`Contributors:         ${topic.data?.num_contributors?.toLocaleString()}`);

  // Get the posts driving the conversation
  const posts = await getTopicPosts("tariffs");

  console.log(`\nšŸ”„ Top Posts Right Now:`);
  for (const post of (posts.data || []).slice(0, 5)) {
    const platform = post.network || "unknown";
    const engagement = post.interactions_total?.toLocaleString() || "0";
    const text = (post.body || post.title || "").slice(0, 100);
    console.log(`  [${platform}] ${engagement} engagements: ${text}...`);
  }
}

main();
Enter fullscreen mode Exit fullscreen mode

Run it

LUNARCRUSH_API_KEY=your_key node index.js
Enter fullscreen mode Exit fullscreen mode

Output looks something like:

šŸ“Š TARIFFS - Social Intelligence Report
==================================================
Total posts (24h):    847,291
Total engagements:    2,341,882,104
Sentiment:            38% bullish
Contributors:         412,847

šŸ”„ Top Posts Right Now:
  [twitter] 1,247,382 engagements: Breaking: EU announces retaliatory tariffs...
  [reddit] 892,411 engagements: Can someone ELI5 why tariffs make everything...
  [youtube] 743,219 engagements: The REAL impact of tariffs on your wallet...
  [tiktok] 521,883 engagements: POV: you work in manufacturing and just heard...
  [news] 412,092 engagements: Apple warns tariffs could increase iPhone price...
Enter fullscreen mode Exit fullscreen mode

Make it interesting: compare companies

Want to see how tariffs are hitting different stocks in the social conversation?

async function compareTariffImpact(tickers) {
  const results = [];

  for (const ticker of tickers) {
    const data = await getTopicData(ticker);
    results.push({
      ticker,
      sentiment: data.data?.sentiment,
      volume: data.data?.num_posts,
      engagements: data.data?.interactions,
    });
  }

  // Sort by most negative sentiment
  results.sort((a, b) => (a.sentiment || 0) - (b.sentiment || 0));

  console.log(`\nšŸ“‰ Tariff Sentiment Impact by Company:`);
  console.log(`${"Ticker":<10} ${"Sentiment":<12} ${"Posts (24h)":<15} ${"Engagements"}`);
  console.log("-".repeat(55));

  for (const r of results) {
    const mood = r.sentiment < 40 ? "😰" : r.sentiment < 60 ? "😐" : "šŸ˜Ž";
    console.log(
      `${mood} ${r.ticker:<8} ${r.sentiment || "N/A":<12} ${(r.volume || 0).toLocaleString():<15} ${(r.engagements || 0).toLocaleString()}`
    );
  }
}

compareTariffImpact(["apple", "nike", "tesla", "walmart", "amazon"]);
Enter fullscreen mode Exit fullscreen mode

Add a sentiment shift alert

Run this on a cron and get notified when public opinion changes:

const fs = require("fs");
const STATE_FILE = "./sentiment_state.json";

function loadState() {
  try { return JSON.parse(fs.readFileSync(STATE_FILE)); } 
  catch { return {}; }
}

function saveState(state) {
  fs.writeFileSync(STATE_FILE, JSON.stringify(state, null, 2));
}

async function checkForShifts(keywords) {
  const state = loadState();

  for (const keyword of keywords) {
    const data = await getTopicData(keyword);
    const current = data.data?.sentiment;
    const previous = state[keyword]?.sentiment;

    if (previous && Math.abs(current - previous) > 10) {
      const direction = current > previous ? "šŸ“ˆ UP" : "šŸ“‰ DOWN";
      console.log(
        `🚨 ALERT: "${keyword}" sentiment shifted ${direction} ` +
        `(${previous}% -> ${current}%, change: ${current - previous > 0 ? "+" : ""}${current - previous}%)`
      );
    }

    state[keyword] = { sentiment: current, timestamp: new Date().toISOString() };
  }

  saveState(state);
}

checkForShifts(["tariffs", "trade war", "apple", "tesla", "nvidia"]);
Enter fullscreen mode Exit fullscreen mode

Set it up as a cron job to run every hour:

# crontab -e
0 * * * * cd /path/to/tariff-tracker && LUNARCRUSH_API_KEY=your_key node alert.js >> alerts.log
Enter fullscreen mode Exit fullscreen mode

What's cool about this

The LunarCrush API isn't just price data or news feeds. It's aggregating the actual social conversation -- 50M+ posts per hour -- across every major platform. You get:

  • Sentiment that's calculated from real posts, not just positive/negative keyword matching
  • Cross-platform comparison -- is Reddit bearish while TikTok is bullish?
  • Creator-level data -- who's driving the conversation?
  • Galaxy Score and AltRank -- proprietary metrics that rank social health

This works for crypto, stocks, topics, people -- basically anything the internet talks about.

Try it

I'm building a bunch of small projects like this. Follow along if you're into this kind of thing.

Top comments (0)