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) <noreply@anthropic.com>
This commit is contained in:
parent
fa148da196
commit
9249d0f4d9
4
main.py
4
main.py
@ -110,6 +110,9 @@ def run_cycle():
|
|||||||
if w.get("type") == "exchange":
|
if w.get("type") == "exchange":
|
||||||
wallet_balances[w["currency"]] = w.get("balance", 0)
|
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():
|
for sym, pos in port.get("positions", {}).items():
|
||||||
if pos.get("amount", 0) <= 0:
|
if pos.get("amount", 0) <= 0:
|
||||||
continue
|
continue
|
||||||
@ -196,7 +199,6 @@ def run_cycle():
|
|||||||
|
|
||||||
# --- Detect filled stop-loss orders ---
|
# --- Detect filled stop-loss orders ---
|
||||||
sl_filled = []
|
sl_filled = []
|
||||||
tracked_stops = _load_tracked_stops()
|
|
||||||
active_order_ids = {str(o["id"]) for o in active_orders}
|
active_order_ids = {str(o["id"]) for o in active_orders}
|
||||||
for sym, sinfo in list(tracked_stops.items()):
|
for sym, sinfo in list(tracked_stops.items()):
|
||||||
if str(sinfo.get("order_id")) in active_order_ids:
|
if str(sinfo.get("order_id")) in active_order_ids:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user