Weird things happen during the very beginning seconds of the market.

AAAAAAAAAA
Today, my algo was supposed to buy a put contract at 9:15:03. The code for order did go through. But for some reason the next steps did not happen, but the console still showed my algo running. I checked my Zerodha to see what happened, and there was an open order. But it did not register in my algo.

Then I restarted my algo and everything worked very fine. Why is that?

PS - I place limit orders, and I check for every order status. And as I said, the algo worked just fine later. Please help me figure out what was wrong.

Attached are the screenshots of a part of my algo and the log. The "BEFORE WHILE LOOP" was never printed, not on the console and not in the logs.


Please help!
  • AAAAAAAAAA
    This is not the first time the algo has behaved unexpectedly during the starting seconds of the market. Sometimes, it skips some parts of a function altogether, but when restarted later, it works just as expected. Why is this?
  • AAAAAAAAAA
    AAAAAAAAAA edited February 2022
    That is fine! I have things coded to wait 10 seconds after an order is placed, and if not placed, then its fine too. That part is covered and tested.

    Thats not the issue, the issue that the code after "placed buy..." did not follow through. The logs are empty after that last line. But that must not happen, it should have reached the "Before while loop.." and then move on to other things.

    As seen in the logs, for some reason, it did not retrieve the order_id as well!
  • SRIJAN
    That line has 2 functions kite.order_history,and your local function 'retrieve_order_id'. The code must be stuck in either of those functions.
  • AAAAAAAAAA


    This is my retrieve order id funtion. It just readjusts the list and from kite.orders and gets me that id. Do I add a timer in here to avoid this from happening?
    How do I tackle the kite.order_history() tho?
  • AAAAAAAAAA
    @sujith @rakeshr would be grateful for any help :)
  • SRIJAN
    Yes,I guess some sleep would help.
  • sujith
    The place order method itself will give you order id right? Why are you fetching orderbook to get order id?
    Maybe you can fetch orderbook and see if you encounter network exception right?
  • AAAAAAAAAA
    I had no idea one could get order_id from kite.place_orders() method. Will you guide how I can do that? I was under the impression that it just needs what type of order to place and what instrument to trade and thats it.

    To get to order_id, one needed to get the order book and get the latest order parameters.

    But I can get id from place_orders too? Pray tell how.
  • SRIJAN
    SRIJAN edited February 2022
    Just do order_id=kite.place_order(order_params). It will return order_id. Read documentation here:
    https://github.com/zerodha/pykiteconnect
  • AAAAAAAAAA
    AAAAAAAAAA edited February 2022
    yea, my bad, place_orders return the order_id. Now I know.

    However, do you think that it might have gotten stuck somewhere in the api calls, order_history() or orders() in the above mentioned case? @sujith
Sign In or Register to comment.