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

@@ -4,7 +4,7 @@
- KST 기준 장 시작/종료 시간 판별
- 공휴일, 주말 휴장 체크
"""
from datetime import datetime, time, date as date_type
from datetime import datetime, time, date as date_type, timedelta
try:
import pytz
@@ -66,6 +66,28 @@ def is_opening_range_period() -> bool:
return time(9, 0) <= t < time(9, 30)
def seconds_until_market_open() -> float | None:
"""다음 정규장 개장(09:00 KST)까지 남은 초. 이미 장중이면 None.
장 마감 중 긴 sleep이 개장 시각을 건너뛰어 ORB 수집(09:00~09:30)을 통째로
놓치는 문제를 막기 위해 스케줄러가 사용한다. (2026-09-23)
최대 7일 앞까지 탐색(주말·공휴일 건너뜀), 찾지 못하면 None.
"""
if is_market_open():
return None
now = datetime.now(KST)
for day_offset in range(8):
cand = (now + timedelta(days=day_offset)).replace(
hour=9, minute=0, second=0, microsecond=0
)
if cand <= now:
continue
if cand.weekday() >= 5 or _is_holiday(cand.date()):
continue
return (cand - now).total_seconds()
return None
def is_day_trade_entry_window() -> bool:
"""데이트레이딩 신규 진입 가능 시간 (09:30~14:59)"""
now = datetime.now(KST)