Skip to main content
The News Agent retrieves crypto news headlines from NewsData.io and scores each one against lists of bullish and bearish keywords. It aggregates the per-headline scores into an overall market sentiment verdict alongside per-sentiment counts and the full classified headline list. Stage 4/6 of the Elyra pipeline calls this agent automatically; you can also invoke it directly.

Requirements

You need a NewsData.io API key. Get one at newsdata.io and set it in your environment:
You can also pass the key directly as the api_key parameter. If the key is absent, the underlying collector will fail and the agent will raise an exception — unless the full pipeline is running, which catches the error and substitutes neutral defaults automatically.

CLI usage

The script reads NEWSDATA_API_KEY from the environment and prints the full sentiment result as JSON.

Python usage

get_news_sentiment()

Fetches up to limit headlines matching query from NewsData.io, classifies each headline as "bullish", "bearish", or "neutral", and returns an aggregate sentiment result. Signature

Parameters

number
default:"10"
Maximum number of headlines to fetch from NewsData.io.
string
default:"cryptocurrency"
Search query passed to the NewsData.io API. Change this to focus on a specific asset or topic (e.g. "bitcoin", "solana ETF").
string
NewsData.io API key. If omitted, the function reads NEWSDATA_API_KEY from the environment.

Sentiment classification

Each headline’s title and description are combined, lowercased, and matched against two keyword lists:
  • Bullish keywords include: surge, rally, gain, bullish, breakout, all-time high, ath, adoption, etf, approval, record high, and others.
  • Bearish keywords include: crash, plunge, drop, bearish, collapse, ban, crackdown, hack, exploit, liquidation, and others.
A headline is classified as "bullish" if its bullish keyword count exceeds its bearish count, "bearish" if the reverse is true, and "neutral" if they are equal. The overall sentiment field is set to whichever per-headline class has a strict majority. If no class has a strict majority, the overall sentiment is "neutral".

Return value

Returns dict[str, Any].
string
required
Aggregate market sentiment across all fetched headlines. One of "bullish", "bearish", or "neutral".
number
required
Number of headlines classified as bullish.
number
required
Number of headlines classified as bearish.
number
required
Number of headlines classified as neutral.
object[]
required
List of classified headline objects, one per fetched article.

Example response

Graceful degradation

If NEWSDATA_API_KEY is not set and no api_key argument is provided, the full pipeline (main.py) catches the resulting error and substitutes these neutral defaults:
The pipeline continues through the remaining stages — only news-derived context will be absent from the final report.
Sentiment classification uses predefined keyword lists for bullish and bearish signals. The bullish list includes terms like surge, rally, ath, etf, and adoption. The bearish list includes terms like crash, hack, exploit, ban, and liquidation.