Incomplete repayment with AUTO_REPAY

Hi,

I am having an issue with my bot trading on isolated margin accounts. I have done some debugging and I think it might be a problem on the binance side (but I might be wrong).

Sometimes, when closing a short position using a market buy order with “AUTO_REPAY”, the original loan is not repaid fully, but only part of it.

Here is a recent example. I am reporting screenshots from my binance history pages of the initial borrow+sell order and of the repayment+buy order. I can only post one image as I am a new user, so bear with me for this collage.

This is the initial borrow from the Borrowing history

As you can see, I am buying 2148 VITE in the VITE/USDT isolated account, but only ~1931 get repaid.

Because the repayment is incomplete, the account is left with some amount still shown as borrowed, triggering a bunch of errors in my code.

One idea I have is that it just takes some time for the repayment to complete and I should wait longer. Is that possible, or is there a bug from the binance side?

What’s the best way to check the repayment has gone through?

Hi @pistello, are you sure you had enough amount for the full repayment?
If you think your calculation looks right, I would recommend reaching out to the customer support on Binance’s website for a more detailed research and analysis, as we’re limited on this side because don’t have access to user’s data and trading history.

I have done further investigation into this issue and I have noticed that it can take some time for the loan to get repaid after the “AUTO_REPAY” order gets sent.

So, I think I might have an answer and I leave it here in case it may help anyone in the future. My bot was clearing any remaining quote and base currency from the isolated margin account after 30 seconds, but it was not checking if the loan repayment had gone through. Now I am clearing the account only after the borrowed amount gets changed to zero and I have not seen the issue appearing again so far.

1 Like

I am having the same problem but with the repay (/sapi/v1/margin/repay), generally the amount that remains to be paid is similar to the interest, I reviewed my code thinking that an error occurred when consulting the interest or that at the time of calculating the total interest would be wrong but there is no error, and yes, I do have a sufficient balance since I do the repay operation after a purchase operation for a much larger amount than the amount lent, here is part of the code

marketOrder(this.account.toUpperCase(), this.kl.symbol, 'BUY', qty, null, 'MARGIN_BUY').then(order => {
                    if(this.borrowed) {                    
                        this.interest *= Math.ceil((order.transactTime - this.market.ctime) / intervals['1h'].ms) || 1
                        this.borrowed = (this.borrowed + this.interest).fix(8)
                        repay(this.baseasset, this.borrowed, this.account != 'cross' ? this.kl.symbol : null)
                    }

I just need you to confirm if what you say about the delay in payment is correct, so even though it has already been paid, the system still takes time to apply the payment or if the repay charges a commission and that is why the payment is not made in full ?

I had the same problem, and I figured out two causes:
1.- You have to add the binance fee to your buy order, because when you buy binance substracts you the fee from the order amount, otherwise you will not have enough funds to repay the debt.
2.- When the auto repay cannot be done (ie. point 1, you not have funds enough), binance repays only 90% of the debt (found here How to Use the One-Click Borrow & Repay Function | Binance), which matches your history (2145.8*0.9 = 1931)