When a trade is open, its PnL (profit and loss) is unrealized, i.e. not yet deducted from or added to your balance.
When a trade is closed, unrealized PnL becomes realized, i.e. deducted from or added to your balance. All loans related to the trade are paid back to borrower. Trades can be closed partially.