I am writing python code in an attempt to handle various errors that can arise on invoking an API for order placement. I was hoping to find information on what kind of errors can one expect. Obviously there are errors like timeouts , failure to establish connection and so on. I was thinking that these would eventually be a part of kiteconnect.exceptions.NetworkException but looks like I have to first handle the socket exception and then look at kitconnect - NetworkExceptions. Under what circumstances can we get kiteconnect - NetworkExceptions. It would be useful to have some documentation on this because reproducing network errors is hard. And I am assuming zerodha team would have more experience and so can share the knowledge with the users. Thanks for any inputs
except (kiteconnect.exceptions.NetworkException, kiteconnect.exceptions.DataException, requests.exceptions.ConnectionError): # Handle network exceptions it here
except kiteconnect.exceptions.InputException: # You get this when you have incorrect parameters such as zero in quantity
has worked for almost all cases of network errors and input errors, which are the only ones I've encountered so far, as far as I remember when placing orders. The team should be able to provide more insight
You can also refer to this function that I wrote to check if your order has been rejected on the server using order_id that is returned from the place_order() function, as they do get rejected due to various reasons at times https://pastebin.com/78vFELGp
Hi @rvsw, You can refer to the documentation for all the type of Kite Connect errors and the syntax of the same.
You may come across, TokenException, InputException, NetworkException, DataException, GeneralException. Basically, check for status code 200 from order place response. If you get anything else then check orderbook and then retry otherwise you might end up placing two orders.
Thank you @rishiswethan for providing the code. Thank you @sujith also. However, the documentation you refer to only provides the class of exceptions, not the exception messages within every class of exception. For example, today I got an exception stating that guide could not retrieve the order status of a given order ID. However, I could see that the order was properly placed. so now I need to find a way on what to do if we get a message that the order status could not be retrieved. It would have been better if the documentation also included each exception that is generated within a given class and also describe what circumstances would lead to that kind of an exception being generated. That would enable the developers to handle various exceptions instead of finding it out by experience.
PS: before I got a message that the order status could not be retrieved, I got a Kite network exception twice followed by a successful order status check followed by an unsuccessful order status check.
if threading is enabled there are chances first thread might read status as "error" and when second thread was reading the order status it would have found that order is placed...... Threading is tricky at times....
except (kiteconnect.exceptions.NetworkException, kiteconnect.exceptions.DataException, requests.exceptions.ConnectionError):
# Handle network exceptions it here
except kiteconnect.exceptions.InputException:
# You get this when you have incorrect parameters such as zero in quantity
has worked for almost all cases of network errors and input errors, which are the only ones I've encountered so far, as far as I remember when placing orders. The team should be able to provide more insight
You can also refer to this function that I wrote to check if your order has been rejected on the server using order_id that is returned from the place_order() function, as they do get rejected due to various reasons at times
https://pastebin.com/78vFELGp
You can refer to the documentation for all the type of Kite Connect errors and the syntax of the same.
You may come across, TokenException, InputException, NetworkException, DataException, GeneralException. Basically, check for status code 200 from order place response. If you get anything else then check orderbook and then retry otherwise you might end up placing two orders.
so now I need to find a way on what to do if we get a message that the order status could not be retrieved. It would have been better if the documentation also included each exception that is generated within a given class and also describe what circumstances would lead to that kind of an exception being generated. That would enable the developers to handle various exceptions instead of finding it out by experience.
PS: before I got a message that the order status could not be retrieved, I got a Kite network exception twice followed by a successful order status check followed by an unsuccessful order status check.
Threading is tricky at times....