fix: 한투 호가 2키 전용, LS RAM 합집합, 분봉 쓰레기면 다음 소스 통째
메인 시세 41에 H0STASP0를 붙이는 폴백을 없앤다. MINIMAL과 무관하게 후보∪보유∪영구를 LS RAM에 붙인다. 그 분 틱이 없거나 봉끝 대비 늦으면 그 WS 봉을 버리고 2차·LS·REST 봉을 통째로 쓴다. 같은 파일에 직전 커밋 이후 쌓인 시세 폴백/ENV 키 정리도 포함된다. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -75,6 +75,28 @@ def _pairs_in_sql(pairs: Sequence[ReadPair]) -> Tuple[str, List[str]]:
|
||||
return " AND (" + " OR ".join(parts) + ")", params
|
||||
|
||||
|
||||
def _ticks_for_bar_garbage(db, code: str, start_key: str, end_key: str) -> Optional[List[Dict[str, Any]]]:
|
||||
from kis_trader.engine.feed_fallback import candle_garbage_fallback_enabled
|
||||
|
||||
if not candle_garbage_fallback_enabled():
|
||||
return None
|
||||
sk = str(start_key or "").strip()
|
||||
ek = str(end_key or "").strip()
|
||||
if len(sk) == 12:
|
||||
sk = sk + "00"
|
||||
if len(ek) == 12:
|
||||
ek = ek + "59"
|
||||
try:
|
||||
rows = db.conn.execute(
|
||||
"SELECT tick_time, source, tick_time_raw FROM ws_ticks "
|
||||
"WHERE code=%s AND tick_time >= %s AND tick_time <= %s",
|
||||
(str(code).strip(), sk, ek),
|
||||
).fetchall()
|
||||
return [dict(r) for r in (rows or [])]
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def list_ws_candle_codes(
|
||||
db,
|
||||
timeframe: int,
|
||||
@@ -147,7 +169,11 @@ def fetch_ws_candles_for_code(
|
||||
+ " ORDER BY candle_time ASC",
|
||||
[int(timeframe), code, start_key, end_key, *src_params],
|
||||
).fetchall()
|
||||
return dedupe_by_read_pairs([dict(r) for r in rows], pairs)
|
||||
ticks = _ticks_for_bar_garbage(db, str(code), start_key, end_key)
|
||||
return dedupe_by_read_pairs(
|
||||
[dict(r) for r in rows], pairs, ticks=ticks, tf_min=int(timeframe),
|
||||
missing_policy="hole", live_cover=False,
|
||||
)
|
||||
|
||||
|
||||
def fetch_ws_candles_warmup_before(
|
||||
@@ -180,5 +206,17 @@ def fetch_ws_candles_warmup_before(
|
||||
+ " ORDER BY candle_time DESC LIMIT %s",
|
||||
[int(timeframe), code, before_candle_time, *src_params, fetch_limit],
|
||||
).fetchall()
|
||||
bars = dedupe_by_read_pairs([dict(r) for r in reversed(rows)], pairs)
|
||||
raw_rows = [dict(r) for r in reversed(rows)]
|
||||
t0 = str(raw_rows[0].get("candle_time") or "")[:12] if raw_rows else ""
|
||||
ticks = (
|
||||
_ticks_for_bar_garbage(db, str(code), t0, str(before_candle_time))
|
||||
if t0 else None
|
||||
)
|
||||
bars = dedupe_by_read_pairs(
|
||||
raw_rows, pairs,
|
||||
ticks=ticks,
|
||||
tf_min=int(timeframe),
|
||||
missing_policy="hole",
|
||||
live_cover=False,
|
||||
)
|
||||
return bars[-limit:] if len(bars) > limit else bars
|
||||
|
||||
Reference in New Issue
Block a user