[2026-05-15] 작업 스케줄러 자동화 + main.py 타이밍 수정

- scripts/run_morning.ps1: claude_morning 실행 스크립트
- scripts/run_bot.bat: 매매봇 실행 스크립트
- scripts/setup_scheduler.ps1: 작업 스케줄러 등록 스크립트
- app/main.py: AI 컨텍스트 로드 타이밍 08:05→08:30으로 수정
  (claude_morning이 08:15 시작해 08:30 전에 완료되므로)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-15 14:02:53 +09:00
parent 9ea0a5101d
commit e60b59a644
4 changed files with 86 additions and 7 deletions
+4 -7
View File
@@ -437,10 +437,10 @@ async def run():
while True: while True:
now = datetime.now().strftime("%H:%M") now = datetime.now().strftime("%H:%M")
# 07:30 AI 판단 (컨텍스트 로드) # 08:30 AI 컨텍스트 로드 + 유니버스 갱신
if now == "08:05": # (claude_morning이 08:15에 시작해 08:30 전에 daily_context.json 생성)
bot.strategy.load_ai_context() if now == "08:30":
ctx = bot.strategy.context ctx = bot.strategy.load_ai_context()
await notify_ai_result( await notify_ai_result(
ctx["market_sentiment"], ctx["market_sentiment"],
ctx["sentiment_score"], ctx["sentiment_score"],
@@ -449,9 +449,6 @@ async def run():
ctx.get("reason", ""), ctx.get("reason", ""),
) )
bot.risk.set_risk_level(ctx.get("risk_level", "보통")) bot.risk.set_risk_level(ctx.get("risk_level", "보통"))
# 08:30 유니버스 갱신 (claude_morning은 Claude Code headless가 별도 실행)
elif now == "08:30":
await bot.update_universe() await bot.update_universe()
# 08:50 목표가 계산 # 08:50 목표가 계산
+6
View File
@@ -0,0 +1,6 @@
@echo off
REM 매매 봇 실행 스크립트
REM 작업 스케줄러에서 07:55에 실행 (평일)
cd /d "C:\Users\whdwo\OneDrive\바탕 화면\stockbot_v3"
python app\main.py
+17
View File
@@ -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 완료"
+59
View File
@@ -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