fix: 장 마감 중 30분 sleep이 09:00 개장을 건너뛰어 ORB 수집 누락

데이트레이딩 스케줄러는 장 마감 시 무조건 1800초를 자서, 08:31~09:00 사이에 잠들면
09:01~09:30에 깨어나 ORB 수집 구간(09:00~09:30)을 통째로 놓쳤음(2026-09-23 감시종목 0 확인).
- market_schedule.seconds_until_market_open() 추가 (주말·공휴일 건너뜀)
- 스케줄러: 마감 중 sleep = min(1800, 개장까지 남은 시간), 개장 3분 전 watchlist 선구성
- 회귀 테스트 4건

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-23 09:05:36 +09:00
parent a57c720559
commit 546cf17edb
3 changed files with 81 additions and 2 deletions

View File

@@ -0,0 +1,44 @@
"""장 마감 중 sleep이 개장(09:00)을 건너뛰지 않는지 검증 — ORB 수집 누락 방지."""
from datetime import datetime, timedelta
import pytest
from app.core import market_schedule as ms
def _at(monkeypatch, y, m, d, hh, mm):
fake = datetime(y, m, d, hh, mm, tzinfo=ms.KST)
class _DT(datetime):
@classmethod
def now(cls, tz=None):
return fake if tz else fake.replace(tzinfo=None)
monkeypatch.setattr(ms, "datetime", _DT)
return fake
def test_seconds_until_open_same_day(monkeypatch):
_at(monkeypatch, 2026, 9, 23, 8, 59) # 수요일 08:59
assert ms.seconds_until_market_open() == pytest.approx(60, abs=1)
def test_none_during_market_hours(monkeypatch):
_at(monkeypatch, 2026, 9, 23, 10, 0)
assert ms.seconds_until_market_open() is None
def test_skips_weekend(monkeypatch):
_at(monkeypatch, 2026, 9, 25, 16, 0) # 금요일 폐장 후
secs = ms.seconds_until_market_open()
nxt = datetime(2026, 9, 25, 16, 0, tzinfo=ms.KST) + timedelta(seconds=secs)
assert nxt.weekday() == 0 and (nxt.hour, nxt.minute) == (9, 0) # 다음 월요일 09:00
def test_sleep_never_overshoots_open(monkeypatch):
"""스케줄러가 쓰는 계산식이 개장을 넘겨 자지 않는다."""
for hh, mm in [(8, 0), (8, 59), (7, 30), (6, 0)]:
_at(monkeypatch, 2026, 9, 23, hh, mm)
until = ms.seconds_until_market_open()
sleep = 1800.0 if until is None else max(15.0, min(1800.0, until))
assert sleep <= until, f"{hh}:{mm} — sleep {sleep}s가 개장({until}s 후)을 넘김"