diff --git a/app/main.py b/app/main.py index f6776e3..80b3b26 100644 --- a/app/main.py +++ b/app/main.py @@ -437,10 +437,10 @@ async def run(): while True: now = datetime.now().strftime("%H:%M") - # 07:30 AI 판단 (컨텍스트 로드) - if now == "08:05": - bot.strategy.load_ai_context() - ctx = bot.strategy.context + # 08:30 AI 컨텍스트 로드 + 유니버스 갱신 + # (claude_morning이 08:15에 시작해 08:30 전에 daily_context.json 생성) + if now == "08:30": + ctx = bot.strategy.load_ai_context() await notify_ai_result( ctx["market_sentiment"], ctx["sentiment_score"], @@ -449,9 +449,6 @@ async def run(): ctx.get("reason", ""), ) bot.risk.set_risk_level(ctx.get("risk_level", "보통")) - - # 08:30 유니버스 갱신 (claude_morning은 Claude Code headless가 별도 실행) - elif now == "08:30": await bot.update_universe() # 08:50 목표가 계산 diff --git a/scripts/run_bot.bat b/scripts/run_bot.bat new file mode 100644 index 0000000..e26224b --- /dev/null +++ b/scripts/run_bot.bat @@ -0,0 +1,6 @@ +@echo off +REM 매매 봇 실행 스크립트 +REM 작업 스케줄러에서 07:55에 실행 (평일) + +cd /d "C:\Users\whdwo\OneDrive\바탕 화면\stockbot_v3" +python app\main.py diff --git a/scripts/run_morning.ps1 b/scripts/run_morning.ps1 new file mode 100644 index 0000000..64766d4 --- /dev/null +++ b/scripts/run_morning.ps1 @@ -0,0 +1,17 @@ +# claude_morning 실행 스크립트 +# 작업 스케줄러에서 08:15에 실행 (평일) +# claude_morning이 완료되면 08:30 전에 daily_context.json이 준비됨 + +$PROJECT = "C:\Users\whdwo\OneDrive\바탕 화면\stockbot_v3" +$LOG = "$PROJECT\logs\morning.log" + +Set-Location $PROJECT + +$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" +Add-Content $LOG "[$timestamp] claude_morning 시작" + +# Claude Code headless 실행 +claude -p "/morning" --dangerously-skip-permissions *>> $LOG + +$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" +Add-Content $LOG "[$timestamp] claude_morning 완료" diff --git a/scripts/setup_scheduler.ps1 b/scripts/setup_scheduler.ps1 new file mode 100644 index 0000000..54117e5 --- /dev/null +++ b/scripts/setup_scheduler.ps1 @@ -0,0 +1,59 @@ +# StockBot 작업 스케줄러 등록 +# 관리자 권한 없이도 현재 사용자 계정으로 등록 가능 + +$PROJECT = "C:\Users\whdwo\OneDrive\바탕 화면\stockbot_v3" + +# ── 평일(월~금) 트리거 ────────────────────────────────────────────────────── +$weekdays = @( + [DayOfWeek]::Monday, + [DayOfWeek]::Tuesday, + [DayOfWeek]::Wednesday, + [DayOfWeek]::Thursday, + [DayOfWeek]::Friday +) + +# ── Task 1: claude_morning (08:15, 평일) ──────────────────────────────────── +$morningTrigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek $weekdays -At "08:15" +$morningAction = New-ScheduledTaskAction ` + -Execute "powershell.exe" ` + -Argument "-NonInteractive -ExecutionPolicy Bypass -File `"$PROJECT\scripts\run_morning.ps1`"" ` + -WorkingDirectory $PROJECT +$morningSettings = New-ScheduledTaskSettingsSet ` + -ExecutionTimeLimit (New-TimeSpan -Minutes 20) ` + -StartWhenAvailable + +Register-ScheduledTask ` + -TaskName "StockBot_Morning" ` + -TaskPath "\StockBot\" ` + -Trigger $morningTrigger ` + -Action $morningAction ` + -Settings $morningSettings ` + -RunLevel Limited ` + -Force + +Write-Host "[OK] StockBot_Morning 등록 완료 (평일 08:15)" -ForegroundColor Green + +# ── Task 2: 매매봇 (07:55, 평일) ──────────────────────────────────────────── +$botTrigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek $weekdays -At "07:55" +$botAction = New-ScheduledTaskAction ` + -Execute "cmd.exe" ` + -Argument "/c `"$PROJECT\scripts\run_bot.bat`"" ` + -WorkingDirectory $PROJECT +$botSettings = New-ScheduledTaskSettingsSet ` + -ExecutionTimeLimit (New-TimeSpan -Hours 8) ` + -StartWhenAvailable + +Register-ScheduledTask ` + -TaskName "StockBot_Bot" ` + -TaskPath "\StockBot\" ` + -Trigger $botTrigger ` + -Action $botAction ` + -Settings $botSettings ` + -RunLevel Limited ` + -Force + +Write-Host "[OK] StockBot_Bot 등록 완료 (평일 07:55)" -ForegroundColor Green + +Write-Host "" +Write-Host "등록된 작업 확인:" -ForegroundColor Cyan +Get-ScheduledTask -TaskPath "\StockBot\" | Select-Object TaskName, State