Sequence of placing orders

Snischal
Hi, I am coding my algo in python to place 2 buy and 2 sell orders. the sequence in which I'm passing the orders is : BUY CE, SELL CE, BUY PE, SELL PE. in response I am saving the orders id in a list.
The order IDs in the list are coming in the desired sequence i.e. BUY CE, SELL CE, BUY PE, SELL PE ; but the sequence in which orders are being shown on the kite app or the terminal, is different from the sequence in which I have placed the orders.

Illustration:

Sequence of passing orders : BUY CE, SELL CE, BUY PE, SELL PE

Response received in python : [220726200517040', '220726200517088', '220726200517140', '220726200517208]
*Note : This response is in correct sequence as mentioned above.
the sequence of orders as shown in the app is as per this image :


Please clarify if the orders are being paced as shown in the image or as per the sequence of order IDs received.
My concern is if the orders are not placed in the same sequence as they were passed, it will have an effect on the margin and some orders might be rejected.
Thanks.

  • SRIJAN
    SRIJAN edited July 2022
    The orders are placed as shown on the Kite app.

    The order placement requests were made as per your sequence.
    But sometimes there could be a very small delay between receiving the order id and the order being placed.

    To avoid this,you can add some sleep between the orders.
    Or the best way is to use postbacks/websocket order updates and only place the next order after the previous order has been placed .
  • Snischal
    Thanks, pls share some link or info regarding postbacks/websocket order updates.
  • DD1365
    Place your orders as I have explained in your other post named "creating basket using API". Hope you are placing market orders to ensure there is immediate execution.

    Just to be safe that you don't encounter the problem that you are facing, we can add one more step in my previous explanation:

    Make a parent list of 2 sub-lists, first sub-list containing buy orders and the second sub-list containing sell orders. Then loop through the parent list and use parallel processing using concurrent.futures.ThreadPoolExecutor() to first place all buy orders simultaneously (keep appending the placed order IDs in a placed_orders list) -

    Ping the order book API and cross-check status of the buy orders, they must show "COMPLETED"

    - if all buy order status is returned as completed then proceed with placing all sell orders simultaneously (keep appending the placed order IDs in a placed_orders list)
  • Snischal
    thanks srijan, was really helpful.
This discussion has been closed.