diff --git a/src/strategies/ping_pong_bot.py b/src/strategies/ping_pong_bot.py index c863ad0..b26525d 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.3.2" + self.version = "1.3.3" with open(config_path, 'r') as f: self.config = yaml.safe_load(f) @@ -134,7 +134,16 @@ class PingPongBot: hurst_cfg = self.config['hurst'] mcl = hurst_cfg['period'] / 2 mcl_2 = int(round(mcl / 2)) - df['tr'] = df[['high', 'low', 'close']].apply(lambda x: max(x[0]-x[1], abs(x[0]-x[2]), abs(x[1]-x[2])), axis=1) + + # Vectorized TR calculation + df['tr'] = np.maximum( + df['high'] - df['low'], + np.maximum( + abs(df['high'] - df['close'].shift(1)), + abs(df['low'] - df['close'].shift(1)) + ) + ) + df['ma_mcl'] = self.rma(df['close'], mcl) df['atr_mcl'] = self.rma(df['tr'], mcl) df['center'] = df['ma_mcl'].shift(mcl_2).fillna(df['ma_mcl']) @@ -144,9 +153,9 @@ class PingPongBot: last_row = df.iloc[-1] now_str = datetime.now().strftime("%H:%M:%S") - self.current_indicators["rsi"] = {"value": last_row['rsi'], "timestamp": now_str} - self.current_indicators["hurst_lower"] = {"value": last_row['hurst_lower'], "timestamp": now_str} - self.current_indicators["hurst_upper"] = {"value": last_row['hurst_upper'], "timestamp": now_str} + self.current_indicators["rsi"] = {"value": float(last_row['rsi']), "timestamp": now_str} + self.current_indicators["hurst_lower"] = {"value": float(last_row['hurst_lower']), "timestamp": now_str} + self.current_indicators["hurst_upper"] = {"value": float(last_row['hurst_upper']), "timestamp": now_str} return df @@ -167,7 +176,7 @@ class PingPongBot: # 3. Balance wallet = self.session.get_wallet_balance(category="linear", accountType="UNIFIED", coin="USDT") if wallet['retCode'] == 0: - result_list = wallet_response = wallet['result']['list'] + result_list = wallet['result']['list'] if result_list: self.wallet_balance = float(result_list[0].get('totalWalletBalance', 0)) if self.wallet_balance == 0: @@ -271,6 +280,7 @@ class PingPongBot: latest = candles[0] if latest['time'] != self.last_candle_time: df = pd.DataFrame(candles[::-1]) + df = df.astype({'open': float, 'high': float, 'low': float, 'close': float, 'volume': float}) df = self.calculate_indicators(df) signal = self.check_signals(df) if signal: await self.execute_trade(signal)