From 9249d0f4d9cedaac35e39fcd9dcbe793791ca31e Mon Sep 17 00:00:00 2001 From: kroutony Date: Sat, 14 Mar 2026 03:21:44 +0000 Subject: [PATCH] Fix UnboundLocalError: load tracked_stops before stop-loss sync loop tracked_stops was used in the stop reconciliation loop (line 141) but only loaded later in the fill detection section, causing a crash every cycle since the last commit. Co-Authored-By: Claude Opus 4.6 (1M context) --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index ab2dec9..9c00f71 100644 --- a/main.py +++ b/main.py @@ -110,6 +110,9 @@ def run_cycle(): if w.get("type") == "exchange": wallet_balances[w["currency"]] = w.get("balance", 0) + # Load tracked stops early — needed for both stop sync and fill detection + tracked_stops = _load_tracked_stops() + for sym, pos in port.get("positions", {}).items(): if pos.get("amount", 0) <= 0: continue @@ -196,7 +199,6 @@ def run_cycle(): # --- Detect filled stop-loss orders --- sl_filled = [] - tracked_stops = _load_tracked_stops() active_order_ids = {str(o["id"]) for o in active_orders} for sym, sinfo in list(tracked_stops.items()): if str(sinfo.get("order_id")) in active_order_ids: