- 스윙 체결가 확인 전 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
62 lines
2.6 KiB
Python
62 lines
2.6 KiB
Python
"""trade_helpers 추격매수/트렌드 필터 — KIS 일봉 순서(최신 우선) 회귀 테스트."""
|
|
import asyncio
|
|
from datetime import timedelta
|
|
from unittest.mock import AsyncMock
|
|
|
|
from app.services import trade_helpers as th
|
|
from app.core.timeutil import now_kst
|
|
|
|
|
|
def _bars(n, today_included=True, last=100.0, old=80.0):
|
|
"""KIS 순서(최신 우선) n봉. 최근 3봉은 last, 이전은 old."""
|
|
base = now_kst() - timedelta(days=0 if today_included else 1)
|
|
rows = []
|
|
for i in range(n):
|
|
d = (base - timedelta(days=i)).strftime("%Y%m%d")
|
|
px = last if i < 4 else old
|
|
rows.append({"stck_bsop_date": d, "stck_clpr": str(px),
|
|
"stck_hgpr": str(px * 1.01), "stck_lwpr": str(px * 0.99)})
|
|
return rows
|
|
|
|
|
|
def _api(**kw):
|
|
api = type("A", (), {})()
|
|
for k, v in kw.items():
|
|
setattr(api, k, v)
|
|
return api
|
|
|
|
|
|
def test_surge_blocks_recent_rally(monkeypatch):
|
|
monkeypatch.setattr(th, "korea_investment_api",
|
|
_api(get_daily_chart=AsyncMock(return_value={"output2": _bars(30)})))
|
|
assert asyncio.run(th.check_surge_prevention("005930", True, "", 120.0))["skip"] is True
|
|
|
|
|
|
def test_surge_ignores_month_old_rally(monkeypatch):
|
|
monkeypatch.setattr(th, "korea_investment_api",
|
|
_api(get_daily_chart=AsyncMock(return_value={"output2": _bars(30)})))
|
|
assert asyncio.run(th.check_surge_prevention("005930", True, "", 101.0)) == {"skip": False}
|
|
|
|
|
|
def test_surge_today_bar_absent(monkeypatch):
|
|
monkeypatch.setattr(th, "korea_investment_api",
|
|
_api(get_daily_chart=AsyncMock(return_value={"output2": _bars(30, False)})))
|
|
assert asyncio.run(th.check_surge_prevention("005930", True, "", 101.0)) == {"skip": False}
|
|
assert asyncio.run(th.check_surge_prevention("005930", True, "", 120.0))["skip"] is True
|
|
|
|
|
|
def test_trend_filter_no_data_passes(monkeypatch):
|
|
monkeypatch.setattr(th, "TREND_FILTER_ENABLED", True)
|
|
monkeypatch.setattr(th, "korea_investment_api",
|
|
_api(get_daily_chart=AsyncMock(return_value={"output": _bars(30)})))
|
|
r = asyncio.run(th.check_trend_filter("005930", "x", True, "", 100.0, {"ma20": 100.0}))
|
|
assert r == {"skip": False}
|
|
|
|
|
|
def test_trend_filter_uses_stock_ma60_no_kis_call(monkeypatch):
|
|
monkeypatch.setattr(th, "TREND_FILTER_ENABLED", True)
|
|
monkeypatch.setattr(th, "korea_investment_api",
|
|
_api(get_daily_chart=AsyncMock(side_effect=AssertionError("KIS 호출 금지"))))
|
|
r = asyncio.run(th.check_trend_filter("005930", "x", True, "", 100.0, {"ma20": 90.0, "ma60": 100.0}))
|
|
assert r["skip"] is True
|