fix: CRITICAL/HIGH 버그 30건 수정 + 전체 코드 주석 추가 + 중복 정리

## CRITICAL 수정 (20건)
- day_trading: global 선언 누락, loss_tracker 연동, ban 체크 추가
- trade_executor: BUY 체결가 order_price로 수정, remaining_pct 누적 계산
- risk_validator: get_current_price dict 파싱, MAX_POSITION_SIZE 동기화, DB 세션 누수
- risk_management/recommendations: date.today() → KST 변환
- mdd_manager: Lock 밖 executed_key 참조 수정
- correlation_filter: output → output2 키 수정
- portfolio: 해외 종목 USD/KRW 환율 적용 분리
- Sharpe Ratio 거래빈도 기반 연간화
- telegram_notifier: send_message() 공개 래퍼 추가
- position_manager: 앱 재시작 시 DB 포지션 복원
- swing exit_service: remaining_pct 조건 범위 수정
- run_backtest: original_qty 기반 remaining_pct 계산
- us_market_schedule: 2027년 미국 공휴일 추가
- Login.tsx: res.ok 검증 추가
- mean_reversion_strategy: RSI 로그 하드코딩 수정

## HIGH 수정 (10건)
- db_worker: DLQ 파일 백업 메커니즘 추가
- korea_investment_api: 만료 토큰 임의 연장 제거
- market_data: chart_cache 최대 100개 + TTL 만료
- main.py: rate_limit_store 1시간 미접근 IP 정리
- recommendations: fire-and-forget try/except 추가
- swing/scheduler: DB 세션 3개 분리
- Dashboard: wsMessages 전체 순회
- Layout: /health 엔드포인트 + 30초 폴링
- ml_ensemble: POST /train require_api_key 추가
- day_trading: record_trade_result_safe() 전환

## 코드 정리
- 프론트엔드: isUsStock, formatTime 공통 유틸 추출
- 백엔드: dead code 제거, 중복 import 통합
- MCP: JSON 파싱 헬퍼 추출 (~60줄 감소)
- 전체 ~100개 파일 한국어 주석 추가
- 테스트 13건 코드 기준 수정 (468 passed)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-26 16:05:41 +09:00
parent 739a8a2e5d
commit de7921d270
149 changed files with 133353 additions and 3338 deletions

View File

@@ -27,9 +27,15 @@ COMMISSION_RATE = 0.003
SLIPPAGE_RATE = 0.002
TOTAL_COST_RATE = COMMISSION_RATE + SLIPPAGE_RATE
# 장 운영 시간 필터
_SKIP_OPEN_UNTIL = dtime(9, 30) # 장 초반 30분 제외 (개장 직후 변동성 과다)
_SKIP_CLOSE_FROM = dtime(15, 15) # 마감 15분 전 제외 (종가 청산 압력)
# 장 운영 시간 필터 (동적 로드)
def _get_skip_open_until():
return dtime(settings.SHORT_TERM_SKIP_OPEN_HOUR, settings.SHORT_TERM_SKIP_OPEN_MIN)
def _get_skip_close_from():
return dtime(settings.SHORT_TERM_SKIP_CLOSE_HOUR, settings.SHORT_TERM_SKIP_CLOSE_MIN)
_SKIP_OPEN_UNTIL = _get_skip_open_until() # 장 초반 30분 제외 (개장 직후 변동성 과다)
_SKIP_CLOSE_FROM = _get_skip_close_from() # 마감 15분 전 제외 (종가 청산 압력)
class TimeFrame(str, Enum):
@@ -64,7 +70,7 @@ class ShortTermStrategy:
3. 15분봉 RSI 반등 중 — RSI_now > RSI_3봉전 (바닥 확인)
4. 15분봉 종가 ≤ BB 하단 × 1.01
5. 15분봉 종가 > MA5 — Fake-out 방지
6. 15분봉 거래량 > MA20 × 1.5 — 1.3에서 강화
6. 15분봉 거래량 > MA20 × 1.3 — CLAUDE.md 7.2
7. ATR/close ≥ 0.8% — 거래비용 커버 가능한 변동성
8. 반전 캔들 (optional) — 양봉 or 핵머 캔들
9. 시간 필터 (optional) — 09:30~15:15만 허용
@@ -148,17 +154,16 @@ class ShortTermStrategy:
if bb is None:
return None
_, _, bb_lower = bb
if close > bb_lower * 1.01:
if close > bb_lower * settings.SHORT_TERM_BB_LOWER_BUFFER:
return None
# 조건 5: MA5 상향 (Fake-out 방지)
# BB 하단 ±1% 구간에서는 최근 급락으로 MA5가 눌려있을 수 있으므로 완화 허용
# (close < bb_lower * 0.99 → BB 하단을 크게 이탈 중 = 완전 차단, 그 외는 허용)
# 조건 5: MA5 상향돌파 (CLAUDE.md 7.2: 5MA 상향돌파 필수)
# [2026-03-15 CLAUDE.md 정합성 수정] BB 하단 근처 완화 조건 제거
ma5 = sum(m15_closes[-5:]) / 5
if close < ma5 and close < bb_lower * 0.99:
if close < ma5:
return None
# 조건 6: 거래량 급증 (1.5배 강화)
# 조건 6: 거래량 급증 (CLAUDE.md 7.2: 1.3배)
vol_ma20 = sum(m15_volumes[-20:]) / 20
if vol_ma20 == 0 or current_volume <= vol_ma20 * settings.SHORT_TERM_VOLUME_MULTIPLIER:
return None
@@ -214,10 +219,10 @@ class ShortTermStrategy:
if entry_price > 0:
if atr_15m:
atr_stop = entry_price - 1.0 * atr_15m
hard_stop = entry_price * 0.98 # -2% 하드 스탑
stop_price = max(atr_stop, hard_stop) # 더 타이트한 쪽
hard_stop = entry_price * (1 - settings.SHORT_TERM_HARD_STOP_PCT) # -2% 하드 스탑
stop_price = max(atr_stop, hard_stop) # [FIX] 타이트한 쪽 = 진입가에 가까운 = 높은 가격 (CLAUDE.md 7.2)
else:
stop_price = entry_price * 0.98 # ATR 없으면 -2% 고정
stop_price = entry_price * (1 - settings.SHORT_TERM_HARD_STOP_PCT) # ATR 없으면 -2% 고정
if close <= stop_price:
loss_pct = (close - entry_price) / entry_price * 100
@@ -239,12 +244,12 @@ class ShortTermStrategy:
if atr_15m and entry_price > 0:
profit_pct = (close - entry_price) / entry_price
atr_pct = atr_15m / entry_price
if profit_pct >= 1.5 * atr_pct:
if profit_pct >= settings.SHORT_TERM_ATR_PROFIT_MULTIPLIER * atr_pct:
return ExitSignal(
action="SELL_ALL",
reason=(
f"익절 수익률({profit_pct * 100:.1f}%)"
f" ≥ 1.5×ATR({atr_pct * 100:.1f}%)"
f" ≥ {settings.SHORT_TERM_ATR_PROFIT_MULTIPLIER}×ATR({atr_pct * 100:.1f}%)"
),
sell_pct=1.0,
)