Account has insufficient balance for requested action

Hello Everyone.
I’m having some issues when selling through the API.
I buy some coin and when i’m going to sell, it won’t.

BUY:
Request sent: timestamp=1617848998979&symbol=OGNUSDT&side=BUY&type=MARKET&quoteOrderQty=100

Response Received:

10:29:59 - {
“symbol”: “OGNUSDT”,
“orderId”: 121352258,
“orderListId”: -1,
“clientOrderId”: “5U48bLYkcScWqzEX9e8PHw”,
“transactTime”: 1617848998873,
“price”: “0.00000000”,
“origQty”: “30.61000000”,
“executedQty”: “30.61000000”,
“cummulativeQuoteQty”: “99.97220900”,
“status”: “FILLED”,
“timeInForce”: “GTC”,
“type”: “MARKET”,
“side”: “BUY”,
“fills”: [
{
“price”: “3.26480000”,
“qty”: “1.64000000”,
“commission”: “0.00164000”,
“commissionAsset”: “OGN”,
“tradeId”: 10987866
},
{
“price”: “3.26490000”,
“qty”: “3.09000000”,
“commission”: “0.00309000”,
“commissionAsset”: “OGN”,
“tradeId”: 10987867
},
{
“price”: “3.26520000”,
“qty”: “4.80000000”,
“commission”: “0.00480000”,
“commissionAsset”: “OGN”,
“tradeId”: 10987868
},
{
“price”: “3.26530000”,
“qty”: “4.00000000”,
“commission”: “0.00400000”,
“commissionAsset”: “OGN”,
“tradeId”: 10987869
},
{
“price”: “3.26670000”,
“qty”: “17.08000000”,
“commission”: “0.01708000”,
“commissionAsset”: “OGN”,
“tradeId”: 10987870
}
]
}

Now, as you can see, the executedQty value is 30.61000000

SELL:
Request sent:
timestamp=1617869890597&symbol=OGNUSDT&side=SELL&type=MARKET&quantity=30.61

Response Received:
04:18:10 - {“code”:-2010,“msg”:“Account has insufficient balance for requested action.”}
04:18:10 - {“code”:-2010,“msg”:“Account has insufficient balance for requested action.”}

So my question is, why does this happens? I’m requesting to sell the same ammount that i bought.

What am i missing here? Can anyone point me in the right direction?

Thanks in advance

You need to take into account maker/taker fees. Multiply the amount by 0.999 or something.

However, I’m just about to post a question about this too, because I’m getting this error so much when placing consecutive limit buys.

Thanks a lot for your answer. I’ll check that, but it not always happens. Sometimes, the executedQty value is used when the sell takes place and there’s no error.

Anyway i’ll change the code so it can try several times with lower quantities.

Thanks again!

Ah yeah then you’re having the same issue I am then. Are you trying to place multiple orders on the same ticker in rapid succession? For some reason I’m getting errors with this too - only solution I have at the moment is to try the same order 50 times; which sucks because it prohibits high frequency trading.

Depends on what succession means. The operation time difference could be 40 seconds to 10 minutes appart (buy - sell).
That, for me, is not high frequency trading at all. It should not fail.
I changed the code, now i substract 0.1% from de quantity and try again. If it doesnt work it does it again, just 3 times. I’,m waiting for a buy / sell to occur.

It worked with 0.1% less

BUY:
Request:
timestamp=1617870518562&symbol=ENJUSDT&side=BUY&type=MARKET&quoteOrderQty=100
Response:
04:28:39 - {
“symbol”: “ENJUSDT”,
“orderId”: 320745295,
“orderListId”: -1,
“clientOrderId”: “Vf4nn9LutfvkUwgFWDgqbN”,
“transactTime”: 1617870518529,
“price”: “0.00000000”,
“origQty”: “33.50000000”,
“executedQty”: “33.50000000”,
“cummulativeQuoteQty”: “99.91743500”,
“status”: “FILLED”,
“timeInForce”: “GTC”,
“type”: “MARKET”,
“side”: “BUY”,
“fills”: [
{
“price”: “2.98261000”,
“qty”: “33.50000000”,
“commission”: “0.03350000”,
“commissionAsset”: “ENJ”,
“tradeId”: 25445075
}
]
}

