Pārlūkot izejas kodu

Update ROE retrieval across multiple modules to use 'returnOnEquity' instead of 'percentage'.

- Changed references in ExternalEventMonitor, MarketMonitor, RiskCleanupManager, SimplePositionTracker, AggregationManager, and PerformanceCalculator to ensure consistent data handling.
- Enhanced calculations for ROE in NotificationManager to improve clarity and accuracy in performance metrics.
Carles Sentis 1 nedēļu atpakaļ
vecāks
revīzija
91275e4f8f

+ 1 - 1
src/monitoring/external_event_monitor.py

@@ -204,7 +204,7 @@ class ExternalEventMonitor:
                 # Get ROE directly from exchange data
                 info_data = existing_lc.get('info', {})
                 position_info = info_data.get('position', {})
-                roe_raw = position_info.get('percentage')  # This is the same field used by /positions
+                roe_raw = position_info.get('returnOnEquity')  # Changed from 'percentage' to 'returnOnEquity'
                 
                 if roe_raw is not None:
                     try:

+ 1 - 1
src/monitoring/market_monitor.py

@@ -333,7 +333,7 @@ class MarketMonitor:
                             if position_value is None and mark_price is not None and current_position_size is not None:
                                 position_value = abs(current_position_size) * mark_price
 
-                            roe_from_ex = ex_pos.get('percentage')
+                            roe_from_ex = ex_pos.get('returnOnEquity')
                             # The exchange provides ROE as a decimal (e.g., -0.326 for -32.6%)
                             # We need to multiply by 100 and keep the sign
                             unrealized_pnl_percentage_val = float(roe_from_ex) * 100 if roe_from_ex is not None else None

+ 1 - 1
src/monitoring/risk_cleanup_manager.py

@@ -146,7 +146,7 @@ class RiskCleanupManager:
                     # Get ROE directly from exchange data
                     info_data = position.get('info', {})
                     position_info = info_data.get('position', {})
-                    roe_raw = position_info.get('percentage')  # This is the same field used by /positions
+                    roe_raw = position_info.get('returnOnEquity')  # Changed from 'percentage' to 'returnOnEquity'
                     
                     if roe_raw is not None:
                         try:

+ 1 - 1
src/monitoring/simple_position_tracker.py

@@ -478,7 +478,7 @@ class SimplePositionTracker:
                 # Get ROE directly from exchange data
                 info_data = details.get('info', {})
                 position_info = info_data.get('position', {})
-                roe_raw = position_info.get('percentage')  # This is the same field used by /positions
+                roe_raw = position_info.get('returnOnEquity')  # Changed from 'percentage' to 'returnOnEquity'
                 
                 if roe_raw is not None:
                     try:

+ 10 - 6
src/notifications/notification_manager.py

@@ -425,14 +425,18 @@ class NotificationManager:
             if entry_price > 0:
                 if position_side == 'long':
                     pnl = amount * (price - entry_price)
-                    pnl_percent = ((price - entry_price) / entry_price) * 100
+                    # Get ROE directly from exchange data
+                    info_data = stop_loss_info.get('info', {})
+                    position_info = info_data.get('position', {})
+                    roe_raw = position_info.get('returnOnEquity')
+                    roe = float(roe_raw) * 100 if roe_raw is not None else 0.0
                 else:  # short
                     pnl = amount * (entry_price - price) 
-                    pnl_percent = ((entry_price - price) / entry_price) * 100
-                
-                # Calculate ROE (Return on Equity) more clearly
-                cost_basis = amount * entry_price
-                roe = (pnl / cost_basis) * 100
+                    # Get ROE directly from exchange data
+                    info_data = stop_loss_info.get('info', {})
+                    position_info = info_data.get('position', {})
+                    roe_raw = position_info.get('returnOnEquity')
+                    roe = float(roe_raw) * 100 if roe_raw is not None else 0.0
                 
                 pnl_emoji = "🟢" if pnl >= 0 else "🔴"
                 pnl_info = f"""

+ 5 - 2
src/stats/aggregation_manager.py

@@ -73,8 +73,11 @@ class AggregationManager:
             except Exception:
                 duration_seconds = 0
 
-        # Calculate ROE percentage
-        roe_percentage = (realized_pnl / entry_value * 100) if entry_value > 0 else 0.0
+        # Get ROE directly from exchange data
+        info_data = trade_data.get('info', {})
+        position_info = info_data.get('position', {})
+        roe_raw = position_info.get('returnOnEquity')
+        roe_percentage = float(roe_raw) * 100 if roe_raw is not None else 0.0
 
         # Update token_stats
         token_upsert_query = """

+ 4 - 1
src/stats/performance_calculator.py

@@ -230,7 +230,10 @@ class PerformanceCalculator:
             token['profit_factor'] = sum_winning / sum_losing if sum_losing > 0 else float('inf') if sum_winning > 0 else 0
             
             # Get ROE directly from the exchange data
-            token['roe_percentage'] = token.get('roe_percentage', 0.0)
+            info_data = token.get('info', {})
+            position_info = info_data.get('position', {})
+            roe_raw = position_info.get('returnOnEquity')
+            token['roe_percentage'] = float(roe_raw) * 100 if roe_raw is not None else 0.0
             
             # Format durations
             total_duration = token.get('total_duration_seconds', 0)

+ 1 - 1
trading_bot.py

@@ -14,7 +14,7 @@ from datetime import datetime
 from pathlib import Path
 
 # Bot version
-BOT_VERSION = "2.3.180"
+BOT_VERSION = "2.3.181"
 
 # Add src directory to Python path
 sys.path.insert(0, str(Path(__file__).parent / "src"))