in the bussiness -but wip
This commit is contained in:
@ -134,6 +134,9 @@ class CleanTradingDashboard:
|
||||
self.total_fees = 0.0
|
||||
self.current_position: Optional[dict] = None
|
||||
|
||||
# Live balance caching for real-time portfolio updates
|
||||
self._cached_live_balance: float = 0.0
|
||||
|
||||
# ENHANCED: Model control toggles - separate inference and training
|
||||
self.dqn_inference_enabled = True # Default: enabled
|
||||
self.dqn_training_enabled = True # Default: enabled
|
||||
@ -319,6 +322,42 @@ class CleanTradingDashboard:
|
||||
logger.warning(f"Error getting balance: {e}")
|
||||
return 100.0 # Default balance
|
||||
|
||||
def _get_live_account_balance(self) -> float:
|
||||
"""Get live account balance from MEXC API in real-time"""
|
||||
try:
|
||||
if not self.trading_executor:
|
||||
return self._get_initial_balance()
|
||||
|
||||
# If in simulation mode, use simulation balance
|
||||
if hasattr(self.trading_executor, 'simulation_mode') and self.trading_executor.simulation_mode:
|
||||
return self._get_initial_balance()
|
||||
|
||||
# For live trading, get actual MEXC balance
|
||||
if hasattr(self.trading_executor, 'get_account_balance'):
|
||||
balances = self.trading_executor.get_account_balance()
|
||||
if balances:
|
||||
# Get USDC balance (MEXC primary) and USDT as fallback
|
||||
usdc_balance = balances.get('USDC', {}).get('total', 0.0)
|
||||
usdt_balance = balances.get('USDT', {}).get('total', 0.0)
|
||||
|
||||
# Use the higher balance (primary currency)
|
||||
live_balance = max(usdc_balance, usdt_balance)
|
||||
|
||||
if live_balance > 0:
|
||||
logger.debug(f"Live MEXC balance: USDC=${usdc_balance:.2f}, USDT=${usdt_balance:.2f}, Using=${live_balance:.2f}")
|
||||
return live_balance
|
||||
else:
|
||||
logger.warning("Live account balance is $0.00 - check MEXC account funding")
|
||||
return 0.0
|
||||
|
||||
# Fallback to initial balance if API calls fail
|
||||
logger.warning("Failed to get live balance, using initial balance")
|
||||
return self._get_initial_balance()
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Error getting live account balance: {e}, using initial balance")
|
||||
return self._get_initial_balance()
|
||||
|
||||
def _setup_layout(self):
|
||||
"""Setup the dashboard layout using layout manager"""
|
||||
self.app.layout = self.layout_manager.create_main_layout()
|
||||
@ -411,9 +450,15 @@ class CleanTradingDashboard:
|
||||
trade_count = len(self.closed_trades)
|
||||
trade_str = f"{trade_count} Trades"
|
||||
|
||||
# Portfolio value
|
||||
initial_balance = self._get_initial_balance()
|
||||
portfolio_value = initial_balance + total_session_pnl # Use total P&L including unrealized
|
||||
# Portfolio value - use live balance every 10 seconds to avoid API spam
|
||||
if n % 10 == 0 or not hasattr(self, '_cached_live_balance'):
|
||||
self._cached_live_balance = self._get_live_account_balance()
|
||||
logger.debug(f"Updated live balance cache: ${self._cached_live_balance:.2f}")
|
||||
|
||||
# For live trading, show actual account balance + session P&L
|
||||
# For simulation, show starting balance + session P&L
|
||||
current_balance = self._cached_live_balance if hasattr(self, '_cached_live_balance') else self._get_initial_balance()
|
||||
portfolio_value = current_balance + total_session_pnl # Live balance + unrealized P&L
|
||||
portfolio_str = f"${portfolio_value:.2f}"
|
||||
|
||||
# MEXC status
|
||||
|
@ -33,7 +33,7 @@ class DashboardLayoutManager:
|
||||
"Clean Trading Dashboard"
|
||||
], className="text-light mb-0"),
|
||||
html.P(
|
||||
f"Ultra-Fast Updates • Portfolio: ${self.starting_balance:,.0f} • {trading_mode}",
|
||||
f"Ultra-Fast Updates • Live Account Balance Sync • {trading_mode}",
|
||||
className="text-light mb-0 opacity-75 small"
|
||||
)
|
||||
], className="bg-dark p-2 mb-2")
|
||||
|
Reference in New Issue
Block a user