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:
@@ -27,6 +27,7 @@ from datetime import datetime, date, timedelta
|
||||
from typing import Optional, List, Dict, Tuple
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.timeutil import now_kst
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -791,7 +792,7 @@ async def build_stock_profile(stock_code: str) -> Optional[StockProfile]:
|
||||
total_trades=trade_stats["total_trades"],
|
||||
beta=beta,
|
||||
sector="", # 별도 섹터 DB 필요 시 확장
|
||||
last_updated=datetime.utcnow().isoformat(),
|
||||
last_updated=now_kst().isoformat(),
|
||||
)
|
||||
return profile
|
||||
|
||||
@@ -899,7 +900,7 @@ async def refresh_all_profiles_with_percentile(stock_codes: List[str]) -> int:
|
||||
# 해당 종목의 순위 → 백분위
|
||||
rank = sorted_ranges.index(p.avg_daily_range_pct)
|
||||
p.volatility_percentile = round(rank / n * 100, 1) if n > 1 else 50.0
|
||||
p.last_updated = datetime.utcnow().isoformat()
|
||||
p.last_updated = now_kst().isoformat()
|
||||
|
||||
# 3단계: 캐시 저장
|
||||
success = 0
|
||||
|
||||
Reference in New Issue
Block a user