From a771a1afe4797b5c743c623b14f1cf34d3a09371 Mon Sep 17 00:00:00 2001 From: Marc Blatter Date: Sun, 2 Aug 2026 10:06:18 +0200 Subject: [PATCH] v0.7.1-fix: Preload 24h price history on startup (correct calculations from cycle 1) --- src/main_ml.py | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/main_ml.py b/src/main_ml.py index cec56e8..eb921f1 100644 --- a/src/main_ml.py +++ b/src/main_ml.py @@ -38,28 +38,18 @@ class TradingBotV07: self.portfolio_value = 0 self.max_trade_usdt = 0 - # TRADE RECOVERY - try: - account = self.client.get_account() - for b in account['balances']: - asset = b['asset'] - free = float(b['free']) - - if asset in TRACKED_COINS and free > 0.0001: - symbol = asset + 'USDT' - try: - price = self.get_current_price(symbol) - if price: - self.active_trades[symbol] = { - 'entry_price': price, - 'qty': free, - 'entry_time': datetime.now().isoformat() - } - logger.info(f"[RECOVERED] {symbol} {free} @ {price}") - except: - pass - except Exception as e: - logger.warning(f"Recovery failed: {e}") + # LOAD 24H PRICE HISTORY ON STARTUP + logger.info("[v0.7.1] Loading 24h price history from Binance...") + for symbol in SYMBOLS: + try: + klines = self.client.get_historical_klines(symbol, '1m', '1 day ago UTC') + for k in klines: + self.price_history[symbol].append(float(k[4])) # close price + logger.info(f" ✅ {symbol}: {len(self.price_history[symbol])} candles") + except Exception as e: + logger.warning(f" ⚠️ {symbol} history failed: {e}") + + logger.info(f"[v0.7.1 INIT] Price history loaded. Ready for ±1.5% signals.") logger.info("[v0.7 INIT] Coin-Level Contrarian (9 Coins, ±1.5% Thresholds)") @@ -319,7 +309,7 @@ class TradingBotV07: 'portfolio_value': round(portfolio_val, 2), 'max_trade_usdt': round(self.max_trade_usdt, 2), 'timestamp': datetime.now().isoformat(), - 'version': 'v0.7.1-coin-level-contrarian-1.5pct' + 'version': 'v0.7.1-fixed-24h-history' }, f) os.replace(temp, '/home/marc/bot-deploy/active_trades.json') except: