fix: switch price target from FMP to yfinance
All checks were successful
continuous-integration/drone/push Build is passing

FMP provider requires a paid API key. yfinance provides
targetMeanPrice in ticker.info for free.
This commit is contained in:
Yaojia Wang
2026-03-19 15:58:17 +01:00
parent f5b22deec3
commit ac101c663a

View File

@@ -104,13 +104,15 @@ async def get_financials(symbol: str) -> dict:
async def get_price_target(symbol: str) -> float | None: 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: try:
result = await asyncio.to_thread( return await asyncio.to_thread(_fetch)
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")
except Exception: except Exception:
logger.warning("Failed to get price target for %s", symbol, exc_info=True) logger.warning("Failed to get price target for %s", symbol, exc_info=True)
return None return None