Skip to main content
Glama

get_symbol_sentiment

Analyze recent news sentiment for financial symbols to assess market perception and inform trading decisions.

Instructions

Fetches recent news for a symbol and calculates aggregate sentiment. Args: symbol: Ticker symbol. Returns: Aggregate sentiment analysis of recent news.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes

Implementation Reference

  • The core handler function for the 'get_symbol_sentiment' tool. It fetches the latest 10 news articles for the given symbol using yfinance, analyzes the sentiment of each title using the 'analyze_sentiment' helper, computes the average polarity score, classifies as BULLISH/BEARISH/NEUTRAL, and returns a formatted string summary.
    def get_symbol_sentiment(symbol: str) -> str: """ Fetches recent news for a symbol and calculates aggregate sentiment. Args: symbol: Ticker symbol. Returns: Aggregate sentiment analysis of recent news. """ try: ticker = yf.Ticker(symbol) news = ticker.news[:10] # Last 10 articles if not news: return f"No news found for {symbol}" sentiments = [] model_used = "Unknown" for item in news: title = item.get("title", "") if title: result = analyze_sentiment(title) if "polarity" in result: sentiments.append(result["polarity"]) model_used = result.get("model", "Unknown") if not sentiments: return f"No valid news titles for {symbol}" avg_polarity = sum(sentiments) / len(sentiments) if avg_polarity > 0.1: classification = "BULLISH" elif avg_polarity < -0.1: classification = "BEARISH" else: classification = "NEUTRAL" return (f"Sentiment Analysis for {symbol} ({len(sentiments)} articles):\n" f"Average Polarity: {avg_polarity:.3f}\n" f"Market Sentiment: {classification}\n" f"Model: {model_used}") except Exception as e: return f"Error analyzing sentiment for {symbol}: {str(e)}"
  • server.py:405-408 (registration)
    Registration of the 'get_symbol_sentiment' tool (along with related news tools) using the 'register_tools' helper function, which applies the @mcp.tool() decorator to make it available in the MCP server.
    register_tools( [get_news, analyze_sentiment, get_symbol_sentiment], "News & Sentiment" )
  • Import statement that brings the 'get_symbol_sentiment' function into the server.py scope for registration.
    from tools.news_intelligence import get_news, analyze_sentiment, get_symbol_sentiment

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/N-lia/MonteWalk'

If you have feedback or need assistance with the MCP directory API, please join our Discord server