diff --git a/src/trading/journal.py b/src/trading/journal.py index ca0241b..591c165 100644 --- a/src/trading/journal.py +++ b/src/trading/journal.py @@ -485,7 +485,8 @@ def get_open_trades_summary() -> dict: count() as num_orders, groupArray(position_id) as position_ids FROM stock_db.trades - WHERE exit_price IS NULL + WHERE (exit_price IS NULL OR exit_price = '') + AND (exit_date IS NULL) GROUP BY ticker HAVING total_shares > 0 ORDER BY ticker ASC @@ -507,7 +508,13 @@ def get_open_trades_summary() -> dict: 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" + query = """ + SELECT * + FROM stock_db.trades + WHERE (exit_price IS NULL OR exit_price = '') + AND (exit_date IS NULL) + ORDER BY entry_date DESC + """ print(f"Executing query: {query}") # Debug try: result = client.query(query).result_rows