ZhuLinsen/daily_stock_analysis · warning · DataFetchError
[AlphaVantage] No data in date range for {symbol}
Error message
[AlphaVantage] No data in date range for {symbol} What it means
A DataFetchError raised by AlphaVantageFetcher._fetch_raw_data when the time series parsed successfully but zero rows fall inside the requested [start_date, end_date] window. AV's 'compact' outputsize returns only the most recent ~100 trading points, so older date ranges yield no matching rows even though the symbol is valid.
Source
Thrown at data_provider/alphavantage_fetcher.py:88
raise DataFetchError(f"[AlphaVantage] No time series data for {symbol}")
rows = []
start = datetime.strptime(start_date, '%Y-%m-%d').date()
end = datetime.strptime(end_date, '%Y-%m-%d').date()
for date_str, values in data[ts_key].items():
row_date = datetime.strptime(date_str, '%Y-%m-%d').date()
if start <= row_date <= end:
rows.append({
'date': date_str,
'1. open': float(values.get('1. open', 0)),
'2. high': float(values.get('2. high', 0)),
'3. low': float(values.get('3. low', 0)),
'4. close': float(values.get('4. close', 0)),
'5. volume': float(values.get('5. volume', 0)),
})
if not rows:
raise DataFetchError(f"[AlphaVantage] No data in date range for {symbol}")
df = pd.DataFrame(rows)
df.index = pd.to_datetime(df['date'])
df.index.name = None # 避免与 _normalize_data 重新添加的 'date' 列冲突
return df.drop(columns=['date'])
def _normalize_data(self, df: pd.DataFrame, stock_code: str) -> pd.DataFrame:
if df.empty:
return df
df = df.copy()
df['date'] = pd.to_datetime(df.index).date
df = df.rename(columns={
'1. open': 'open', '2. high': 'high', '3. low': 'low',
'4. close': 'close', '5. volume': 'volume',
})
# AlphaVantage returns newest-first; sort ascending before computing pct_chg
df = df.sort_values('date', ascending=True).reset_index(drop=True)View on GitHub (pinned to 5159bd72e8)
Solutions
- If you need >100 days of history, request with outputsize='full' (requires editing the params in the fetcher or using a custom call).
- Verify start/end are within the last ~100 trading days when using compact mode.
- Check the symbol still trades; delisted ones have no recent rows.
- Fall back to Yfinance (free full history) for long backfills.
Example fix
# before (in alphavantage_fetcher.py params) 'outputsize': 'compact', # only ~100 recent points # after 'outputsize': 'full', # full history; heavier response
Defensive patterns
Strategy: fallback
Validate before calling
from datetime import date, timedelta
compact_horizon = date.today() - timedelta(days=150) # ~100 trading days
if date.fromisoformat(start_date) < compact_horizon:
logger.info('range older than compact window; prefer a full-history source') Try / catch
try:
df = av_fetcher.fetch(sym, start, end)
except DataFetchError as e:
if 'No data in date range' in str(e):
df = yfinance_fetcher.fetch(sym, start, end) # free full history
else:
raise Prevention
- Remember outputsize is hardcoded 'compact' (~100 recent points); long backfills belong on Yfinance.
- Validate start_date <= end_date and both within recent history before calling.
- For symbols that may be delisted, fall back instead of failing the batch.
When it happens
Trigger: Requesting a date range older than the last ~100 trading days (outputsize is hardcoded to 'compact'); requesting a range entirely in the future; weekends/holidays-only ranges for very recent windows; symbol whose recent data ends before start_date (delisted).
Common situations: Backfill jobs asking for years of history with a compact response; end_date accidentally formatted wrong (e.g. '2025-13-01' parsing failure happens earlier, but swapped day/month can silently shift the window); delisted symbols.
Related errors
- Invalid share image record ID
- Desktop share images require the configured backend origin
- Desktop share image source did not return HTML
- invalid_params
- [AlphaVantage] API key not configured
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/7b278d96bb9bf266.
Report an issue: GitHub.