fix: resolve KeyError in indicators and fix wallet balance logic (v1.3.3)

This commit is contained in:
Gemini CLI
2026-03-05 22:21:35 +01:00
parent 40178ca469
commit 38d8e5f1de

View File

@ -68,7 +68,7 @@ class DatabaseManager:
class PingPongBot: class PingPongBot:
def __init__(self, config_path="config/ping_pong_config.yaml"): 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: with open(config_path, 'r') as f:
self.config = yaml.safe_load(f) self.config = yaml.safe_load(f)
@ -134,7 +134,16 @@ class PingPongBot:
hurst_cfg = self.config['hurst'] hurst_cfg = self.config['hurst']
mcl = hurst_cfg['period'] / 2 mcl = hurst_cfg['period'] / 2
mcl_2 = int(round(mcl / 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['ma_mcl'] = self.rma(df['close'], mcl)
df['atr_mcl'] = self.rma(df['tr'], mcl) df['atr_mcl'] = self.rma(df['tr'], mcl)
df['center'] = df['ma_mcl'].shift(mcl_2).fillna(df['ma_mcl']) df['center'] = df['ma_mcl'].shift(mcl_2).fillna(df['ma_mcl'])
@ -144,9 +153,9 @@ class PingPongBot:
last_row = df.iloc[-1] last_row = df.iloc[-1]
now_str = datetime.now().strftime("%H:%M:%S") now_str = datetime.now().strftime("%H:%M:%S")
self.current_indicators["rsi"] = {"value": last_row['rsi'], "timestamp": now_str} self.current_indicators["rsi"] = {"value": float(last_row['rsi']), "timestamp": now_str}
self.current_indicators["hurst_lower"] = {"value": last_row['hurst_lower'], "timestamp": now_str} self.current_indicators["hurst_lower"] = {"value": float(last_row['hurst_lower']), "timestamp": now_str}
self.current_indicators["hurst_upper"] = {"value": last_row['hurst_upper'], "timestamp": now_str} self.current_indicators["hurst_upper"] = {"value": float(last_row['hurst_upper']), "timestamp": now_str}
return df return df
@ -167,7 +176,7 @@ class PingPongBot:
# 3. Balance # 3. Balance
wallet = self.session.get_wallet_balance(category="linear", accountType="UNIFIED", coin="USDT") wallet = self.session.get_wallet_balance(category="linear", accountType="UNIFIED", coin="USDT")
if wallet['retCode'] == 0: if wallet['retCode'] == 0:
result_list = wallet_response = wallet['result']['list'] result_list = wallet['result']['list']
if result_list: if result_list:
self.wallet_balance = float(result_list[0].get('totalWalletBalance', 0)) self.wallet_balance = float(result_list[0].get('totalWalletBalance', 0))
if self.wallet_balance == 0: if self.wallet_balance == 0:
@ -271,6 +280,7 @@ class PingPongBot:
latest = candles[0] latest = candles[0]
if latest['time'] != self.last_candle_time: if latest['time'] != self.last_candle_time:
df = pd.DataFrame(candles[::-1]) df = pd.DataFrame(candles[::-1])
df = df.astype({'open': float, 'high': float, 'low': float, 'close': float, 'volume': float})
df = self.calculate_indicators(df) df = self.calculate_indicators(df)
signal = self.check_signals(df) signal = self.check_signals(df)
if signal: await self.execute_trade(signal) if signal: await self.execute_trade(signal)