Fix stop-loss placement failure after cancel by increasing delay and adding retry
Bitfinex needs time to release locked balance after cancelling a stop order. Increased wait from 0.3s to 1.0s, and added a one-time retry with 2s delay if the first attempt fails. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
36225df832
commit
41ad549ae2
7
main.py
7
main.py
@ -413,7 +413,7 @@ def run_cycle():
|
|||||||
cancelled_any = True
|
cancelled_any = True
|
||||||
logger.info("Cancelled old stop %s for %s (position size changed)", s["id"], sym)
|
logger.info("Cancelled old stop %s for %s (position size changed)", s["id"], sym)
|
||||||
if cancelled_any:
|
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
|
# Place new stop-loss for TOTAL position amount at new avg entry
|
||||||
total_amount = pos.get("amount", amount)
|
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)
|
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)
|
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:
|
if sl:
|
||||||
stop_price = sl["stop_price"]
|
stop_price = sl["stop_price"]
|
||||||
# Update stop_orders_by_sym so subsequent actions in this cycle see it
|
# Update stop_orders_by_sym so subsequent actions in this cycle see it
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user