fix: resolve curl_cffi TLS errors and fix FRED/upgrades endpoints
All checks were successful
continuous-integration/drone/push Build is passing

- Pin curl_cffi==0.7.4 to avoid BoringSSL bug in 0.12-0.14
- Patch curl_cffi Session to use safari TLS fingerprint instead of
  chrome, which triggers SSL_ERROR_SYSCALL on some networks
- Register FRED API key with OpenBB credentials at startup
- Fix macro overview to return latest data instead of oldest, and
  extract values by FRED series ID key
- Replace Finnhub upgrades endpoint (premium-only) with yfinance
  upgrades_downgrades which includes price target changes
- Remove redundant curl_cffi upgrade from Dockerfile
This commit is contained in:
Yaojia Wang
2026-03-19 15:40:41 +01:00
parent b631c888a5
commit f5b22deec3
6 changed files with 77 additions and 25 deletions

View File

@@ -36,19 +36,31 @@ def _to_dicts(result: Any) -> list[dict[str, Any]]:
return [vars(result.results)]
async def get_series(series_id: str, limit: int = 10) -> list[dict[str, Any]]:
async def get_series(
series_id: str, limit: int = 10, latest: bool = False,
) -> list[dict[str, Any]]:
"""Get a FRED time series by ID."""
try:
fetch_limit = limit if not latest else None
kwargs: dict[str, Any] = {
"symbol": series_id,
"provider": PROVIDER,
}
if fetch_limit is not None:
kwargs["limit"] = fetch_limit
result = await asyncio.to_thread(
obb.economy.fred_series,
symbol=series_id,
limit=limit,
provider=PROVIDER,
**kwargs,
)
items = _to_dicts(result)
for item in items:
if "date" in item and not isinstance(item["date"], str):
item = {**item, "date": str(item["date"])}
items = [
{**item, "date": str(item["date"])}
if "date" in item and not isinstance(item["date"], str)
else item
for item in items
]
if latest:
items = items[-limit:]
return items
except Exception:
logger.warning("Failed to fetch FRED series %s", series_id, exc_info=True)
@@ -58,20 +70,22 @@ async def get_series(series_id: str, limit: int = 10) -> list[dict[str, Any]]:
async def get_macro_overview() -> dict[str, Any]:
"""Get a summary of key macro indicators."""
tasks = {
name: get_series(series_id, limit=1)
name: get_series(series_id, limit=1, latest=True)
for name, series_id in SERIES.items()
}
results = await asyncio.gather(*tasks.values(), return_exceptions=True)
overview: dict[str, Any] = {}
for name, result in zip(tasks.keys(), results):
for (name, series_id), result in zip(SERIES.items(), results):
if isinstance(result, BaseException):
logger.warning("Failed to fetch %s: %s", name, result)
overview[name] = None
elif result and len(result) > 0:
entry = result[0]
entry = result[-1]
# FRED returns values keyed by series ID, not "value"
value = entry.get(series_id) or entry.get("value")
overview[name] = {
"value": entry.get("value"),
"value": value,
"date": str(entry.get("date", "")),
}
else: