Merge pull request #35 from fourblocks2020/feat/dcy-036-kis-credential-inject

feat(dcy-036/bat-054): KISBroker 양의 경로 — 데몬-스코프 KIS 인증정보 실거래 주입
This commit is contained in:
2026-06-30 13:54:49 +09:00
committed by GitHub
10 changed files with 733 additions and 1 deletions
@@ -50,6 +50,7 @@ class SnapshotScheduler:
alarm_emitter: Optional[AlarmEmitter] = None,
warn_store: Optional[ReconcileWarningStore] = None,
credential_fetch_enabled: bool = False,
kis_reinit_callback: Optional[Callable[[BrokerCredentialPayload], None]] = None,
) -> None:
self._read = read_port
self._store = store
@@ -72,6 +73,10 @@ class SnapshotScheduler:
# dcy-036 / REQ-113/114/115: credential fetch opt-in + break-glass detection.
# credential_fetch_enabled=False (default) → env-only, no portfolio-hub fetch.
self._credential_fetch_enabled: bool = credential_fetch_enabled
# dcy-036 / REQ-113 AC-2 / REQ-115 AC-1: optional callback to reinitialize
# KISBroker with the fetched day-start credential. None = no reinit (paper
# broker or credential_fetch_enabled=False). Set by daemon.py assembly.
self._kis_reinit_callback: Optional[Callable[[BrokerCredentialPayload], None]] = kis_reinit_callback
# REQ-113: detect break-glass at init time (env var set by operator).
self._break_glass: bool = (
os.environ.get("TREX_KIS_BROKER_BREAK_GLASS", "").lower()
@@ -206,6 +211,26 @@ class SnapshotScheduler:
ctx.broker.credential_version,
self._instance_key,
)
# dcy-036 / REQ-113 AC-2 / REQ-115 AC-1: reinitialize KISBroker with
# fetched credential so intraday KIS API calls use the day-start creds.
# Failure does NOT flip entry_allowed — the broker runs on existing env
# credentials until next checkpoint (graceful degrade, not fail-closed).
if self._kis_reinit_callback is not None:
try:
self._kis_reinit_callback(ctx.broker)
_log.info(
"DAY_START KISBroker reinitialized with fetched credential "
"(account_ref=%s, instance=%s)",
ctx.broker.account_ref,
self._instance_key,
)
except Exception as exc: # noqa: BLE001
_log.error(
"DAY_START KISBroker reinitialize failed: %s (instance=%s) "
"— trading continues with existing env credential",
exc.__class__.__name__,
self._instance_key,
)
def _emit_day_start_alarm(self, *, reason: str) -> None:
"""Publish CRITICAL DAY_START_LOAD_FAILED alarm (REQ-114)."""