v0.7.1-fix: Preload 24h price history on startup (correct calculations from cycle 1)

This commit is contained in:
Marc Blatter 2026-08-02 10:06:18 +02:00
parent 90a0928904
commit e2b6319a8d
1 changed files with 13 additions and 23 deletions

View File

@ -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: