From 4ebfcfebd1aa0665931d7c9bfd5c54f1f6784d85 Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Mon, 10 Feb 2025 09:39:35 -0800 Subject: [PATCH] fix: Update database operations for clickhouse-connect compatibility --- src/trading/journal.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/trading/journal.py b/src/trading/journal.py index 744ee36..bcef2e2 100644 --- a/src/trading/journal.py +++ b/src/trading/journal.py @@ -60,7 +60,7 @@ def create_trades_table(): ) ENGINE = MergeTree() ORDER BY (position_id, id, entry_date) """ - client.execute(query) + client.command(query) def generate_id() -> int: """Generate a unique ID for the trade""" @@ -132,7 +132,7 @@ def add_trade(trade: TradeEntry): {f"'{trade.notes}'" if trade.notes else 'NULL'} ) """ - client.execute(query) + client.command(query) def update_trade_exit(trade_id: int, exit_price: float, exit_date: datetime, followed_rules: bool, exit_reason: str, notes: Optional[str] = None): @@ -147,14 +147,14 @@ def update_trade_exit(trade_id: int, exit_price: float, exit_date: datetime, notes = {f"'{notes}'" if notes else 'notes'} WHERE id = {trade_id} """ - client.execute(query) + client.command(query) def get_open_trades(): with create_client() as client: query = "SELECT * FROM stock_db.trades WHERE exit_price IS NULL ORDER BY entry_date DESC" - result = client.execute(query) - columns = ['id', 'ticker', 'entry_date', 'shares', 'entry_price', 'target_price', - 'stop_loss', 'strategy', 'followed_rules', 'entry_reason', 'exit_price', + result = client.query(query).result_rows + columns = ['id', 'position_id', 'ticker', 'entry_date', 'shares', 'entry_price', 'target_price', + 'stop_loss', 'strategy', 'order_type', 'followed_rules', 'entry_reason', 'exit_price', 'exit_date', 'exit_reason', 'notes', 'created_at'] return [dict(zip(columns, row)) for row in result] @@ -166,9 +166,9 @@ def get_trade_history(limit: int = 50): ORDER BY exit_date DESC LIMIT {limit} """ - result = client.execute(query) - columns = ['id', 'ticker', 'entry_date', 'shares', 'entry_price', 'target_price', - 'stop_loss', 'strategy', 'followed_rules', 'entry_reason', 'exit_price', + result = client.query(query).result_rows + columns = ['id', 'position_id', 'ticker', 'entry_date', 'shares', 'entry_price', 'target_price', + 'stop_loss', 'strategy', 'order_type', 'followed_rules', 'entry_reason', 'exit_price', 'exit_date', 'exit_reason', 'notes', 'created_at'] return [dict(zip(columns, row)) for row in result]