jugaad-trader icon indicating copy to clipboard operation
jugaad-trader copied to clipboard

how to refresh the position and holdings?

Open ak4zh opened this issue 1 year ago • 1 comments

Describe the bug

Documentation is not clear on how to refresh the data once you have logged in. I am using this code to calculate my position pnl but the data is not getting updated.

Code snippet

from dotenv import load_dotenv
import os
import pyotp
import time
from jugaad_trader import Zerodha
load_dotenv()

otp_gen = pyotp.TOTP(os.getenv("ZERODHA_TOTP_HASH"))
kite = Zerodha(
    user_id=os.getenv("ZERODHA_ID"), 
    password=os.getenv("ZERODHA_PASSWORD"), 
    twofa=otp_gen.now()
)
kite.login()

while True:
    pnl = 0
    positions = kite.positions()
    for position in positions.get("net"):
        pnl += position.get('pnl')
    print(pnl)
    time.sleep(1)

ak4zh avatar Feb 16 '24 06:02 ak4zh

Your code looks alright and there is nothing extra that we can add in documentation to address it.

You are getting what Zerodha is sending.. so either portfolio is not updated every second, other than this we are at mercy of Zerodha backend

sevakram avatar Feb 16 '24 10:02 sevakram