From 52839b451eb51feb178fb5fe5775e4341dd8dc5c Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Thu, 13 Feb 2025 10:29:50 -0800 Subject: [PATCH] feat: Add debug logging to get_open_trades function --- src/trading/journal.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/trading/journal.py b/src/trading/journal.py index d922c3f..98cd77d 100644 --- a/src/trading/journal.py +++ b/src/trading/journal.py @@ -512,13 +512,23 @@ def get_open_trades_summary() -> dict: raise def get_open_trades(): + print("\n=== Fetching Open Trades ===") # Debug with create_client() as client: query = "SELECT * FROM stock_db.trades WHERE exit_price IS NULL ORDER BY entry_date DESC" - 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] + print(f"Executing query: {query}") # Debug + try: + result = client.query(query).result_rows + print(f"Query returned {len(result)} rows") # Debug + + 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'] + trades = [dict(zip(columns, row)) for row in result] + print(f"Processed trades: {trades}") # Debug + return trades + except Exception as e: + print(f"Error in get_open_trades: {str(e)}") # Debug + raise def get_current_prices(tickers: list) -> dict: """Get current prices for multiple tickers using yfinance"""