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:
@@ -38,6 +38,7 @@ from sqlalchemy import select
|
||||
|
||||
from app.core.database import AsyncSessionLocal
|
||||
from app.models.models import TradeHistory
|
||||
from app.core.timeutil import now_kst
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -291,7 +292,7 @@ async def enqueue_trade_journal(trade, content: str) -> None:
|
||||
"trade_id": trade.id,
|
||||
"stock_code": trade.stock_code,
|
||||
"stock_name": trade.stock_name,
|
||||
"journal_date": trade.executed_at or trade.created_at or datetime.utcnow(),
|
||||
"journal_date": trade.executed_at or trade.created_at or now_kst(),
|
||||
"content": content,
|
||||
"strategy_name": strategy,
|
||||
"mood": mood,
|
||||
@@ -450,7 +451,7 @@ async def db_writer_worker() -> None:
|
||||
set_={
|
||||
"consecutive_losses": stmt.excluded.consecutive_losses,
|
||||
"ban_until": stmt.excluded.ban_until,
|
||||
"updated_at": datetime.utcnow(),
|
||||
"updated_at": now_kst(),
|
||||
},
|
||||
)
|
||||
await session.execute(stmt)
|
||||
@@ -612,7 +613,7 @@ async def db_writer_worker() -> None:
|
||||
|
||||
if record:
|
||||
record.status = "closed"
|
||||
record.updated_at = _dt.utcnow()
|
||||
record.updated_at = now_kst()
|
||||
await session.commit()
|
||||
logger.debug(
|
||||
"✅ [Worker] ActiveTrade closed: %s (strategy=%s)",
|
||||
|
||||
Reference in New Issue
Block a user