fix: Handle missing trade direction by inferring from exit price

This commit is contained in:
Bobby (aider) 2025-02-13 11:05:38 -08:00
parent 731b4e9e2d
commit 6d29558752

View File

@ -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'])}")