자동매매 관련로직 수정

This commit is contained in:
2026-02-26 14:40:12 +09:00
parent 77e7464884
commit 8c8de61d67
6 changed files with 43 additions and 13 deletions

View File

@@ -13,7 +13,8 @@ from sqlalchemy import select
from app.core.config import settings
from app.services.market_analyzer import (
check_market_regime, get_all_tradable_stocks, analyze_stock,
check_market_regime, get_all_tradable_stocks, analyze_stock,
analyze_stock_for_batch,
RecommendationCriteria, StockRecommendation, KST
)
from app.services.trade_executor import execute_auto_trade_background, execute_auto_trade

View File

@@ -73,6 +73,23 @@ class Settings(BaseSettings):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._apply_kis_mode()
self._apply_docker_db_override()
def _apply_docker_db_override(self):
"""If running inside Docker, convert localhost in DATABASE_URL to the
postgres service hostname.
Users often copy `.env.example` which defaults to
`postgresql://...@localhost:5432/...`. That works on the host machine,
but inside the backend container `localhost` refers to the container
itself, not the Postgres server. When `/.dockerenv` exists we assume the
code is running in Docker and automatically patch the URL.
"""
if os.path.exists("/.dockerenv"):
# simple string replacement; pydantic does not throw if format
# changes after initialization
if "localhost" in self.DATABASE_URL:
self.DATABASE_URL = self.DATABASE_URL.replace("localhost", "postgres")
def _apply_kis_mode(self):
"""KIS_MODE에 따라 모의/실전 API 설정을 자동 선택"""
@@ -254,8 +271,8 @@ class Settings(BaseSettings):
# ═════════════════════════════════════════════════════════════════════════════
# 감시 목록 (watchlist.py)
# ═════════════════════════════════════════════════════════════════════════════
WATCHLIST_INIT_SIZE: int = 50 # 아침 배치 초기화 종목 수
WATCHLIST_MAX_SIZE: int = 100 # 최대 관리 종목 수
WATCHLIST_INIT_SIZE: int = 150 # 아침 배치 초기화 종목 수
WATCHLIST_MAX_SIZE: int = 150 # 최대 관리 종목 수
WATCHLIST_ENTRY_SCORE: int = 60 # 장중 신규 진입 기준 점수
WATCHLIST_EXIT_SCORE: int = 20 # 장중 제거 기준 점수

View File

@@ -24,7 +24,7 @@ from app.models.models import WatchlistStock, StockAnalysis
logger = logging.getLogger(__name__)
# 스캐너 신호 종목에 배정하는 최대 슬롯 수 (settings.WATCHLIST_INIT_SIZE 중 이 수만큼 우선)
SCANNER_PRIORITY_SLOTS: int = 20
SCANNER_PRIORITY_SLOTS: int = 50
async def initialize_watchlist(