# BAT-014 Implementation - Status: completed - Batch: BAT-014 ## Plan Summary - REQ-053(config 2종) → REQ-052(쿨다운 로직) → REQ-054(runtime-flows). 인메모리만, DB/스레드/인터페이스 변경 없음. ## Changed Files - 수정: - `trex_core/runtime/config.py` — `SafetySellConfig.min_retry_interval_sec`(기본 600)·`max_retry_warn_count`(기본 3) + `from_env` 파싱(`TREX_SAFETY_SELL_MIN_RETRY_INTERVAL`/`TREX_SAFETY_SELL_MAX_RETRY_WARN_COUNT`) (REQ-053) - `trex_core/application/safety_sell.py` — `_last_attempt`/`_attempt_count` dict, `_in_cooldown`/`_attempt_sell`/`_prune_cooldown`, `check_forced_close`·`check_prices` 쿨다운 gate(skip→KIS poll skip 포함)·경고, `run_once` 시작 시 prune. market_close 는 미적용 (REQ-052) - `docs/runtime-flows.md` — safety-sell 재시도 쿨다운 flow + 가격체크 tr_id(FHKST01010100) 정정 (REQ-054) - `tests/runtime/test_safety_sell_config.py` — 쿨다운 env 기본값/파싱 2종 - `tests/application/test_safety_sell_worker.py` — TestRetryCooldown 6종(skip/만료 재시도/경고/prune/market_close 제외/트리거 해소) ## Execution Log 1. REQ-053 config 2종 + from_env → `test_safety_sell_config.py` green. 2. REQ-052 쿨다운(`_in_cooldown`/`_attempt_sell`/`_prune_cooldown` + forced_close/prices gate) → TestRetryCooldown 6 green (non-transitioning sell stub 으로 영속 거부 시뮬). 3. REQ-054 runtime-flows 쿨다운 flow 추가. 4. 전체 회귀: 단위 278 passed / 30 skipped, ruff clean. ## Validation - `pytest tests/application/test_safety_sell_worker.py tests/runtime/test_safety_sell_config.py` → 34 passed. - 전체 `pytest -q --deselect ...::test_sandbox_token_and_submit` → 278 passed / 30 skipped. - `ruff check trex_core tests` → All passed. ## Remaining Risks - R-2(재시작 시 쿨다운 초기화 → 1회 즉시 재시도): 허용(문서 명시). - 실 운영 거부 시나리오(휴장/잔고)에서의 쿨다운 동작은 차기 거래일 실 관찰로 보강(단위는 stub 로 시뮬). 인메모리·additive 변경이라 release 위험 낮음.