From c4ac27b5ac5ab356e1d6a76985efffcb25138a2f Mon Sep 17 00:00:00 2001 From: jongjae Date: Fri, 15 May 2026 14:10:51 +0900 Subject: [PATCH] =?UTF-8?q?[2026-05-15]=20=EC=99=84=EC=A0=84=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=ED=99=94=20-=20=EB=B4=87=20=EC=8B=9C=EC=9E=91?= =?UTF-8?q?=EB=8F=84=20Claude=20Code=20=EA=B2=BD=EC=9C=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ~/.claude/commands/start-bot.md: /start-bot 슬래시 커맨드 추가 (DETACHED_PROCESS로 Python 봇 백그라운드 실행 + Discord 알림) - scripts/run_bot.ps1: python 직접 실행 → claude -p "/start-bot" 로 변경 - scripts/setup_scheduler.ps1: 3개 태스크 통합 재등록 스크립트 업데이트 - StockBot_Bot 태스크 업데이트 완료 Co-Authored-By: Claude Sonnet 4.6 --- scripts/run_bot.ps1 | 16 ++++++++ scripts/setup_scheduler.ps1 | 77 +++++++++++++------------------------ 2 files changed, 43 insertions(+), 50 deletions(-) create mode 100644 scripts/run_bot.ps1 diff --git a/scripts/run_bot.ps1 b/scripts/run_bot.ps1 new file mode 100644 index 0000000..d9a5b82 --- /dev/null +++ b/scripts/run_bot.ps1 @@ -0,0 +1,16 @@ +# 매매 봇 시작 스크립트 +# 작업 스케줄러에서 07:55에 실행 (평일) +# Claude Code가 /start-bot 커맨드를 실행 → Python 봇을 백그라운드로 띄움 + +$PROJECT = "C:\Users\whdwo\OneDrive\바탕 화면\stockbot_v3" +$LOG = "$PROJECT\logs\bot_start.log" + +Set-Location $PROJECT + +$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" +Add-Content $LOG "[$timestamp] /start-bot 실행" + +claude -p "/start-bot" --dangerously-skip-permissions *>> $LOG + +$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" +Add-Content $LOG "[$timestamp] /start-bot 완료" diff --git a/scripts/setup_scheduler.ps1 b/scripts/setup_scheduler.ps1 index 54117e5..0ba1ad5 100644 --- a/scripts/setup_scheduler.ps1 +++ b/scripts/setup_scheduler.ps1 @@ -1,59 +1,36 @@ -# StockBot 작업 스케줄러 등록 -# 관리자 권한 없이도 현재 사용자 계정으로 등록 가능 +# StockBot 작업 스케줄러 등록 (전체 재등록용) +# 실행: powershell -ExecutionPolicy Bypass -File scripts\setup_scheduler.ps1 -$PROJECT = "C:\Users\whdwo\OneDrive\바탕 화면\stockbot_v3" - -# ── 평일(월~금) 트리거 ────────────────────────────────────────────────────── +$PROJECT = "C:\Users\whdwo\OneDrive\바탕 화면\stockbot_v3" $weekdays = @( - [DayOfWeek]::Monday, - [DayOfWeek]::Tuesday, - [DayOfWeek]::Wednesday, - [DayOfWeek]::Thursday, - [DayOfWeek]::Friday + [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 +function Register-StockTask($name, $time, $script, $limitMin) { + $trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek $weekdays -At $time + $action = New-ScheduledTaskAction ` + -Execute "powershell.exe" ` + -Argument "-NonInteractive -ExecutionPolicy Bypass -File `"$PROJECT\scripts\$script`"" ` + -WorkingDirectory $PROJECT + $settings = New-ScheduledTaskSettingsSet ` + -ExecutionTimeLimit (New-TimeSpan -Minutes $limitMin) ` + -StartWhenAvailable + Register-ScheduledTask -TaskName $name -TaskPath "\StockBot\" ` + -Trigger $trigger -Action $action -Settings $settings -RunLevel Limited -Force + Write-Host "[OK] $name 등록 완료 (평일 $time)" -ForegroundColor Green +} -Register-ScheduledTask ` - -TaskName "StockBot_Morning" ` - -TaskPath "\StockBot\" ` - -Trigger $morningTrigger ` - -Action $morningAction ` - -Settings $morningSettings ` - -RunLevel Limited ` - -Force +# ── 3개 태스크 등록 ────────────────────────────────────────────────────────── +# 07:55 claude /start-bot → Python 봇 백그라운드 시작 +Register-StockTask "StockBot_Bot" "07:55" "run_bot.ps1" 10 -Write-Host "[OK] StockBot_Morning 등록 완료 (평일 08:15)" -ForegroundColor Green +# 08:15 claude /morning → 뉴스+KIS 수집 → daily_context.json +Register-StockTask "StockBot_Morning" "08:15" "run_morning.ps1" 20 -# ── 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 +# 15:30 claude /evening → 결과 분석 → 리포트 → Discord +Register-StockTask "StockBot_Evening" "15:30" "run_evening.ps1" 30 Write-Host "" -Write-Host "등록된 작업 확인:" -ForegroundColor Cyan -Get-ScheduledTask -TaskPath "\StockBot\" | Select-Object TaskName, State +Write-Host "등록된 작업:" -ForegroundColor Cyan +Get-ScheduledTask -TaskPath "\StockBot\" | Format-Table TaskName, State