{"record":{"id":"a9222f17754c2ad3","repo":"QuantConnect/Lean","slug":"unexpected-open-order-for-emitted-insight-order","errorCode":null,"errorMessage":"Unexpected open order for emitted insight: {order}","messagePattern":"Unexpected open order for emitted insight: (.+?)","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/EmitInsightNoAlphaModelAlgorithm.cs","lineNumber":87,"sourceCode":"\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            }\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>","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/EmitInsightNoAlphaModelAlgorithm.cs#L69-L105","documentation":"After asserting an order exists, this checks the order's Direction is Sell and its Symbol equals _symbol. The Down insight must produce a Sell order on the correct symbol. A mismatch means the PCM/Execution produced an order of the wrong direction (e.g. Buy for a Down insight) or for the wrong symbol.","triggerScenarios":"The PCM inverted the direction (Down insight -> Buy), or the order's symbol does not match _symbol due to canonical symbol mapping.","commonSituations":"PCM target-sign logic bug (negative insight -> positive target -> Buy); symbol canonicalization (e.g. mapped/equity mapping) changing the order symbol; insight direction enum handling change.","solutions":["Inspect the insight Direction and the resulting PCM target sign for consistency.","Compare the order.Symbol SID against _symbol to rule out canonical-symbol remapping.","Fix the PCM target calculation so a Down insight yields a Sell (negative target)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (order.Direction != OrderDirection.Sell || order.Symbol != _symbol)\n{\n    Log($\"Insight->order mismatch: insight=Down, order={order.Direction} sym={order.Symbol}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify PCM target-sign logic maps Down insights to negative targets (Sell).","Compare order.Symbol SID against the insight symbol to catch canonical remapping.","Add a unit test on the PCM for each InsightDirection."],"tags":["quantconnect","lean","regression-test","insights","portfolio-construction","order-direction","postcondition"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}