From 4196a61b99c923cc0319fa3f16e67c1f1662c510 Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Thu, 13 Feb 2025 11:18:00 -0800 Subject: [PATCH] refactor: Update open trades queries to handle empty exit prices and null exit dates --- src/trading/journal.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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