feat: add 67 new endpoints across 10 feature groups

Prerequisite refactor:
- Consolidate duplicate _to_dicts into shared obb_utils.to_list
- Add fetch_historical and first_or_empty helpers to obb_utils

Phase 1 - Local computation (no provider risk):
- Group I: 12 technical indicators (ATR, ADX, Stoch, OBV, Ichimoku,
  Donchian, Aroon, CCI, Keltner, Fibonacci, A/D, Volatility Cones)
- Group J: Sortino, Omega ratios + rolling stats (variance, stdev,
  mean, skew, kurtosis, quantile via generic endpoint)
- Group H: ECB currency reference rates

Phase 2 - FRED/Federal Reserve providers:
- Group C: 10 fixed income endpoints (treasury rates, yield curve,
  auctions, TIPS, EFFR, SOFR, HQM, commercial paper, spot rates,
  spreads)
- Group D: 11 economy endpoints (CPI, GDP, unemployment, PCE, money
  measures, CLI, HPI, FRED search, balance of payments, Fed holdings,
  FOMC documents)
- Group E: 5 survey endpoints (Michigan, SLOOS, NFP, Empire State,
  BLS search)

Phase 3 - SEC/stockgrid/FINRA providers:
- Group B: 4 equity fundamental endpoints (management, dividends,
  SEC filings, company search)
- Group A: 4 shorts/dark pool endpoints (short volume, FTD, short
  interest, OTC dark pool)
- Group F: 3 index/ETF enhanced (S&P 500 multiples, index
  constituents, ETF N-PORT)

Phase 4 - Regulators:
- Group G: 5 regulatory endpoints (COT report, COT search, SEC
  litigation, institution search, CIK mapping)

Security hardening:
- Service-layer allowlists for all getattr dynamic dispatch
- Regex validation on date, country, security_type, form_type params
- Exception handling in fetch_historical
- Callable guard on rolling stat dispatch

Total: 32 existing + 67 new = 99 endpoints, all free providers.
This commit is contained in:
Yaojia Wang
2026-03-19 17:28:31 +01:00
parent b6f49055ad
commit 87260f4b10
24 changed files with 1877 additions and 64 deletions

View File

@@ -5,36 +5,18 @@ from typing import Any
from openbb import obb
from obb_utils import to_list, first_or_empty
logger = logging.getLogger(__name__)
PROVIDER = "yfinance"
def _to_dicts(result: Any) -> list[dict[str, Any]]:
"""Convert OBBject results to list of dicts."""
if result is None or result.results is None:
return []
if isinstance(result.results, list):
return [
item.model_dump() if hasattr(item, "model_dump") else vars(item)
for item in result.results
]
if hasattr(result.results, "model_dump"):
return [result.results.model_dump()]
return [vars(result.results)]
def _first_or_empty(result: Any) -> dict[str, Any]:
"""Get first result as dict, or empty dict."""
items = _to_dicts(result)
return items[0] if items else {}
async def get_quote(symbol: str) -> dict:
result = await asyncio.to_thread(
obb.equity.price.quote, symbol, provider=PROVIDER
)
return _first_or_empty(result)
return first_or_empty(result)
async def get_historical(symbol: str, days: int = 365) -> list[dict]:
@@ -45,7 +27,7 @@ async def get_historical(symbol: str, days: int = 365) -> list[dict]:
start_date=start,
provider=PROVIDER,
)
items = _to_dicts(result)
items = to_list(result)
return [
{**item, "date": str(item["date"])}
if "date" in item and not isinstance(item["date"], str)
@@ -58,35 +40,35 @@ async def get_profile(symbol: str) -> dict:
result = await asyncio.to_thread(
obb.equity.profile, symbol, provider=PROVIDER
)
return _first_or_empty(result)
return first_or_empty(result)
async def get_metrics(symbol: str) -> dict:
result = await asyncio.to_thread(
obb.equity.fundamental.metrics, symbol, provider=PROVIDER
)
return _first_or_empty(result)
return first_or_empty(result)
async def get_income(symbol: str) -> list[dict]:
result = await asyncio.to_thread(
obb.equity.fundamental.income, symbol, provider=PROVIDER
)
return _to_dicts(result)
return to_list(result)
async def get_balance(symbol: str) -> list[dict]:
result = await asyncio.to_thread(
obb.equity.fundamental.balance, symbol, provider=PROVIDER
)
return _to_dicts(result)
return to_list(result)
async def get_cash_flow(symbol: str) -> list[dict]:
result = await asyncio.to_thread(
obb.equity.fundamental.cash, symbol, provider=PROVIDER
)
return _to_dicts(result)
return to_list(result)
async def get_financials(symbol: str) -> dict:
@@ -122,7 +104,7 @@ async def get_news(symbol: str) -> list[dict]:
result = await asyncio.to_thread(
obb.news.company, symbol, provider=PROVIDER
)
return _to_dicts(result)
return to_list(result)
async def get_summary(symbol: str) -> dict:
@@ -144,35 +126,35 @@ async def get_gainers() -> list[dict]:
result = await asyncio.to_thread(
obb.equity.discovery.gainers, provider=PROVIDER
)
return _to_dicts(result)
return to_list(result)
async def get_losers() -> list[dict]:
result = await asyncio.to_thread(
obb.equity.discovery.losers, provider=PROVIDER
)
return _to_dicts(result)
return to_list(result)
async def get_active() -> list[dict]:
result = await asyncio.to_thread(
obb.equity.discovery.active, provider=PROVIDER
)
return _to_dicts(result)
return to_list(result)
async def get_undervalued() -> list[dict]:
result = await asyncio.to_thread(
obb.equity.discovery.undervalued_large_caps, provider=PROVIDER
)
return _to_dicts(result)
return to_list(result)
async def get_growth() -> list[dict]:
result = await asyncio.to_thread(
obb.equity.discovery.growth_tech, provider=PROVIDER
)
return _to_dicts(result)
return to_list(result)
async def get_upgrades_downgrades(symbol: str, limit: int = 20) -> list[dict]:
@@ -200,3 +182,37 @@ async def get_upgrades_downgrades(symbol: str, limit: int = 20) -> list[dict]:
]
return await asyncio.to_thread(_fetch)
# --- Equity Fundamentals Extended (Group B) ---
async def get_management(symbol: str) -> list[dict]:
"""Get executive team info (name, title, compensation)."""
result = await asyncio.to_thread(
obb.equity.fundamental.management, symbol, provider=PROVIDER
)
return to_list(result)
async def get_dividends(symbol: str) -> list[dict]:
"""Get historical dividend records."""
result = await asyncio.to_thread(
obb.equity.fundamental.dividends, symbol, provider=PROVIDER
)
return to_list(result)
async def get_filings(symbol: str, form_type: str | None = None) -> list[dict]:
"""Get SEC filings (10-K, 10-Q, 8-K, etc.)."""
kwargs: dict[str, Any] = {"symbol": symbol, "provider": "sec"}
if form_type:
kwargs["type"] = form_type
result = await asyncio.to_thread(obb.equity.fundamental.filings, **kwargs)
return to_list(result)
async def search_company(query: str) -> list[dict]:
"""Search for companies by name."""
result = await asyncio.to_thread(obb.equity.search, query, provider="sec")
return to_list(result)