In order to start a margin trade, the trader must take up a loan, either in quote currency or base currency. Right before taking up a loan, the trader will send out a loan ask (a request for a loan). This will be matched with a loan bid (a loan offer from lenders). The matching results in a loan, in which loan amount is deducted from lender's balance and credited to borrower ("loan" transaction).
Interest ("interest transfer" transaction) and loan fee ("loan fee" transaction) are collected immediately after. Interest is calculated by multiplying loan amount with interest rate, both of which are determined by the lender. For every day as long as the trade is held open, interest is deducted from borrower's balance at 7AM JST*. Loan fee, on the other hand, is deducted from lender's balance, and is 50% of interest.
When the trade closes, loan amount is deducted from borrower's balance and credited back to lender ("repay" transaction).
*If a trade is opened before 7AM JST, borrower will pay interest twice - once at trade opening, once at 7AM JST.
To know how to lend your assets to margin traders, please see the For Liquidity Providers section.