There are several ways your trade may be closed out:
In most cases closeout occurs naturally at the maturity of the transaction. Borrower pays out the interest and the loan, and receives back the full collateral bar the applicable fees.
Smart Contract may close out your transaction automatically should the market value of the collateral fall significantly and become insufficient to cover the loan. Your collateral will be transferred to the counterparty to cover the loan amount and you will receive any excess collateral after the deduction of loan amount and any applicable fees.
If you are a borrower, your transaction may be closed out automatically should you default on your obligations (e.g. do not pay out the loan in time). In this case your collateral will be transferred to lender to cover the loan and the applicable interest and fees and you will receive any excess amount left.