fix: Improve trade direction detection in position performance calculation

This commit is contained in:
Bobby (aider) 2025-02-13 09:09:39 -08:00
parent bd880cbb46
commit a3eae62be3

View File

@ -21,10 +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 order_type to determine if it's a buy or sell # First check explicit direction field
# since direction field is corrupted with datetime
is_buy = True is_buy = True
if trade.get('order_type', '').lower() == 'sell': if isinstance(trade.get('direction'), str) and trade['direction'].lower() == 'sell':
is_buy = False
# Fallback to order_type if direction is corrupted
elif trade.get('order_type', '').lower() == 'sell':
is_buy = False is_buy = False
if is_buy: if is_buy: