From e6df50bbb185e182ad90a19adc8f9be9b803984c Mon Sep 17 00:00:00 2001 From: gahusb Date: Tue, 24 Mar 2026 07:53:39 +0900 Subject: [PATCH] =?UTF-8?q?stock=20=EC=8B=A4=ED=98=84=EC=86=90=EC=9D=B5?= =?UTF-8?q?=EC=97=90=20=EC=84=B8=EA=B8=88=EB=9E=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stock-lab/app/db.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/stock-lab/app/db.py b/stock-lab/app/db.py index 78701e2..3c7b4e5 100644 --- a/stock-lab/app/db.py +++ b/stock-lab/app/db.py @@ -75,6 +75,7 @@ def init_db(): quantity INTEGER NOT NULL, avg_price REAL NOT NULL, sell_price REAL NOT NULL, + commission REAL NOT NULL DEFAULT 0, buy_amount REAL NOT NULL, sell_amount REAL NOT NULL, realized_profit REAL NOT NULL, @@ -83,6 +84,11 @@ def init_db(): ) """) + # sell_history 마이그레이션: commission 컬럼 추가 + sh_cols = {r["name"] for r in conn.execute("PRAGMA table_info(sell_history)").fetchall()} + if "commission" not in sh_cols: + conn.execute("ALTER TABLE sell_history ADD COLUMN commission REAL NOT NULL DEFAULT 0") + def save_articles(articles: List[Dict[str, str]]) -> int: count = 0 with _conn() as conn: @@ -212,13 +218,13 @@ def add_sell_history(data: Dict[str, Any]) -> Dict[str, Any]: cur = conn.execute(""" INSERT INTO sell_history (broker, ticker, name, quantity, avg_price, sell_price, - buy_amount, sell_amount, realized_profit, realized_rate, sold_at) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + commission, buy_amount, sell_amount, realized_profit, realized_rate, sold_at) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( data["broker"], data["ticker"], data["name"], data["quantity"], - data["avg_price"], data["sell_price"], data["buy_amount"], - data["sell_amount"], data["realized_profit"], data["realized_rate"], - data["sold_at"], + data["avg_price"], data["sell_price"], data.get("commission", 0), + data["buy_amount"], data["sell_amount"], data["realized_profit"], + data["realized_rate"], data["sold_at"], )) row = conn.execute("SELECT * FROM sell_history WHERE id = ?", (cur.lastrowid,)).fetchone() return dict(row) @@ -244,9 +250,9 @@ def get_sell_history(broker: str = None, days: int = None) -> List[Dict[str, Any def update_sell_history(record_id: int, data: Dict[str, Any]) -> Dict[str, Any] | None: fields = ["broker", "ticker", "name", "quantity", "avg_price", "sell_price", - "buy_amount", "sell_amount", "realized_profit", "realized_rate", "sold_at"] + "commission", "buy_amount", "sell_amount", "realized_profit", "realized_rate", "sold_at"] set_clause = ", ".join(f"{f} = ?" for f in fields) - values = [data[f] for f in fields] + [record_id] + values = [data.get(f, 0) if f == "commission" else data[f] for f in fields] + [record_id] with _conn() as conn: cur = conn.execute(f"UPDATE sell_history SET {set_clause} WHERE id = ?", values) if cur.rowcount == 0: