refactor(stock): Phase 1 리뷰 반영 (public get_krx_tickers·타입·limit명명·테스트)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -117,7 +117,7 @@ def init_db():
|
||||
close INTEGER,
|
||||
pnl_rate REAL,
|
||||
reasons TEXT,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now','localtime')),
|
||||
PRIMARY KEY (date, ticker)
|
||||
);
|
||||
"""
|
||||
@@ -321,10 +321,24 @@ def get_asset_snapshots(days: int = 30) -> List[Dict[str, Any]]:
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
# --- KRX Master ---
|
||||
|
||||
def get_krx_tickers() -> set:
|
||||
with _conn() as conn:
|
||||
try:
|
||||
rows = conn.execute("SELECT ticker FROM krx_master").fetchall()
|
||||
except Exception:
|
||||
return set()
|
||||
return {r["ticker"] for r in rows}
|
||||
|
||||
|
||||
# --- Holdings Signals CRUD ---
|
||||
|
||||
def upsert_holdings_signal(date, ticker, name, action, tech_score, exit_flags,
|
||||
issues, close, pnl_rate, reasons) -> None:
|
||||
def upsert_holdings_signal(
|
||||
date: str, ticker: str, name: Optional[str], action: str,
|
||||
tech_score: Optional[float], exit_flags: dict, issues: list,
|
||||
close: Optional[int], pnl_rate: Optional[float], reasons: Optional[str],
|
||||
) -> None:
|
||||
with _conn() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
@@ -358,9 +372,10 @@ def get_latest_holdings_date() -> str | None:
|
||||
r = conn.execute("SELECT MAX(date) AS d FROM holdings_signals").fetchone()
|
||||
return r["d"] if r and r["d"] else None
|
||||
|
||||
def get_holdings_signal_history(ticker: str, days: int = 30) -> list:
|
||||
def get_holdings_signal_history(ticker: str, limit: int = 30) -> list:
|
||||
"""최근 N개 시그널 행 (시그널은 거래일당 1행이라 ≈ N 거래일)."""
|
||||
with _conn() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT * FROM holdings_signals WHERE ticker=? ORDER BY date DESC LIMIT ?",
|
||||
(ticker, days)).fetchall()
|
||||
(ticker, limit)).fetchall()
|
||||
return [_row_to_signal(r) for r in rows]
|
||||
|
||||
Reference in New Issue
Block a user