Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/ml4t/backtest/core/execution_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,14 @@ def _process_single_order(self, order, use_open: bool, filled_orders: list) -> N
# Permissive mode: silently skip unaffordable orders for this cycle
# by cancelling them instead of keeping them pending forever.
order.status = OrderStatus.CANCELLED
elif broker.partial_fills_allowed and "insufficient" in rejection_reason.lower() or (
order.rebalance_id is not None
and broker.share_type.value == "integer"
elif (
broker.partial_fills_allowed
and "insufficient" in rejection_reason.lower()
or (
order.rebalance_id is not None
and broker.share_type.value == "integer"
and "insufficient" in rejection_reason.lower()
)
Comment on lines +499 to +506

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mixed and/or condition here is hard to read and repeats "insufficient" in rejection_reason.lower() (and calls .lower() multiple times in this function). Consider computing a single insufficient_cash = "insufficient" in rejection_reason.lower() once and then expressing the condition as insufficient_cash AND (partial fills allowed OR (rebalance_id set AND share_type is integer)) to make precedence unambiguous and avoid duplicated work.

Copilot uses AI. Check for mistakes.
):
if fill.try_partial_fill(order, fill_price):
filled_orders.append(order)
Expand Down
Loading