변경 사항 ---- - _test_kiwoom_condition_list.py: 키움 웹소켓 조건검색 '목록조회' 기능을 단독으로 테스트하는 스크립트 추가 - _test_kiwoom_condition_realtime.py: 'momentum' 조건식을 실시간으로 등록하고 초기 매칭 종목 리스트 및 실시간 편입/이탈을 수신하는 테스트 스크립트 추가 - _verify_columnar_bitid.py, _verify_shared_e2e_breakout.py, _verify_shared_e2e.py: 공유 메모리 및 dict 간의 데이터 일관성을 검증하는 테스트 추가 영향 ---- - 신규 테스트 스크립트 추가로 키움 웹소켓 API의 기능 검증 및 안정성을 높임 - 기존 기능에 대한 영향 없음 Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
"""
|
|
kis_trader/utils/universe_source.py — {SID}_UNIVERSE_SOURCE 단일 해석
|
|
======================================================================
|
|
매니저 폴링·history·전략 후보 로드가 같은 규칙을 쓰도록 공통 helper.
|
|
|
|
운영 스위치는 env **하나**:
|
|
``{STRATEGY_ID}_UNIVERSE_SOURCE`` → ``ranking`` | ``condition`` | ``kiwoom_condition``
|
|
|
|
비활성 전략(``STRATEGY_{SID}_ENABLED=false``)은 main 이 매니저에 등록하지 않으므로
|
|
별도 UNIVERSE_SOURCE 설정 불필요.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import FrozenSet
|
|
|
|
from .env import get_env_from_db
|
|
|
|
VALID_UNIVERSE_SOURCES: FrozenSet[str] = frozenset(
|
|
{"ranking", "condition", "kiwoom_condition"}
|
|
)
|
|
|
|
# BaseStrategy.DEFAULT_UNIVERSE_SOURCES · main._DEFAULT_SOURCE 와 동기화
|
|
_DEFAULT_SOURCES: dict[str, str] = {
|
|
"SCALP": "condition",
|
|
"SHORT": "kiwoom_condition",
|
|
"BREAKOUT": "kiwoom_condition",
|
|
"MOMENTUM": "kiwoom_condition",
|
|
"UPDOW": "condition",
|
|
"RANGE_BREAK": "condition",
|
|
"DBBAND": "condition",
|
|
}
|
|
|
|
|
|
def resolve_universe_source(strategy_id: str, *, default: str | None = None) -> str:
|
|
"""DB/env 에서 전략 유니버스 소스 해석. 잘못된 값이면 default 로 폴백."""
|
|
sid = (strategy_id or "").strip().upper()
|
|
if not sid:
|
|
return "ranking"
|
|
fb = default if default is not None else _DEFAULT_SOURCES.get(sid, "ranking")
|
|
if fb not in VALID_UNIVERSE_SOURCES:
|
|
fb = "ranking"
|
|
key = f"{sid}_UNIVERSE_SOURCE"
|
|
src = (get_env_from_db(key, fb) or fb).strip().lower()
|
|
if src not in VALID_UNIVERSE_SOURCES:
|
|
return fb
|
|
return src
|
|
|
|
|
|
def universe_source_active(strategy_id: str, want: str) -> bool:
|
|
"""현재 active UNIVERSE_SOURCE 가 want 와 같을 때만 True (REST/WS 반영 gate)."""
|
|
want_norm = (want or "").strip().lower()
|
|
if want_norm not in VALID_UNIVERSE_SOURCES:
|
|
return False
|
|
return resolve_universe_source(strategy_id) == want_norm
|