get_news_sentiment
Analyze sentiment of news articles for a specific stock ticker to gain insights into market perception and trends. Retrieve relevant news data from Yahoo Finance to inform investment decisions.
Instructions
获取指定股票的相关新闻列表。
参数说明: ticker: str 股票代码,例如 "AAPL"
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticker | Yes |
Implementation Reference
- server.py:160-187 (handler)Handler function that fetches recent news articles for the given stock ticker using the Financial Modeling Prep API (v4/general_news endpoint), extracts title, text summary, and URL for each article, and formats them into a string response.async def get_news_sentiment(ticker: str) -> str: """Get news for a given ticker symbol""" api_key = os.environ.get("FMP_API_KEY") if not api_key: return "Error: FMP_API_KEY environment variable not set." url = "https://financialmodelingprep.com/api/v4/general_news" try: resp = requests.get( url, params={"tickers": ticker, "page": 0, "size": 50, "apikey": api_key}, timeout=10 ) resp.raise_for_status() data = resp.json() except Exception as e: return f"Error: getting news for {ticker}: {e}" news_list = [] for item in data: title = item.get("title", "") summary = item.get("text", "") link = item.get("url", "") news_list.append(f"Title: {title}\nSummary: {summary}\nURL: {link}") if not news_list: return f"No news found for {ticker}" return "\n\n".join(news_list)
- server.py:151-159 (registration)Tool registration using the @fmp_server.tool decorator, specifying the name and Chinese description with parameter details.@fmp_server.tool( name="get_news_sentiment", description="""获取指定股票的相关新闻列表。 参数说明: ticker: str 股票代码,例如 "AAPL" """, )
- server.py:37-37 (helper)Mention of the tool in the server instructions string listing available tools.- get_news_sentiment:获取股票相关新闻。