diff options
Diffstat (limited to 'services/fmp_service.py')
| -rw-r--r-- | services/fmp_service.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/services/fmp_service.py b/services/fmp_service.py index 4dea211..0a3419d 100644 --- a/services/fmp_service.py +++ b/services/fmp_service.py @@ -117,3 +117,46 @@ def get_company_news(ticker: str, limit: int = 20) -> list[dict]: if data and isinstance(data, list): return data return [] + + +@st.cache_data(ttl=86400) +def get_historical_ratios(ticker: str, limit: int = 10) -> list[dict]: + """Annual historical valuation ratios (P/E, P/B, P/S, EV/EBITDA, etc.).""" + data = _get(LEGACY_BASE, f"/ratios/{ticker.upper()}", params={"limit": limit}) + return data if isinstance(data, list) else [] + + +@st.cache_data(ttl=86400) +def get_historical_key_metrics(ticker: str, limit: int = 10) -> list[dict]: + """Annual historical key metrics (ROE, ROA, margins, debt/equity, etc.).""" + data = _get(LEGACY_BASE, f"/key-metrics/{ticker.upper()}", params={"limit": limit}) + return data if isinstance(data, list) else [] + + +@st.cache_data(ttl=3600) +def get_analyst_estimates(ticker: str) -> dict: + """Return annual and quarterly forward analyst estimates.""" + annual = _get(LEGACY_BASE, f"/analyst-estimates/{ticker.upper()}", params={"limit": 5}) + quarterly = _get( + LEGACY_BASE, + f"/analyst-estimates/{ticker.upper()}", + params={"limit": 10, "period": "quarter"}, + ) + return { + "annual": annual if isinstance(annual, list) else [], + "quarterly": quarterly if isinstance(quarterly, list) else [], + } + + +@st.cache_data(ttl=3600) +def get_insider_transactions(ticker: str, limit: int = 50) -> list[dict]: + """Return recent insider buy/sell transactions.""" + data = _get(LEGACY_BASE, "/insider-trading", params={"symbol": ticker.upper(), "limit": limit}) + return data if isinstance(data, list) else [] + + +@st.cache_data(ttl=3600) +def get_sec_filings(ticker: str, limit: int = 30) -> list[dict]: + """Return recent SEC filings (10-K, 10-Q, 8-K, etc.).""" + data = _get(LEGACY_BASE, f"/sec_filings/{ticker.upper()}", params={"limit": limit}) + return data if isinstance(data, list) else [] |
