hi all, please have a look at below. P.S psudo code.intention is not to ask coding suggestion but to understand kite.place_order() function behaviour. while True: try: orderid = kite.place_order() break except Exception as e print(e) anything wrong in this code ? intention here is that if kite.placeorder is successful it will breakout and if its unsuccessful it will again try. Reason to ask this question is that i am not sure about api errors and is there any possibility of api to throw a error and still order gets through ? if its true than this logic has a possibility of Failing but if we kite throws a exception in place_order means no order is placed than this logic seems perfect to me
@pawan12, Never retry post orders without checking the result. In some scenarios when OMS times out. Kite trade will send an exception, you need to fetch orderbook and check before doing a retry. In the above case, sometimes order could have been placed. If you keep place order in the loop and for some reason external like if the instrument is banned, leverage changes and you don't have funds or any other issue. If your algorithm keeps pumping order then RMS systems will mark your app as spam then your app will be suspended. Please ensure you never run write requests in a loop like get requests, as the outcome could bring in more damage.
hi sujith when OMS times out and throws a Exception can the returned order id be trusted to fetch details for that order ? or we need to do it some other way
placed_by,order_id,exchange_order_id,parent_order_id,status,status_message,status_message_raw order_timestamp,exchange_update_timestamp,exchange_timestamp abpve are many fields for each order in orderbook. lets say i placed a order and OMS throw a exception how will i know wht happend to my order since order book might have many orders and also it might have many orders of same symbol.
@rakeshr@sujith thank you both for your inputs here is what i am thinking as final solution please suggest if there any logical flow. place every order with unique tag. after placing a order using orderbook and search that tag to find orderid. than we can do anything by reading order status. whether OMS throws a exception or not tag-> orderid mapping will always remain intact.basically using tag i can always retrive order id beit OMS error or not am i correct ?
sujith now your comment is confusing. do you mean to say if OMS throws a error and tag not found in orderbook than the order is not placed and we can retry ? if OMS throws a error and tag found means order placed and we can read order status to know what to do ?
Please go through the documentation here for order placement. A successful response will only have an order id in the response. If there is a timeout then you can fetch the orderbook and check for the order with the tag you sent. You can check out the error response format here.
@sujith i read the doc i am now asking a very simple question if i get a successful response i get a order id if i dont get a successful response i dont get a order id but i can search it by tag in orderbook. my quesiton is if tag not found in orderbook does this means that order didnt get placed ?
You can also refer - https://kite.trade/docs/connect/v3/exceptions/
Never retry post orders without checking the result. In some scenarios when OMS times out. Kite trade will send an exception, you need to fetch orderbook and check before doing a retry. In the above case, sometimes order could have been placed.
If you keep place order in the loop and for some reason external like if the instrument is banned, leverage changes and you don't have funds or any other issue. If your algorithm keeps pumping order then RMS systems will mark your app as spam then your app will be suspended.
Please ensure you never run write requests in a loop like get requests, as the outcome could bring in more damage.
You need to fetch orderbook and check. You won't receive order id if OMS times out the request.
abpve are many fields for each order in orderbook. lets say i placed a order and OMS throw a exception how will i know wht happend to my order since order book might have many orders and also it might have many orders of same symbol.
You may use order tags while placing each order and check the same on the orderbook.
Yes, you can search in your order book with the required tag. Go through this documentation to know, more about order tagging.
You can check below example.
kite.place_order(variety='regular',
exchange='NSE', tradingsymbol='NTPC', transaction_type='BUY',
quantity=1,
price=87.5, product='CNC', order_type='LIMIT',tag='Order15')
If the order gets placed then it will have a tag in it.
A successful response will only have an order id in the response. If there is a timeout then you can fetch the orderbook and check for the order with the tag you sent.
You can check out the error response format here.