From f162cdb91b474ac24ef41177be85830a8f5abaf6 Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Thu, 13 Feb 2025 09:26:18 -0800 Subject: [PATCH] fix: Correct trade direction processing in trading journal --- src/pages/journal/trading_journal_page.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/pages/journal/trading_journal_page.py b/src/pages/journal/trading_journal_page.py index c50d1dc..a90659b 100644 --- a/src/pages/journal/trading_journal_page.py +++ b/src/pages/journal/trading_journal_page.py @@ -21,18 +21,11 @@ def calculate_position_performance(trades): shares = float(trade['shares']) price = float(trade['entry_price']) - # First check explicit direction field - is_buy = True - 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: + # Check direction field directly + if trade.get('direction', '').lower() == 'buy': total_bought += shares total_cost += shares * price - else: + elif trade.get('direction', '').lower() == 'sell': total_sold += shares total_proceeds += shares * price except (ValueError, TypeError) as e: @@ -414,7 +407,7 @@ def trading_journal_page(): # Show buy trades st.subheader("Buy Orders") for trade in trades: - if trade.get('order_type', '').lower() != 'sell': # If not sell, assume buy + if trade.get('direction', '').lower() == 'buy': # Check direction field instead of order_type col1, col2, col3 = st.columns(3) with col1: st.text(f"Date: {format_datetime(trade['entry_date'])}") @@ -434,7 +427,7 @@ def trading_journal_page(): # Show sell trades st.subheader("Sell Orders") for trade in trades: - if trade.get('order_type', '').lower() == 'sell': + if trade.get('direction', '').lower() == 'sell': # Check direction field instead of order_type col1, col2 = st.columns(2) with col1: st.text(f"Date: {format_datetime(trade['entry_date'])}")