Incorrect pnl and unrealised m2m coming in position - sometimes

Shaha
Shaha edited March 2018 in Python client
Guys,

Since yesterday, observed a new issue.

In the list downloaded using kite.positions() , the pnl and unrealised m2m is coming incorrect for some of the orders.

So far observation is that, the error is coming for such BO orders with SL entry, whose parent order is triggered but still in OPEN state.

See below one such example:




This has been working fine since months earlier. I wish this is checked and fixed as soon as possible. This is creating an issue in identifying overall m2m for the account.

Also, can u suggest any other way to keep a track of realised+unrealised pnl ? Any Websocket callback exists for it?
  • Shaha
    Shaha edited March 2018
    Some more examples..


  • Shaha
    Shaha edited March 2018
    Below is the orders details. This time the parent order is in executed state instead of OPEN state.


  • Shaha
    Any response please... This issue is very important for me.
  • sujith
    We will look into this.
  • sujith
    what version of pykiteconnect are you using?
  • Shaha
    I m using the older version since last 8 months, as not able to upgrade to 3.0
  • Shaha
    This thing has been working perfectly fine from all these days.. It broke apart after recent release.
  • Shaha
    Few comments:

    1) You mentioned that you are using this formula to calculate the pnl.
    pnl = (sellValue - buyValue) + (netQuantity * lastPrice * multiplier);
    So the issue now boils down to ... that lastprice would have been considered as zero during my request to get the positions. Think on that area to get direction to the analysis.

    2) I have stopped using it after the issues occured consecutive 2-3 days, so do not have details whether this issue is still there.

    3) In the thread link u mentioned that its not a good idea to poll for pnl even for big frequency.
    - So what is the alternative? Can we get it thru websockets?
    - If i want to calculate at our end, I can get live value of ltp from tick data, but how would i be getting the correct live value of netQuantity, total Sell value, total buy value? Order updates also cannot be relied for this calculation. One order update missed and the calculation all these values will get off. Please suggest... ? Any sample example will also be appreciated.
    - To get live values for these 3 things (Quantity,sell value, buy value) , again i will have to enquire net positions. If this option is choosen, it doesnt makes sense, of not polling positions for pnl directly.
    - The formula you mentioned can be used only to recalculate the pnl and crosscheck with the value supplied in positions..

    I may be wrong. Please correct me in that case.

    Please let me know your views, as my use case require implementing, max loss a day limit on entire portfolio while the algo is running in the account. This is most important parameter for me to safeguard against technical issues and incorrect behaviour of algorithm. Hope u will understand.
  • kairon007
    Facing the same issue, kindly lemme know whats wrong
  • sujith
    A sell value and buy value won't change unless there is an order execution. You can use postbacks or order updates via websockets as an event to pull orderbook and positions. It is a reliable solution being used by many production apps.
    We don't recommend polling positions. So the only variable is LTP which can be fetched using getQuote or use Websockets API.
  • kairon007
    Thanks @sujith for the prompt response but the thing is, the other positions were showing profits accurately, how is that possible, please explain. I wouldnt mind going an extra step to add a call, the only thing is my profits are showing accurate values but losses showing up as less than half, that is my concern. Thanks again but would really appreciate an explanation of how other positions show accurate pnl. Cheers
  • sujith
    @kairon007,
    Can you give us the debug logs? We use the same formula to calculate profit and loss. We can check and get back to you once we have complete the request and response logs.
    Make sure to remove app and client-specific tokens.
  • kairon007
    Could you guide me how. I would love to help you in any way I can.
  • sujith
    You can check out here to know more about enabling debug logs.
  • kairon007
    I'll try although today it worked for me, but next time I'll enable it. Thanks
Sign In or Register to comment.