fix: Correct trade direction processing in trading journal
This commit is contained in:
parent
94671119f2
commit
f162cdb91b
@ -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'])}")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user