수정본
This commit is contained in:
69
backend/diagnose_autotrade.py
Normal file
69
backend/diagnose_autotrade.py
Normal file
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python3
|
||||
"""자동매매 진단 스크립트"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, '/app')
|
||||
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
|
||||
# 1. 현재 시간 확인
|
||||
KST = pytz.timezone('Asia/Seoul')
|
||||
now = datetime.now(KST)
|
||||
print(f"🕐 현재 시간 (KST): {now.strftime('%Y-%m-%d %H:%M:%S %A')}")
|
||||
print(f" 요일: {now.weekday()} (0=월, 6=일)")
|
||||
current_minutes = now.hour * 60 + now.minute
|
||||
print(f" 시간(분): {current_minutes} (장시간: 540-930)")
|
||||
|
||||
# 2. 장 운영 시간 체크
|
||||
from app.core.market_schedule import is_market_open
|
||||
market_status = is_market_open()
|
||||
print(f"\n📊 장 운영 상태: {'✅ OPEN (자동매매 가능)' if market_status else '❌ CLOSED (자동매매 중단)'}")
|
||||
|
||||
# 3. 설정 확인
|
||||
from app.core.config import settings
|
||||
print(f"\n⚙️ 자동매매 설정:")
|
||||
print(f" AUTO_TRADE_ENABLED: {settings.AUTO_TRADE_ENABLED}")
|
||||
print(f" STOP_LOSS_PERCENT: {settings.STOP_LOSS_PERCENT}%")
|
||||
print(f" TAKE_PROFIT_PERCENT: {settings.TAKE_PROFIT_PERCENT}%")
|
||||
print(f" MAX_DAILY_TRADES: {settings.MAX_DAILY_TRADES}")
|
||||
print(f" TREND_FILTER_ENABLED: {settings.TREND_FILTER_ENABLED}")
|
||||
|
||||
# 4. API 키 확인
|
||||
print(f"\n🔑 API 인증 정보:")
|
||||
print(f" KIS_APP_KEY: {'✅ 설정됨' if settings.KOREA_INVESTMENT_APP_KEY else '❌ 미설정'}")
|
||||
print(f" KIS_APP_SECRET: {'✅ 설정됨' if settings.KOREA_INVESTMENT_APP_SECRET else '❌ 미설정'}")
|
||||
print(f" KIS_ACCOUNT_NO: {'✅ 설정됨' if settings.KOREA_INVESTMENT_ACCOUNT_NUMBER else '❌ 미설정'}")
|
||||
|
||||
# 5. 자동매매 가능 여부 최종 판단
|
||||
can_trade = market_status and settings.AUTO_TRADE_ENABLED
|
||||
print(f"\n🎯 최종 판단: {'✅ 자동매매 실행 가능' if can_trade else '❌ 자동매매 실행 불가'}")
|
||||
|
||||
if not can_trade:
|
||||
reasons = []
|
||||
if not market_status:
|
||||
reasons.append("- 장 마감 시간입니다")
|
||||
if not settings.AUTO_TRADE_ENABLED:
|
||||
reasons.append("- AUTO_TRADE_ENABLED가 False입니다")
|
||||
if not settings.KOREA_INVESTMENT_APP_KEY:
|
||||
reasons.append("- KIS API 인증 정보가 없습니다")
|
||||
|
||||
print("\n⚠️ 자동매매 불가 원인:")
|
||||
for r in reasons:
|
||||
print(f" {r}")
|
||||
|
||||
# 6. 데이터베이스 연결 확인
|
||||
print(f"\n💾 데이터베이스:")
|
||||
try:
|
||||
from sqlalchemy import create_engine, text
|
||||
engine = create_engine(settings.DATABASE_URL.replace('+asyncpg', ''))
|
||||
with engine.connect() as conn:
|
||||
result = conn.execute(text("SELECT COUNT(*) FROM portfolio"))
|
||||
portfolio_count = result.scalar()
|
||||
print(f" ✅ 연결 성공")
|
||||
print(f" 포트폴리오 종목 수: {portfolio_count}")
|
||||
except Exception as e:
|
||||
print(f" ❌ 연결 실패: {e}")
|
||||
|
||||
print("\n" + "="*60)
|
||||
Reference in New Issue
Block a user