issue with greek data



  • LOGIN FUNCTION

    -----------------------

    def login_once():
    print("šŸ” Logging in...")
    totp = pyotp.TOTP(totp_secret).now()
    smart = SmartConnect(api_key)
    session = smart.generateSession(client_code, pin, totp)
    jwt = session['data']['jwtToken']
    return jwt

    -----------------------

    MAIN EXECUTION

    -----------------------

    if name == "main":
    jwt_token = login_once()

    # āœ… Your machine info
    local_ip =
    public_ip =
    mac_addr =
    
    url = "https://apiconnect.angelone.in/rest/secure/angelbroking/marketData/v1/optionGreek"
    
    headers = {
        "Authorization": f"Bearer {jwt_token}",
        "X-ClientLocalIP": local_ip,
        "X-ClientPublicIP": public_ip,
        "X-MACAddress": mac_addr,
        "X-UserType": "USER",
        "X-SourceID": "WEB",
        "Content-Type": "application/json",
        "Accept": "application/json"
    }
    
    payload = {
        "name": "NIFTY",            
        "expirydate": "26JUN2025"   
    }
    
    print("šŸ“” Fetching Greeks...")
    try:
        response = requests.post(url, headers=headers, json=payload, timeout=10)
        data = response.json()
        print("šŸ“¦ Full response:")
        print(data)
    
        if "data" in data and data["data"]:
            print("āœ… Option Greeks:")
            for option in data["data"]:
                print(
                    f"{option['strikePrice']} {option['optionType']} | "
                    f"Ī”={option['delta']} Ī“={option['gamma']} Θ={option['theta']} "
                    f"Vega={option['vega']} IV={option['impliedVolatility']} Vol={option['tradeVolume']}"
                )
        else:
            print("āš ļø No data found in response or empty 'data' array.")
    except Exception as e:
        print("āŒ Failed to fetch or parse response:", e)
    

    getting error as follwoing
    šŸ” Logging in...
    [I 250625 16:22:56 smartConnect:121] in pool
    šŸ“” Fetching Greeks...
    šŸ“¦ Full response:
    {'success': False, 'message': 'Invalid Token', 'errorCode': 'AG8001', 'data': ''}
    āš ļø No data found in response or empty 'data' array.