fix: 로그 WARNING 2종 수정 - scanner 오해 메시지 및 홀딩 종목 rsi 누락 (#267)
Some checks failed
CI / test (pull_request) Has been cancelled

1. WARNING → DEBUG: fallback_stocks 없어도 overseas ranking API로 scanner
   정상 동작하므로 오해를 주는 WARNING 레벨을 DEBUG로 낮춤 (2곳)

2. 홀딩 종목 market_data 보강: scanner를 통하지 않은 종목(NVDA 등)에
   price_change_pct 기반 implied_rsi와 volume_ratio=1.0 기본값 설정,
   scenario_engine 조건 평가 완전화

3. test_main.py: 새로운 동작에 맞게 관련 테스트 2개 업데이트

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
agentson
2026-02-26 01:39:45 +09:00
parent b1b728f62e
commit ccb00ee77d
2 changed files with 18 additions and 10 deletions

View File

@@ -581,6 +581,11 @@ async def trading_cycle(
if candidate:
market_data["rsi"] = candidate.rsi
market_data["volume_ratio"] = candidate.volume_ratio
else:
# Holding stocks not in scanner: derive implied RSI from price change,
# volume_ratio defaults to 1.0 (no surge data available).
market_data["rsi"] = max(0.0, min(100.0, 50.0 + price_change_pct * 2.0))
market_data["volume_ratio"] = 1.0
# Enrich market_data with holding info for SELL/HOLD scenario conditions
open_pos = get_open_position(db_conn, stock_code, market.code)
@@ -1499,8 +1504,9 @@ async def run_daily_session(
active_stocks={},
)
if not fallback_stocks:
logger.warning(
"No dynamic overseas symbol universe for %s; scanner cannot run",
logger.debug(
"No dynamic overseas symbol universe for %s;"
" scanner will use overseas ranking API",
market.code,
)
try:
@@ -2812,9 +2818,9 @@ async def run(settings: Settings) -> None:
active_stocks=active_stocks,
)
if not fallback_stocks:
logger.warning(
logger.debug(
"No dynamic overseas symbol universe for %s;"
" scanner cannot run",
" scanner will use overseas ranking API",
market.code,
)

View File

@@ -1668,10 +1668,10 @@ class TestScenarioEngineIntegration:
scan_candidates={"US": {"005930": us_candidate}}, # Wrong market
)
# Should NOT have rsi/volume_ratio because candidate is under US, not KR
# Should NOT use US candidate's rsi (=15.0); fallback implied_rsi used instead
market_data = engine.evaluate.call_args[0][2]
assert "rsi" not in market_data
assert "volume_ratio" not in market_data
assert market_data["rsi"] != 15.0 # US candidate's rsi must be ignored
assert market_data["volume_ratio"] == 1.0 # Fallback default
@pytest.mark.asyncio
async def test_scenario_engine_called_without_scanner_data(
@@ -1702,11 +1702,13 @@ class TestScenarioEngineIntegration:
scan_candidates={}, # No scanner data
)
# Should still work, just without rsi/volume_ratio
# Holding stocks without scanner data use implied_rsi (from price_change_pct)
# and volume_ratio=1.0 as fallback, so rsi/volume_ratio are always present.
engine.evaluate.assert_called_once()
market_data = engine.evaluate.call_args[0][2]
assert "rsi" not in market_data
assert "volume_ratio" not in market_data
assert "rsi" in market_data # Implied RSI from price_change_pct=2.5 → 55.0
assert market_data["rsi"] == pytest.approx(55.0)
assert market_data["volume_ratio"] == 1.0
assert market_data["current_price"] == 50000.0
@pytest.mark.asyncio