Skip to content

News

news

yfinance-based news data fetching functions.

Functions:

Name Description
get_news_yfinance

Retrieve news for a specific stock ticker using yfinance.

get_global_news_yfinance

Retrieve global/macro economic news using yfinance Search.

logger

logger = getLogger(__name__)

get_news_yfinance

get_news_yfinance(ticker: str, start_date: str, end_date: str) -> str

Retrieve news for a specific stock ticker using yfinance.

Parameters:

Name Type Description Default

ticker

str

Stock ticker symbol, such as "AAPL".

required

start_date

str

Start date in YYYY-MM-DD format.

required

end_date

str

End date in YYYY-MM-DD format.

required

Returns:

Name Type Description
str str

A formatted news report, a no-data message, or an error message.

Source code in src/tradingagents/dataflows/news.py
def get_news_yfinance(ticker: str, start_date: str, end_date: str) -> str:
    """Retrieve news for a specific stock ticker using yfinance.

    Args:
        ticker (str): Stock ticker symbol, such as "AAPL".
        start_date (str): Start date in YYYY-MM-DD format.
        end_date (str): End date in YYYY-MM-DD format.

    Returns:
        str: A formatted news report, a no-data message, or an error message.
    """
    try:
        return _get_news_yfinance(ticker, start_date, end_date)
    except Exception as exc:
        logger.debug("Failed to fetch news for %s", ticker, exc_info=True)
        return f"Error fetching news for {ticker}: {exc!s}"

get_global_news_yfinance

get_global_news_yfinance(curr_date: str, look_back_days: int = 7, limit: int = 10) -> str

Retrieve global/macro economic news using yfinance Search.

Parameters:

Name Type Description Default

curr_date

str

Current date in YYYY-MM-DD format.

required

look_back_days

int

Number of days used for the report window label. Defaults to 7.

7

limit

int

Maximum number of articles to return. Defaults to 10.

10

Returns:

Name Type Description
str str

A formatted global news report, a no-data message, or an error message.

Source code in src/tradingagents/dataflows/news.py
def get_global_news_yfinance(curr_date: str, look_back_days: int = 7, limit: int = 10) -> str:
    """Retrieve global/macro economic news using yfinance Search.

    Args:
        curr_date (str): Current date in YYYY-MM-DD format.
        look_back_days (int, optional): Number of days used for the report
            window label. Defaults to 7.
        limit (int, optional): Maximum number of articles to return. Defaults to 10.

    Returns:
        str: A formatted global news report, a no-data message, or an error message.
    """
    try:
        return _get_global_news_yfinance(curr_date, look_back_days, limit)
    except Exception as exc:
        logger.debug("Failed to fetch global news", exc_info=True)
        return f"Error fetching global news: {exc!s}"