aboutsummaryrefslogtreecommitdiff
path: root/services/fmp_service.py
diff options
context:
space:
mode:
authorOpenclaw <openclaw@mail.tylerhoang.xyz>2026-03-29 13:21:39 -0700
committerOpenclaw <openclaw@mail.tylerhoang.xyz>2026-03-29 13:21:39 -0700
commit4fdcb4ce0f00bc8f62d50ba5d352dd2fe01cd7e7 (patch)
tree35dc4234751521d5a89a124f53eeaa827813be07 /services/fmp_service.py
parentfc55820f5128f97e231de5388e59912e4a675782 (diff)
Add historical ratios, forward estimates, insider transactions, SEC filings
- services/fmp_service.py: add get_historical_ratios, get_historical_key_metrics, get_analyst_estimates, get_insider_transactions, get_sec_filings - components/valuation.py: add Historical Ratios and Forward Estimates subtabs - components/insiders.py: new — insider buy/sell summary, monthly chart, detail table - components/filings.py: new — SEC filings with type filter and direct links - app.py: wire in Insiders and Filings top-level tabs
Diffstat (limited to 'services/fmp_service.py')
-rw-r--r--services/fmp_service.py43
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 []