import streamlit as st import logging from api import APIFactory import pandas as pd def test_api_configuration(): """Test the API configuration and secrets.""" logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) try: # Initialize API factory api_factory = APIFactory() # Test FMP client logger.info("Testing FMP client...") fmp_client = api_factory.get_client('fmp') # Test with a known ETF test_symbol = "SPY" # Test profile data logger.info(f"Getting profile data for {test_symbol}...") profile = fmp_client.get_etf_profile(test_symbol) if isinstance(profile, dict) and not profile.get('error'): logger.info("✅ Profile data retrieved successfully") else: logger.error("❌ Failed to get profile data") logger.error(f"Error: {profile.get('message', 'Unknown error')}") # Test historical data logger.info(f"Getting historical data for {test_symbol}...") historical = fmp_client.get_historical_data(test_symbol, period='1mo') if isinstance(historical, pd.DataFrame) and not historical.empty: logger.info("✅ Historical data retrieved successfully") logger.info(f"Data points: {len(historical)}") else: logger.error("❌ Failed to get historical data") # Test cache logger.info("Testing cache...") cache_stats = api_factory.get_cache_stats() logger.info(f"Cache stats: {cache_stats}") # Test fallback to yfinance logger.info("Testing fallback to yfinance...") yfinance_data = api_factory.get_data(test_symbol, 'etf_profile', provider='yfinance') if isinstance(yfinance_data, dict) and not yfinance_data.get('error'): logger.info("✅ YFinance fallback working") else: logger.error("❌ YFinance fallback failed") logger.error(f"Error: {yfinance_data.get('message', 'Unknown error')}") return True except Exception as e: logger.error(f"❌ Test failed: {str(e)}") return False if __name__ == "__main__": success = test_api_configuration() if success: print("\n✅ All tests passed!") else: print("\n❌ Some tests failed. Check the logs for details.")