refactor: Improve trade direction handling and debug output
This commit is contained in:
parent
58c59a4633
commit
522e889467
@ -17,20 +17,19 @@ def calculate_position_performance(trades):
|
||||
total_proceeds = 0
|
||||
|
||||
for trade in trades:
|
||||
# Debug print to see what we're getting
|
||||
print(f"Processing trade: {trade}")
|
||||
|
||||
# Convert direction to lowercase and strip whitespace
|
||||
direction = str(trade.get('direction', '')).lower().strip()
|
||||
|
||||
try:
|
||||
shares = float(trade['shares'])
|
||||
price = float(trade['entry_price'])
|
||||
|
||||
if direction == 'buy':
|
||||
# Check if this is a buy or sell based on order type and direction
|
||||
is_buy = True
|
||||
if isinstance(trade.get('direction'), str) and trade['direction'].lower() == 'sell':
|
||||
is_buy = False
|
||||
|
||||
if is_buy:
|
||||
total_bought += shares
|
||||
total_cost += shares * price
|
||||
elif direction == 'sell':
|
||||
else:
|
||||
total_sold += shares
|
||||
total_proceeds += shares * price
|
||||
except (ValueError, TypeError) as e:
|
||||
@ -405,7 +404,7 @@ def trading_journal_page():
|
||||
# Convert direction to lowercase and strip whitespace
|
||||
direction = str(trade.get('direction', '')).lower().strip()
|
||||
|
||||
if direction == 'buy':
|
||||
if isinstance(trade.get('direction'), str) and trade['direction'].lower() == 'buy':
|
||||
col1, col2, col3 = st.columns(3)
|
||||
with col1:
|
||||
st.text(f"Date: {format_datetime(trade['entry_date'])}")
|
||||
@ -428,7 +427,7 @@ def trading_journal_page():
|
||||
# Convert direction to lowercase and strip whitespace
|
||||
direction = str(trade.get('direction', '')).lower().strip()
|
||||
|
||||
if direction == 'sell':
|
||||
if isinstance(trade.get('direction'), str) and trade['direction'].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