The single-source problem
You pick one free data API for financial information. It works well most of the time. But:
Some companies report through non-standard channels and the API misses them
Cash flow data for certain sectors is systematically wrong
The API rate-limits you and returns empty data without saying so
A company restructuring causes a gap in the data for 2–3 weeks
Your analysis breaks silently for affected companies. You don't know which ones until you manually check.
The layering pattern
Instead of choosing one source, define a priority order:
def get_cash_flow ( ticker : str ) -> float | None : # 1. Try the primary source primary = fetch_from_primary_api ( ticker , " freeCashFlow " ) if primary is not None : return primary
# 2. Fall back to secondary source (e.g. official regulatory filings) secondary = fetch_from_sec_filings ( ticker , " FreeCashFlow " ) if secondary is not None : return secondary
# 3.…