From e322743f3353b428c565d323313e670d18c6a8b8 Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Thu, 13 Feb 2025 09:32:40 -0800 Subject: [PATCH] fix: Add direction field to trade history query and improve error handling --- src/pages/journal/trading_journal_page.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pages/journal/trading_journal_page.py b/src/pages/journal/trading_journal_page.py index 05ca611..0b46a4f 100644 --- a/src/pages/journal/trading_journal_page.py +++ b/src/pages/journal/trading_journal_page.py @@ -21,11 +21,12 @@ def calculate_position_performance(trades): shares = float(trade['shares']) price = float(trade['entry_price']) - # Check direction field directly - if trade.get('direction', '').lower() == 'buy': + direction = str(trade.get('direction', '')).lower() + + if direction == 'buy': total_bought += shares total_cost += shares * price - elif trade.get('direction', '').lower() == 'sell': + elif direction == 'sell': total_sold += shares total_proceeds += shares * price except (ValueError, TypeError) as e: