Browse Source

Increment BOT_VERSION to 2.2.146 and introduce MARKET_MONITOR_CLEANUP_INTERVAL_HEARTBEATS configuration.

- Updated BOT_VERSION for the upcoming release.
- Added MARKET_MONITOR_CLEANUP_INTERVAL_HEARTBEATS to env.example and config.py for managing less frequent cleanup tasks in MarketMonitor.
- Enhanced TradingEngine to ensure cache age checks are robust against None values, improving stability in data retrieval.
Carles Sentis 1 day ago
parent
commit
52dcbe63dc
4 changed files with 10 additions and 4 deletions
  1. 5 0
      config/env.example
  2. 1 0
      src/config/config.py
  3. 3 3
      src/trading/trading_engine.py
  4. 1 1
      trading_bot.py

+ 5 - 0
config/env.example

@@ -55,6 +55,11 @@ TELEGRAM_CUSTOM_KEYBOARD_LAYOUT="/daily,/performance,/balance|/stats,/positions,
 # Maximum recommended: 300 seconds (5 minutes)
 BOT_HEARTBEAT_SECONDS=10
 
+# Interval (in heartbeats) for running less frequent cleanup tasks in MarketMonitor
+# (e.g., orphaned stop loss cleanup, position synchronization)
+# Default: 10 heartbeats (e.g., if BOT_HEARTBEAT_SECONDS is 10s, cleanup runs every 100s)
+MARKET_MONITOR_CLEANUP_INTERVAL_HEARTBEATS=10
+
 # ========================================
 # Logging
 # ========================================

+ 1 - 0
src/config/config.py

@@ -33,6 +33,7 @@ class Config:
     
     # Bot monitoring configuration
     BOT_HEARTBEAT_SECONDS = int(os.getenv('BOT_HEARTBEAT_SECONDS', '30'))
+    MARKET_MONITOR_CLEANUP_INTERVAL_HEARTBEATS: int = int(os.getenv('MARKET_MONITOR_CLEANUP_INTERVAL_HEARTBEATS', '10'))
     
     # Logging
     LOG_LEVEL: str = os.getenv('LOG_LEVEL', 'INFO')

+ 3 - 3
src/trading/trading_engine.py

@@ -63,7 +63,7 @@ class TradingEngine:
             cache_age = self.market_monitor.get_cache_age_seconds()
             
             # Use cached data if it's fresh (less than 30 seconds old)
-            if cached_balance and cache_age < 30:
+            if cached_balance and cache_age is not None and cache_age < 30:
                 logger.debug(f"Using cached balance (age: {cache_age:.1f}s)")
                 return cached_balance
         
@@ -79,7 +79,7 @@ class TradingEngine:
             cache_age = self.market_monitor.get_cache_age_seconds()
             
             # Use cached data if it's fresh (less than 30 seconds old)
-            if cached_positions is not None and cache_age < 30:
+            if cached_positions is not None and cache_age is not None and cache_age < 30:
                 logger.debug(f"Using cached positions (age: {cache_age:.1f}s): {len(cached_positions)} positions")
                 return cached_positions
         
@@ -95,7 +95,7 @@ class TradingEngine:
             cache_age = self.market_monitor.get_cache_age_seconds()
             
             # Use cached data if it's fresh (less than 30 seconds old)
-            if cached_orders is not None and cache_age < 30:
+            if cached_orders is not None and cache_age is not None and cache_age < 30:
                 logger.debug(f"Using cached orders (age: {cache_age:.1f}s): {len(cached_orders)} orders")
                 return cached_orders
         

+ 1 - 1
trading_bot.py

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