From 6d295587524cf38445e43eaf8857ccb172a77a0b Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Thu, 13 Feb 2025 11:05:38 -0800 Subject: [PATCH] fix: Handle missing trade direction by inferring from exit price --- src/pages/journal/trading_journal_page.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/pages/journal/trading_journal_page.py b/src/pages/journal/trading_journal_page.py index 97a02d1..8ef236d 100644 --- a/src/pages/journal/trading_journal_page.py +++ b/src/pages/journal/trading_journal_page.py @@ -465,7 +465,13 @@ def trading_journal_page(): # Show buy trades st.subheader("Buy Orders") for trade in trades: - if trade.get('direction', '').lower() == 'buy': # Check direction field instead of order_type + # Infer direction if not set + if 'direction' not in trade or not trade['direction']: + is_buy = trade.get('exit_price') is None + else: + is_buy = trade.get('direction', '').lower() == 'buy' + + if is_buy: col1, col2, col3 = st.columns(3) with col1: st.text(f"Date: {format_datetime(trade['entry_date'])}") @@ -485,7 +491,13 @@ def trading_journal_page(): # Show sell trades st.subheader("Sell Orders") for trade in trades: - if trade.get('direction', '').lower() == 'sell': # Check direction field instead of order_type + # Infer direction if not set + if 'direction' not in trade or not trade['direction']: + is_sell = trade.get('exit_price') is not None + else: + is_sell = trade.get('direction', '').lower() == 'sell' + + if is_sell: col1, col2 = st.columns(2) with col1: st.text(f"Date: {format_datetime(trade['entry_date'])}")