{"record":{"id":"195420b1e802f788","repo":"QuantConnect/Lean","slug":"there-should-be-no-open-orders","errorCode":null,"errorMessage":"There should be no open orders","messagePattern":"There should be no open orders","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs","lineNumber":188,"sourceCode":"            if (!_optionDelistedWarningReceived)\n            {\n                throw new RegressionTestException(\"Option delisting warning was not received\");\n            }\n\n            if (!_optionDelisted)\n            {\n                throw new RegressionTestException(\"Option was not delisted\");\n            }\n\n            if (!_orderCanceled)\n            {\n                throw new RegressionTestException(\"Order was not canceled\");\n            }\n\n            var openOrders = Transactions.GetOpenOrders();\n            if (openOrders.Count != 0)\n            {\n                throw new RegressionTestException(\"There should be no open orders\");\n            }\n\n            if (!Portfolio.Invested)\n            {\n                throw new RegressionTestException(\"Portfolio should be invested\");\n            }\n\n            // We should have the stock since the option was assigned\n            if (Portfolio.Positions.Groups.Single().Single().Symbol != _stock)\n            {\n                throw new RegressionTestException(\"Portfolio should have the stock\");\n            }\n        }\n\n        /// <summary>\n        /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.\n        /// </summary>\n        public bool CanRunLocally { get; } = true;","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs#L170-L206","documentation":"Asserts that after the full lifecycle there are no open orders: Transactions.GetOpenOrders().Count == 0. The delisting/cancellation should have cleared all orders. A non-empty open-orders list means an order was left dangling.","triggerScenarios":"An order remains open because it was not filled and not canceled, or the delisting-driven cancellation did not cover it.","commonSituations":"New order type not handled by the delisting cancel sweep; a partial fill left a residual open order; cancellation logic scoped to the wrong symbol.","solutions":["Log the contents of GetOpenOrders() to identify the dangling order(s) and their status.","Confirm the delisting/cancel sweep in the TransactionHandler cancels orders for the delisted symbol.","Ensure the test's own logic does not submit an order that is never resolved."],"exampleFix":"// before\nvar openOrders = Transactions.GetOpenOrders();\nif (openOrders.Count != 0)\n{\n    throw new RegressionTestException(\"There should be no open orders\");\n}\n\n// after\nvar openOrders = Transactions.GetOpenOrders();\nif (openOrders.Count != 0)\n{\n    throw new RegressionTestException(\n        $\"There should be no open orders. Open: {string.Join(\", \", openOrders)}\");\n}","handlingStrategy":"validation","validationCode":"var openOrders = Transactions.GetOpenOrders();\nif (openOrders.Count > 0)\n{\n    foreach (var o in openOrders) Log($\"Open order remains: {o.Symbol} {o.Type} {o.Quantity} status={o.Status}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include the open-order details in the assertion message.","Ensure the delisting-driven cancel sweep covers every open order symbol.","Avoid leaving the algorithm with partially-filled orders."],"tags":["quantconnect","lean","regression-test","orders","postcondition","cleanup"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}