From a3eae62be373d8ceed3d347b48e708a9c4ae74f5 Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Thu, 13 Feb 2025 09:09:39 -0800 Subject: [PATCH] fix: Improve trade direction detection in position performance calculation --- src/pages/journal/trading_journal_page.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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: