How to COMPLETELY repay borrowed asset on Cross Margin acc using sideEffectType=AUTO_REPAY?

Hello,

I will appreciate help regarding the problem I have with this endpoint on Margin account:
POST /sapi/v1/margin/order

The issue is that POST will not completely repay all borrowed+interest asset in spite of positive netAsset balance. Example:

STATUS before POST

"asset": "AVAX",
"free": "0.03518132",
"locked": "0",
"borrowed": "2.67772132",
"interest": "0.00004144",
"netAsset": "-2.64258144"

POST (/sapi/v1/margin/order) symbol=AVAXUSDT&side=BUY&type=MARKET&quantity=2.65&sideEffectType=AUTO_REPAY&timestamp=1715052885689 (notice AUTO REPAY!!!)

RESPONSE PAYLOAD

"symbol": "AVAXUSDT",
"orderId": XXX,
"clientOrderId": "XXX",
"transactTime": 1715052885880,
"price": "0",
"origQty": "2.65",
"executedQty": "2.65",
"cummulativeQuoteQty": "97.361",
"status": "FILLED",
"timeInForce": "GTC",
"type": "MARKET",
"side": "BUY",
"fills": [
    {
        "price": "36.74",
        "qty": "2.65",
        "commission": "0.00265",
        "commissionAsset": "AVAX",
        "tradeId": XXX
    }
],
"isIsolated": false,
"selfTradePreventionMode": "EXPIRE_MAKER"

STATUS PAYLOAD (there is(was) enough of free AVAX to repay * but it was not repaid completely !!!)

"asset": "AVAX",
"free": "0.03518132",
"locked": "0",
"borrowed": "0.03041276",
"interest": "0",
"netAsset": "0.00476856"

POST to /sapi/v1/margin/borrow-repay after that, specifying the amount to be repaid (borrowed + insterest), will repay all debts as it is supposed to.

Question is does sideEffectType=AUTO_REPAY work as intended or am I feeding it with the wrong data? I have calculated the amount I need to buy (borrowed+interest+fee and lot size filter). In the example above that is 2.65.

Fall back to simple 2 stage BUY + REPAY seems more convenient.

JFTR, I am trying all this on sub account.

Cheers!

(buy amount - comission) - (borrow + interest) = balance
(2.65 - 0.00265) - (2.67772132 + 0.00004144) = -0.03041276 debit balance

you have to pay (borrow + interest + comission) to settle the account, in this case

comission = (2.67772132 + 0.00004144) * 0.001 = 0.00267776276
total to pay = 2.67772132 + 0.00004144 + 0.00267776276 = 2.68044052276

if your lotsize is 0.01 you would have to round the number up having to buy 2.69usdt to settle your account

Thank you Saratoga, much appreciated!

In my first attempt the calculation was how much base asset I have to buy to have enough to repay the debt based on “netAsset” and “free” asset on the account. I guess “free” asset on cross margin account does not matter when it comes to AUTO REPAY.