Introduction Context is as critical as data. Relying solely on price movements is like evaluating a novel by its cover—you risk overlooking the deeper narrative
by Thomas Cotter
February 5, 2025

Introduction
Context is as critical as data. Relying solely on price movements is like evaluating a novel by its cover—you risk overlooking the deeper narrative behind market shifts. Benzinga’s Newsfeed & Bars APIs bridge this gap by combining market-moving headlines with detailed historical price data, which gives a better view of market behavior.
In this guide, we will walk you through integrating these robust data sources into your trading strategy. You’ll learn how to extract full-length articles using Benzinga’s Why Is It Moving v2 endpoint and obtain precise price bars from the Bars endpoint. By merging these insights into a sentiment-based model, you can uncover actionable intelligence that enhances your market predictions. This straightforward yet powerful approach showcases how real-time news sentiment can elevate your decision-making in a dynamic market environment.
1. The APIs at a Glance
Newsfeed (Why Is It Moving v2)
Endpoint: GET /news
Purpose: Pulls news items by ticker, date, and other filters.
Notable Parameters:
token (your API key)
tickers (comma-separated list of symbols)
displayOutput (e.g., full to see the entire article body)
dateFrom, dateTo or page and pageSize to organize how many articles you get.
Why Use It?
Up-to-date headlines and deeper stories are essential for gauging sentiment and discovering why a stock is in the spotlight.
Bars Endpoint
Endpoint: GET /bars
Purpose: Returns historical candlestick (bar) data to measure how a stock’s price changes over time.
Key Parameters:
symbols (one or more comma-separated tickers)
from, to (date range)
interval (1D, 5M, 1W, etc.)
Why Use It?
Comparing sentiment against price movements can help uncover patterns in how news influences stock returns.
2. Let’s Build a Sentiment-Fueled Predictor
Below, we’ll walk through the code in manageable parts to show how we fetch data, analyze it, and make a simple prediction about tomorrow’s price movement.
2.1 Import Libraries & Set Up Endpoints
First, we need our usual suspects for making requests, handling data, performing sentiment analysis, and running a model.
requests helps us call the Benzinga APIs.
pandas structures our data in easy-to-use data frames.
TextBlob quickly calculates text sentiment.
sklearn libraries let us build and evaluate a simple Logistic Regression model.
2.2 Fetching News Data
Next, we define a helper function to retrieve articles from the Newsfeed endpoint. We pass parameters like tickers, dateFrom, dateTo, and—most importantly—our API key.
displayOutput=full ensures we get the article’s full text.
pageSize=20 controls how many articles come back in a single query.
2.3 Fetching Price Bars
Similarly, our fetch_bar_data function grabs daily candlestick data. We can adjust the interval to 1D, 5M, or other increments.
symbols can be multiple tickers, comma-separated.
interval=1D suits our plan to look at daily moves.
2.4 Combining News & Bars
Now it’s time to call our functions, parse the returned data, and build a pandas DataFrame. Notice how we handle the date in articles, then merge everything by date.
Key Points
We parse out the “created” field, trimming the string to avoid time-zone quirks.
We combine the title and body to get the entire text for sentiment analysis.
2.5 Calculating Sentiment
Here’s where TextBlob comes in. We average the polarity (sentiment) of all articles that appear on the same day. Values range from -1 (very negative) to 1 (very positive).
2.6 Merging with Bar Data
Let’s grab the bar data, convert it to a DataFrame, and then merge the sentiment we just computed. We fill missing sentiment data with 0.
2.7 Creating a Label and Training the Model
Finally, we shift the closing price by one day to see if tomorrow’s close is higher than today’s.
label is 1 if the stock price goes up, 0 otherwise.
We’re using an 80/20 split for training and testing.
2.8 Evaluating & Making a Prediction
We check accuracy on the test set, then predict tomorrow’s movement.
3. The Output
Below is a sample output you might see when running the script:
4. Why This Matters
Market headlines can trigger sudden spikes or drops, so ignoring news is like driving with one eye closed. By pairing Benzinga’s robust news feed (including article titles, teasers, and full bodies) with bar data, you can catch subtle shifts in investor sentiment. Even a simple logistic regression reveals how bullish or bearish signals in the news might align with a stock’s next-day performance.
Final Thoughts
That’s all it takes to build a basic sentiment-based stock predictor—and you can level it up in countless ways. Try analyzing multiple tickers at once, applying advanced natural language processing, or adding technical indicators on top of price bars.
With Benzinga’s APIs, you have the raw ingredients for your own unique “recipe” in market analysis. The beauty is in experimenting, refining, and seeing how each new insight helps you navigate the market more confidently.


OTHER ARTICLES
Utilizing the Benzinga News Archive to Power your LLM
The Benzinga News S3 bucket houses an extraordinary source of comprehensive data with the potential to power any Large Language Model (LLM).
Client Spotlight: Yahoo! Finance’s Integration of the Benzinga Analyst Ratings API
Check out how Yahoo! Finance integrated the Benzinga Analyst Ratings API.
Predicting and Analyzing Markets Utilizing a News Archive
LLMs can play a crucial role in decision-making, offering insights into market directions, strategic choices, and an accurate portrayal of the market landscape.
Quick Contact
Address
1 Campus Martius Detroit,
MI 48226, United States
Phone
Get in Touch






