Delayed position updates after order completion

enliyo
enliyo edited October 2020 in API clients
When order is complete (bo/co) and the /positions are queried, Kite used to return the newest positions immediately. It seems that since couple of days it is not happening promptly and there could be delay of 1-2seconds between order gets completed and latest positions are fetched.

Steps:
1. Let order be complete and listen for this update on websocket.
2. Immediately fire /positions API to get latest positions.
3. Positions intermittently do not have latest completed position for order.

Anybody noticed this? I do not wish to patch this on my side.
  • sujith
    sujith edited October 2020
    Is this happening consistently or intermittently?
    Do you observe this during opening or throughout the day? Exact log will help to debug this further.
  • enliyo
    @sujith happening intermittently. What kind of logs would help? Simple timestamps when this happens?
  • rakeshr
    Yes, timestamp log with API end-point request detail.
  • enliyo
    I did not see the issue. I have added log for order update which may cause this positions issue. I will keep checking and update here once I spot the issue again.
  • enliyo
    09:45:31 - Received websocket order update where CO order sl got hit for BANKNIFTY20N0525600CE
    09:45:31 - After receiving order completion fired /positions API from Kite JS but /positions API response still showed that above position was open.
    09:45:32 - Received REST postback URL callback for order completion

    My setup has been rock solid for last 6 months and I have not faced such issues. Recently I have been facing one or another order handling related issues from Kite side. Have you guys undertaken some kind of refactoring or some systems got changed?

    @sujith @rakeshr
  • rakeshr
    @enliyo
    Can you private message us your client_id and API key? We will check on this.
  • enliyo
    @rakeshr this happened again today during spike in banknifty ~10.18 AM. What I have noticed that the issue occurs when the volatility is high. Websocket and both postback get callback of order completion but positions response doesn't reflect the completed order.

    This happened few times last few days too but I was busy so could not log in here. The problem seems to be during volatility spikes. Something seems to be regressed from your side because earlier when order postback was received, /positions was always consistent.

    I had added 100ms delay after postback receipt to fire /positions but still /positions was not updated correctly. Last few days 100ms was sufficient but not today.

    API Subscribers shouldn't be needing to patch behaviours like this so please fix this from your side.

    I will be sending you message about keys. Please look into this.
  • rakeshr
    @enliyo
    We are checking on this.
  • milli
    Hi,

    This problem of positions reporting with a delay is not new. I had raised a similar query back in May (). There is, many times, a significant lag in the values displayed by positions() using API and that shown on the App / Website. Similarly, there is a lag in displaying / executing the orders sent using the API and introducing a lag is the only way I could think of.

    Thanks
  • sujith
    @milli,
    How much delay are you referring to? Is this happening consistently or intermittently? Is there any pattern?
  • enliyo
    enliyo edited November 2020
    I do not use pnl values from /positions API but recalculate it based on latest last_price of instruments. So I am not concerned with pnl values. I have never faced issue with executing/displaying of the orders. So I am not sure what @milli is referring to.

    The completed orders not reflecting (quantity not updated) immediately in positions is the problem I face intermittently and its a downer. Seeing this problem since approx 1 month.
  • sujith
    @milli,
    If this is about cached P&L then you need to do it as mentioned by @enliyo
  • enliyo
    Any update on this? Additionally I see that orders are also not updating and are not consistent just like positions. Does that help for troubleshoot?
  • sujith
    @enliyo,
    We have informed the concerned team, they are looking into this. It is taking time because it is happening intermittently.
    Today it happened at the opening, is it?
  • enliyo
    @sujith, yes it happened today as well but only for one out of 3-4 orders. Happened for banknifty 29300 weekly CO short call hit sl at 9:51:20 AM. I mostly have seen this happening during volatility spikes and rarely at quite times.

    Today noticed that orders were not updated when position was not updated after 100ms delay of postback. I had not observed this before so cant say for sure that if positions and orders become inconsistent at the same time and are related. May be you will want to check that aspect too.
  • milli
    @sujith , I have not measured the exact delay as I have changed the strategy since then. However, I back in May the delay was several seconds (1 to 3 seconds) and I had to introduce a delay of 5 seconds to be sure that it appeared.
  • sujith
    @milli,
    Can you confirm if this is happening now?
  • milli
    @sujith give me a few days. I am making a new code and I will be able to test it again.
  • enliyo
    @sujith / @rakeshr it has been ~1 month since I reported this issue and it still occurs. Was the team able to troubleshoot it? Or I am to patch this on my side using minute or two delay?
  • sujith
    @enliyo,
    This is happening outside of our systems, we are coordinating with the teams to resolve this.
  • srikanthg
    It happened today to me. To ensure that a wrong sale of option does not happen I check the positions and only sell it if quantity is above 0. I was surprised to see it giving wrong position data. I would have made heavy loss today if I was not lucky.
Sign In or Register to comment.