from abc import ABC, abstractmethod from typing import Optional, Dict, Any class StockAPIBase(ABC): """ Abstract base class for stock price data providers. This design allows seamless switching between different stock APIs. """ @abstractmethod def get_stock_price(self, ticker: str) -> Optional[Dict[str, Any]]: """ Retrieve current stock price and related data for a given ticker. Args: ticker: Stock ticker symbol (e.g., 'PYPL', 'AAPL') Returns: Dictionary containing: - ticker: str - current_price: float - previous_close: float - change_dollar: float - change_percent: float - market_open: bool Returns None if ticker is invalid or data unavailable. """ pass @abstractmethod def is_available(self) -> bool: """ Check if the API service is currently available. Returns: True if API is accessible, False otherwise. """ pass