|
@@ -215,15 +215,21 @@ class PositionsCommands(InfoCommandsBase):
|
|
total_unrealized_pnl = 0.0
|
|
total_unrealized_pnl = 0.0
|
|
total_roe = 0.0
|
|
total_roe = 0.0
|
|
for pos in open_positions:
|
|
for pos in open_positions:
|
|
- size = float(pos.get('size', 0))
|
|
|
|
- entry_price = float(pos.get('entryPrice', 0))
|
|
|
|
- mark_price = float(pos.get('markPrice', 0))
|
|
|
|
- roe = float(pos.get('roe_percentage', 0))
|
|
|
|
- if size != 0 and entry_price != 0:
|
|
|
|
- position_value = abs(size * entry_price)
|
|
|
|
- total_unrealized_pnl += size * (mark_price - entry_price)
|
|
|
|
- total_roe += roe * position_value
|
|
|
|
- total_position_value += position_value
|
|
|
|
|
|
+ try:
|
|
|
|
+ size = float(pos.get('size', 0)) if pos.get('size') is not None else 0.0
|
|
|
|
+ entry_price = float(pos.get('entryPrice', 0)) if pos.get('entryPrice') is not None else 0.0
|
|
|
|
+ # Handle None markPrice safely
|
|
|
|
+ mark_price_raw = pos.get('markPrice')
|
|
|
|
+ mark_price = float(mark_price_raw) if mark_price_raw is not None else entry_price
|
|
|
|
+ roe = float(pos.get('roe_percentage', 0)) if pos.get('roe_percentage') is not None else 0.0
|
|
|
|
+ if size != 0 and entry_price != 0:
|
|
|
|
+ position_value = abs(size * entry_price)
|
|
|
|
+ total_unrealized_pnl += size * (mark_price - entry_price)
|
|
|
|
+ total_roe += roe * position_value
|
|
|
|
+ total_position_value += position_value
|
|
|
|
+ except (ValueError, TypeError) as e:
|
|
|
|
+ logger.warning(f"Error calculating portfolio totals for position: {e}")
|
|
|
|
+ continue
|
|
# Weighted average ROE
|
|
# Weighted average ROE
|
|
avg_roe = (total_roe / total_position_value) if total_position_value > 0 else 0.0
|
|
avg_roe = (total_roe / total_position_value) if total_position_value > 0 else 0.0
|
|
roe_emoji = "🟢" if avg_roe >= 0 else "🔴"
|
|
roe_emoji = "🟢" if avg_roe >= 0 else "🔴"
|