v0.7.1-recovery: Fix trade recovery from Binance holdings on startup

This commit is contained in:
Marc Blatter 2026-08-02 10:18:58 +02:00
parent e8e2568e1d
commit 3ae96f34e6
1 changed files with 28 additions and 1 deletions

View File

@ -49,6 +49,33 @@ class TradingBotV07:
except Exception as e:
logger.warning(f" ⚠️ {symbol} history failed: {e}")
# LOAD EXISTING HOLDINGS FROM BINANCE
logger.info("[v0.7.1] Recovering existing holdings from Binance...")
try:
account = self.client.get_account()
for b in account['balances']:
asset = b['asset']
free = float(b['free'])
if asset in ['BTC', 'ETH', 'BNB', 'XRP', 'SOL', 'ADA', 'DOGE', 'DOT', 'AVAX'] and free > 0.0001:
symbol = asset + 'USDT'
try:
price = self.get_current_price(symbol)
if price and price > 0:
self.active_trades[symbol] = {
'entry_price': price,
'qty': free,
'entry_time': datetime.now().isoformat()
}
logger.info(f" ✅ RECOVERED {symbol} {free} @ ${price}")
except Exception as e:
logger.warning(f" ⚠️ {symbol} recovery error: {e}")
except Exception as e:
logger.warning(f"Recovery failed: {e}")
logger.info(f"[v0.7.1] Startup complete. Active trades: {len(self.active_trades)}")
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)")
@ -309,7 +336,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-fixed-24h-history'
'version': 'v0.7.1-recovery-fix'
}, f)
os.replace(temp, '/home/marc/bot-deploy/active_trades.json')
except: