diff --git a/main.py b/main.py index fbe61bd..da36461 100644 --- a/main.py +++ b/main.py @@ -413,7 +413,7 @@ def run_cycle(): cancelled_any = True logger.info("Cancelled old stop %s for %s (position size changed)", s["id"], sym) if cancelled_any: - time.sleep(0.3) # Wait for Bitfinex to release locked balance + time.sleep(1.0) # Wait for Bitfinex to release locked balance # Place new stop-loss for TOTAL position amount at new avg entry total_amount = pos.get("amount", amount) @@ -433,6 +433,11 @@ def run_cycle(): logger.info("ATR unavailable for %s, using fixed %.0f%% stop", sym, config.STOP_LOSS_PCT * 100) sl = trader.place_stop_loss_order(sym, total_amount, entry_price, stop_price=atr_stop) + if sl is None and cancelled_any: + # Retry once — Bitfinex may need more time to release locked balance + time.sleep(2.0) + logger.info("Retrying stop-loss for %s after balance release delay", sym) + sl = trader.place_stop_loss_order(sym, total_amount, entry_price, stop_price=atr_stop) if sl: stop_price = sl["stop_price"] # Update stop_orders_by_sym so subsequent actions in this cycle see it