def get_latest_news_for_stock(
    api_key: Dict[str, str], stock_id: str, limit: int = 10
) -> List[Dict[str, Any]]:
    """Returns latest news for a given stock_name by querying results via newsapi."""
    newsapi = NewsApiClient(api_key=api_key["NEWSAPI"])
    cat_to_id = defaultdict(list)
    for source in newsapi.get_sources()["sources"]:
        cat_to_id[source["category"]].append(source["id"])
    business_sources = [
        "bloomberg",
        "business-insider",
        "financial-post",
        "fortune",
        "info-money",
        "the-wall-street-journal",
    ]
    for source in business_sources:
        assert source in cat_to_id["business"]

    start_date = (datetime.now() - timedelta(days=7)).strftime("%Y-%m-%d")
    end_date = datetime.now().strftime("%Y-%m-%d")
    articles = newsapi.get_everything(
        q=stock_id,
        sources=",".join(business_sources),
        from_param=start_date,
        to=end_date,
        language="en",
        sort_by="relevancy",
        page=1,
    )["articles"]
    return articles[:limit]
Returns latest news for a given stock_name by querying results via newsapi.
llama-index-integrations/tools/llama-index-tools-finance/llama_index/tools/finance/news.py