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 observed an intriguing anomaly in our sentiment data: a 24h momentum spike of +0.750. This kind of spike can indicate significant shifts in market sentiment that might otherwise go unnoticed if your analytics pipeline isn’t equipped to handle it. In a fast-moving environment, such as finance, a seemingly small change can be the precursor to larger trends. Notably, this spike is occurring now, in the US, where sentiments have shifted noticeably, making it a critical moment for us to respond.

When you’re working with sentiment data, missing nuances can be detrimental. If your model missed this spike by even a few hours, it could result in decisions made based on outdated information. This is especially true for entities or languages that dominate the conversation. For instance, if your pipeline doesn't account for the US market’s dominant English language, your analysis will likely overlook vital signals like this one. You might find yourself reacting too late, losing out on potential opportunities.

To catch these anomalies programmatically, we can leverage our API. Below is a Python snippet to identify sentiment shifts like the one we just observed:

import requests

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


topic = 'markets'
score = +0.000
confidence = 0.87
momentum = +0.750

# Geographic origin filter
geo_filter = {
    "topic": topic,
    "region": "us"
}

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


response = requests.get('https://api.pulsebit.com/dataset/daily_dataset', params=geo_filter)
data = response.json()

# Check if geo filter data is available
if data:
    print("Geo filter data found.")
else:
    print("DATA UNAVAILABLE: no geo filter data returned — verify /dataset/daily_dataset and /news_recent for topic: markets")

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

print(meta_sentiment)
Enter fullscreen mode Exit fullscreen mode

In this code block, we first filter for sentiment data specific to the "markets" topic in the US. Ensure to check the availability of geo-filtered data, as it’s crucial for accurate sentiment analysis. If geo-filtering isn’t applicable due to unavailable data, that’s a significant gap in our pipeline.

We then send a narrative string through our API to analyze its sentiment. This step is essential because it allows us to evaluate how the sentiment cluster is framing the narrative itself, which can offer deeper insights into the underlying drivers of the spike.

Now, let’s talk about practical applications. Here are three builds we suggest implementing based on this momentum spike:

  1. Sentiment Alert System: Set a threshold for momentum spikes above +0.500. Trigger alerts when the API detects such spikes, allowing for timely responses to shifts in sentiment.

  2. Geo-Filtered Analytics Dashboard: Create a dashboard that visualizes sentiment data by region. Use the geo filter to display trends specifically for the US, enabling more targeted decision-making based on localized sentiment shifts.

  3. Meta-Sentiment Analytics: Implement a routine that runs the meta-sentiment loop every 6 hours. Capture the narrative framing of major sentiment clusters and assess how these narratives evolve over time, thus providing context around sentiment spikes.

If you’re ready to dive into this kind of analysis, we’ve got all the resources you need at pulsebit.lojenterprise.com/docs. You can copy-paste the code above and run it in under 10 minutes. Let’s start catching those anomalies before they pass us by!

![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]

Top comments (0)