How can I fix the "Order would immediately trigger" error in binance

Sometimes when trading small-cap altcoins on Binance Futures, you might have faced the Order would immediately trigger error.

According to my research, this error occurs when the order price that your strategy submits (for example in the case of a long trade) is above the current price which would cause a STOP order, but the moment that order reaches Binance the price has changed and that order would get executed (or triggered as Binance's error mentions) but unfortunately, Binance's API decides to throw an error instead of executing the order as a MARKET order.

What is the fix?

This is one way I have come up with to solve this issue. We need to make sure that if our order is a STOP order (meaning that the order-price is above the current price), it is far away enough from the current price so that if the price moves up until the moment our order hits Binance, our order price would still be valid. And if it's not far enough, we might as well submit a MARKET order in the first place so Binance won't have anything to complain about.

You might be asking but how do I submit a MARKET order with Jesse? The answer is when the order price equals the current price, Jesse (behind the scenes) decides to submit a MARKET order.

Here's an example code:

def go_long(self):
    # in your strategy you will calculate this, but for the sake of this example, let's consider 100
    order_price = 100

    # if the difference between the order_price and current_price is less than 0.5%, just use
    # the current_price instead which will cause a MARKET order. You can of course use any other
    # number instead of the 0.5%
    if abs(order_price - self.price) / self.price * 100 < 0.5:
        order_price = self.price
Last updated: 2 years ago