A leveraged margin position is a spot trade executed through an advance financed by Kraken. For example, a long XBT/EUR position is opened by advancing the trader EUR to buy XBT in a spot trade. And a short XBT/EUR position is opened by advancing the trader XBT to sell for EUR in a spot trade. To close the position, the funds advanced to the trader must be returned to Kraken.
One way to return the funds and close the position is by executing an opposing trade to acquire the advanced asset from the market (a sell order to close a long position or a buy order to close a short position).
For example, suppose you buy 1 XBT of XBT/EUR at 2:1 leverage. To close the entire position, you sell 1 XBT of XBT/EUR (at any leverage). To close half the position, you sell 0.5 XBT of XBT/EUR (at any leverage). Note that the closing leverage does not need to match the opening leverage, but it does need to be a leveraged order to close a position. Be careful that you don’t execute a closing order for more volume than your position, since this will create a new leveraged position on the opposite side (unless this is what you want to do).
Please note: If you have multiple positions, they will be closed in the order they were created following the "First in First Out" (FIFO) rule.
Another way is to return the advanced funds directly from the trader’s account balance with no trade involved - this is position settlement.