|
@@ -120,7 +120,7 @@ class PerformanceCalculator:
|
|
|
initial_balance = float(self.db._get_metadata('initial_balance') or '0.0')
|
|
|
roi_percentage = (total_realized_pnl / initial_balance * 100) if initial_balance > 0 else 0
|
|
|
|
|
|
- # Calculate best and worst performing tokens
|
|
|
+ # Calculate best and worst performing tokens based on total P&L
|
|
|
best_token_name = "N/A"
|
|
|
best_token_pnl_pct = 0.0
|
|
|
best_token_volume = 0.0
|
|
@@ -138,13 +138,15 @@ class PerformanceCalculator:
|
|
|
if entry_volume > 0:
|
|
|
pnl_pct = (total_pnl / entry_volume) * 100
|
|
|
|
|
|
- if best_token_name == "N/A" or pnl_pct > best_token_pnl_pct:
|
|
|
+ # Best token = highest total P&L
|
|
|
+ if best_token_name == "N/A" or total_pnl > best_token_pnl_value:
|
|
|
best_token_name = token['token']
|
|
|
best_token_pnl_pct = pnl_pct
|
|
|
best_token_volume = entry_volume
|
|
|
best_token_pnl_value = total_pnl
|
|
|
|
|
|
- if worst_token_name == "N/A" or pnl_pct < worst_token_pnl_pct:
|
|
|
+ # Worst token = lowest total P&L
|
|
|
+ if worst_token_name == "N/A" or total_pnl < worst_token_pnl_value:
|
|
|
worst_token_name = token['token']
|
|
|
worst_token_pnl_pct = pnl_pct
|
|
|
worst_token_volume = entry_volume
|
|
@@ -206,10 +208,10 @@ class PerformanceCalculator:
|
|
|
}
|
|
|
|
|
|
def get_token_performance(self, limit: int = 20) -> List[Dict[str, Any]]:
|
|
|
- """Get performance stats by token, sorted by ROE (Return on Equity)."""
|
|
|
+ """Get performance stats by token, sorted by total P&L (dollar amount)."""
|
|
|
formatter = get_formatter()
|
|
|
|
|
|
- # Get all token stats first, then sort by ROE in Python
|
|
|
+ # Get all token stats first, then sort by total P&L in Python
|
|
|
token_stats = self.db._fetch_query(
|
|
|
"SELECT * FROM token_stats",
|
|
|
()
|
|
@@ -240,10 +242,10 @@ class PerformanceCalculator:
|
|
|
# Token display name (use token as-is)
|
|
|
token['display_name'] = token['token'].upper()
|
|
|
|
|
|
- # Sort by ROE percentage (highest to lowest), then by total PnL as tiebreaker
|
|
|
+ # Sort by total P&L (highest to lowest), then by ROE as tiebreaker
|
|
|
sorted_tokens = sorted(
|
|
|
token_stats,
|
|
|
- key=lambda x: (x.get('roe_percentage', 0), x.get('total_realized_pnl', 0)),
|
|
|
+ key=lambda x: (x.get('total_realized_pnl', 0), x.get('roe_percentage', 0)),
|
|
|
reverse=True
|
|
|
)
|
|
|
|