DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

How to Detect Markets Sentiment Anomalies with the Pulsebit API (Python)

How to Detect Markets Sentiment Anomalies with the Pulsebit API (Python)

We just uncovered something interesting: a 24-hour momentum spike of +1.550. This anomaly indicates a sharp shift in market sentiment that you can’t afford to overlook. It’s not just a number; it’s indicative of significant underlying changes that could influence your trading strategies.

Without a robust pipeline to handle multilingual origins or dominant entities, you risk missing critical insights. Imagine this: your model missed this anomaly by hours, all because it couldn't analyze sentiment from key regions or languages. For instance, if your model was primarily tuned to English data, you might overlook critical insights emerging from non-English sources, especially when sentiment dynamics are shifting rapidly.

Arabic coverage led by 4.2 hours. English at T+4.2h. Confide
Arabic coverage led by 4.2 hours. English at T+4.2h. Confidence scores: Arabic 0.82, Mandarin 0.68, English 0.41 Source: Pulsebit /sentiment_by_lang.

Here’s how we can catch this anomaly using Python. The first step is to filter by geographic origin, assuming that language or country data is available. Below is a code snippet that demonstrates this:

Geographic detection output for markets filter. No geo data
Geographic detection output for markets filter. No geo data leads by article count. Bar colour: sentiment direction. Source: Pulsebit articles[].country.

import requests

![Left: Python GET /news_semantic call for 'markets'. Right: l](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_code_output_split_1773058935819.png)
*Left: Python GET /news_semantic call for 'markets'. Right: live JSON response structure. Three lines of Python. Clean JSON. No infrastructure required. Source: Pulsebit /news_semantic.*


# Example payload for checking momentum
payload = {
    'topic': 'markets',
    'momentum_24h': +1.550,
    'sentiment_score': +0.000,
    'confidence': 0.87,
}

# Geographic origin filter (assuming we have geo data)
geo_filter = {
    'language': 'en',
    'country': 'US'
}

# Fetching data with geo filter
response = requests.get('https://api.pulsebit.com/data', params={**payload, **geo_filter})
data = response.json()

if data:
    print("Anomaly Detected:", data)
else:
    print("No anomaly detected.")
Enter fullscreen mode Exit fullscreen mode

Currently, we don’t have geo filter data returned in /dataset/daily_dataset or /news_recent for the topic "markets," but when it becomes available, this filter will be invaluable.

Now, let's run the meta-sentiment moment. This will analyze the narrative framing itself to see how it aligns with the sentiment data:

# Input example for meta-sentiment loop
narrative_input = "Markets narrative sentiment cluster analysis"
meta_sentiment_response = requests.post('https://api.pulsebit.com/sentiment', json={'text': narrative_input})
meta_sentiment_data = meta_sentiment_response.json()

print("Meta-Sentiment Analysis:", meta_sentiment_data)
Enter fullscreen mode Exit fullscreen mode

This step allows us to assess how the narrative itself might be influencing market sentiment. By feeding the cluster analysis back through our sentiment endpoint, we can gain deeper insights into how narratives can drive sentiment shifts.

Here are three specific builds you can create using this anomaly detection pattern:

  1. Geo-Filtered Anomaly Detector: Set a threshold for momentum spikes (e.g., +1.500) and implement a geo filter that alerts you when sentiment from major non-English regions, like Chinese or Spanish, experiences a similar spike.

  2. Meta-Sentiment Alert System: Create a system that runs the meta-sentiment loop whenever a sentiment score is anomalous (e.g., below -0.500 or above +0.500). This will help you understand if the prevailing narratives are amplifying or counteracting the sentiment you're observing.

  3. Sentiment Trends Dashboard: Build a dashboard using the sentiment data that visualizes trends over time alongside momentum shifts. Use a threshold of +1.500 for momentum spikes to highlight periods where sentiment drastically changes, particularly focusing on clusters from different languages.

To get started with these builds, check out our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste the provided code and be up and running in under 10 minutes. This discovery has the potential to transform how you approach market sentiment analysis. Don’t let these anomalies slip through the cracks!

Top comments (0)