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.