Harden scheduler and stale breakout reentry

This commit is contained in:
whdwo
2026-06-15 18:52:42 +09:00
parent eac4ece01e
commit 901243348e
16 changed files with 181 additions and 61 deletions
+20 -3
View File
@@ -844,15 +844,28 @@ class StockBot:
async def calc_targets(self):
"""당일 시가 기반 목표가 계산"""
logger.info("목표가 계산 시작")
self.strategy.targets.clear()
self.strategy.today_open.clear()
now_str = datetime.now().strftime("%H:%M")
valid_count = 0
for ticker in self.universe:
try:
price_info = await self._get_price_with_retry(ticker, "TARGET")
self.strategy.set_today_open(ticker, price_info["open"])
target = self.strategy.get_target(ticker)
open_price = price_info.get("open") or 0
name = self.ticker_names.get(ticker, ticker)
if open_price <= 0:
current = price_info.get("current") or 0
if now_str >= "09:00" and current > 0:
open_price = current
logger.warning(f"시가 0 감지({name}/{ticker}) → 현재가 {current:,}를 임시 시가로 사용")
else:
logger.info(f"목표가 제외({name}/{ticker}): 시가 미확정(open=0)")
await asyncio.sleep(1.1)
continue
self.strategy.set_today_open(ticker, open_price)
target = self.strategy.get_target(ticker)
if target > 0:
logger.info(f"목표가: {name}({ticker}) {target:,.0f}원 [시가 {price_info['open']:,}]")
logger.info(f"목표가: {name}({ticker}) {target:,.0f}원 [시가 {open_price:,}]")
valid_count += 1
await asyncio.sleep(1.1)
except Exception as e:
@@ -1329,6 +1342,9 @@ async def run():
ctx = bot.strategy.load_ai_context()
bot.risk.set_risk_level(ctx.get("risk_level", "보통"))
await bot.update_universe()
if now >= "08:50":
logger.info("08:50 이후 장 전 재시작 감지 → 목표가 즉시 계산")
await bot.calc_targets()
while True:
now = datetime.now().strftime("%H:%M")
@@ -1354,6 +1370,7 @@ async def run():
# 09:00 매매 루프 시작
elif now == "09:00":
await bot.calc_targets()
await bot.trading_loop()
# 15:10 결산