fix: Use order_type instead of corrupted direction field for trade classification
This commit is contained in:
parent
522e889467
commit
bd880cbb46
@ -21,9 +21,10 @@ def calculate_position_performance(trades):
|
||||
shares = float(trade['shares'])
|
||||
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
|
||||
if isinstance(trade.get('direction'), str) and trade['direction'].lower() == 'sell':
|
||||
if trade.get('order_type', '').lower() == 'sell':
|
||||
is_buy = False
|
||||
|
||||
if is_buy:
|
||||
@ -401,10 +402,7 @@ def trading_journal_page():
|
||||
# Show buy trades
|
||||
st.subheader("Buy Orders")
|
||||
for trade in trades:
|
||||
# Convert direction to lowercase and strip whitespace
|
||||
direction = str(trade.get('direction', '')).lower().strip()
|
||||
|
||||
if isinstance(trade.get('direction'), str) and trade['direction'].lower() == 'buy':
|
||||
if trade.get('order_type', '').lower() != 'sell': # If not sell, assume buy
|
||||
col1, col2, col3 = st.columns(3)
|
||||
with col1:
|
||||
st.text(f"Date: {format_datetime(trade['entry_date'])}")
|
||||
@ -424,10 +422,7 @@ def trading_journal_page():
|
||||
# Show sell trades
|
||||
st.subheader("Sell Orders")
|
||||
for trade in trades:
|
||||
# Convert direction to lowercase and strip whitespace
|
||||
direction = str(trade.get('direction', '')).lower().strip()
|
||||
|
||||
if isinstance(trade.get('direction'), str) and trade['direction'].lower() == 'sell':
|
||||
if trade.get('order_type', '').lower() == 'sell':
|
||||
col1, col2 = st.columns(2)
|
||||
with col1:
|
||||
st.text(f"Date: {format_datetime(trade['entry_date'])}")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user