I am working with an options spread strategy that sometimes sees short legs getting assigned before expiration. My code looks to see if I'm holding any position in an underlying and if so liquidates both the underlying and any options still held for that underlying. 

I've attached a demo project in which this works the way I expect. (The closing of assigned positions is handled in the Update of the alpha model.) The backtester shows a market order for 2100 shares of TRN right after assignment happens.

But when I try this in a "real" project, it's not working at all; I never see that order. In the Alpha Model's LiquidateEquity I added some details to try to see what's going on:

        private void LiquidateEquity(Symbol symbol, QCAlgorithmFramework algorithm)
        {
          var current_quantity = algorithm.Securities[symbol].Holdings.Quantity;
          var ordered_quantity = algorithm.Transactions.GetOpenOrders(symbol).Sum(o => o.Quantity);
          var order_direction = (current_quantity + ordered_quantity) > 0 ? OrderDirection.Sell : OrderDirection.Buy;
          var buying_power = algorithm.Portfolio.GetBuyingPower(symbol, order_direction);
            
          var target_quantity = 0 - (current_quantity + ordered_quantity);
          // algorithm.MarketOrder(symbol, target_quantity);
          // algorithm.RemoveSecurity(symbol);
          algorithm.SetHoldings(symbol, 0);
            
   algorithm.Log($"LIQUIDATING EQUITY {symbol} current qty {current_quantity} ordered qty {ordered_quantity} buying power {buying_power} target qty {target_quantity}");

        }
 

I see the log line "LIQUIDATING EQUITY TRN R735QTJ8XC9X current qty -2100 ordered qty 0 buying power 108984.05000000000000000000000 target qty 2100" so I know this code is getting hit. However, the backtester shows no order has been put in to close the position -- regardless of whether I use algorithm.SetHoldings, algorithm.MarketOrder, or algorithm.RemoveSecurity. It looks like I have plenty of buying power to close the position. 

I also have logging in the execution model that should alert me if there are any open orders for TRN, and I never see that line. So for some reason it doesn't look like the order has been submitted.

I know that the position hasn't been closed because further along I get margin calls on the open equity position. But there doesn't seem to be anything I can do to close it.

Any ideas?