Fix: run survival check once before order loop, not per order
This commit is contained in:
@@ -292,6 +292,23 @@ class GridManager:
|
|||||||
f"{[f'${p:.2f}' for p in missing]}"
|
f"{[f'${p:.2f}' for p in missing]}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Run survival check ONCE before placing any orders.
|
||||||
|
# No need to repeat for each order — the grid doesn't change
|
||||||
|
# between placements in the same loop.
|
||||||
|
full_sim = calc._simulate_grid(
|
||||||
|
s.highest_open_price, spacing_pct, s.gbpusd, s.all_levels()
|
||||||
|
)
|
||||||
|
survival = calc.survival_check(
|
||||||
|
s.equity, s.highest_open_price, full_sim, s.gbpusd,
|
||||||
|
override_pct=60.0
|
||||||
|
)
|
||||||
|
if not survival["safe"]:
|
||||||
|
log.warning(
|
||||||
|
f"Survival check failed — no orders placed. "
|
||||||
|
f"Margin at floor: {survival['margin_level_at_floor_pct']:.1f}%"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
for target_price in missing:
|
for target_price in missing:
|
||||||
# Safety: never place at or above current price
|
# Safety: never place at or above current price
|
||||||
if target_price >= s.current_price:
|
if target_price >= s.current_price:
|
||||||
@@ -308,24 +325,6 @@ class GridManager:
|
|||||||
log.info(f"Skipping ${target_price:.2f} — at/above no-TP position.")
|
log.info(f"Skipping ${target_price:.2f} — at/above no-TP position.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Survival check — simulate FULL grid at 60% drop
|
|
||||||
# (not just current orders — honest worst case)
|
|
||||||
full_sim = calc._simulate_grid(
|
|
||||||
s.highest_open_price, spacing_pct, s.gbpusd,
|
|
||||||
s.all_levels()
|
|
||||||
)
|
|
||||||
survival = calc.survival_check(
|
|
||||||
s.equity, s.highest_open_price,
|
|
||||||
full_sim, s.gbpusd,
|
|
||||||
override_pct=60.0
|
|
||||||
)
|
|
||||||
if not survival["safe"]:
|
|
||||||
log.warning(
|
|
||||||
f"Survival check failed — stopping. "
|
|
||||||
f"Margin at floor: {survival['margin_level_at_floor_pct']:.1f}%"
|
|
||||||
)
|
|
||||||
break
|
|
||||||
|
|
||||||
size = calc.get_size(target_price, s.highest_open_price)
|
size = calc.get_size(target_price, s.highest_open_price)
|
||||||
tp_price = calc.get_tp_price(target_price, size, s.gbpusd)
|
tp_price = calc.get_tp_price(target_price, size, s.gbpusd)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user