diff options
Diffstat (limited to 'services/fmp_service.py')
| -rw-r--r-- | services/fmp_service.py | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/services/fmp_service.py b/services/fmp_service.py index 914c14d..c72524f 100644 --- a/services/fmp_service.py +++ b/services/fmp_service.py @@ -2,6 +2,7 @@ import os import requests import streamlit as st +from concurrent.futures import ThreadPoolExecutor, as_completed from dotenv import load_dotenv from services.data_service import get_company_info, get_historical_ratios_yfinance, compute_ttm_ratios @@ -76,6 +77,17 @@ def get_key_ratios(ticker: str) -> dict: if info.get("forwardPE") is not None: merged["forwardPE"] = info["forwardPE"] + # Growth fields — yfinance info provides these directly + for key, alias in ( + ("revenueGrowth", "revenueGrowthTTM"), + ("earningsGrowth", "earningsGrowthTTM"), + ): + val = info.get(key) + if val is not None: + try: + merged[alias] = float(val) + except (TypeError, ValueError): + pass # Fallback: dividends from info dict when cash-flow data is missing if merged.get("dividendYieldTTM") is None and info.get("dividendYield") is not None: merged["dividendYieldTTM"] = info["dividendYield"] @@ -116,13 +128,22 @@ def get_peers(ticker: str) -> list[str]: @st.cache_data(ttl=3600) def get_ratios_for_tickers(tickers: list[str]) -> list[dict]: - """Return merged TTM ratios/metrics rows for a list of tickers.""" - results = [] - for t in tickers: + """Return merged TTM ratios/metrics rows for a list of tickers, fetched in parallel.""" + def _fetch(t: str) -> dict | None: row = get_key_ratios(t) if row: + row = dict(row) row["symbol"] = t.upper() - results.append(row) + return row + return None + + results = [] + with ThreadPoolExecutor(max_workers=min(len(tickers), 8)) as pool: + futures = {pool.submit(_fetch, t): t for t in tickers} + for future in as_completed(futures): + result = future.result() + if result: + results.append(result) return results |