Quantity according to buy: “executedQty”: “33.50000000”,

SELL: 1st Attempt
Request: timestamp=1617882749849&symbol=ENJUSDT&side=SELL&type=MARKET&quantity=33.5

Response:
Connection: keep-alive
Date: Thu, 08 Apr 2021 11:52:29 GMT
Server: nginx
x-mbx-uuid: 0335be3f-735d-4c8f-9e0a-35a24d4e2ea0
x-mbx-used-weight: 210
x-mbx-used-weight-1m: 210
x-mbx-order-count-10s: 1
x-mbx-order-count-1d: 41
Strict-Transport-Security: max-age=31536000; includeSubdomains
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Content-Security-Policy: default-src ‘self’
X-Content-Security-Policy: default-src ‘self’
X-WebKit-CSP: default-src ‘self’
Cache-Control: no-store, must-revalidate, no-cache
Pragma: no-cache
X-Cache: Error from cloudfront
Via: 1.1 d46b7521718ba1ecd6db2ceb1c50f1f8.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: SCL50-C1
X-Amz-Cf-Id: mYS3HhpcZi8kLtxcZHt5kW1oVxXaY6irxaiupJthNBkBYIDJqBmlZg==
Content-Type: application/json; charset=UTF-8
Content-Length: 77
Expires: 0

07:52:30 - {“code”:-2010,“msg”:“Account has insufficient balance for requested action.”}
07:52:30 - {“code”:-2010,“msg”:“Account has insufficient balance for requested action.”}

SELL Second Attempt:
Request: timestamp=1617882750834&symbol=ENJUSDT&side=SELL&type=MARKET&quantity=33.4

Response:
07:52:31 - {
“symbol”: “ENJUSDT”,
“orderId”: 321747143,
“orderListId”: -1,
“clientOrderId”: “mSXDaGS1A4bSOqT2hn1ABt”,
“transactTime”: 1617882750641,
“price”: “0.00000000”,
“origQty”: “33.40000000”,
“executedQty”: “33.40000000”,
“cummulativeQuoteQty”: “101.42678200”,
“status”: “FILLED”,
“timeInForce”: “GTC”,
“type”: “MARKET”,
“side”: “SELL”,
“fills”: [
{
“price”: “3.03673000”,
“qty”: “32.80000000”,
“commission”: “0.09960474”,
“commissionAsset”: “USDT”,
“tradeId”: 25600609
},
{
“price”: “3.03673000”,
“qty”: “0.60000000”,
“commission”: “0.00000345”,
“commissionAsset”: “BNB”,
“tradeId”: 25600610
}
]
}

So Harry, your workaround worked. I’m marking your response as a solution to this, but the real issue for me is still unknown.

Thanks a lot!

Hey,

It seems the issue is that you are not taking into consideration the commission you are paying, which is in the same currency of the bought coin.

The commissions get taken out of the executed quantity, so you can’t sell the exact amount you asked to buy because you don’t have that much. This is why you get the message saying you have sufficient balance to sell.

That’s why when you are multiplying by 0,99(or something like that) before selling, you have enough balance to sell.

The other option is to have enough BNB on your spot wallet to pay fees in BNB, rather than in the bought asset.

The solutions:
1 - Calculate how much balance you really have after paying the fees by looking into the fills array (executed - commission), or query your SPOT wallet for your balance after buying or before selling.
2 - Have BNB on your SPOT wallet to pay for the transaction fees. You pay smaller fees and also you always get the same balance of the bought coin as the executed qty.

I hope this helps :slight_smile:

I have BNB in my account.

and I am trying to sell ALCX sell still get the error.

binance.exceptions.BinanceAPIException: APIError(code=-2010): Account has insufficient balance for requested action.

I am trying to market sell .

order = client.order_market_sell(
    symbol="ALCXBUSD",
    quantity=100
)

I even try to decrease the quantity. still get the error.