diff --git a/src/pages/journal/trading_journal_page.py b/src/pages/journal/trading_journal_page.py index 35bda09..72b60da 100644 --- a/src/pages/journal/trading_journal_page.py +++ b/src/pages/journal/trading_journal_page.py @@ -21,10 +21,12 @@ def calculate_position_performance(trades): shares = float(trade['shares']) price = float(trade['entry_price']) - # Check order_type to determine if it's a buy or sell - # since direction field is corrupted with datetime + # First check explicit direction field is_buy = True - if trade.get('order_type', '').lower() == 'sell': + if isinstance(trade.get('direction'), str) and trade['direction'].lower() == 'sell': + is_buy = False + # Fallback to order_type if direction is corrupted + elif trade.get('order_type', '').lower() == 'sell': is_buy = False if is_buy: