create_order buys slightly different number of coins

Hi, can anyone help me to solve this issue?

Currently, when I buying a coin, my bot purchase approximately 10 USDT worth of coin, following format of the lot size.

For example, lot size of MTL is 1, so when buying MTLUSDT, I create an order to buy 8.1 MTL(which is worth around $10.1).

buy_market = client.create_order(symbol='MTLUSDT', side='BUY', type='MARKET', quantity=8.1)

If I print buy_markey['origQty'], it says 8.1 of MTL was bought

But I check on Binance app, 8.0919 was bought. This kind of issue happens all the time. So when my bot try to sell them like

sell_market = client.create_order(symbol='MTLUSDT', side='SELL', type='MARKET', quantity=8.1)

it always throws an error saying insufficient balance to perform the action.

can anyone help me to solve this issue?

Thanks

You should check the response returned from the server after you placed to order to confirm if the quantity is 8.1. If you want to place an order of 10USDT, you can use parameter quoteOrderQty instead of quantity. Not really sure about the library you are using, but here is an official package from Binance: GitHub - binance/binance-connector-python: a simple connector to Binance Public API

1 Like

Thanks but using quoteOrderQty won’t solve my current problem.

When my bot buys coins it updates portfolio hashmap like this:
portfolio = {‘XMRUSDT’: 0.072}, so when I want to sell I can create an order like

client.create_order(symbol='XMRUSDT', side='SELL', type='MARKET', quantity=portfolio['XMRUSDT'])

But it if I create an order to buy 0.072, it actually buys 0.07189. So I have to sell 0.071(because of lot sizes). Then 0.00089 of XMR being left unsellable. So every trade, leftover is being created.

Is there any way to solve this problem?
Thanks

Okay, so i don’t know reason why, but this bug magically just disappeared today. Now the same line of code

buy_market = client.create_order(symbol='MTLUSDT', side='BUY', type='MARKET', quantity=8.1)
exactly buy 8.1 not 8.0919. Tested with others and the problem doesn’t happen any more.