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

@@ -176,6 +176,57 @@ def build_rule_briefing(data: Dict[str, Any]) -> str:
lines.append(f"학습용 통과 {n_all}건 · 사후합격(results_gated) {n_gated}")
lines.append("")
# 과적합·적용가능도 (휴리스틱) + 임계값 분포 요약
diag = data.get("overfit_diagnostics")
if not isinstance(diag, dict) or diag.get("overfit_risk_pct") is None:
try:
from kis_trader.backtest.optuna_common import build_optuna_overfit_diagnostics
diag = build_optuna_overfit_diagnostics(data)
data["overfit_diagnostics"] = diag
except Exception:
diag = {}
if isinstance(diag, dict) and diag.get("overfit_risk_pct") is not None:
lines.append("## 과적합·적용 가능도 (휴리스틱)")
lines.append(
f"- **과적합 위험 {diag.get('overfit_risk_pct')}%** · "
f"**적용 가능도 {diag.get('apply_readiness_pct')}%** · "
f"판정: **{diag.get('verdict')}** — {diag.get('verdict_ko')}"
)
for fac in (diag.get("factors") or [])[:6]:
if not isinstance(fac, dict):
continue
lines.append(
f" - {fac.get('label')}: +{fac.get('points')}p — {fac.get('detail')}"
)
dist = diag.get("threshold_distribution") or []
if dist:
lines.append(
f"- 임계값 분포 표본: {diag.get('threshold_pool')} "
f"상위 {diag.get('threshold_pool_n')}"
)
lines.append(
"| 파라미터 | median | p25~p75 | mode(비율) |"
)
lines.append("|---|---:|---|---|")
for row in dist[:12]:
if not isinstance(row, dict):
continue
med = row.get("median")
p25, p75 = row.get("p25"), row.get("p75")
band = (
f"{p25} ~ {p75}" if p25 is not None and p75 is not None else ""
)
med_s = f"{med}" if med is not None else ""
share = row.get("mode_share")
share_s = f"{float(share)*100:.0f}%" if share is not None else "?"
lines.append(
f"| `{row.get('param')}` | {med_s} | {band} | "
f"{row.get('mode')} ({share_s}) |"
)
if diag.get("note"):
lines.append(f"- _참고: {diag.get('note')}_")
lines.append("")
lines.append("## 이전 장에서는")
live = _live_pnl_snapshot(strategy, start, end)
if live:
@@ -370,9 +421,15 @@ def write_briefing_for_json(
with open(abs_path, "r", encoding="utf-8") as f:
data = json.load(f)
except (OSError, json.JSONDecodeError) as exc:
lg.warning("⚠️ 브리핑 JSON 읽기 실패: %s", exc)
lg.warning("⚠️ 브리핑 JSON 읽기 실패: %s", abs_path)
return None
try:
from kis_trader.backtest.optuna_common import attach_optuna_overfit_diagnostics
attach_optuna_overfit_diagnostics(data)
except Exception:
pass
rule = build_rule_briefing(data)
ai, provider = _call_ai_briefing(rule, data)
if ai: