QuantConnect/Lean · error · AssertionError
The Algorithms was not handled any StopMarketOrders
Error message
The Algorithms was not handled any StopMarketOrders
What it means
End-of-algorithm assertion that every STOP_MARKET order created by the scheduled method reached FILLED status. on_end_of_algorithm iterates transactions.get_orders filtered by OrderType.STOP_MARKET and fails if any order is not FILLED. It guards the prior extended-hours fill behaviour end-to-end.
Source
Thrown at Algorithm.Python/FutureStopMarketOrderOnExtendedHoursRegressionAlgorithm.py:70
# An order fill update the resulting information is passed to this method.
def on_order_event(self, order_event: OrderEvent) -> None:
if self.transactions.get_order_by_id(order_event.order_id).type is not OrderType.STOP_MARKET:
return None
if order_event.status == OrderStatus.FILLED:
# Get Exchange Hours for specific security
exchange_hours = self.market_hours_database.get_exchange_hours(self._sp_500_e_mini.subscription_data_config)
# Validate, Exchange is opened explicitly
if (not exchange_hours.is_open(order_event.utc_time, self._sp_500_e_mini.is_extended_market_hours)):
raise AssertionError("The Exchange hours was closed, verify 'extended_market_hours' flag in Initialize() when added new security(ies)")
def on_end_of_algorithm(self) -> None:
self.stop_market_orders = self.transactions.get_orders(lambda o: o.type is OrderType.STOP_MARKET)
for o in self.stop_market_orders:
if o.status != OrderStatus.FILLED:
raise AssertionError("The Algorithms was not handled any StopMarketOrders")
View on GitHub (pinned to d2c3659f87)
Solutions
- Inspect transactions.get_orders() at on_end_of_algorithm to see each stop order's actual status.
- Ensure the stop price (self._sp_500_e_mini.price * 1.1) is actually crossed during the backtest window.
- Confirm the scheduler's early-return guard (end_date - 1 or not mapped) is not skipping every bar.
- Re-check extended_market_hours=True so the stop can fill in the session the test exercises.
Defensive patterns
Strategy: validation
Validate before calling
# Before on_end_of_algorithm, summarise stop order statuses
statuses = [o.status for o in self.transactions.get_orders(lambda o: o.type is OrderType.STOP_MARKET)]
if any(s != OrderStatus.FILLED for s in statuses):
self.debug(f"Unfilled stop orders: {statuses}") Type guard
def all_stops_filled(algo) -> bool:
orders = algo.transactions.get_orders(lambda o: o.type is OrderType.STOP_MARKET)
return len(orders) > 0 and all(o.status == OrderStatus.FILLED for o in orders) Prevention
- Ensure the stop price is reachable in the backtest window.
- Confirm the scheduler's early-return guard is not skipping every bar.
- Keep extended_market_hours consistent with when stops should trigger.
- Log each stop ticket's status transitions for traceability.
When it happens
Trigger: Stop-market orders left SUBMITTED/PARTIALLY_FILLED/CANCELED because the market was closed at the stop price; the scheduler never placed orders (make_market_and_stop_market_order early-returned); fills happened but were registered under a different order type after symbol mapping.
Common situations: extended_market_hours flag missing so stops cannot trigger; stop price set beyond the data range for the backtest window; data gaps preventing the stop from being touched; mapping/rollover changing the ticket symbol so get_orders filter misses them.
Related errors
- The Exchange hours was closed, verify 'extended_market_hours
- [{UtcTime}] We hold a delisted securities: {string.Join(",",
- Expected at least two future contracts with option chains, b
- Expected 3 futures chains from history request, but got {his
- Expected {expected_chain_count} futures in chain on {date},
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/d2d726a3c0b22cdc.
Report an issue: GitHub.