trader.config.loader module¶
Resolution and enforcement of the paper/live safety gate (requirements §9).
Two independent controls must BOTH be satisfied before any real-money order: TRADING_MODE=live and LIVE_TRADING_ENABLED=true. If the first is set without the second, this module fails closed — it raises, and the caller exits. It never silently downgrades to paper, because a user who asked for live and got paper without noticing would draw false conclusions from the results.
- class trader.config.loader.EffectiveTradingConfig(trading_mode, live_trading_enabled, api_key, api_secret, database_url)[source]¶
Bases:
objectThe validated, immutable trading configuration for this process.
- Parameters:
trading_mode (TradingMode)
live_trading_enabled (bool)
api_key (str)
api_secret (str)
database_url (str)
- trading_mode: TradingMode¶
- live_trading_enabled: bool¶
- api_key: str¶
- api_secret: str¶
- database_url: str¶
- property is_live: bool¶
True when the configured mode is live.
A mode signal, not a permission — call assert_live_orders_allowed() before any order.
- property use_paper_endpoint: bool¶
The paper= flag to hand to the Alpaca SDK.
- assert_live_orders_allowed()[source]¶
Re-check the gate immediately before placing an order.
resolve_trading_config already rejects unsafe combinations, so this is defense in depth: any future code path that builds a config by another route still cannot place a live order without both controls. Slice 2’s trade executor must call this before every submission.
- Return type:
None
- trader.config.loader.assemble_database_url(template, password)[source]¶
Insert password into a password-less DSN template.
Uses SQLAlchemy’s own URL parser (make_url/.set(password=…)) rather than string concatenation, so a password containing @, :, / or any other DSN-special character is correctly percent-encoded rather than silently producing a malformed or wrong-field DSN.
- Parameters:
template (str)
password (SecretStr)
- Return type:
str
- trader.config.loader.load_trading_config()[source]¶
Load .env and resolve the trading config in one call.
- Return type:
- trader.config.loader.resolve_trading_config(settings)[source]¶
Validate raw settings into an EffectiveTradingConfig.
- Raises:
UnsafeConfigError – live mode requested without the explicit toggle.
MissingCredentialsError – the selected mode’s key pair is incomplete.
- Parameters:
settings (Settings)
- Return type: