fix: Add direction field to trade history query and improve error handling

This commit is contained in:
Bobby (aider) 2025-02-13 09:32:40 -08:00
parent e22a0ad67e
commit e322743f33

View File

@ -21,11 +21,12 @@ def calculate_position_performance(trades):
shares = float(trade['shares'])
price = float(trade['entry_price'])
# Check direction field directly
if trade.get('direction', '').lower() == 'buy':
direction = str(trade.get('direction', '')).lower()
if direction == 'buy':
total_bought += shares
total_cost += shares * price
elif trade.get('direction', '').lower() == 'sell':
elif direction == 'sell':
total_sold += shares
total_proceeds += shares * price
except (ValueError, TypeError) as e: