fix: add KR_FALLBACK_STOCKS for domestic scanner when ranking API returns empty (#153)
Some checks failed
CI / test (pull_request) Has been cancelled

KIS VTS (paper trading) does not return data from the domestic
volume-rank API. The smart scanner had no fallback for KR market,
causing permanent "No candidates" and zero trades all day.

- src/config.py: add KR_FALLBACK_STOCKS with 10 major KRX stocks
  (삼성전자, SK하이닉스, NAVER, 현대차, 셀트리온, LG화학, 카카오,
   삼성SDI, 삼성바이오로직스, 기아)
- src/main.py: pass KR fallback stocks to scanner.scan() for domestic
  markets (mirrors the overseas build_overseas_symbol_universe pattern)
- tests/test_main.py: add TestKrFallbackStocksConfig (3 tests)

Closes #153

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
agentson
2026-02-19 09:17:14 +09:00
parent c76e2dfed5
commit 86a47bec7f
3 changed files with 56 additions and 1 deletions

View File

@@ -1678,3 +1678,43 @@ def test_start_dashboard_server_enabled_starts_thread() -> None:
assert thread == mock_thread
mock_thread_cls.assert_called_once()
mock_thread.start.assert_called_once()
# ---------------------------------------------------------------------------
# KR fallback stocks config (issue #153)
# ---------------------------------------------------------------------------
class TestKrFallbackStocksConfig:
"""Test KR_FALLBACK_STOCKS default value and parsing."""
def test_default_contains_samsung(self) -> None:
settings = Settings(
KIS_APP_KEY="k",
KIS_APP_SECRET="s",
KIS_ACCOUNT_NO="12345678-01",
GEMINI_API_KEY="g",
)
codes = [c.strip() for c in settings.KR_FALLBACK_STOCKS.split(",") if c.strip()]
assert "005930" in codes # 삼성전자
def test_default_has_ten_codes(self) -> None:
settings = Settings(
KIS_APP_KEY="k",
KIS_APP_SECRET="s",
KIS_ACCOUNT_NO="12345678-01",
GEMINI_API_KEY="g",
)
codes = [c.strip() for c in settings.KR_FALLBACK_STOCKS.split(",") if c.strip()]
assert len(codes) == 10
def test_env_override(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("KR_FALLBACK_STOCKS", "005930,000660")
settings = Settings(
KIS_APP_KEY="k",
KIS_APP_SECRET="s",
KIS_ACCOUNT_NO="12345678-01",
GEMINI_API_KEY="g",
)
codes = [c.strip() for c in settings.KR_FALLBACK_STOCKS.split(",") if c.strip()]
assert codes == ["005930", "000660"]