fix: 하드닝 루프 8회차 — 체결 보정·고아 감지·청산 경보·실시간/차트·리스크 가드 일괄 수정

- 스윙 체결가 확인 전 executed_price NULL + fill_sweep, 진입가 resolve(ActiveTrade↔Portfolio), 0체결/부분체결 매수 장부 원복
- DT 고아 감지(근거 한정)·0체결 매도 복원·stale 점검 확대, 시간손절 -0.3% 원복
- 폴백 손절 ATR 캐시, 거래량부족-차단 신호 매수 차단, 현금 5% 유보 재적용, MDD peak/reset 수정
- KIS 서킷브레이커 청산 우회·경보, db_worker 재큐잉 순서, heartbeat·health-watch 사이드카
- 실시간 WS 재구독·41건 우선순위·다건 프레임 분할, 차트 샘플 제거·당일봉 합성, WS 서브프로토콜 인증
- 프론트: 미관리 그룹·확인 모달·차트 실시간 반영·예수금 표시 정정
- 전문가 에이전트 6종 추가(.claude/agents)
- 유닛 스위트 2667 passed (소켓 차단 하), tsc OK

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y83Za98XsNw9zuA4FTUytN
This commit is contained in:
2026-10-10 12:17:49 +09:00
parent 5c4803b339
commit a264561576
230 changed files with 41160 additions and 2334 deletions

View File

@@ -64,7 +64,7 @@ async def test_mdd_reduction_reflects_quantities():
await m._sync_active_trade_after_reduction("005930", quantity=10, remaining_qty=7)
assert len(captured) == 1, "축소 반영 payload 가 큐잉되지 않음"
assert captured[0].get("quantity") == 7, "ActiveTrade 잔량 미반영 → 다음 청산이 과다매도"
assert captured[0]["remaining_pct_multiply"] == pytest.approx(0.7)
assert "remaining_pct_multiply" not in captured[0], "익절 단계(remaining_pct) 오염 금지"
# (2) DT 포지션 병존 → DT 행은 건드리지 않고(비-DT 필터) 스윙 잔량만 반영
captured.clear()
@@ -154,3 +154,27 @@ def test_sync_dt_tagging_applies_to_domestic_and_survives_missing_output1():
assert 'return "daytrading"' in pure_src and "quantity <= _dt_held" in pure_src
# 정의가 output1 블록보다 앞이어야 NameError 가 없다
assert src.index("_dt_codes = set(_dt_qty)") < src.index('if "output1" in balance_data')
@pytest.mark.asyncio
async def test_mdd_reduction_never_touches_remaining_pct_stage():
"""[하드닝 R3] MDD 축소 payload 는 remaining_pct(익절 단계)를 건드리지 않는다.
×0.7 이 곱해지면 모멘텀 1차 익절 게이트(remaining>0.75)가 영구 폐쇄된다.
"""
from app.services import mdd_manager as m
captured: list = []
async def _cap(payload):
captured.append(payload)
for dt in (0, 3):
captured.clear()
with patch("app.services.db_worker.enqueue_active_trade_upsert", _cap), \
patch.object(m, "_dt_position_qty", lambda _c, _d=dt: _d):
await m._sync_active_trade_after_reduction("005930", quantity=10, remaining_qty=7)
assert len(captured) == 1
assert "remaining_pct_multiply" not in captured[0]
assert "remaining_pct" not in captured[0]
assert captured[0]["quantity"] == 7