I have code that loops over open tickets, and I want to close a particular position. All the examples I found show the use of setHoldings. How do I close a particular position?

 

// All filled orders

var tickets = Transactions

     .GetOrderTickets(x => x.Status == OrderStatus.Filled);

//loop over order tickets

     foreach (OrderTicket ticket in tickets) {

                      //what is the code to flatten the order here?

}