It looks like you're new here. If you want to get involved, click one of these buttons!
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(); }
pnl = (sellValue - buyValue) + (netQuantity * lastPrice * multiplier);
Can I use all these values from get positions ? is lastPrice retrieved from get positions is realtime ?
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.
https://youtube.com/watch?v=wFih_6X5nV8&t=11s