Authentication error
-
Define the API endpoints
login_url = 'https://smartapi.angelbroking.com/rest/auth/login'
market_data_url = 'https://smartapi.angelbroking.com/rest/secure/angelbroking/currentdayextremes'Prepare the request headers for authentication
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}Prepare the request data for authentication
data = {
'api_key': api_key,
'password': api_secret,
}Authenticate and obtain an access token
response = requests.post(login_url, data=data, headers=headers)
if response.status_code == 200:
access_token = response.json()['data']['accessToken']# Prepare headers for fetching market data with the access token headers = { 'Authorization': f'Bearer {access_token}', 'Content-Type': 'application/json', } # Fetch today's Bank Nifty price response = requests.get(market_data_url, headers=headers) if response.status_code == 200: try: market_data = response.json() today_banknifty_price = market_data['data']['CASH']['BANKNIFTY'] print(f"Today's Bank Nifty Price: {today_banknifty_price}") except json.JSONDecodeError: print("Error: Unable to decode JSON response.") else: print(f"Error fetching market data: {response.status_code} - {response.text}")
else:
print(f"Authentication error: {response.status_code} - {response.text}")kindly please guide where I am doing mistake.
-
@C50781558 I don't have algo software in my company.
what you are interested to tell? -
@pskale7755
Are you available of algo software in your company -
@Moderator_1 thanks you. Problem solved.
-
Hello @pskale7755 ,
Apologies for the delayed response.
The API for login is https://apiconnect.angelbroking.com//rest/auth/angelbroking/user/v1/loginByPasswordand the API for Historical Data is :
https://apiconnect.angelbroking.com/rest/secure/angelbroking/historical/v1/getCandleDataPlease use these endpoints for the same.
-
As per the github documentation, these are the deatils need to define.
I knew about the api_key ,clientId , pwdapi_key = 'Your Api Key'
clientId = 'Your Client Id'
pwd = 'Your Pin'
smartApi = SmartConnect(api_key)
token = "Your QR code value"
totp=pyotp.TOTP(token).now()
correlation_id = "abc123"from where I will get the token , correlation_id ?
@admin123 @admin @MNAGESH
Can you please help me here, I am starting over this API. -