delay in profit loss

vishnux
When I calculate profit via open positions , api profit loss is delayed , how long is the delay ?
  • sujith
    You can refer to this similar thread.
  • vishnux
    @sujith

    pnl = (sellValue - buyValue) + (netQuantity * lastPrice * multiplier);

    Can I use all these values from get positions ? is lastPrice retrieved from get positions is realtime ?
  • sujith
    The whole point is to defer polling the positions. Now you want to calculate the same P&L with the last price provided in the same response.

    You need to use GetQuote or websocket to get the latest last traded price. The last price in the positions response is a cached value.
  • vishnux
    Hmm , I get it , it makes no sense why its cached , you could just interlink it with get quote and just give the pnl
  • zw0330
    zw0330 edited June 2020
    public void getmtm()
    {
    kite = new Kite(MyAPIKey, Debug: true);
    initSession();
    kite.SetAccessToken(MyAccessToken);

    PositionResponse positions = kite.GetPositions();
    //pnl = (sellValue - buyValue) + (netQuantity * lastPrice * multiplier);
    decimal pnls = 0;
    for (int i = 0; i < positions.Net.Count; i++)
    {
    Dictionary<string, Quote> ohlcs = kite.GetQuote(InstrumentId: new string[] { positions.Net[i].InstrumentToken.ToString() });
    decimal LastPrice = 0;
    foreach (KeyValuePair<string, Quote> entry in ohlcs)
    {
    LastPrice = entry.Value.LastPrice;
    }

    pnls += (positions.Net[i].SellValue - positions.Net[i].BuyValue) +
    (positions.Net[i].Quantity * LastPrice * positions.Net[i].Multiplier);
    }
    //get pnl in label
    lbl_mtm.Text = pnls.ToString();


    }
    Learn Algo Trading

    https://youtube.com/watch?v=wFih_6X5nV8&t=11s
Sign In or Register to comment.