If you do not have enough funds in your account denominated in the quote currency of the pair you are trading to cover any remaining loss, funds in your account will be converted, as necessary, into funds denominated in the quote currency of the pair you are trading, subject to a fee (a 1.5% fee for converting between two cash currencies), 2.5% fee for a conversion of BTC or ETH to or from cash, and a 5% fee for all other conversions). As a result, you may want to execute an order for the type and amount of funds you need before entering into a closing transaction so that your closing transaction does not result in a conversion fee.
Note: If you have multiple open positions on margin, they will be closed in the order they were created following the "First In, First Out" (FIFO) rule.
Each individual position will follow the logic outlined above for realizing any loss.