fix(정합성): 틱 lag wall-clock 정합 + 3벤더 DB 저장 스위치 통일

- feed_fallback.bar_is_garbage: 봉끝 기준 → 각 틱의 recv_ts wall-clock 기준으로 정정
  실매 RAM 3초컷과 동일 논리 → 유동성 낮은 종목 부당 스킵 해소
- candle_garbage_fallback_enabled: 기본 True 복원 (wall-clock 정정 후 안전)
- param_search_optuna·run_tail_backtest_cli: CANDLE_GARBAGE_FALLBACK·BACKTEST_USE_RUST
  강제 os.environ 세팅 제거 → DB env·CLI 플래그로만 관리 (UI 존중)
- WS_TICK_DB_SAVE_LAG_CUT_ENABLED 신설 (bool, 기본 false, 3벤더 공통)
  OFF=키움/KIS/LS 모든 틱 lag 무관 전부 저장 (벤더 통계·재현·백테 정합)
  ON=lag > LIVE_FEED_FALLBACK_MAX_AGE_SEC 이면 미저장 (미래 A안)
- KIWOOM_TICK_LIVE_MAX_LAG_SEC 완전 폐기 → 위 스위치로 통일
- kiwoom_ws: _skip_persist 로직 새 스위치로 교체
- kis_ws·ls_ws: _skip_persist_kis/_ls 신규 (벤더별 상이했던 정책 통일)
- docs/정합성.md §9 신설 (문제·결정·시나리오·향후 A안 전환법)
- docs/rust_engine_parity_port_plan.md (신규 설계)

실매 스모크: logs/test_live_execution_validation_20260906_191845.log
  → 최종: 통과 · 👑 완결
브라우저 검증: http://192.168.0.149:5050/#liveconfig → 새 스위치 노출, JS 오류 없음

영향: 실매(DB 저장 정책 통일, RAM 컷 변경 없음) + 백테/Optuna(실매 정합)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Your Name
2026-09-06 19:23:01 +09:00
parent e1ac8d119b
commit 1d69c217e2
12 changed files with 600 additions and 42 deletions

View File

@@ -1820,23 +1820,33 @@ class LSWebSocketPriceCache:
"_price_f": price,
}
skip_ram = False
_lag_ls = 0.0
try:
from kis_trader.engine.feed_fallback import (
is_feed_read_stale,
packet_lag_seconds,
)
skip_ram = is_feed_read_stale(packet_lag_seconds(chetime))
_lag_ls = float(packet_lag_seconds(chetime) or 0.0)
skip_ram = is_feed_read_stale(_lag_ls)
except Exception:
skip_ram = False
# 2026-09-06: DB 저장 컷 스위치 (3벤더 공통 · docs/정합성.md §9)
try:
_ls_db_cut_on = bool(get_env_bool("WS_TICK_DB_SAVE_LAG_CUT_ENABLED", False))
_ls_max_age = float(get_env_float("LIVE_FEED_FALLBACK_MAX_AGE_SEC", 3.0) or 3.0)
except Exception:
_ls_db_cut_on = False
_ls_max_age = 3.0
_skip_persist_ls = bool(_ls_db_cut_on and _ls_max_age > 0 and _lag_ls > _ls_max_age)
if not skip_ram:
with self._cache_lock:
self._cache[code] = row
self._notify_price_listeners(code, price, row)
# TICK_SAVE 는 ls_ws_ticks INSERT 만 게이트(_on_tick). 여기까지 막으면
# 호가 틱동기(LS_WS_ORDERBOOK_SAVE)도 같이 꺼진다. 늦은 체결시각은
# RAM skip 과 같이 콜백 생략(지금 호가를 옛 시각으로 찍으면 look-ahead).
if self._tick_recorder and not skip_ram:
# 2026-09-06: DB 적재는 새 스위치로 게이트 (기본 OFF=전부 저장).
# RAM 은 skip_ram(look-ahead 방지)이지만 통계·재현을 위해 DB 는 별개.
# 호가 틱동기는 아래에서 별도 처리 (skip_ram 그대로 유지 — 지금 호가를 옛 시각에 붙이면 look-ahead)
if self._tick_recorder and not _skip_persist_ls:
try:
self._tick_recorder(
code,