from app.config import Settings from app.market.base import MarketDataSource from app.market.replay import ReplaySource from app.market.yahoo import YahooSource def live_source(settings: Settings) -> MarketDataSource: if settings.live_source == "yahoo": return YahooSource(settings.yahoo_poll_seconds) if settings.live_source == "schwab": # Imported here so schwab-py stays optional while the live source is # Yahoo, which is still the default. from app.market.schwab import SchwabSource return SchwabSource(settings) if settings.live_source == "replay" and settings.replay_file: return ReplaySource(settings.replay_file) raise ValueError(f"Unsupported LIVE_SOURCE: {settings.live_source}") def seed_source(settings: Settings) -> MarketDataSource | None: """The source of history, which is never Schwab. Schwab serves price history for equities and ETFs only, so with LIVE_SOURCE=schwab the seed stays on Yahoo. That pairing is the intended configuration, not a fallback: Yahoo supplies the past, Schwab the present. """ if settings.seed_source == "none": return None if settings.seed_source in ("yahoo", "schwab"): return YahooSource(settings.yahoo_poll_seconds) if settings.seed_source == "replay" and settings.replay_file: return ReplaySource(settings.replay_file) raise ValueError(f"Unsupported SEED_SOURCE: {settings.seed_source}")