feat(runtime): dcy-014 trading_date KST 타임존 분리 + 일일 슬롯 preallocation (BAT-018)

데몬이 시스템 UTC 날짜로 슬롯을 1회만 preallocate 해 trading_date 가 KST 캘린더와
어긋나고 재시작 없이는 다음날 슬롯이 안 생기던 문제(issue #14) 정정.

거버넌스: 전부 change-req (신규 REQ 없음, dcy-014 OQ-3; 스케줄러는 REQ-030 패턴 준용).
- REQ-005: trading_date 를 설정 타임존(기본 Asia/Seoul) 기준 계산(timestamp 는 UTC
  유지). DailyPreallocationScheduler 신규 — TZ 일자당 1회 멱등 fire, 재시작 없이
  다음날 슬롯 자동 생성. setup() 배선 + trex-preallocation 스레드
- REQ-048: TOML trading_timezone/daily_preallocation_time 키 + from_config 전파
- REQ-009: runtime-flows/data-model 정합 + instance.example.toml

OQ-1 기본 00:00(TZ 자정, TOML 설정 가능) / OQ-2 매 캘린더일 생성(거래일 캘린더 후속).
멱등 preallocate 로 중복 tick·다중 인스턴스 중복 생성 0.

검증: 단위 302 passed/32 skipped, 인프라 게이트(PG+RabbitMQ) 334 passed, ruff clean.
신규 test_preallocation_scheduler(고정 clock) + test_instance_config 확장.
BAT-018 release-candidate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-08 15:39:04 +09:00
co-authored by Claude Opus 4.8
parent 4746f74aae
commit 0b7db66463
20 changed files with 818 additions and 15 deletions
+19 -1
View File
@@ -99,6 +99,10 @@ class DaemonInstanceConfig:
instance_key: str
portfolio_hub_token: str = ""
# dcy-014 / REQ-048: trading_date timezone + daily preallocation trigger.
# Optional — absent keys fall back to KST / midnight defaults.
trading_timezone: str = "Asia/Seoul"
daily_preallocation_time: str = "00:00"
@staticmethod
def from_toml(path: str) -> "DaemonInstanceConfig":
@@ -114,6 +118,8 @@ class DaemonInstanceConfig:
return DaemonInstanceConfig(
instance_key=str(instance_key),
portfolio_hub_token=str(data.get("portfolio_hub_token") or ""),
trading_timezone=str(data.get("trading_timezone") or "Asia/Seoul"),
daily_preallocation_time=str(data.get("daily_preallocation_time") or "00:00"),
)
@@ -144,6 +150,11 @@ class DaemonConfig:
# threshold in seconds. 0 disables (default). When >0, dispatched-pending
# slots older than this are surfaced (WARN + counter) without state change.
pending_stale_threshold_sec: int = 0
# dcy-014 / REQ-005 (BAT-018): trading_date timezone (default KST) + daily
# preallocation trigger time (HH:MM, TZ-local). Operative surface is the
# per-instance TOML (REQ-048); these are the env-only defaults.
trading_timezone: str = "Asia/Seoul"
daily_preallocation_time: str = "00:00"
@staticmethod
def from_env() -> "DaemonConfig":
@@ -241,4 +252,11 @@ class DaemonConfig:
pf = base.portfolio_hub
if inst.portfolio_hub_token and pf is not None:
pf = replace(pf, token=inst.portfolio_hub_token)
return replace(base, instance_key=inst.instance_key, portfolio_hub=pf)
# dcy-014 / REQ-048: trading_date TZ + daily trigger come from TOML.
return replace(
base,
instance_key=inst.instance_key,
portfolio_hub=pf,
trading_timezone=inst.trading_timezone,
daily_preallocation_time=inst.daily_preallocation_time,
)