버그 수정 - 14:00 이후 신규 진입 차단·SL 재진입 차단 재시작 초기화

check_entries 진입 시 현재 시간 재확인 추가
_restore_sl_tickers_from_db 추가: 봇 재시작 시 당일 SL 종목 복원
일일 리포트 bug11·12 내용 반영
This commit is contained in:
2026-05-18 15:35:32 +09:00
parent 2c2def0fd2
commit 4eee610b5d
2 changed files with 21 additions and 1 deletions
+18
View File
@@ -107,6 +107,8 @@ class StockBot:
# DB에서 열린 포지션 복원 (재시작 시)
self._restore_positions_from_db()
# 당일 SL 종목 복원 (재시작 후에도 재진입 차단 유지)
self._restore_sl_tickers_from_db()
await send(f"[시작] 단타봇 가동 | 예수금: {cash:,}원 | "
f"{'모의투자' if self.kis.is_mock else '실거래'}")
@@ -131,6 +133,19 @@ class StockBot:
if self.positions:
logger.info(f"DB 포지션 복원: {list(self.positions.keys())}")
def _restore_sl_tickers_from_db(self):
"""재시작 시 당일 SL 종목 복원 — 재진입 차단 유지"""
today = datetime.now().strftime("%Y-%m-%d")
with get_conn() as conn:
rows = conn.execute(
"SELECT DISTINCT ticker FROM trades WHERE date=? AND exit_reason='SL'",
(today,)
).fetchall()
for (ticker,) in rows:
self.sl_tickers.add(ticker)
if self.sl_tickers:
logger.info(f"당일 SL 종목 복원(재진입 차단): {self.sl_tickers}")
def _db_save_position(self, ticker: str, pos: dict, target_price: float):
with get_conn() as conn:
conn.execute("""
@@ -296,6 +311,9 @@ class StockBot:
async def check_entries(self):
"""유니버스 전체 진입 신호 확인"""
# check_exits 처리 중 14:00을 넘었을 경우 진입 차단
if datetime.now().strftime("%H:%M") > "14:00":
return
for ticker in self.universe:
if ticker in self.positions:
continue