fix: DB 타임스탬프 KST 통일 + KIS 토큰 캐시 영속화
시간대 혼재: 모델 기본값은 datetime.utcnow(UTC), 수동 매매 등 일부 경로는 _get_kst_now(KST)로 저장해 같은 테이블에 9시간 차가 섞였다(화면 매매시각 02:14 등). 조회 구간(utcnow - days)도 KST 저장분과 비교돼 어긋났고, 추가매수 쿨다운은 (UTC now - KST created_at)이 음수라 상시 발동했다. app.core.timeutil.now_kst() 도입 후 모델 기본값 27곳과 app/ 전역 utcnow() 호출을 모두 KST 기준으로 통일(잔존 0건, 테스트로 고정). KIS 토큰 캐시(~/.cache/auto-stock)가 컨테이너에만 있어 배포마다 사라지고 토큰을 새로 발급받다 KIS가 EGW00103(유효하지 않은 AppKey)로 거부 → 502·잔고 0 유발. 볼륨 마운트로 재배포 후에도 재사용. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database import get_db, AsyncSessionLocal
|
||||
from app.models.models import StrategyOptimizationLog, TradeJournal
|
||||
from app.core.timeutil import now_kst
|
||||
from app.services.trade_analyzer import (
|
||||
analyze_performance,
|
||||
build_insights,
|
||||
@@ -71,7 +72,7 @@ async def get_insights(
|
||||
"performance_summary": perf.get("summary", {}),
|
||||
"last_optimization_date": last_opt_date.isoformat() if last_opt_date else None,
|
||||
"period_days": days,
|
||||
"generated_at": datetime.utcnow().isoformat(),
|
||||
"generated_at": now_kst().isoformat(),
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"insights 생성 실패: {e}", exc_info=True)
|
||||
|
||||
Reference in New Issue
Block a user