When you close a position (fully or partially), these things happen:
System generates an order that is in the opposite direction of the first order you placed upon starting the position. The quantity of the order and its direction (buy or sell) depends on how much of the position you're closing and the direction of the position.
Once this order is filled, the proceeds from the sell are used to pay back what you borrowed. If the proceeds alone aren't enough to cover, system will use your real balance. When this happens, the portion of the balance used is your loss (negative P&L).
The position is marked as closed (if closed fully) and P&L is recorded accordingly.
Locate the position you want to close in Positions panel.
You will need to specify how much of the position you want to close. Enter the whole quantity of the position to close it all, or a smaller number to close just a part of it. P&L, used margin, and available margin will change accordingly.
Click Submit to confirm, or Dismiss to go back.