execution and training fixes
This commit is contained in:
@ -4716,8 +4716,50 @@ class CleanTradingDashboard:
|
||||
return 0
|
||||
|
||||
def _get_trading_statistics(self) -> Dict[str, Any]:
|
||||
"""Calculate trading statistics from closed trades"""
|
||||
"""Get trading statistics from trading executor"""
|
||||
try:
|
||||
# Try to get statistics from trading executor first
|
||||
if self.trading_executor:
|
||||
executor_stats = self.trading_executor.get_daily_stats()
|
||||
closed_trades = self.trading_executor.get_closed_trades()
|
||||
|
||||
if executor_stats and executor_stats.get('total_trades', 0) > 0:
|
||||
# Calculate largest win/loss from closed trades
|
||||
largest_win = 0.0
|
||||
largest_loss = 0.0
|
||||
|
||||
if closed_trades:
|
||||
for trade in closed_trades:
|
||||
try:
|
||||
# Handle both dictionary and object formats
|
||||
if isinstance(trade, dict):
|
||||
pnl = trade.get('pnl', 0)
|
||||
else:
|
||||
pnl = getattr(trade, 'pnl', 0)
|
||||
|
||||
if pnl > 0:
|
||||
largest_win = max(largest_win, pnl)
|
||||
elif pnl < 0:
|
||||
largest_loss = max(largest_loss, abs(pnl))
|
||||
|
||||
except Exception as e:
|
||||
logger.debug(f"Error processing trade for statistics: {e}")
|
||||
continue
|
||||
|
||||
# Map executor stats to dashboard format
|
||||
return {
|
||||
'total_trades': executor_stats.get('total_trades', 0),
|
||||
'winning_trades': executor_stats.get('winning_trades', 0),
|
||||
'losing_trades': executor_stats.get('losing_trades', 0),
|
||||
'win_rate': executor_stats.get('win_rate', 0.0) * 100, # Convert to percentage
|
||||
'avg_win_size': executor_stats.get('avg_winning_trade', 0.0), # Correct mapping
|
||||
'avg_loss_size': abs(executor_stats.get('avg_losing_trade', 0.0)), # Make positive for display
|
||||
'largest_win': largest_win,
|
||||
'largest_loss': largest_loss,
|
||||
'total_pnl': executor_stats.get('total_pnl', 0.0)
|
||||
}
|
||||
|
||||
# Fallback to dashboard's own trade list if no trading executor
|
||||
if not self.closed_trades:
|
||||
return {
|
||||
'total_trades': 0,
|
||||
|
Reference in New Issue
Block a user