sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
5.91k stars 2.19k forks source link

Binance Futures API: Error executing order with code -4003 "Quantity less than zero" #1308

Open Sikani1 opened 1 year ago

Sikani1 commented 1 year ago

I'm encountering an issue when placing orders using the Binance Futures API in Python. I'm trying to place an order using the python-binance library, but I keep receiving the error 'APIError(code=-4003): Quantity less than zero.' I have calculated the order quantity based on the current price and the amount I want to trade. I have also rounded the quantity before placing the order, but I still receive the error. I believe my code adheres to the Binance API documentation, but the error persists. Here's the error: 'Calculated quantity for ETHUSDT: 0.0109421162052741 Error executing ETHUSDT BUY order: APIError(code=-4003): Quantity less than zero.'

Could anyone please help me understand what might be causing this issue and suggest a solution? Thank you in advance for your assistance! Find below the code snippet

async def create_market_order(symbol, side, quantity): try: quantity = round(quantity) order = await client.futures_create_order( symbol=symbol, side=side, type=ORDER_TYPE_MARKET, quantity=quantity, newClientOrderId=f'hma_scalpingstrategy{int(time.time())}' ) print(f"{symbol} order {side} executed at {order['avgPrice']}") except BinanceAPIException as e: print(f"Error executing {symbol} {side} order: {e}")

sirfrank commented 1 year ago

i guess here is the problem : quantity = round(quantity)

you need to get quantity precision from API first to make the quantity to be precise enough

Sikani1 @.***> ezt írta (időpont: 2023. ápr. 5., Sze, 0:32):

I'm encountering an issue when placing orders using the Binance Futures API in Python. I'm trying to place an order using the python-binance library, but I keep receiving the error 'APIError(code=-4003): Quantity less than zero.' I have calculated the order quantity based on the current price and the amount I want to trade. I have also rounded the quantity before placing the order, but I still receive the error. I believe my code adheres to the Binance API documentation, but the error persists. Here's the error: ' Calculated quantity for ETHUSDT: 0.0109421162052741 Error executing ETHUSDT BUY order: APIError(code=-4003): Quantity less than zero.'

Could anyone please help me understand what might be causing this issue and suggest a solution? Thank you in advance for your assistance! Find below the code snippet

async def create_market_order(symbol, side, quantity): try: quantity = round(quantity) order = await client.futures_create_order( symbol=symbol, side=side, type=ORDER_TYPE_MARKET, quantity=quantity, newClientOrderId=f'hma_scalpingstrategy{int(time.time())}' ) print(f"{symbol} order {side} executed at {order['avgPrice']}") except BinanceAPIException as e: print(f"Error executing {symbol} {side} order: {e}")

— Reply to this email directly, view it on GitHub https://github.com/sammchardy/python-binance/issues/1308, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVKGM6VKIYXU3TC2PT5NSLW7SOO3ANCNFSM6AAAAAAWTJ2FFM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Sikani1 commented 1 year ago

Thanks for your input but I noticed the code can only take futures trade in full contracts and not in fractions e.g. BNBUSDT, LTCUSDT, XRPUSDT etc all are successfully executed without the error but making a BUY entry of fractions BTCUSDT/ETHUSDT results in the Quantity less than zero error. I employ leverage of 50x, Buy_Quantity = 300, Order_Precision = 8