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 came across a fascinating data point: a 24h momentum spike of +1.550. This sudden surge in sentiment could indicate a significant shift in market dynamics that might have gone unnoticed in your usual monitoring routines. When momentum spikes like this occur, they often reflect changes in sentiment that can influence trading decisions. Ignoring such anomalies can lead to missed opportunities or misinformed strategies.

In our experience, many models struggle to capture these nuanced shifts, especially when they lack the ability to account for multilingual content or the dominance of specific entities. Your model might have missed this spike by several hours, simply because it wasn't equipped to handle the nuances of global sentiment. For instance, English-language assessments can dominate the narrative, overshadowing critical insights from other regions or languages, which can skew your understanding of momentum.

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

To catch anomalies like this one, we can leverage our API with a straightforward Python script. Below is a code snippet that sets the foundation for detecting sentiment spikes:

import requests

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


# Define your data parameters
topic = 'markets'
score = +0.000
confidence = 0.87
momentum = +1.550

# Step 1: Geographic origin filter
# Note: Ensure geo filter data is available in your dataset
# Example endpoint (update with actual data sources)
geo_filter_url = "https://api.pulsebit.com/dataset/daily_dataset"
params = {
    "topic": topic,
    "language": "en",  # Specify the language filter
    "country": "US"    # Specify the country filter
}

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


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

# Check if geo filter data is available
if 'data' in data:
    print("Geo-filtered data:", data)
else:
    print("DATA UNAVAILABLE: Check /dataset/daily_dataset or /news_recent for topic:", topic)

# Step 2: Meta-sentiment moment
narrative_input = "Markets narrative sentiment cluster analysis"
sentiment_url = "https://api.pulsebit.com/sentiment"
sentiment_response = requests.post(sentiment_url, json={"input": narrative_input})
sentiment_data = sentiment_response.json()

print("Meta-sentiment score:", sentiment_data)
Enter fullscreen mode Exit fullscreen mode

In the code above, we first set up a geographic origin filter. This is critical when you have language or country data available, allowing you to focus on specific regions that may have driven the momentum spike. However, if that data isn't accessible, you might miss out on critical insights.

Next, we run a meta-sentiment moment to analyze the narrative framing itself. This step is essential because it helps us understand how the sentiment is constructed around our data. By analyzing the narrative, we can identify if the underlying sentiment is being influenced by particular events or trends that could explain the spike.

Now that we've established how to detect these sentiment anomalies, let's outline three specific builds you can create using this newfound knowledge:

  1. Geo-Filtered Alert System: Set a threshold for momentum (e.g., +1.500) and create a notification system that alerts you when sentiment spikes occur in a specified region. This could help you respond quickly to shifts in localized sentiment.

  2. Cluster Analysis Dashboard: Build a dashboard that visualizes sentiment clusters around specific topics, such as "markets," and track how these clusters change over time. This can highlight emerging narratives that may influence market behavior.

  3. Dynamic Sentiment Scoring: Implement a dynamic scoring system that not only considers raw sentiment but also analyzes the narrative around it. Use the meta-sentiment loop to refine your scoring model and improve its predictive capabilities, especially during major market events.

By integrating these builds into your workflow, you can enhance your ability to respond to market sentiment shifts effectively.

To get started, check out our documentation at pulsebit.lojenterprise.com/docs. We believe you can copy-paste and run the example code in under 10 minutes, putting you on the fast track to detecting market sentiment anomalies like the +1.550 momentum spike we just uncovered.

Top comments (0)