fix: Use order_type instead of corrupted direction field for trade classification

This commit is contained in:
Bobby (aider) 2025-02-13 09:07:12 -08:00
parent 522e889467
commit bd880cbb46

View File

@ -21,9 +21,10 @@ def calculate_position_performance(trades):
shares = float(trade['shares']) shares = float(trade['shares'])
price = float(trade['entry_price']) price = float(trade['entry_price'])
# Check if this is a buy or sell based on order type and direction # Check order_type to determine if it's a buy or sell
# since direction field is corrupted with datetime
is_buy = True is_buy = True
if isinstance(trade.get('direction'), str) and trade['direction'].lower() == 'sell': if trade.get('order_type', '').lower() == 'sell':
is_buy = False is_buy = False
if is_buy: if is_buy:
@ -401,10 +402,7 @@ def trading_journal_page():
# Show buy trades # Show buy trades
st.subheader("Buy Orders") st.subheader("Buy Orders")
for trade in trades: for trade in trades:
# Convert direction to lowercase and strip whitespace if trade.get('order_type', '').lower() != 'sell': # If not sell, assume buy
direction = str(trade.get('direction', '')).lower().strip()
if isinstance(trade.get('direction'), str) and trade['direction'].lower() == 'buy':
col1, col2, col3 = st.columns(3) col1, col2, col3 = st.columns(3)
with col1: with col1:
st.text(f"Date: {format_datetime(trade['entry_date'])}") st.text(f"Date: {format_datetime(trade['entry_date'])}")
@ -424,10 +422,7 @@ def trading_journal_page():
# Show sell trades # Show sell trades
st.subheader("Sell Orders") st.subheader("Sell Orders")
for trade in trades: for trade in trades:
# Convert direction to lowercase and strip whitespace if trade.get('order_type', '').lower() == 'sell':
direction = str(trade.get('direction', '')).lower().strip()
if isinstance(trade.get('direction'), str) and trade['direction'].lower() == 'sell':
col1, col2 = st.columns(2) col1, col2 = st.columns(2)
with col1: with col1:
st.text(f"Date: {format_datetime(trade['entry_date'])}") st.text(f"Date: {format_datetime(trade['entry_date'])}")