Skip to content

Commit 7cb7dd2

Browse files
committed
fix: skip margin call deferral when OHLC extremum equals close price
When mc_size==1 and the check price (H for shorts, L for longs) equals the close price, deferring the margin call to post-script is pointless as no recovery is possible at the same price. Firing immediately during OHLC ensures close_all orders see the updated position size, preventing phantom opposite-direction trades from stale close_all quantities.
1 parent 26220cd commit 7cb7dd2

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/pynecore/lib/strategy/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,8 @@ def _check_margin_call(self, check_price: float, *, for_short: bool,
11291129
margin_call_size = quantity
11301130

11311131
# Deferral check: mc_size==1 at first OHLC extremum, check if AF@C<0
1132-
if not at_open and can_defer and margin_call_size == 1:
1132+
# Skip deferral when check_price == close: no recovery possible at same price
1133+
if not at_open and can_defer and margin_call_size == 1 and check_price != self.c:
11331134
c_mvs = quantity * self.c
11341135
c_open_profit = c_mvs - money_spent
11351136
if self.sign < 0:

0 commit comments

Comments
 (0)