Hello,
I’ve been integrating the Definedge API into a Python trading bot and running into an authentication issue. I’m able to successfully authenticate and obtain an access token using my client_id and client_secret. However, after about 5 minutes, the token stops working, and every request starts returning this error:
{
"status": "error",
"message": "Invalid or expired access token"
}
According to the docs, the token should be valid for at least 30 minutes.
Code Sample:
import requests
BASE_URL = "https://api.definedgesecurities.com"
login_payload = {
"client_id": "my_client_id",
"client_secret": "my_secret",
"grant_type": "client_credentials"
}
token_res = requests.post(f"{BASE_URL}/auth/token", data=login_payload)
token = token_res.json().get("access_token")
headers = {"Authorization": f"Bearer {token}"}
r = requests.get(f"{BASE_URL}/market/quotes?symbol=NIFTY", headers=headers)
print(r.json())
Has anyone else faced this premature token expiry issue? Do I need to explicitly refresh the token with another API call, or is there a configuration I might be missing on the Definedge side?