From 2b09ab6d13de7bf791f560cdb1aa936e45a665f9 Mon Sep 17 00:00:00 2001 From: Marc Blatter Date: Thu, 9 Jul 2026 19:59:00 +0200 Subject: [PATCH] Bugfix: Bot + Dashboard sync - Save active_trades.json every cycle so dashboard shows real-time positions (2026-07-09 20:00) --- src/main_ml.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main_ml.py b/src/main_ml.py index 03baa08..0d868d0 100644 --- a/src/main_ml.py +++ b/src/main_ml.py @@ -218,6 +218,13 @@ class TradingBotV03: self.place_buy_order(best_signal, trade_amount) logger.info(f"CYCLE END | Active trades: {len(self.active_trades)} | Free USDT: ${usdt_free:.2f}") + # Save active trades for dashboard + import json + try: + with open('/home/marc/bot-deploy/active_trades.json', 'w') as f: + json.dump({'active_trades': self.active_trades, 'count': len(self.active_trades)}, f) + except Exception as e: + logger.warning(f'Failed to save active_trades.json: {e}') logger.info("=" * 70) def run(self): @@ -226,8 +233,8 @@ class TradingBotV03: logger.info("TRADING BOT V0.3 STARTED") logger.info(f"Symbols: {SYMBOLS}") logger.info(f"Strategy: Local Min Signals | Risk: TP=+{TAKE_PROFIT_PCT*100:.1f}% / SL={STOP_LOSS_PCT*100:.1f}%") - logger.info(f"Position size: Max ${MAX_TRADE_USDT}/trade (50% capital)") - logger.info(f"KEY FIX: Fresh balance fetched EVERY cycle (no stale cache!)") + logger.info(f"Position size: Max ${MAX_TRADE_USDT}/trade (50% capital avail)") + logger.info(f"") logger.info("=" * 70) try: