From f3491e94e4eb50fc6b7f031841597d0244205131 Mon Sep 17 00:00:00 2001 From: agentson Date: Sun, 22 Feb 2026 00:33:21 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20CB=20=EA=B2=8C=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?pnl=5Fpct=20=EC=A0=80=EC=9E=A5=20=EB=A0=88=EC=9D=B4=EC=96=B4?= =?UTF-8?q?=EB=A5=BC=20L7=20=E2=86=92=20L6=5FDAILY=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit portfolio_pnl_pct는 일별 성과 지표이므로 실시간 종목 데이터(L7)보다 일별 P&L 레이어(L6_DAILY)가 더 적합함. (PR #197 코드리뷰 반영) - main.py: L7_REALTIME + ISO timestamp → L6_DAILY + date(YYYY-MM-DD) - app.py: contexts 쿼리 layer/timeframe 조건 동기화 - tests: _seed_cb_context L6_DAILY + today 날짜로 수정 Co-Authored-By: Claude Sonnet 4.6 --- src/dashboard/app.py | 6 ++++-- src/main.py | 6 +++--- tests/test_dashboard.py | 10 ++++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/dashboard/app.py b/src/dashboard/app.py index 623a64d..d1b1558 100644 --- a/src/dashboard/app.py +++ b/src/dashboard/app.py @@ -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: diff --git a/src/main.py b/src/main.py index ca7d519..166b241 100644 --- a/src/main.py +++ b/src/main.py @@ -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)}, ) diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index f870dd2..b88cb5f 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -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()