Files
auto-stock/backend/tests/test_execution_quality.py
shuim a264561576 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
2026-10-10 12:17:49 +09:00

45 lines
1.7 KiB
Python

from datetime import datetime
import pytest
from app.services import execution_quality as eq
def test_side_adjust_no_cancellation():
rows = [
{"order_type": "BUY", "slippage": 0.1, "strategy_type": "daytrading"},
{"order_type": "SELL", "slippage": 0.1, "strategy_type": "daytrading"},
]
r = eq.aggregate_execution_quality_v1(rows)["overall"]
assert r["mean_cost_bp"] == 0.0
assert r["mean_abs_bp"] == 10.0
assert eq.slippage_cost_bp_v3("BUY", 0.1) == pytest.approx(10.0)
assert eq.slippage_cost_bp_v3("SELL", 0.1) == pytest.approx(-10.0)
def test_matches_trade_executor_v2():
te = pytest.importorskip("app.services.trade_executor")
for side in ("BUY", "SELL", "HOLD"):
for v in (0.1, -0.3, None, "x"):
assert eq.slippage_cost_bp_v3(side, v) == te.slippage_cost_bp_v2(side, v)
def test_low_sample_null_and_groups():
rows = [
{"order_type": "BUY", "slippage": None, "strategy_type": "swing", "executed_quantity": 0},
{"order_type": "BUY", "slippage": 0.2, "strategy_type": "daytrading", "executed_quantity": 5,
"executed_at": datetime(2026, 10, 7, 9, 5), "fill_verified": True},
]
r = eq.aggregate_execution_quality_v1(rows)
assert r["overall"]["low_sample"] and r["overall"]["n_slippage"] == 1
assert r["by_strategy"]["swing"]["mean_cost_bp"] is None
assert r["by_hour"][9]["fill_verified_ratio"] == 1.0
big = [{"order_type": "BUY", "slippage": 0.1}] * eq.LOW_SAMPLE_THRESHOLD
assert not eq.aggregate_execution_quality_v1(big)["overall"]["low_sample"]
def test_invalid_inputs():
for bad in (None, "x", float("nan"), float("inf")):
assert eq.slippage_cost_bp_v3("BUY", bad) is None
assert eq.slippage_cost_bp_v3("HOLD", 0.1) is None