feat: add bounded KIS account read recovery
This commit is contained in:
@@ -112,6 +112,28 @@ class SnapshotScheduleConfig:
|
||||
tick_sec: float = 60.0
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class AccountSnapshotConfig:
|
||||
"""Opt-in bounded KIS account-read recovery (dcy-041 / GitHub #45)."""
|
||||
|
||||
enabled: bool = False
|
||||
buy_max_age_sec: int = 600
|
||||
sell_max_age_sec: int = 3600
|
||||
refresh_interval_sec: float = 300.0
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if self.buy_max_age_sec < 0:
|
||||
raise ValueError("account snapshot buy_max_age_sec must be >= 0")
|
||||
if self.sell_max_age_sec < self.buy_max_age_sec:
|
||||
raise ValueError(
|
||||
"account snapshot sell_max_age_sec must be >= buy_max_age_sec"
|
||||
)
|
||||
if self.sell_max_age_sec > 21_600:
|
||||
raise ValueError("account snapshot sell_max_age_sec exceeds six hours")
|
||||
if self.refresh_interval_sec <= 0:
|
||||
raise ValueError("account snapshot refresh_interval_sec must be > 0")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SafetySellConfig:
|
||||
"""Safety-sell feature tuning (REQ-041 / BAT-010).
|
||||
@@ -227,6 +249,9 @@ class DaemonConfig:
|
||||
rabbitmq: Optional[RabbitMQConfig] = None
|
||||
# REQ-030 (BAT-008): daily snapshot refresh.
|
||||
snapshot_schedule: SnapshotScheduleConfig = SnapshotScheduleConfig()
|
||||
# dcy-041 / GitHub #45: opt-in account read snapshot. Disabled keeps the
|
||||
# previous live-only balance path byte-for-byte compatible.
|
||||
account_snapshot: AccountSnapshotConfig = AccountSnapshotConfig()
|
||||
# REQ-041 (BAT-010): safety-sell feature config.
|
||||
safety_sell: SafetySellConfig = SafetySellConfig()
|
||||
# dcy-013 / REQ-014 (BAT-017): Alert-only pending-order stale watchdog
|
||||
@@ -301,6 +326,20 @@ class DaemonConfig:
|
||||
kst_time=os.environ.get("TREX_SNAPSHOT_SCHEDULE_KST", "07:30").strip() or "07:30",
|
||||
tick_sec=float(os.environ.get("TREX_SNAPSHOT_TICK_SEC", "60")),
|
||||
)
|
||||
account_snapshot = AccountSnapshotConfig(
|
||||
enabled=os.environ.get(
|
||||
"TREX_ACCOUNT_SNAPSHOT_ENABLED", ""
|
||||
).lower() in ("1", "true", "yes"),
|
||||
buy_max_age_sec=int(
|
||||
os.environ.get("TREX_ACCOUNT_SNAPSHOT_BUY_MAX_AGE_SEC", "600")
|
||||
),
|
||||
sell_max_age_sec=int(
|
||||
os.environ.get("TREX_ACCOUNT_SNAPSHOT_SELL_MAX_AGE_SEC", "3600")
|
||||
),
|
||||
refresh_interval_sec=float(
|
||||
os.environ.get("TREX_ACCOUNT_SNAPSHOT_REFRESH_INTERVAL_SEC", "300")
|
||||
),
|
||||
)
|
||||
_mc_time = os.environ.get("TREX_MARKET_CLOSE_LIQUIDATION_TIME", "").strip() or None
|
||||
safety_sell = SafetySellConfig(
|
||||
watchdog_timeout_sec=int(os.environ.get("TREX_WATCHDOG_TIMEOUT", "120")),
|
||||
@@ -329,6 +368,7 @@ class DaemonConfig:
|
||||
ledger_interval_sec=float(os.environ.get("TREX_LEDGER_INTERVAL_SEC", "1.0")),
|
||||
rabbitmq=rabbitmq,
|
||||
snapshot_schedule=snapshot_schedule,
|
||||
account_snapshot=account_snapshot,
|
||||
safety_sell=safety_sell,
|
||||
pending_stale_threshold_sec=int(
|
||||
os.environ.get("TREX_PENDING_STALE_THRESHOLD", "0")
|
||||
|
||||
Reference in New Issue
Block a user