feat: 대시보드 Circuit Breaker 게이지 추가 (#196) #197

Merged
jihoson merged 3 commits from feature/issue-196-cb-gauge into main 2026-02-22 11:49:57 +09:00
3 changed files with 13 additions and 9 deletions
Showing only changes of commit f3491e94e4 - Show all commits

View File

@@ -85,11 +85,13 @@ def create_dashboard_app(db_path: str) -> FastAPI:
"""
SELECT key, value
FROM contexts
WHERE layer = 'L7_REALTIME'
WHERE layer = 'L6_DAILY'
AND timeframe = ?
AND key LIKE 'portfolio_pnl_pct_%'
ORDER BY updated_at DESC
LIMIT 20
"""
""",
(today,),
).fetchall()
current_pnl_pct: float | None = None
if pnl_pct_rows:

View File

@@ -430,10 +430,10 @@ async def trading_cycle(
{"volume_ratio": candidate.volume_ratio},
)
# Store latest pnl_pct in L7 so the dashboard can display the CB gauge
# Store latest pnl_pct in L6 (daily P&L layer) so the dashboard can display the CB gauge
context_store.set_context(
ContextLayer.L7_REALTIME,
timeframe,
ContextLayer.L6_DAILY,
datetime.now(UTC).date().isoformat(),
f"portfolio_pnl_pct_{market.code}",
{"pnl_pct": round(pnl_pct, 4)},
)

View File

@@ -355,18 +355,20 @@ def test_positions_empty_when_no_trades(tmp_path: Path) -> None:
def _seed_cb_context(conn: sqlite3.Connection, pnl_pct: float, market: str = "KR") -> None:
import json as _json
from datetime import UTC, datetime
today = datetime.now(UTC).date().isoformat()
conn.execute(
"""
INSERT OR REPLACE INTO contexts (layer, timeframe, key, value, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?)
""",
(
"L7_REALTIME",
"2026-02-21T10:00:00+00:00",
"L6_DAILY",
today,
f"portfolio_pnl_pct_{market}",
_json.dumps({"pnl_pct": pnl_pct}),
"2026-02-21T10:00:00+00:00",
"2026-02-21T10:00:00+00:00",
f"{today}T10:00:00+00:00",
f"{today}T10:00:00+00:00",
),
)
conn.commit()