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'])
|
shares = float(trade['shares'])
|
||||||
price = float(trade['entry_price'])
|
price = float(trade['entry_price'])
|
||||||
|
|
||||||
# Check direction field directly
|
direction = str(trade.get('direction', '')).lower()
|
||||||
if trade.get('direction', '').lower() == 'buy':
|
|
||||||
|
if direction == 'buy':
|
||||||
total_bought += shares
|
total_bought += shares
|
||||||
total_cost += shares * price
|
total_cost += shares * price
|
||||||
elif trade.get('direction', '').lower() == 'sell':
|
elif direction == 'sell':
|
||||||
total_sold += shares
|
total_sold += shares
|
||||||
total_proceeds += shares * price
|
total_proceeds += shares * price
|
||||||
except (ValueError, TypeError) as e:
|
except (ValueError, TypeError) as e:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user