Files
momentum devandClaude Fable 5 3871bda616 fix: label broker sync events by actual execution broker (tradier stack)
Tradier stack emitted account/positions/orders events hardcoded as
broker_name=alpaca_paper while the executor filters snapshots by
client.broker_name (tradier) — position cap and re-entry block read zero
positions, and the dashboard showed 'Alpaca Paper' over real Tradier values.
Mode label now defaults from BROKER/TRADIER_ENV (tradier_live) instead of
alpaca_paper.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-04 10:52:01 -05:00

31 lines
1.1 KiB
Python

from __future__ import annotations
import os
from dataclasses import dataclass
from typing import Literal, cast
TradingMode = Literal["schwab_live", "alpaca_paper", "tradier_live", "tradier_sandbox"]
@dataclass(frozen=True)
class TradingModeSettings:
execution_mode: TradingMode = "alpaca_paper"
@classmethod
def from_env(cls, env: dict[str, str] | None = None) -> "TradingModeSettings":
values = dict(os.environ)
if env is not None:
values.update(env)
# BROKER=tradier swaps the execution client, so the default mode label
# must follow it — else the Tradier stack reports "alpaca_paper".
if values.get("BROKER", "alpaca").strip().lower() == "tradier":
sandbox = values.get("TRADIER_ENV", "sandbox").strip().lower() != "live"
default = "tradier_sandbox" if sandbox else "tradier_live"
else:
default = "alpaca_paper"
mode = values.get("TRADING_EXECUTION_MODE", default)
if mode not in {"schwab_live", "alpaca_paper", "tradier_live", "tradier_sandbox"}:
mode = default
return cls(execution_mode=cast(TradingMode, mode))