DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

Your Pipeline Is 22.9h Behind: Catching Trade Sentiment Leads with Pulsebit

Your Pipeline Is 22.9h Behind: Catching Trade Sentiment Leads with Pulsebit

We recently uncovered a significant anomaly: a 24h momentum spike of +0.424 in trade sentiment. This spike indicates a sudden shift in sentiment that could impact decision-making in our trading strategies. Specifically, the leading language was English, with a notable press narrative emerging around the theme "Europe Has to Take on China to Save Free Trade." The clustering of articles reveals shared themes that can provide insight into emerging market trends.

The Problem

This spike highlights a potential gap in any pipeline that doesn’t handle multilingual origin or entity dominance effectively. Your model missed this sentiment shift by 22.9 hours. With the leading language being English and the dominant entity being China, the delay in capturing this information could mean the difference between seizing an opportunity or missing it entirely. If you’re not equipped to account for multilingual sources or dominant narratives, you risk falling behind in a rapidly shifting sentiment landscape.

English coverage led by 22.9 hours. Nl at T+22.9h. Confidenc
English coverage led by 22.9 hours. Nl at T+22.9h. Confidence scores: English 0.75, Spanish 0.75, French 0.75 Source: Pulsebit /sentiment_by_lang.

The Code

To catch this sentiment spike, we can utilize our API to filter news articles by language and assess the narrative. Here’s how we can do it in Python:

import requests

![Left: Python GET /news_semantic call for 'trade'. Right: ret](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_code_output_split_1784600007741.png)
*Left: Python GET /news_semantic call for 'trade'. Right: returned JSON response structure (clusters: 3). Source: Pulsebit /news_semantic.*


# Define parameters
topic = 'trade'
score = -0.053
confidence = 0.75
momentum = +0.424
lang = 'en'

# Geographic origin filter: Query by language/country
url = f"https://api.pulsebit.com/articles?topic={topic}&lang={lang}&momentum={momentum}"

![Geographic detection output for trade. India leads with 7 ar](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_geo_output_1784600007812.png)
*Geographic detection output for trade. India leads with 7 articles and sentiment -0.04. Source: Pulsebit /news_recent geographic fields.*


response = requests.get(url)
articles = response.json()

# Assume we have retrieved a relevant narrative
cluster_reason = "Clustered by shared themes: has, take, china, save, free."

# Meta-sentiment moment: Score the narrative framing itself
sentiment_url = "https://api.pulsebit.com/sentiment"
sentiment_response = requests.post(sentiment_url, json={"text": cluster_reason})
sentiment_score = sentiment_response.json()

print(f"Articles: {articles}, Sentiment Score: {sentiment_score}")
Enter fullscreen mode Exit fullscreen mode

In this code, we first filter for articles related to 'trade' in English, ensuring we are tapping into the right sentiment. Then, we score the cluster reason string to get an understanding of how the narrative itself aligns with the moment.

Three Builds Tonight

With this momentum spike insight, here are three specific things we can build:

  1. Geo Filter Alert: Set up an alert system that triggers whenever there’s a momentum spike in trade sentiment in English. Use the threshold of +0.424 to monitor and notify us immediately when such spikes occur.

  2. Meta-Sentiment Dashboard: Build a dashboard that visualizes the sentiment scores of narratives around critical topics like trade and China. Use the output from the meta-sentiment loop to give real-time insights into how these narratives are evolving.

  3. Forming Themes Detector: Create a detection mechanism that identifies forming themes based on sentiment analysis. For example, monitor the phrases "trade", "google", and "china" against mainstream narratives to uncover upcoming trends. If any of these phrases show a significant deviation from the mainstream in terms of sentiment score, it could indicate a market shift.

Get Started

For those ready to dive deeper, visit pulsebit.lojenterprise.com/docs. With our straightforward API, you can copy-paste and run this in under 10 minutes. Don’t get left behind—stay ahead of the sentiment curve!

Top comments (0)