- 스윙 체결가 확인 전 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
57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
"""미국 매수 경로 loss_tracker 밴 게이트 회귀 (§5.1)."""
|
|
import pytest
|
|
from unittest.mock import AsyncMock
|
|
|
|
from app.services import us_market_scheduler as ums
|
|
|
|
|
|
class _Order(Exception):
|
|
pass
|
|
|
|
|
|
def _setup(monkeypatch, banned):
|
|
monkeypatch.setattr(ums, "_get_us_account_info", AsyncMock(return_value={
|
|
"exchange_rate": 1400.0, "total_assets_krw": 100_000_000.0,
|
|
"available_cash_krw": 50_000_000.0, "current_us_allocation_krw": 0.0}))
|
|
monkeypatch.setattr(ums, "_monitor_us_exits", AsyncMock(return_value=[]))
|
|
monkeypatch.setattr(ums, "_can_enter_new_position", lambda: True)
|
|
monkeypatch.setattr(ums.mdd_manager, "can_open_new_position", AsyncMock(return_value=True))
|
|
monkeypatch.setattr(ums, "get_us_watchlist", lambda: ["AAPL"])
|
|
monkeypatch.setattr(ums, "scan_us_stocks", AsyncMock(return_value=[
|
|
{"ticker": "AAPL", "price": 100.0, "rsi": 30.0, "description": "t"}]))
|
|
monkeypatch.setattr(ums, "calculate_us_position_size", lambda **k: 5_000_000.0)
|
|
# 공통 종단(주문)은 예외 발생형 — 밴 게이트가 뚫리면 여기서 터진다
|
|
async def _boom(*a, **k):
|
|
raise _Order("order reached")
|
|
monkeypatch.setattr("app.services.trade_executor._place_order_with_retry", _boom)
|
|
if isinstance(banned, Exception):
|
|
monkeypatch.setattr(ums.loss_tracker, "is_banned_safe", AsyncMock(side_effect=banned))
|
|
else:
|
|
monkeypatch.setattr(ums.loss_tracker, "is_banned_safe", AsyncMock(return_value=banned))
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_banned_ticker_not_ordered(monkeypatch):
|
|
_setup(monkeypatch, True)
|
|
r = await ums.us_trade_cycle()
|
|
assert r["trades"] == []
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_ban_check_failure_is_fail_closed(monkeypatch):
|
|
_setup(monkeypatch, RuntimeError("db down"))
|
|
r = await ums.us_trade_cycle()
|
|
assert r["trades"] == []
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_unbanned_reaches_order(monkeypatch):
|
|
_setup(monkeypatch, False)
|
|
called = []
|
|
async def _rec(*a, **k):
|
|
called.append(1)
|
|
raise _Order("x")
|
|
monkeypatch.setattr("app.services.trade_executor._place_order_with_retry", _rec)
|
|
await ums.us_trade_cycle()
|
|
assert called
|