How to catch this exception? APIError(code=-2010): Stop price would trigger immediately.

Hi there, so i’m getting this error sometimes, yes i know is becasue the price probably changed before the order was processed and sent to the server, the thing is i’d like to CATCH this specific exception to re-make the order and re-send it, but documentation says that “create_order” can raise: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException

I don’t known which one is the right one for this particular error, obviously not “BinanceOrderMinAmountException” or ones which name is pretty much self-explanatory, so it must be some of these: BinanceRequestException, BinanceAPIException, BinanceOrderException (i think), anyone knows?

Thanks!

Hey @mayhem7, Binance is not responsible for python-binance and we’re not updated with its code, you’ll probably get more help if the question is redirected to the community of the library.

1 Like

Better 1 year late than never.
I have the same problem, and the answer to this particular error is BinanceAPIException.
The thing is that you should first import it:
–>from binance.exceptions import BinanceAPIException
than you can follow the code here:
https://python-binance.readthedocs.io/en/latest/exceptions.html
here is my code for reference:

from binance.client import Client
from binance.exceptions import BinanceAPIException
try:
stop_loss_order = client.create_order(symbol=data2[‘symbol’], side=data2[‘toposite_side’], type=“STOP_LOSS_LIMIT”,quantity=data2[‘amount’], stopPrice=data2[‘loss’], price=data2[‘loss’],timeInForce=‘GTC’)
print(stop_loss_order)
except BinanceAPIException as e:
print(e.status_code)
print (e.message)

and of course in order to run this one should fill data2 dictionary :slightly_smiling_face: