feat: Enhance trading system with new permanent subscription features and order book management

Changes:
- Added a new API endpoint for managing permanent subscriptions, allowing users to enable or disable subscriptions dynamically.
- Implemented a function to fill candle data from Kiwoom, ensuring that only relevant data is inserted into the database.
- Introduced a mechanism to handle master subscription states, improving the management of subscription statuses.
- Updated the database schema to include new fields for managing subscription states and order book filtering.

Impact:
- These enhancements improve the flexibility and reliability of the trading system, allowing for better management of subscriptions and order book data, while reducing the risk of data inconsistencies.

히스토리 align 제거 븅신같은 초기설계 아예 제거
진입모드에 구멍메움
호가진입을 켜도 호가가 안들어올때 호가 안보고 그냥 사버림
This commit is contained in:
Your Name
2026-08-15 23:01:14 +09:00
parent 4a18ce2697
commit 36a3e2b4a1
94 changed files with 6368 additions and 1639 deletions

View File

@@ -0,0 +1,82 @@
#!/usr/bin/env python3
"""0814 filter_eval 매도벽 — ASK_MAX_MULT 2 vs 3 vs 완화 시 통과 건수 (조회 전용)."""
from __future__ import annotations
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from database import TradeDB
from kis_trader.utils.env import get_env_from_db, invalidate_merged_env_cache
def main() -> None:
invalidate_merged_env_cache()
db = TradeDB()
try:
cols = [dict(r)["Field"] for r in db.conn.execute("SHOW COLUMNS FROM ws_orderbook").fetchall()]
print("ws_orderbook cols ok", "eval_price" in cols, "ask_qty_l3" in cols)
slot = float(get_env_from_db("SLOT_MONEY_DEFAULT", "300000") or 300000)
print("SLOT", slot)
for k in (
"MOMENTUM_ORDERBOOK_ENTRY_ASK_MAX_MULT",
"BREAKOUT_ORDERBOOK_ENTRY_ASK_MAX_MULT",
"SCALP_ORDERBOOK_ENTRY_ASK_MAX_MULT",
"TAIL_ORDERBOOK_ENTRY_ASK_MAX_MULT",
):
print(k, repr(get_env_from_db(k, "")))
like = "20260814%"
br = db.conn.execute(
"SELECT strategy, reject_code, COUNT(*) AS n FROM ws_orderbook "
"WHERE source=%s AND snap_time LIKE %s GROUP BY strategy, reject_code",
("filter_eval", like),
).fetchall()
print("\n=== reject_code 0814 ===")
for r in br:
d = dict(r)
print(f" {d.get('strategy')} {d.get('reject_code')!r}: {d.get('n')}")
rows = [
dict(r)
for r in db.conn.execute(
"SELECT strategy, eval_price, ask_qty_l3, reject_code FROM ws_orderbook "
"WHERE source=%s AND snap_time LIKE %s AND eval_price > 0 AND ask_qty_l3 >= 0",
("filter_eval", like),
).fetchall()
]
print("rows with eval_price", len(rows))
mults = (2.0, 3.0, 8.0, 20.0, 50.0, 100.0)
by = {}
for row in rows:
sid = str(row.get("strategy") or "")
px = float(row.get("eval_price") or 0)
ask = int(row.get("ask_qty_l3") or 0)
if px <= 0:
continue
qty = max(1, int(slot / px))
rec = by.setdefault(sid, {"n": 0, "pass": {m: 0 for m in mults}})
rec["n"] += 1
for m in mults:
if ask <= int(qty * m):
rec["pass"][m] += 1
print("\n=== 매도벽만 단독 적용 시 통과율 (다른 탈락 무시) ===")
print("규칙: 매도3호가합 <= 필요주수 × 배수 이면 통과")
print("필요주수 = floor(슬롯/평가가)")
for sid, rec in sorted(by.items()):
n = rec["n"]
print(f"\n[{sid}] n={n}")
for m in mults:
p = rec["pass"][m]
pct = (100.0 * p / n) if n else 0
print(f" ×{m:g}: 통과 {p}/{n} ({pct:.1f}%)")
finally:
db.close()
if __name__ == "__main__":
main()