fix: Add direction field to trade history query and improve error handling
This commit is contained in:
parent
e22a0ad67e
commit
e322743f33
@ -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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user