Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    Authentication error

    Python SDK
    0
    7
    36
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bm0126782 last edited by

      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.

      B 1 Reply Last reply Reply Quote 1
      • B
        bm0126782 @bm0126782 last edited by

        @admin123 @admin kindly please help

        C 1 Reply Last reply Reply Quote 0
        • B
          bm0126782 last edited by

          As per the github documentation, these are the deatils need to define.
          I knew about the api_key ,clientId , pwd

          api_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.

          1 Reply Last reply Reply Quote 0
          • M
            Moderator_1 last edited by

            Hello @pskale7755 ,

            Apologies for the delayed response.
            The API for login is https://apiconnect.angelbroking.com//rest/auth/angelbroking/user/v1/loginByPassword

            and the API for Historical Data is :
            https://apiconnect.angelbroking.com/rest/secure/angelbroking/historical/v1/getCandleData

            Please use these endpoints for the same.

            B 1 Reply Last reply Reply Quote 0
            • B
              bm0126782 @Moderator_1 last edited by

              @Moderator_1 thanks you. Problem solved.

              1 Reply Last reply Reply Quote 0
              • C
                C50781558 @bm0126782 last edited by

                @pskale7755
                Are you available of algo software in your company

                B 1 Reply Last reply Reply Quote 0
                • B
                  bm0126782 @C50781558 last edited by

                  @C50781558 I don't have algo software in my company.
                  what you are interested to tell?

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post