diff --git a/src/strategies/ping_pong_bot.py b/src/strategies/ping_pong_bot.py index 65f049b..3fdf1bb 100644 --- a/src/strategies/ping_pong_bot.py +++ b/src/strategies/ping_pong_bot.py @@ -68,7 +68,7 @@ class DatabaseManager: class PingPongBot: def __init__(self, config_path="config/ping_pong_config.yaml"): - self.version = "1.5.1" + self.version = "1.5.2" with open(config_path, 'r') as f: self.config = yaml.safe_load(f) @@ -161,9 +161,13 @@ class PingPongBot: """Logic Point I: 1D MA44 check and Point II: Asset/Perp selection""" try: logger.info("Checking direction based on SMA(44, 1D)...") - candles_1d = await self.db.get_candles(self.db_symbol, "1d", limit=50) + # Increase limit to ensure we get enough data even with potential gaps + candles_1d = await self.db.get_candles(self.db_symbol, "1d", limit=100) + if not candles_1d or len(candles_1d) < 44: - self.status_msg = "Error: Not enough 1D data for MA44" + got = len(candles_1d) if candles_1d else 0 + logger.warning(f"Not enough 1D data for MA44. Got {got} candles for {self.db_symbol}.") + self.status_msg = f"Error: Need 44 1D candles (Got {got})" return False df_1d = pd.DataFrame(candles_1d[::-1]) @@ -181,17 +185,14 @@ class PingPongBot: new_direction = "long" if current_price > self.ma_44_val else "short" if new_direction != self.direction: - logger.info(f"DIRECTION CHANGE: {self.direction} -> {new_direction}") + logger.info(f"DIRECTION CHANGE: {self.direction} -> {new_direction} (Price: {current_price:.2f}, MA44: {self.ma_44_val:.2f})") self.status_msg = f"Switching to {new_direction.upper()}" - # 1. Close all positions (Point III.3) if self.direction is not None: await self.close_all_positions() - # 2. Swap Assets on Spot (Point II) await self.swap_assets(new_direction) - # 3. Update configuration self.direction = new_direction if self.direction == "long": self.category = "inverse" @@ -201,7 +202,7 @@ class PingPongBot: self.symbol = f"{self.base_coin}USDC" logger.info(f"Bot configured for {self.direction.upper()} | Symbol: {self.symbol} | Category: {self.category}") - self.last_candle_time = None # Force indicator recalculation + self.last_candle_time = None return True return False