Source code for trader.errors

"""Typed exceptions for the whole package.

Every failure the app raises deliberately derives from `TraderError`, so
callers can distinguish our errors from third-party SDK noise.
"""

__all__ = [
    "BacktestError",
    "BrokerError",
    "ConfigError",
    "MarketDataError",
    "MissingCredentialsError",
    "NonRetryableMarketDataError",
    "OrderError",
    "PerformanceError",
    "ReplayError",
    "RiskHaltError",
    "TraderError",
    "UnsafeConfigError",
]


[docs] class TraderError(Exception): """Base class for all errors raised by this application."""
[docs] class ConfigError(TraderError): """Configuration is missing or invalid."""
[docs] class UnsafeConfigError(ConfigError): """Configuration would risk real money. The app must fail closed."""
[docs] class MissingCredentialsError(ConfigError): """Credentials required for the selected trading mode are absent."""
[docs] class BrokerError(TraderError): """The broker API call failed."""
[docs] class MarketDataError(TraderError): """The market data provider call failed or returned nothing usable."""
[docs] class NonRetryableMarketDataError(MarketDataError): """A `MarketDataError` caused by the content of what was returned, not a transient fetch failure -- retrying reproduces the identical failure (issue #99: yfinance served the same malformed bar 17 minutes apart). `resilience/retrying.py`'s `_NEVER_RETRIED` skips the retry-with-backoff for exactly this reason: waiting does not fix these."""
[docs] class BacktestError(TraderError): """A backtest cannot produce a meaningful result from the inputs given."""
[docs] class OrderError(TraderError): """Submitting, cancelling, or reading an order failed."""
[docs] class RiskHaltError(TraderError): """A guardrail halted trading for the remainder of the day."""
[docs] class PerformanceError(TraderError): """A return (account or benchmark) cannot be computed from the inputs given."""
[docs] class ReplayError(TraderError): """A replay tried to use information from after the decision instant. Raised, never warned: a point-in-time leak does not degrade a replay result, it manufactures one. Issue #7's scoring rule calls this "the easiest thing to get wrong and the one that would silently invent skill". """