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 a striking anomaly: a 24-hour momentum spike of +0.750. This surge in sentiment could be a game-changer for how we perceive market dynamics, especially if we consider the implications of such shifts in real-time. If you’ve been monitoring sentiment data closely, you might have noticed that spikes like this can precede significant market movements. But, if your pipeline doesn’t account for nuances like multilingual origin or entity dominance, you might be missing critical signals.

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.

Your model missed this by 24 hours. Imagine receiving this data and realizing it originates predominantly from the US, yet your model is not tuned to handle language variations or regional influences. This oversight can lead to missed opportunities or delayed responses in your strategies. The leading sentiment narrative might be skewed simply because your model doesn’t account for the origin of the data.

Here’s how we can catch such anomalies using our API. Below is a simple Python script to identify a sentiment spike in the "markets" topic, including a geographic origin filter and a meta-sentiment analysis.

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_1773064981831.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.*


# Step 1: Geographic origin filter (if data is available)
topic = 'markets'
score = +0.000
confidence = 0.87
momentum = +0.750

# Simulating a geo filter request
geo_filter_url = "https://api.pulsebit.lojenterprise.com/v1/dataset/daily_dataset"
params = {
    'topic': topic,
    'region': 'us'  # Filter by US
}

response = requests.get(geo_filter_url, params=params)
geo_data = response.json()

# Check if we have geo-filter data
if geo_data:
    print("Geo-filter data available.")
else:
    print("DATA UNAVAILABLE: no geo filter data returned.")

# Step 2: Meta-sentiment moment
meta_sentiment_url = "https://api.pulsebit.lojenterprise.com/v1/sentiment"
meta_input = "Markets narrative sentiment cluster analysis"
meta_response = requests.post(meta_sentiment_url, json={"text": meta_input})
meta_sentiment = meta_response.json()

print("Meta-sentiment score:", meta_sentiment['score'])
Enter fullscreen mode Exit fullscreen mode

In this code, we first attempt to filter sentiment data by geographic origin. We query the /dataset/daily_dataset endpoint to fetch the latest sentiment data for the "markets" topic in the US region. While the example shows a check for geo-filter data, you would typically want to ensure your data processing accounts for this when analyzing sentiment shifts.

Next, we run a meta-sentiment analysis on the narrative framing itself by sending a specific input string to the /sentiment endpoint. This step gives us insight into how the sentiment cluster is framing the market narrative, enriching our understanding of the underlying sentiments.

Now, what can we build using this newfound pattern? Here are three specific ideas:

  1. Sentiment Spike Alert System: Create a service that triggers notifications when the momentum exceeds a predefined threshold (e.g., +0.500) for the "markets" topic, filtering by geographical origin.

  2. Cross-Language Sentiment Comparison: Develop a dashboard that compares sentiment spikes across different languages and regions, utilizing the geo filter to present a more holistic view of market sentiment.

  3. Narrative Impact Analysis: Implement an analysis tool that utilizes the meta-sentiment loop to score different narratives in real-time, helping you gauge which narratives have the most influence on market sentiment shifts.

Ready to dive in? You can start experimenting with our API right away. Check out our documentation at pulsebit.lojenterprise.com/docs. In under 10 minutes, you can copy-paste the above code and start analyzing sentiment anomalies for yourself. Let’s build something impactful!

Top comments (0)