binance-exchange/node-binance-api

"Account has insufficient balance for requested action."

markusstephanides opened this issue · 6 comments

Hello!

I'm trying to buy and sell assets with market orders but most of the time, it's not working and I get the error: "Account has insufficient balance for requested action.".

Even though I have enough balance to buy/sell. I even can perform the buy/sell on the website with the same amount.

What's the problem there?

Maybe related to quantity, hard to say. I would need to see the code calling the order

Yes it definitely is related to quantity. The bot buys in this example and this is how I calculate the quantity, how I send the order and how I calculate the correct lot size:

let amnt = binanceBalance / ask
amnt = roundStep(amnt, "ETHBTC");
amnt -= amnt * fees;
amnt = roundStep(amnt, "ETHBTC");

binance.marketBuy("ETHBTC", amnt, callback);

function roundStep(number, symbol){
    symbol = convFromSix(symbol);
    // get symbol step size
    let stepSize = 1;
    let prec = 0;
    exchangeInfos.symbols.forEach(sy => {
        if(sy.symbol === symbol) {
            stepSize = parseFloat(sy.filters[1].stepSize);
            prec = sy.baseAssetPrecision;
        }
    });
    let finalNumber = ((number / stepSize) | 0) * stepSize;
    finalNumber = parseFloat(finalNumber.toFixed(prec));
    return finalNumber
}

is binanceBalance your amount in BTC?
If it is let's pretend you have 1btc
ETH is currently .057354 btc
binanceBalance / .057354 = 17.4355
So for 1 btc you can afford 17.43 ETH which would come to a total of .99968 btc

Maybe instead of rounding the step you could try just using Math.floor for now

Yeah binanceBalance is my BTC balance.

Maybe instead of rounding the step you could try just using Math.floor for now

I'm not sure what you mean, can you show me an example?

I can't identify where exactly your code is messing up on the calculations, but you should double check the math so it matches the same numbers you punch in on the website

let amount = (binanceBalance / eth price).toFixed(2);
binance.marketBuy("ETHBTC", amount, callback);

This should work when called by itself, but I suspect roundstep is messing it up

Alright thanks I will look further into it.

EDIT: It's definitely a issue with binance and not your lib, thanks though!