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 recently stumbled upon an intriguing data point: a 24h momentum spike of +1.550. This spike indicates a significant shift in market sentiment, suggesting a growing bullish trend that is not just a fluke but rather a signal worth investigating further. The nuance of this spike, particularly its timing and context, opens up new avenues for understanding sentiment dynamics in real time.

When your model doesn’t account for multilingual origins or the dominance of certain entities, it can miss crucial shifts like this by several hours—sometimes even days. For instance, if your pipeline isn’t equipped to handle a spike originating from a specific region, you might overlook vital sentiment changes that could inform your strategies. With English often dominating sentiment discourse, you may find that anomalies like this are lost in translation if you’re not filtering for language or geographic specificity.

![DATA UNAVAILABLE: lag_hours — verify /dataset/daily_dataset
[DATA UNAVAILABLE: lag_hours — verify /dataset/daily_dataset is returning sentiment_by_lang data for topic: markets]

Here’s how we can catch anomalies like this using Python with our API.

import requests
import json

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


# Define parameters for the API request
topic = 'markets'
score = +0.000
confidence = 0.87
momentum = +1.550

# Geographic origin filter (assuming we have geo data)
# Example: filtering for English-speaking countries
geo_filter = {
    "language": "en",
    "country": ["US", "UK", "CA"]
}

![[DATA UNAVAILABLE: countries  verify /news_recent is return](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_geo_output_1773081209730.png)
*[DATA UNAVAILABLE: countries  verify /news_recent is returning country/region values for topic: markets]*


# Make a request to fetch data with geo filter applied
response = requests.get("https://api.pulsebit.com/dataset/daily_dataset", params=geo_filter)
data = response.json()

# Check data availability
if data:
    print("Data retrieved successfully.")
else:
    print("DATA UNAVAILABLE: no geo filter data returned.")

# Meta-sentiment moment: scoring the narrative framing
narrative = "Markets narrative sentiment cluster analysis"
sentiment_response = requests.post("https://api.pulsebit.com/sentiment", json={"text": narrative})
sentiment_data = sentiment_response.json()

print(json.dumps(sentiment_data, indent=4))
Enter fullscreen mode Exit fullscreen mode

In the above code, we attempt to filter for English-language content from key countries to catch sentiment trends that may not be evident in a broader dataset. This geographic origin filter is crucial when you want to refine your analysis. However, if you don’t have access to language or country data, you may not see results, as indicated by the message in the code.

The second part of our approach involves rerunning the narrative through our sentiment analysis endpoint. The input string we use, "Markets narrative sentiment cluster analysis," allows us to score the narrative framing itself, giving us a deeper understanding of how the market sentiment is constructed and perceived.

Now, what can we build using this pattern?

  1. Sentiment Alert System: Set a threshold for momentum spikes, say +1.500, and trigger alerts when this level is reached. This can be integrated with your existing notification systems.

  2. Geo-Specific Sentiment Dashboard: Build a dashboard that displays sentiment trends filtered by geographic origin, especially for key markets like the US or Europe. This could highlight which regions are driving sentiment changes.

  3. Meta-Sentiment Reporting Tool: Develop a reporting tool that continuously analyzes narrative framing using our sentiment endpoint. Set a daily summary of the top narratives impacting sentiment, providing insights that can adapt to changing market conditions.

To get started, check out our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste the above code and run it in under 10 minutes, putting you on the path to detecting and acting on sentiment anomalies with precision.

Top comments (0)