From e60b59a644a85990a0720b3bda0b95a428b7b350 Mon Sep 17 00:00:00 2001 From: jongjae Date: Fri, 15 May 2026 14:02:53 +0900 Subject: [PATCH] =?UTF-8?q?[2026-05-15]=20=EC=9E=91=EC=97=85=20=EC=8A=A4?= =?UTF-8?q?=EC=BC=80=EC=A4=84=EB=9F=AC=20=EC=9E=90=EB=8F=99=ED=99=94=20+?= =?UTF-8?q?=20main.py=20=ED=83=80=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- app/main.py | 11 +++---- scripts/run_bot.bat | 6 ++++ scripts/run_morning.ps1 | 17 +++++++++++ scripts/setup_scheduler.ps1 | 59 +++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 scripts/run_bot.bat create mode 100644 scripts/run_morning.ps1 create mode 100644 scripts/setup_scheduler.ps1 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