order placing Exceptions

pawan12
pawan12 edited July 2020 in Python client
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
  • vijoeyz
    What's the error?

    You can also refer - https://kite.trade/docs/connect/v3/exceptions/
  • sujith
    sujith edited July 2020
    @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.
  • pawan12
    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
  • sujith
    @pawan12,
    You need to fetch orderbook and check. You won't receive order id if OMS times out the request.
  • pawan12
    so if OMS throws error than i will not have order id but there are some cases where our order gets filled. how will i know the order id for the same ?
  • pawan12
    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.
  • sujith
    A successful order response will only have an order id.
    You may use order tags while placing each order and check the same on the orderbook.
  • pawan12
    got it so there is a way to send tag with each order and this tag can be searched in orderbook ? am i correct
  • rakeshr
    @pawan12
    Yes, you can search in your order book with the required tag. Go through this documentation to know, more about order tagging.
  • pawan12
    @rakeshr hi is there any example code for tags ?
  • rakeshr
    @pawan12
    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')
  • pawan12
    @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
    @pawan12,
    If the order gets placed then it will have a tag in it.
  • pawan12
    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 ?
  • sujith
    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.
  • pawan12
    @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 ?
  • sujith
    Yes, if there is no order with that tag then it is not placed.
Sign In or Register to comment.