DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

How to Detect Biotech Sentiment Shifts with the Pulsebit API (Python)

How to Detect Biotech Sentiment Shifts with the Pulsebit API (Python)

The Problem

As you dive into the biotech sector, you might have noticed something peculiar: sentiment shifts can be ridiculously hard to track without serious data scraping work. Traditional methods involve crawling multiple sources, parsing HTML, and wrestling with inconsistent data formats. Trust me, I've spent countless hours building scrapers only to end up with incomplete or misleading sentiment analysis. The problem is clear: you need a cleaner, more efficient way to access real-time sentiment data without the scraping headaches.

The Solution

Enter the Pulsebit API. This tool offers a straightforward solution to your sentiment analysis woes with a single endpoint. With just a simple GET request, you can pull the latest sentiment data related to biotech, all neatly packaged in a structured JSON format. Let's get right into how you can leverage this API to track shifts in biotech sentiment.

The Code

Here’s a simple Python snippet that demonstrates how to interact with the Pulsebit API. Make sure you have the requests library installed.

import requests

def get_biotech_sentiment():
    url = "https://pulsebit.lojenterprise.com/api/news_semantic"
    params = {
        'topic': 'biotech'
    }
    response = requests.get(url, params=params)

    if response.status_code == 200:
        return response.json()
    else:
        raise Exception(f"Error fetching data: {response.status_code}")

if __name__ == "__main__":
    sentiment_data = get_biotech_sentiment()
    print(sentiment_data)
Enter fullscreen mode Exit fullscreen mode

Reading the Response

Let’s break down the response you receive from this API call. Here’s a sample payload based on the current sentiment data:

Left: Python GET /news_semantic call for 'biotech'. Right: l
Left: Python GET /news_semantic call for 'biotech'. Right: live JSON response structure. Three lines of Python. Clean JSON. No infrastructure required. Source: Pulsebit /news_semantic.

{
  "TOPIC": "biotech",
  "momentum_24h": "+1.400",
  "sentiment_score": "+0.000",
  "confidence": "0.870",
  "sentiment_index_0_100": "67.5",
  "direction": "rising",
  "semantic_clusters": "0",
  "region": "us",
  "semantic_similarity_avg": "0.319"
}
Enter fullscreen mode Exit fullscreen mode

Key Fields Explained:

  • TOPIC: The subject of the sentiment analysis—in this case, biotech.
  • momentum_24h: The change in sentiment momentum over the last 24 hours. The current +1.40 indicates a notable increase, suggesting recent positive news or trends.
  • sentiment_score: This stands at +0.00, which implies neutrality. However, combined with rising momentum, it indicates potential for upward movement.
  • confidence: A high confidence score of 0.87 means you can trust this sentiment reading.
  • sentiment_index_0_100: A score of 67.5 suggests a generally positive outlook, even with a neutral score.
  • direction: “Rising” tells you that sentiment is trending upwards.
  • semantic_clusters: With 0 clusters, it indicates no predominant themes in the recent news—this could mean mixed messages or lack of consensus.
  • region: Data is focused on the US market.
  • semantic_similarity_avg: A score of 0.319 suggests moderate similarity across news sources.

Three Use Cases

  1. Algo Alert: Set up an alert system that triggers whenever the momentum crosses a certain threshold (e.g., +1.00). You can use this to initiate trades or further analysis.

  2. Slack Bot: Create a Slack bot that pings your team when biotech sentiment rises above a specific level. This can keep your team informed and ready to react.

  3. Dashboard: Integrate this data into your existing dashboard for real-time monitoring. Visualizing the momentum and sentiment scores could provide critical insights for your analysis.

Get Started

Ready to dive in? Check out the Pulsebit API Documentation to see how you can expand on this basic setup and tailor it to your needs. With the right tools, you can turn raw sentiment data into actionable insights, all without the hassle of scraping.

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.

Top comments (0)