버그 처리
This commit is contained in:
@@ -18,7 +18,8 @@
|
|||||||
"Bash(pip install:*)",
|
"Bash(pip install:*)",
|
||||||
"Bash(python -c:*)",
|
"Bash(python -c:*)",
|
||||||
"Bash(git pull:*)",
|
"Bash(git pull:*)",
|
||||||
"Bash(git stash:*)"
|
"Bash(git stash:*)",
|
||||||
|
"Bash(git -C /Users/commylife/myproject/java/workspace/auto-stock ls-files)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"enableAllProjectMcpServers": true,
|
"enableAllProjectMcpServers": true,
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -71,3 +71,4 @@ summary_output.json
|
|||||||
|
|
||||||
# Virtual environments
|
# Virtual environments
|
||||||
.venv/
|
.venv/
|
||||||
|
.venv/
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ async def lifespan(app: FastAPI):
|
|||||||
try:
|
try:
|
||||||
from app.models.models import StockAnalysis, TradeHistory, Portfolio
|
from app.models.models import StockAnalysis, TradeHistory, Portfolio
|
||||||
from sqlalchemy import delete
|
from sqlalchemy import delete
|
||||||
from datetime import date, timedelta
|
from datetime import datetime, date, timedelta
|
||||||
|
|
||||||
async with AsyncSessionLocal() as session:
|
async with AsyncSessionLocal() as session:
|
||||||
_kst = pytz.timezone("Asia/Seoul")
|
_kst = pytz.timezone("Asia/Seoul")
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
재시작 후에도 ban 상태 유지: DB(stock_bans 테이블) 영속화.
|
재시작 후에도 ban 상태 유지: DB(stock_bans 테이블) 영속화.
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta, timezone
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -39,7 +39,7 @@ class ConsecutiveLossTracker:
|
|||||||
if is_loss:
|
if is_loss:
|
||||||
entry["consecutive_losses"] += 1
|
entry["consecutive_losses"] += 1
|
||||||
if entry["consecutive_losses"] >= self.ban_count:
|
if entry["consecutive_losses"] >= self.ban_count:
|
||||||
entry["ban_until"] = datetime.now() + timedelta(days=self.ban_calendar_days)
|
entry["ban_until"] = datetime.now(timezone.utc) + timedelta(days=self.ban_calendar_days)
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"{stock_code}: {entry['consecutive_losses']}회 연속 손실 → "
|
f"{stock_code}: {entry['consecutive_losses']}회 연속 손실 → "
|
||||||
f"{entry['ban_until'].strftime('%Y-%m-%d')}까지 진입 금지"
|
f"{entry['ban_until'].strftime('%Y-%m-%d')}까지 진입 금지"
|
||||||
@@ -71,7 +71,7 @@ class ConsecutiveLossTracker:
|
|||||||
else:
|
else:
|
||||||
record.consecutive_losses = entry["consecutive_losses"]
|
record.consecutive_losses = entry["consecutive_losses"]
|
||||||
record.ban_until = entry["ban_until"]
|
record.ban_until = entry["ban_until"]
|
||||||
record.updated_at = datetime.now()
|
record.updated_at = datetime.now(timezone.utc)
|
||||||
|
|
||||||
await db.commit()
|
await db.commit()
|
||||||
logger.debug(f"loss_tracker DB 저장 완료: {stock_code}")
|
logger.debug(f"loss_tracker DB 저장 완료: {stock_code}")
|
||||||
@@ -87,7 +87,7 @@ class ConsecutiveLossTracker:
|
|||||||
result = await db.execute(select(StockBan))
|
result = await db.execute(select(StockBan))
|
||||||
records = result.scalars().all()
|
records = result.scalars().all()
|
||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now(timezone.utc)
|
||||||
loaded = 0
|
loaded = 0
|
||||||
for rec in records:
|
for rec in records:
|
||||||
# 만료된 ban은 초기화
|
# 만료된 ban은 초기화
|
||||||
@@ -117,7 +117,7 @@ class ConsecutiveLossTracker:
|
|||||||
entry = self._tracker.get(stock_code)
|
entry = self._tracker.get(stock_code)
|
||||||
if not entry or not entry["ban_until"]:
|
if not entry or not entry["ban_until"]:
|
||||||
return False
|
return False
|
||||||
if datetime.now() >= entry["ban_until"]:
|
if datetime.now(timezone.utc) >= entry["ban_until"]:
|
||||||
# 금지 기간 만료 → 리셋
|
# 금지 기간 만료 → 리셋
|
||||||
entry["consecutive_losses"] = 0
|
entry["consecutive_losses"] = 0
|
||||||
entry["ban_until"] = None
|
entry["ban_until"] = None
|
||||||
|
|||||||
Reference in New Issue
Block a user