{"record":{"id":"db9c0a446b878d90","repo":"QuantConnect/Lean","slug":"expected-open-order-for-emitted-insight","errorCode":null,"errorMessage":"Expected open order for emitted insight","messagePattern":"Expected open order for emitted insight","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/EmitInsightNoAlphaModelAlgorithm.cs","lineNumber":82,"sourceCode":"        public override void OnData(Slice slice)\n        {\n            if (!Portfolio.Invested)\n            {\n                var order = Transactions.GetOpenOrders(_symbol).FirstOrDefault();\n\n                if (order != null)\n                {\n                    throw new RegressionTestException($\"Unexpected open order {order}\");\n                }\n\n                EmitInsights(Insight.Price(_symbol, Resolution.Daily, 10, InsightDirection.Down));\n\n                // emitted insight should have triggered a new order\n                order = Transactions.GetOpenOrders(_symbol).FirstOrDefault();\n\n                if (order == null)\n                {\n                    throw new RegressionTestException(\"Expected open order for emitted insight\");\n                }\n                if (order.Direction != OrderDirection.Sell\n                    || order.Symbol != _symbol)\n                {\n                    throw new RegressionTestException($\"Unexpected open order for emitted insight: {order}\");\n                }\n\n                SetHoldings(_symbol, 1);\n            }\n        }\n\n        public override void OnEndOfAlgorithm()\n        {\n            var holdings = Securities[_symbol].Holdings;\n            if (Math.Sign(holdings.Quantity) != -1)\n            {\n                throw new RegressionTestException(\"Unexpected holdings\");\n            }","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/EmitInsightNoAlphaModelAlgorithm.cs#L64-L100","documentation":"After EmitInsights(Insight.Price(... Down)), the test asserts an open order now exists for _symbol. The Portfolio Construction Model must have converted the emitted insight into an order. If GetOpenOrders returns null/empty, the insight-to-order pipeline did not produce an order, indicating the PCM did not react to the insight.","triggerScenarios":"The Portfolio Construction Model ignored the insight (wrong direction handling, zero target weight), or the insight was filtered/dropped before reaching the PCM. Insight magnitude/closedTime invalid.","commonSituations":"A custom or default PCM that does not act on InsightDirection.Down; the Execution model not immediately creating a market order; insight validation rejecting the insight.","solutions":["Check which Portfolio Construction Model is set and confirm it emits targets for the insight direction.","Inspect the insight (symbol, direction, period, magnitude) for validity that the PCM requires.","Trace the insight through InsightManager -> PCM -> Execution to find where it was dropped."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before asserting an order exists, validate the insight would drive one\nvar pcm = PortfolioConstruction as IPortfolioConstructionModel;\nif (pcm == null) Log(\"No Portfolio Construction Model set; insight will not produce an order\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Confirm a Portfolio Construction Model is set that reacts to the insight direction.","Validate the insight (direction, period, symbol) before expecting an order.","Trace insight -> PCM -> Execution once to confirm the wiring."],"tags":["quantconnect","lean","regression-test","insights","portfolio-construction","alpha","postcondition"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}