I used this code pnl = (position['sell_value'] - position['buy_value']) + (position['quantity'] * position['last_price'] * position['multiplier']) Even then since yesterday pnl is showing wrong information.
position['pnl'] was working until OCT11. Fine. I'm using the below python code now
for position in positions : pnl = (position['sell_value'] - position['buy_value']) + (position['quantity'] * position['last_price'] * position['multiplier']) sum = sum + position['pnl'] print(sum)
Can you let me know how to use "Websocket API or quote API" in python to get last price
Have used the below code as you mentioned. However even now there is a change pnl of what is show in the kite web and what is shown in the code. Every thing was working fine until OCT 11.
exit = 0 while exit == 0: positions = kite.positions() positions = positions['net'] sum = 0 print('positions is') print(positions) for position in positions : print(position['tradingsymbol']) print(position['pnl']) print("quote is") ins = 'NFO:' + position['tradingsymbol'] lp = kite.quote(ins)[ins]['last_price'] pnl = (position['sell_value'] - position['buy_value']) + (position['quantity'] * lp * position['multiplier']) print('pnl is') print(pnl) sum = sum + position['pnl'] print("###") print(sum) print("Total BANK Nifty P & L") print(sum)
If yes, then the multiplier here is the lot size of a specific contract.
Even then since yesterday pnl is showing wrong information.
There is nothing called net_quantity.
Can you please help
You need to use
quantity
field.for position in positions :
pnl = (position['sell_value'] - position['buy_value']) + (position['quantity'] * position['last_price'] * position['multiplier'])
sum = sum + position['pnl']
print(sum)
Can you let me know how to use "Websocket API or quote API" in python to get last price
exit = 0
while exit == 0:
positions = kite.positions()
positions = positions['net']
sum = 0
print('positions is')
print(positions)
for position in positions :
print(position['tradingsymbol'])
print(position['pnl'])
print("quote is")
ins = 'NFO:' + position['tradingsymbol']
lp = kite.quote(ins)[ins]['last_price']
pnl = (position['sell_value'] - position['buy_value']) + (position['quantity'] * lp * position['multiplier'])
print('pnl is')
print(pnl)
sum = sum + position['pnl']
print("###")
print(sum)
print("Total BANK Nifty P & L")
print(sum)