'binance Order would immediately trigger

Hello I Try To Create An order by type STOP_MARKET in binance future It's My Code :



from binance.client import Client


api_key = '#'
api_secret = '#'


if __name__ == "__main__":

    client = Client(api_key, api_secret)

    price = round(float(client.get_avg_price(symbol='ETHUSDT')['price']), 2)

    stop_percent = 5/20
    target_percent = 15/20

    stopPrice = round(price - (price * (stop_percent / 100)), 2)

    result = client.futures_create_order(
        symbol='ETHUSDT',
        side='BUY',
        type='STOP_MARKET',
        quantity=0.04,
        stopPrice=stopPrice,
    )


    print(f'result : {result}')

but I Get This Error :

APIError(code=-2021): Order would immediately trigger.

Simple Market Order By This Quantity And Client It's Working Please Help Me .



Solution 1:[1]

This error normally means that your stopPrice is lesser than the price of your coin. I think the issue you are having is with rounding your prices.

you need to use binance round helper to round your price according to step size.

from binance.helpers import round_step_size 

sym = (client.get_symbol_info(symbol='ETHUSDT'))
tick=float(sym["filters"][0]["tickSize"])
#price = float(client.get_symbol_ticker(symbol='ETHUSDT')["price"])

price = float(client.get_avg_price(symbol='ETHUSDT')['price'])
stop_percent = 5/20
target_percent = 15/20
stopPrice = round_step_size(price - (price * (stop_percent / 100)), tick)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eno