From ac101c663a2e232a7426ad6e63e558cfab9005a0 Mon Sep 17 00:00:00 2001 From: Yaojia Wang Date: Thu, 19 Mar 2026 15:58:17 +0100 Subject: [PATCH] fix: switch price target from FMP to yfinance FMP provider requires a paid API key. yfinance provides targetMeanPrice in ticker.info for free. --- openbb_service.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/openbb_service.py b/openbb_service.py index c5d4d87..49c536a 100644 --- a/openbb_service.py +++ b/openbb_service.py @@ -104,13 +104,15 @@ async def get_financials(symbol: str) -> dict: async def get_price_target(symbol: str) -> float | None: + """Get consensus analyst price target via yfinance.""" + import yfinance as yf + + def _fetch() -> float | None: + t = yf.Ticker(symbol) + return t.info.get("targetMeanPrice") + try: - result = await asyncio.to_thread( - obb.equity.estimates.price_target, symbol, provider="fmp" - ) - items = _to_dicts(result) - if items: - return items[0].get("adj_price_target") or items[0].get("price_target") + return await asyncio.to_thread(_fetch) except Exception: logger.warning("Failed to get price target for %s", symbol, exc_info=True) return None