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 anomaly: a 24h momentum spike of +1.550, indicating a significant shift in market sentiment. This spike stands out not only for its magnitude but also for the potential insights it can provide into market dynamics. With a sentiment score of +0.000 and a confidence level of 0.87, this anomaly clearly signals a brewing narrative, waiting for us to dive deeper.

Yet, if your model isn’t set up to handle multilingual origins or recognize entity dominance, you might miss crucial signals like this by several hours. Consider this: a spike of this nature could be tied to a specific language or dominant entity that’s influencing market sentiment globally. Ignoring these factors could lead to delayed reactions, costing you valuable insights when the momentum shifts.

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.

Let’s explore how we can catch such anomalies using Python with our API.

import requests

![Left: Python GET /news_semantic call for 'markets'. Right: l](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_code_output_split_1772997725372.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.*


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

# Geographic origin filter: this is what we would use if geo data were available
geo_filter = {
    "language": "en",  # Hypothetical example
    "country": "US"    # Hypothetical example
}

![Geographic detection output for markets filter. No geo data ](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_geo_output_1772997725465.png)
*Geographic detection output for markets filter. No geo data leads by article count. Bar colour: sentiment direction. Source: Pulsebit articles[].country.*


# Here’s where we would query our dataset
response = requests.get(f"https://api.pulsebit.com/dataset/daily_dataset?topic={topic}&geo={geo_filter}")
data = response.json()  # Assuming this returns relevant data

# Now, let's use the meta-sentiment moment
meta_sentiment_response = requests.post("https://api.pulsebit.com/sentiment", json={
    "input": "Markets narrative sentiment cluster analysis"
})

meta_sentiment_data = meta_sentiment_response.json()
print(meta_sentiment_data)  # This will give us insights into the framing itself
Enter fullscreen mode Exit fullscreen mode

In the above code, we’ve set up a hypothetical scenario where we might filter by language and country. Although we currently don’t have geo filter data returned, it’s significant to note that this feature is available if you have access to the appropriate language/country data.

Next, we run the narrative through our sentiment endpoint to score the framing itself. This is where the magic happens. By analyzing how the market narrative is constructed, we can glean deeper insights into sentiment anomalies that may not be visible at first glance.

With this anomaly in mind, here are three specific builds you could create:

  1. Geo-Filtered Anomaly Alert: Set up a signal that triggers when momentum spikes exceed a specific threshold (e.g., +1.500) for a chosen country. This can be particularly useful for markets sensitive to regional events.

  2. Meta-Sentiment Analysis Dashboard: Build a visualization that displays the sentiment of various narratives as they evolve. Use the meta-sentiment loop to continuously update the narrative framing in real-time.

  3. Predictive Sentiment Model: Combine sentiment scores with momentum spikes to create a predictive model that anticipates market movements. Use a threshold of +1.500 for momentum and cross-reference with the sentiment score for validation.

If you’re ready to start detecting sentiment anomalies like this, check out our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste and run this code in under 10 minutes to get started on your own anomaly detection journey!

Top comments (0)