refactor: CB 게이지 pnl_pct 저장 레이어를 L7 → L6_DAILY로 변경
Some checks failed
CI / test (pull_request) Has been cancelled
Some checks failed
CI / test (pull_request) Has been cancelled
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 <noreply@anthropic.com>
This commit is contained in:
@@ -85,11 +85,13 @@ def create_dashboard_app(db_path: str) -> FastAPI:
|
|||||||
"""
|
"""
|
||||||
SELECT key, value
|
SELECT key, value
|
||||||
FROM contexts
|
FROM contexts
|
||||||
WHERE layer = 'L7_REALTIME'
|
WHERE layer = 'L6_DAILY'
|
||||||
|
AND timeframe = ?
|
||||||
AND key LIKE 'portfolio_pnl_pct_%'
|
AND key LIKE 'portfolio_pnl_pct_%'
|
||||||
ORDER BY updated_at DESC
|
ORDER BY updated_at DESC
|
||||||
LIMIT 20
|
LIMIT 20
|
||||||
"""
|
""",
|
||||||
|
(today,),
|
||||||
).fetchall()
|
).fetchall()
|
||||||
current_pnl_pct: float | None = None
|
current_pnl_pct: float | None = None
|
||||||
if pnl_pct_rows:
|
if pnl_pct_rows:
|
||||||
|
|||||||
@@ -430,10 +430,10 @@ async def trading_cycle(
|
|||||||
{"volume_ratio": candidate.volume_ratio},
|
{"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(
|
context_store.set_context(
|
||||||
ContextLayer.L7_REALTIME,
|
ContextLayer.L6_DAILY,
|
||||||
timeframe,
|
datetime.now(UTC).date().isoformat(),
|
||||||
f"portfolio_pnl_pct_{market.code}",
|
f"portfolio_pnl_pct_{market.code}",
|
||||||
{"pnl_pct": round(pnl_pct, 4)},
|
{"pnl_pct": round(pnl_pct, 4)},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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:
|
def _seed_cb_context(conn: sqlite3.Connection, pnl_pct: float, market: str = "KR") -> None:
|
||||||
import json as _json
|
import json as _json
|
||||||
|
from datetime import UTC, datetime
|
||||||
|
today = datetime.now(UTC).date().isoformat()
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"""
|
"""
|
||||||
INSERT OR REPLACE INTO contexts (layer, timeframe, key, value, created_at, updated_at)
|
INSERT OR REPLACE INTO contexts (layer, timeframe, key, value, created_at, updated_at)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
"L7_REALTIME",
|
"L6_DAILY",
|
||||||
"2026-02-21T10:00:00+00:00",
|
today,
|
||||||
f"portfolio_pnl_pct_{market}",
|
f"portfolio_pnl_pct_{market}",
|
||||||
_json.dumps({"pnl_pct": pnl_pct}),
|
_json.dumps({"pnl_pct": pnl_pct}),
|
||||||
"2026-02-21T10:00:00+00:00",
|
f"{today}T10:00:00+00:00",
|
||||||
"2026-02-21T10:00:00+00:00",
|
f"{today}T10:00:00+00:00",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user