MARGIN_BUY does not execute the loan if you have funds

Testing with the parameter sideEffectType = MARGIN_BUY to open a short (borrow and sell) everything worked fine, the problem started after I transferred BTC from my spot wallet to margin since my margin wallet had funds and the loan stopped running That is, when executing the request with the side = SELL it takes the money from my margin wallet and sells it and if I have side = BUY it buys more BTC, if I remove the BTC from my margin wallet again, the sideEffectType = MARGIN_BUY with side = SELL works again, executing the loan and the subsequent sale; for the moment I had to go back to the old technique since I need to have BTC in my margin wallet to be able to trade in pairs against BTC and also in pairs against USDT this is the code that i am applying at the moment

await loan(symbols[symbol].baseAsset, quantity) 
var mkOrder = await marketOrder('MARGIN', symbol, 'SELL', quantity, null, null, d => console.log(d))

and this one doesn’t work if i have funds in my margin wallet, the loan is not executed

var mkOrder = await marketOrder('MARGIN', symbol, 'SELL', quantity, null, 'MARGIN_BUY', d => console.log(d))

Thanks for feedback, I had a try without any issue. However here is something might be helpful to debug.

1, did you borrow over the borrow limit?
2. what’s the error message, are you able to place the order from UI?


I have no error, I was trying to place a SELL MARKET order with MARGIN_BUY of $ 20 usdt, the problem is that the loan was not executed, but the request took the corresponding BTC from my margin wallet and sold them, that is, the loan was not executed. I loan if not that of my balance was sold.

I just executed the following request twice , as you can see in the first image my balance in usdt was $ 10 usdt, after executing the request twice my balance of usdt went up to $ 40 usdt, the first operation was $ 10 usdt and the second of $ 20usdt, but as you can see I decrease my BTC balance and there is no loan


If I empty the BTC wallet and make the same request again, the loan if it is executed, It is as if the system said why I give you BTC if you already have in your wallet, I better sell the ones you have in your wallet and that’s it

Do not worry change some number of the signature even so I already deleted it as you advise, returning to the subject we already know that the basis for opening a SHORT in binance is that you need to request a loan and later sell it and as it is already clear this does not work With the MARGIN_BUY if you have a balance in your wallet of the asset you want to borrow, so in order to open a short with a balance in my BTC wallet, the first thing I have to do is ask for a loan and then sell it as I mentioned at the beginning.

await loan(symbols[symbol].baseAsset, quantity) 
var mkOrder = await marketOrder('MARGIN', symbol, 'SELL', quantity, null, null, d => console.log(d))

thank you for the details, I would suggest to hide the signature in the post.
I see what do you mean, actually the margin_buy is only occur when you don’t have enough fund.
In this case, you are selling 0.001838 btc, and there are 0.05185691 BTC in your margin wallet, so there is no need to apply a loan even you set sideEffectType= MARGIN_BUY.

let’s say, I have 1 BTC in the margin wallet, and I want to sell 3BTC to USDT.

  1. you can call loan endpoint to borrow 2 BTC first, then place the sell order.
  2. you can place the margin order directly, but set ideEffectType= MARGIN_BUY, then the backend will automatically borrow 2BTC and place the order in one request.

But if you have 3 BTC in the wallet, when selling 1BTC, there will be no loan even you set ideEffectType= MARGIN_BUY.

Hope this will be helpful to understand.

It is already clear and the solution for what I want to do is what I mentioned earlier, make the loan and then sell and that if it works even having funds in my BTC wallet

1 Like