fix: Improve trade direction detection in position performance calculation
This commit is contained in:
parent
bd880cbb46
commit
a3eae62be3
@ -21,10 +21,12 @@ def calculate_position_performance(trades):
|
||||
shares = float(trade['shares'])
|
||||
price = float(trade['entry_price'])
|
||||
|
||||
# Check order_type to determine if it's a buy or sell
|
||||
# since direction field is corrupted with datetime
|
||||
# First check explicit direction field
|
||||
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
|
||||
|
||||
if is_buy:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user