news_sentiment_analyzer / src /api /finnhub /financial_news_requester.py
Dmitry Beresnev
add openrouter client, promt generator, etc
bba1099
raw
history blame contribute delete
837 Bytes
import os
import logging
from typing import Any
from dotenv import load_dotenv
import finnhub
load_dotenv()
api_key = os.getenv('FINNHUB_API_TOKEN')
def fetch_comp_financial_news(ticker: str = 'NVDA', date_from = "2025-07-31", date_to = "2025-08-01") -> list[dict[str, Any]] | None:
"""
Fetch financial news using Finnhub API.
"""
try:
finnhub_client = finnhub.Client(api_key=api_key)
news_feed = finnhub_client.company_news(ticker, _from=date_from, to=date_to)
if not news_feed:
logging.warning(f"No news found for ticker {ticker}")
return None
logging.info(f'got total amount of news: {len(news_feed)} for ticker: {ticker}')
return news_feed
except Exception as e:
logging.info(f"Error fetching financial news: {e}")
return None