galaxis-po/backend/jobs/scheduler.py
머니페니 34d09d9d34
Some checks failed
Deploy to Production / deploy (push) Failing after 6m46s
feat: 김종봉식 KOSPI 종목발굴 전략 구현
- KOSPIMarketStateDetector: KOSPI MA 기반 시장 상태 판단 (bull/neutral/bear/crash)
- VolumeScreener: 거래대금 2000억+ 스크리닝 (상한가 우선, 희소성 체크, 대형주 예외)
- SectorPortfolioManager: 섹터 기반 비중 배분
- KJBScreeningSignalGenerator: 눌림목 진입, 5MA 손절, 단계적 익절
- KISTradeExecutor: KIS API 자동 매수/매도 (기본값 모의투자)
- ScreeningSignal / AutoOrder DB 모델 추가
- screening API 엔드포인트 추가
- 스케줄러 잡 3종 추가 (08:30/5분/15:35)
- Price.trading_value 컬럼 추가
- MarketIndex 테이블 추가 (KOSPI/KOSDAQ 지수 일봉)
- IndexCollector 추가 (일일 수집 잡 등록)
- intraday_exit_check 시간 필터 추가 (09:05~15:20 KST)
- 드라이런 스크립트 추가 (scripts/screening_dryrun.py)
2026-05-05 23:03:53 +09:00

145 lines
4.1 KiB
Python

"""
APScheduler configuration for background jobs.
"""
import logging
from zoneinfo import ZoneInfo
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.cron import CronTrigger
KST = ZoneInfo("Asia/Seoul")
from jobs.snapshot_job import create_daily_snapshots
from jobs.collection_job import run_daily_collection, run_financial_collection
from jobs.kjb_signal_job import run_kjb_signals
from jobs.screening_job import run_morning_screening, run_intraday_exit_check, run_closing_review
logger = logging.getLogger(__name__)
# Create scheduler instance
scheduler = BackgroundScheduler()
def configure_jobs():
"""Configure scheduled jobs."""
# Daily data collection at 18:00 (after market close, before snapshot)
scheduler.add_job(
run_daily_collection,
trigger=CronTrigger(
hour=18,
minute=0,
day_of_week='mon-fri',
timezone=KST,
),
id='daily_collection',
name='Collect daily market data',
replace_existing=True,
)
logger.info("Configured daily_collection job at 18:00 KST")
# Weekly financial statement collection at 19:00 Monday
# (after daily collection, financial data updates quarterly)
scheduler.add_job(
run_financial_collection,
trigger=CronTrigger(
hour=19,
minute=0,
day_of_week='mon',
timezone=KST,
),
id='weekly_financial_collection',
name='Collect financial statements from FnGuide',
replace_existing=True,
)
logger.info("Configured weekly_financial_collection job at 19:00 KST Monday")
# Daily snapshot at 18:30 (after data collection completes)
scheduler.add_job(
create_daily_snapshots,
trigger=CronTrigger(
hour=18,
minute=30,
day_of_week='mon-fri',
timezone=KST,
),
id='daily_snapshots',
name='Create daily portfolio snapshots',
replace_existing=True,
)
logger.info("Configured daily_snapshots job at 18:30 KST")
# KJB signal generation at 18:15 (after daily collection, before snapshot)
scheduler.add_job(
run_kjb_signals,
trigger=CronTrigger(
hour=18,
minute=15,
day_of_week='mon-fri',
timezone=KST,
),
id='kjb_daily_signals',
name='Generate KJB trading signals',
replace_existing=True,
)
logger.info("Configured kjb_daily_signals job at 18:15 KST")
# Morning screening at 08:30 KST
scheduler.add_job(
run_morning_screening,
trigger=CronTrigger(
hour=8,
minute=30,
day_of_week='mon-fri',
timezone=KST,
),
id='morning_screening',
name='KOSPI volume screening',
replace_existing=True,
)
logger.info("Configured morning_screening job at 08:30 KST")
# Intraday exit check every 5 minutes during 09:05~15:20 KST
scheduler.add_job(
run_intraday_exit_check,
trigger=CronTrigger(
hour='9-15',
minute='*/5',
day_of_week='mon-fri',
timezone=KST,
),
id='intraday_exit_check',
name='Check exit conditions for held positions',
replace_existing=True,
)
logger.info("Configured intraday_exit_check job every 5min 09:00-15:59 KST")
# Closing review at 15:35 KST
scheduler.add_job(
run_closing_review,
trigger=CronTrigger(
hour=15,
minute=35,
day_of_week='mon-fri',
timezone=KST,
),
id='closing_review',
name='Post-market closing review',
replace_existing=True,
)
logger.info("Configured closing_review job at 15:35 KST")
def start_scheduler():
"""Start the scheduler."""
if not scheduler.running:
configure_jobs()
scheduler.start()
logger.info("Scheduler started")
def stop_scheduler():
"""Stop the scheduler."""
if scheduler.running:
scheduler.shutdown()
logger.info("Scheduler stopped")