How to find Total net P&L?

SHUN74
I am trying to use ".position()", but attributes value don't change in course of time. How to find Total net P&L?
Tagged:
  • sujith
    You need to use Websocket or Quote API and use the last price and calculate P&L of each item in net positions list and then sum it up.
    You can refer to this thread.
  • SHUN74
    Thanks for your reply, This is my code, I am trying to read Last_price, but its value is not changing over time.

    ppp = kcon.positions()['day']

    for i in ppp:
    if (i['tradingsymbol'][0:4] == 'BANK'):
    print(dt.hour,":",dt.minute,":",dt.second )
    print(i['tradingsymbol'][0:4])
    print(i['last_price'])

    this is my output where last_price is not changing over time.

    9 : 29 : 5
    BANK
    251.85
    9 : 29 : 21
    BANK
    251.85
    9 : 29 : 36
    BANK
    251.85
    9 : 29 : 36
    BANK
    251.85
    9 : 29 : 52
    BANK
    251.85
    9 : 30 : 23
    BANK
    251.85
  • rakeshr
    ppp = kcon.positions()['day']
    As explained in the above-linked thread, pnl field won't be updated in real-time for positions API. This thread explains more.
  • SHUN74
    Thanks for your reply rakeshr, I am not checking pnl, I am trying to calculate pnl using 'last_price'(LTP) and suggested formula in your referred thread. but 'last_price' value is not changing. Then how to use this formula

    pnl = (sellValue - buyValue) + (netQuantity * lastPrice * multiplier);
  • rakeshr
    but 'last_price' value is not changing.
    You can use the Websocket streaming(recommended) or quote API calls, to fetch real-time LTP.
  • SHUN74
    ok thanks rakeshr, got it
This discussion has been closed.