#!/usr/bin/env python3 """ Fetch historical data for all configured market indices from 1990-2025. """ import sys from pathlib import Path from datetime import datetime # Add src to path sys.path.append(str(Path(__file__).parent / "src")) def fetch_all_historical_data(): """Fetch historical data for all configured indices.""" try: from src.data.storage import MarketDataStorage from src.utils.config import Config # Initialize storage and config storage = MarketDataStorage() config = Config() indices = config.get_indices() # Date range: 2000-01-01 to 2025-12-31 (more realistic for all indices) start_date = datetime(2000, 1, 1) end_date = datetime(2025, 12, 31) print(f"Fetching historical data from {start_date.date()} to {end_date.date()}") print(f"Database location: {config.get_database_path()}") print(f"Processing {len(indices['indices'])} market indices...\n") total_records = 0 for symbol, info in indices['indices'].items(): print(f"Fetching {symbol} ({info['name']}) - {info['market']}...") try: count = storage.fetch_and_store_historical_data(symbol, start_date, end_date) total_records += count print(f" ✓ Stored {count} records") except Exception as e: print(f" ✗ Error: {e}") print() print(f"Total records stored: {total_records}") # Show summary summary = storage.get_data_summary() print(f"\nDatabase Summary:") print(f" Total records: {summary['total_records']}") print(f" Unique symbols: {summary['unique_symbols']}") if summary['earliest_date']: print(f" Date range: {summary['earliest_date'].date()} to {summary['latest_date'].date()}") except Exception as e: print(f"Error: {e}") return False return True if __name__ == "__main__": success = fetch_all_historical_data() sys.exit(0 if success else 1)