PnL formula not working

xh5018
i used below formula to get live PnL but its giving same result of pnl field. live PnL on app is something else.
is there anything additional needs to be added?

positions_json = kite.positions()

pnl = 0
for obj in positions_json["net"]:
pnl = pnl + obj["pnl"]
print("pnl is:", pnl)

pnl1 = 0
for obj in positions_json["net"]:
pnl1 = pnl1 + (obj["sell_value"] - obj["buy_value"]) + (obj["quantity"] * obj["last_price"] * obj["multiplier"])
print("pnl1 is:", pnl1)

Result :

pnl is: 6258.75
pnl1 is: 6258.75
Tagged:
  • sujith
    You will have to fetch latest last price from Quote API or Websockets API.
Sign In or Register to comment.