From a4626e035154d873a8a371713cbc79f67831f036 Mon Sep 17 00:00:00 2001 From: Hwang Date: Mon, 6 Jul 2026 21:43:00 +0900 Subject: [PATCH] fix: Update imports and enhance error handling in momentum engine and tick replay Changes: - Replaced the import of `get_env_int` with `get_env_from_db` in `momentum_engine.py` to improve environment variable retrieval. - Modified error handling in `momentum_tick_replay.py` to ensure `TickColumnView` is only referenced if successfully imported, enhancing robustness. Impact: - These updates streamline the import process and improve the stability of the momentum trading logic by ensuring that the code handles import errors gracefully. --- kis_trader/engine/momentum_engine.py | 2 +- kis_trader/engine/momentum_tick_replay.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/kis_trader/engine/momentum_engine.py b/kis_trader/engine/momentum_engine.py index f9cccda..0272e66 100644 --- a/kis_trader/engine/momentum_engine.py +++ b/kis_trader/engine/momentum_engine.py @@ -33,7 +33,7 @@ from kis_trader.engine.momentum_env_keys import ( _legacy_float, ) from kis_trader.engine.strategy_eod import is_strategy_eod_bar -from kis_trader.utils.env import get_env_int +from kis_trader.utils.env import get_env_from_db, get_env_int MOMENTUM_STRATEGY_ID = "MOMENTUM" diff --git a/kis_trader/engine/momentum_tick_replay.py b/kis_trader/engine/momentum_tick_replay.py index 9b728dc..ac6ad75 100644 --- a/kis_trader/engine/momentum_tick_replay.py +++ b/kis_trader/engine/momentum_tick_replay.py @@ -314,12 +314,12 @@ def try_momentum_sell_on_ticks( # 백테 틱재생: 공유메모리 컬럼 뷰면 직접집계(실매 dict 경로 무변경). try: from kis_trader.backtest.shared_ticks import TickColumnView - if isinstance(ticks, TickColumnView): - return _try_momentum_sell_on_ticks_columnar( - position, ticks, params, is_eod=is_eod, entry_time=entry_time, - ) - except Exception: - pass + except ImportError: + TickColumnView = None # type: ignore[misc,assignment] + if TickColumnView is not None and isinstance(ticks, TickColumnView): + return _try_momentum_sell_on_ticks_columnar( + position, ticks, params, is_eod=is_eod, entry_time=entry_time, + ) if not ticks: return None