{"record":{"id":"d2d726a3c0b22cdc","repo":"QuantConnect/Lean","slug":"the-algorithms-was-not-handled-any-stopmarketorder","errorCode":null,"errorMessage":"The Algorithms was not handled any StopMarketOrders","messagePattern":"The Algorithms was not handled any StopMarketOrders","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/FutureStopMarketOrderOnExtendedHoursRegressionAlgorithm.py","lineNumber":70,"sourceCode":"    # An order fill update the resulting information is passed to this method.\n    def on_order_event(self, order_event: OrderEvent) -> None:\n        if self.transactions.get_order_by_id(order_event.order_id).type is not OrderType.STOP_MARKET:\n            return None\n\n        if order_event.status == OrderStatus.FILLED:\n            # Get Exchange Hours for specific security\n            exchange_hours = self.market_hours_database.get_exchange_hours(self._sp_500_e_mini.subscription_data_config)\n\n            # Validate, Exchange is opened explicitly\n            if (not exchange_hours.is_open(order_event.utc_time, self._sp_500_e_mini.is_extended_market_hours)):\n                raise AssertionError(\"The Exchange hours was closed, verify 'extended_market_hours' flag in Initialize() when added new security(ies)\")\n\n    def on_end_of_algorithm(self) -> None:\n        self.stop_market_orders = self.transactions.get_orders(lambda o: o.type is OrderType.STOP_MARKET)\n\n        for o in self.stop_market_orders:\n            if o.status != OrderStatus.FILLED:\n                raise AssertionError(\"The Algorithms was not handled any StopMarketOrders\")\n","sourceCodeStart":52,"sourceCodeEnd":71,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/FutureStopMarketOrderOnExtendedHoursRegressionAlgorithm.py#L52-L71","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Before on_end_of_algorithm, summarise stop order statuses\nstatuses = [o.status for o in self.transactions.get_orders(lambda o: o.type is OrderType.STOP_MARKET)]\nif any(s != OrderStatus.FILLED for s in statuses):\n    self.debug(f\"Unfilled stop orders: {statuses}\")","typeGuard":"def all_stops_filled(algo) -> bool:\n    orders = algo.transactions.get_orders(lambda o: o.type is OrderType.STOP_MARKET)\n    return len(orders) > 0 and all(o.status == OrderStatus.FILLED for o in orders)","tryCatchPattern":null,"preventionTips":["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."],"tags":["quantconnect","futures","stop-market-order","order-status","regression-test","scheduler"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}