jugaad-py / jugaad-trader

Unofficial python client for Zerodha
https://marketsetup.in/documentation/jugaad-trader/
156 stars 110 forks source link

how to refresh the position and holdings? #57

Open ak4zh opened 7 months ago

ak4zh commented 7 months ago

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)
sevakram commented 7 months ago

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