|
@@ -36,10 +36,10 @@ class RiskCommands(InfoCommandsBase):
|
|
|
try:
|
|
|
# Get position details
|
|
|
symbol = position.get('symbol', '')
|
|
|
- size = float(position.get('size', 0))
|
|
|
- entry_price = float(position.get('entryPrice', 0))
|
|
|
- mark_price = float(position.get('markPrice', 0))
|
|
|
- liquidation_price = float(position.get('liquidationPrice', 0))
|
|
|
+ size = float(position.get('size', 0) or 0)
|
|
|
+ entry_price = float(position.get('entryPrice', 0) or 0)
|
|
|
+ mark_price = float(position.get('markPrice', 0) or 0)
|
|
|
+ liquidation_price = float(position.get('liquidationPrice', 0) or 0)
|
|
|
|
|
|
if size == 0 or entry_price == 0:
|
|
|
continue
|
|
@@ -57,7 +57,7 @@ class RiskCommands(InfoCommandsBase):
|
|
|
stop_loss_orders = [o for o in orders if o.get('symbol') == symbol and o.get('type') == 'stop']
|
|
|
stop_loss_risk = 0
|
|
|
if stop_loss_orders:
|
|
|
- stop_price = float(stop_loss_orders[0].get('price', 0))
|
|
|
+ stop_price = float(stop_loss_orders[0].get('price', 0) or 0)
|
|
|
if stop_price > 0:
|
|
|
stop_loss_risk = abs((stop_price - mark_price) / mark_price * 100)
|
|
|
|
|
@@ -77,7 +77,8 @@ class RiskCommands(InfoCommandsBase):
|
|
|
continue
|
|
|
|
|
|
# Get portfolio value
|
|
|
- portfolio_value = float(self.trading_engine.get_portfolio_value())
|
|
|
+ balance_data = self.trading_engine.get_balance()
|
|
|
+ portfolio_value = float(balance_data.get('total', {}).get('USDC', 0) or 0) if balance_data else 0.0
|
|
|
|
|
|
# Calculate portfolio risk metrics
|
|
|
portfolio_risk = (total_unrealized_pnl / portfolio_value * 100) if portfolio_value > 0 else 0
|