Logic - Order placement & checking for execution status.

Hello All,

I am working on an intraday options trading system and wanted to get feedback on—how to verify that an order has been executed successfully. (unique tag will be passed with all orders)

(a) Place Order and catch any exceptions.
(a.1) Wait for 1 second.
(a.2) Check Order-book to confirm that order with tag was placed successfully.
(a.2.1) Yes—Means order was placed successfully{Order may have been placed even if there was an exception raised}.
(a.2.2) No—Order was not placed successfully(PC to Z connection issue etc), place order again.
(a.3) Receive a websocket update that an order has received an update.
(a.3.1) For the order, use GET orders/:order_id to get details of the order.
(a.3.2) If the order status is “Complete” then mark the order as filled.
(a.3.2) If the order status is “Open"/Rejected”/“Canceled” then check filled_quantity—if order was partially filled & then canceled/rejected. If partial fill, then handle.
(a.3.2.2) For other order statuses, do nothing and wait for order to be moved to one of above statues.

If you think that we should follow some other logic, please do share.
  • sujith
    In an ideal scenario, once you get order id for place order response, order will be placed. You just need to add a couple of seconds delay and fetch orderbook. But in rare scenarios, when OMS doesn't update orderbook, you will have to add few seconds delay and fetch orderbook again and check order status with order tag.

    Another point is, you may receive Input exception with 400 status code, for order placement API when order is blocked by our mini RMS. It won't show up in orderbook but that request is considered while counting the maximum number of orders per day.
    You can know more about number of orders cap and rate limits on FAQs thread.
  • doubles
    Thanks Sujith.

    One follow-up question:

    How do we decide when to retry placing an order? For instance, there could be a case when an order failed because of a technical glitch(and hence we should re-try placing the order) vs shortage of funds (when the order failed for a valid reason & will fail again).

    One possible solution is that, we try to place the order at-least one more time—whenever we run into an unexpected situation( or error/exceptions). But, in this case, we have to be sure that the original order—didn't go through & will not go through after we place a second order. Is it safe to assume that if an order is not available in orderbook, then it won't get executed?
  • sujith
    If you get order id, it is confirmed that order is placed.

    If you get timeout for place order then you will have to add few seconds delay and then check orderbook and then try again after few seconds and then only place order. Please do remember this is not a recurring behavior but a rare scenario that needs to be handled.
Sign In or Register to comment.