v0.7.1-fix: Preload 24h price history on startup (correct calculations from cycle 1)
This commit is contained in:
parent
90a0928904
commit
a771a1afe4
|
|
@ -38,28 +38,18 @@ class TradingBotV07:
|
||||||
self.portfolio_value = 0
|
self.portfolio_value = 0
|
||||||
self.max_trade_usdt = 0
|
self.max_trade_usdt = 0
|
||||||
|
|
||||||
# TRADE RECOVERY
|
# LOAD 24H PRICE HISTORY ON STARTUP
|
||||||
try:
|
logger.info("[v0.7.1] Loading 24h price history from Binance...")
|
||||||
account = self.client.get_account()
|
for symbol in SYMBOLS:
|
||||||
for b in account['balances']:
|
try:
|
||||||
asset = b['asset']
|
klines = self.client.get_historical_klines(symbol, '1m', '1 day ago UTC')
|
||||||
free = float(b['free'])
|
for k in klines:
|
||||||
|
self.price_history[symbol].append(float(k[4])) # close price
|
||||||
if asset in TRACKED_COINS and free > 0.0001:
|
logger.info(f" ✅ {symbol}: {len(self.price_history[symbol])} candles")
|
||||||
symbol = asset + 'USDT'
|
except Exception as e:
|
||||||
try:
|
logger.warning(f" ⚠️ {symbol} history failed: {e}")
|
||||||
price = self.get_current_price(symbol)
|
|
||||||
if price:
|
logger.info(f"[v0.7.1 INIT] Price history loaded. Ready for ±1.5% signals.")
|
||||||
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}")
|
|
||||||
|
|
||||||
logger.info("[v0.7 INIT] Coin-Level Contrarian (9 Coins, ±1.5% Thresholds)")
|
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),
|
'portfolio_value': round(portfolio_val, 2),
|
||||||
'max_trade_usdt': round(self.max_trade_usdt, 2),
|
'max_trade_usdt': round(self.max_trade_usdt, 2),
|
||||||
'timestamp': datetime.now().isoformat(),
|
'timestamp': datetime.now().isoformat(),
|
||||||
'version': 'v0.7.1-coin-level-contrarian-1.5pct'
|
'version': 'v0.7.1-fixed-24h-history'
|
||||||
}, f)
|
}, f)
|
||||||
os.replace(temp, '/home/marc/bot-deploy/active_trades.json')
|
os.replace(temp, '/home/marc/bot-deploy/active_trades.json')
|
||||||
except:
|
except:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue