Browse Source

Enhance asynchronous initialization in TradingEngine with improved logging. Added start and completion logs for async initialization and updated error logging to include exception details when setting the initial balance.

Carles Sentis 4 days ago
parent
commit
41bf441177
2 changed files with 6 additions and 3 deletions
  1. 5 2
      src/trading/trading_engine.py
  2. 1 1
      trading_bot.py

+ 5 - 2
src/trading/trading_engine.py

@@ -49,7 +49,9 @@ class TradingEngine:
             
             
     async def async_init(self):
     async def async_init(self):
         """Asynchronously initialize the trading engine components."""
         """Asynchronously initialize the trading engine components."""
+        logger.info("🚀 Starting asynchronous initialization of TradingEngine...")
         await self._initialize_stats_async()
         await self._initialize_stats_async()
+        logger.info("✅ Asynchronous initialization of TradingEngine complete.")
 
 
     async def _initialize_stats_async(self):
     async def _initialize_stats_async(self):
         """Fetch initial data asynchronously after the loop has started."""
         """Fetch initial data asynchronously after the loop has started."""
@@ -62,9 +64,10 @@ class TradingEngine:
             balance = self.client.get_balance()
             balance = self.client.get_balance()
             if balance and balance.get('total'):
             if balance and balance.get('total'):
                 usdc_balance = float(balance['total'].get('USDC', 0))
                 usdc_balance = float(balance['total'].get('USDC', 0))
-                await self.stats.set_initial_balance(usdc_balance)
+                # The set_initial_balance method is synchronous
+                self.stats.set_initial_balance(usdc_balance)
         except Exception as e:
         except Exception as e:
-            logger.error(f"Could not set initial balance during async init: {e}")
+            logger.error(f"Could not set initial balance during async init: {e}", exc_info=True)
     
     
     def set_market_monitor(self, market_monitor):
     def set_market_monitor(self, market_monitor):
         """Set the market monitor reference for accessing cached data."""
         """Set the market monitor reference for accessing cached data."""

+ 1 - 1
trading_bot.py

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