diff --git a/app/services/etf_holdings_fetcher.py b/app/services/etf_holdings_fetcher.py index 922cf76..2252771 100644 --- a/app/services/etf_holdings_fetcher.py +++ b/app/services/etf_holdings_fetcher.py @@ -149,6 +149,13 @@ class ETFHoldingsFetcher: snap = res.scalar_one_or_none() if not snap: return None + + # 최대 허용 시차 검증: 120일 초과 시 stale로 판단 → SEC에서 새로 fetch + if as_of_date is not None: + gap = dt_norm - snap.snapshot_date + if gap.days > 120: + return None + hres = await db.execute(select(ETFHolding).where(ETFHolding.snapshot_id == snap.id)) rows = hres.scalars().all() holdings = [] @@ -268,7 +275,11 @@ class ETFHoldingsFetcher: # Candidate list: newest first, filtered by date if provided. # Ensure we include multiple prior days (not just the top day) to avoid missing the target series. if target_date: - eligible = [(dt, acc) for dt, acc in filings if dt <= target_date] + lower_bound = target_date - timedelta(days=365) + eligible = [(dt, acc) for dt, acc in filings if lower_bound <= dt <= target_date] + if not eligible: + # fallback: 하한 없이 전체 검색 (아주 오래된 ETF 등) + eligible = [(dt, acc) for dt, acc in filings if dt <= target_date] if not eligible: early_dt, early_acc = filings[0] xml_url = await self._download_primary_xml(