- 스윙 체결가 확인 전 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
56 lines
2.2 KiB
Python
56 lines
2.2 KiB
Python
"""R3: KODEX200 봉수 부족 시 변동비 공식 폴백 대신 갱신 실패(staleness 경로)."""
|
|
import pytest
|
|
import app.services.adaptive_strategy as ad
|
|
|
|
|
|
def _rows(n):
|
|
return [{"stck_clpr": "100", "stck_hgpr": "101", "stck_lwpr": "99", "acml_vol": "1"} for _ in range(n)]
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _isolate(monkeypatch):
|
|
async def _no(*a, **k):
|
|
raise AssertionError("must not run")
|
|
monkeypatch.setattr(ad, "_save_to_redis", _no)
|
|
monkeypatch.setattr(ad, "_save_data_source_v2", _no)
|
|
monkeypatch.setattr(ad, "_current_params", None)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_short_history_is_failure(monkeypatch):
|
|
async def short(): return _rows(30), "kis_range"
|
|
monkeypatch.setattr(ad, "_fetch_kodex_chart_v2", short)
|
|
called = []
|
|
monkeypatch.setattr(ad, "enforce_staleness_v2", lambda: called.append(1) or None)
|
|
def _boom(*a, **k): raise AssertionError("analyze must not run")
|
|
monkeypatch.setattr(ad, "analyze_market_condition", _boom)
|
|
before = ad._last_success_ts
|
|
await ad.refresh_adaptive_params()
|
|
assert called == [1] and ad._last_success_ts == before
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_fetch_falls_through_to_kis_range(monkeypatch):
|
|
import app.services.naver_finance as nf
|
|
import app.services.korea_investment_api as k
|
|
async def naver(*a, **kw): return _rows(70)
|
|
monkeypatch.setattr(nf, "get_naver_daily_chart", naver)
|
|
class Api:
|
|
async def get_daily_ohlcv_range(self, *a): return _rows(ad._MIN_BARS_FOR_ATR_PCT + 5)
|
|
monkeypatch.setattr(k, "real_market_api", Api())
|
|
data, src = await ad._fetch_kodex_chart_v2()
|
|
assert src == "kis_range" and len(data) == ad._MIN_BARS_FOR_ATR_PCT + 5
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_fetch_naver_sufficient_skips_kis(monkeypatch):
|
|
import app.services.naver_finance as nf
|
|
import app.services.korea_investment_api as k
|
|
async def naver(*a, **kw): return _rows(200)
|
|
monkeypatch.setattr(nf, "get_naver_daily_chart", naver)
|
|
class Api:
|
|
async def get_daily_ohlcv_range(self, *a): raise AssertionError("no kis")
|
|
monkeypatch.setattr(k, "real_market_api", Api())
|
|
data, src = await ad._fetch_kodex_chart_v2()
|
|
assert src == "naver" and len(data) == 200
|