|
@@ -45,8 +45,22 @@ class PositionsCommands(InfoCommandsBase):
|
|
symbol = position_trade['symbol']
|
|
symbol = position_trade['symbol']
|
|
base_asset = symbol.split('/')[0] if '/' in symbol else symbol
|
|
base_asset = symbol.split('/')[0] if '/' in symbol else symbol
|
|
position_side = position_trade.get('position_side', 'unknown')
|
|
position_side = position_trade.get('position_side', 'unknown')
|
|
- entry_price = float(position_trade.get('entry_price', 0.0))
|
|
|
|
- current_amount = float(position_trade.get('current_position_size', 0.0))
|
|
|
|
|
|
+
|
|
|
|
+ # Safely convert numeric values with proper null checks
|
|
|
|
+ entry_price = 0.0
|
|
|
|
+ if position_trade.get('entry_price') is not None:
|
|
|
|
+ try:
|
|
|
|
+ entry_price = float(position_trade['entry_price'])
|
|
|
|
+ except (ValueError, TypeError):
|
|
|
|
+ logger.warning(f"Could not convert entry_price for {symbol}")
|
|
|
|
+
|
|
|
|
+ current_amount = 0.0
|
|
|
|
+ if position_trade.get('current_position_size') is not None:
|
|
|
|
+ try:
|
|
|
|
+ current_amount = float(position_trade['current_position_size'])
|
|
|
|
+ except (ValueError, TypeError):
|
|
|
|
+ logger.warning(f"Could not convert current_position_size for {symbol}")
|
|
|
|
+
|
|
abs_current_amount = abs(current_amount)
|
|
abs_current_amount = abs(current_amount)
|
|
trade_type = position_trade.get('trade_type', 'manual')
|
|
trade_type = position_trade.get('trade_type', 'manual')
|
|
|
|
|
|
@@ -78,16 +92,37 @@ class PositionsCommands(InfoCommandsBase):
|
|
duration_str = "Error"
|
|
duration_str = "Error"
|
|
|
|
|
|
# Get price data with defaults
|
|
# Get price data with defaults
|
|
- mark_price = float(position_trade.get('mark_price', entry_price))
|
|
|
|
|
|
+ mark_price = entry_price # Default to entry price
|
|
|
|
+ if position_trade.get('mark_price') is not None:
|
|
|
|
+ try:
|
|
|
|
+ mark_price = float(position_trade['mark_price'])
|
|
|
|
+ except (ValueError, TypeError):
|
|
|
|
+ logger.warning(f"Could not convert mark_price for {symbol}")
|
|
|
|
|
|
# Calculate unrealized PnL
|
|
# Calculate unrealized PnL
|
|
- unrealized_pnl = float(position_trade.get('unrealized_pnl', 0.0))
|
|
|
|
|
|
+ unrealized_pnl = 0.0
|
|
|
|
+ if position_trade.get('unrealized_pnl') is not None:
|
|
|
|
+ try:
|
|
|
|
+ unrealized_pnl = float(position_trade['unrealized_pnl'])
|
|
|
|
+ except (ValueError, TypeError):
|
|
|
|
+ logger.warning(f"Could not convert unrealized_pnl for {symbol}")
|
|
|
|
|
|
# Get ROE from database
|
|
# Get ROE from database
|
|
- roe_percentage = float(position_trade.get('roe_percentage', 0.0))
|
|
|
|
|
|
+ roe_percentage = 0.0
|
|
|
|
+ if position_trade.get('roe_percentage') is not None:
|
|
|
|
+ try:
|
|
|
|
+ roe_percentage = float(position_trade['roe_percentage'])
|
|
|
|
+ except (ValueError, TypeError):
|
|
|
|
+ logger.warning(f"Could not convert roe_percentage for {symbol}")
|
|
|
|
|
|
# Add to totals
|
|
# Add to totals
|
|
- individual_position_value = float(position_trade.get('position_value', 0.0))
|
|
|
|
|
|
+ individual_position_value = 0.0
|
|
|
|
+ if position_trade.get('position_value') is not None:
|
|
|
|
+ try:
|
|
|
|
+ individual_position_value = float(position_trade['position_value'])
|
|
|
|
+ except (ValueError, TypeError):
|
|
|
|
+ logger.warning(f"Could not convert position_value for {symbol}")
|
|
|
|
+
|
|
if individual_position_value <= 0:
|
|
if individual_position_value <= 0:
|
|
individual_position_value = abs_current_amount * mark_price
|
|
individual_position_value = abs_current_amount * mark_price
|
|
|
|
|
|
@@ -95,7 +130,13 @@ class PositionsCommands(InfoCommandsBase):
|
|
total_unrealized += unrealized_pnl
|
|
total_unrealized += unrealized_pnl
|
|
|
|
|
|
# Add margin to total
|
|
# Add margin to total
|
|
- margin_used = float(position_trade.get('margin_used', 0.0))
|
|
|
|
|
|
+ margin_used = 0.0
|
|
|
|
+ if position_trade.get('margin_used') is not None:
|
|
|
|
+ try:
|
|
|
|
+ margin_used = float(position_trade['margin_used'])
|
|
|
|
+ except (ValueError, TypeError):
|
|
|
|
+ logger.warning(f"Could not convert margin_used for {symbol}")
|
|
|
|
+
|
|
if margin_used > 0:
|
|
if margin_used > 0:
|
|
total_margin_used += margin_used
|
|
total_margin_used += margin_used
|
|
|
|
|