Navigation

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

    Historical API returns error 400!!!! - Python

    Test
    0
    8
    48
    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.
    • S
      SKExplorer last edited by

      Historical API keeps returning Http Status 400 even with the EXAMPLE GIVEN!!!!! why ?

      here is my code...

      http = urllib3.PoolManager()
      API_ENDPOINT = "https://apiconnect.angelbroking.com/rest/secure/angelbroking/historical/v1/getCandleData"
      
      #thirty_days_ago = datetime.now() - timedelta(days=30)
      #from_date = thirty_days_ago.strftime("%Y-%m-%d %H:%M")
      #to_date = datetime.now().strftime("%Y-%m-%d %H:%M")
      
      from_date = "2021-07-01 09:41"
      to_date = "2021-07-29 10:41"
      
      print(from_date)
      print(to_date)
      
      payload = { "exchange": "NSE",    
                  "symboltoken": "3045",
                   "interval": "ONE_HOUR",  
                  "fromdate": from_date,
                   "todate": to_date
                   }
      
      
      encoded_data = json.dumps(payload).encode('utf-8')
      
      r = http.request('POST', API_ENDPOINT,
                      headers=headers,
                      
                      body=encoded_data)
      
      print(r.status)
      print('DRAW:',r.data)
      resp_body = r.data.decode('utf-8')
      print(f'DATA:{resp_body}')
      
      M 1 Reply Last reply Reply Quote 0
      • M
        Moderator_2 @SKExplorer last edited by

        Hi @SKExplorer

        Apologies for the delayed response.
        We are not facing any issue on Historical API at our end.
        Please refer
        getCandleData func on our SDK.
        https://github.com/angel-one/smartapi-python/blob/main/SmartApi/smartConnect.py

        Regards,
        SmartAPi team

        S 1 Reply Last reply Reply Quote 0
        • S
          SKExplorer @Moderator_2 last edited by

          @Moderator_2

          I am using python sdk for authentication..

          I have checked the code (for getting candle data again...(given in this post) ... It still returns http 404 error... can you see anything wrong with the code ???

          I am successfully using market data API...

          M 1 Reply Last reply Reply Quote 1
          • M
            Moderator_2 @SKExplorer last edited by

            Hi @SKExplorer

            Kindly share us the client code and issue occurred date and time to analyze on this matter

            Regards,
            SmartAPI team

            S 1 Reply Last reply Reply Quote 0
            • S
              SKExplorer @Moderator_2 last edited by

              @Moderator_2 below is the simple code that I am testing... I am trying off market hours not live...

              http = urllib3.PoolManager()
              API_ENDPOINT = "https://apiconnect.angelbroking.com/rest/secure/angelbroking/historical/v1/getCandleData"

              #thirty_days_ago = datetime.now() - timedelta(days=30)
              #from_date = thirty_days_ago.strftime("%Y-%m-%d %H:%M")
              #to_date = datetime.now().strftime("%Y-%m-%d %H:%M")

              from_date = "2021-07-01 09:41"
              to_date = "2021-07-29 10:41"

              print(from_date)
              print(to_date)

              payload = { "exchange": "NSE",
              "symboltoken": "3045",
              "interval": "ONE_HOUR",
              "fromdate": from_date,
              "todate": to_date
              }

              encoded_data = json.dumps(payload).encode('utf-8')

              r = http.request('POST', API_ENDPOINT,
              headers=headers,

                          body=encoded_data)
              

              print(r.status)
              print('DRAW:',r.data)

              resp_body = r.data.decode('utf-8')
              print(f'DATA:{resp_body}')

              M 1 Reply Last reply Reply Quote 0
              • M
                Moderator_2 @SKExplorer last edited by Moderator_2

                Hi @SKExplorer

                As verified on the API request params from the shared code snippet, we are able to retrieve the response without facing 400 status code. Please refer our working python SDK getCandleData() function
                https://github.com/angel-one/smartapi-python/blob/main/SmartApi/smartConnect.py

                Regards,
                SmartAPI team

                S 2 Replies Last reply Reply Quote 0
                • S
                  SKExplorer @Moderator_2 last edited by

                  @Moderator_2 I am posting the code again.....

                  http = urllib3.PoolManager()
                  API_ENDPOINT = "https://apiconnect.angelbroking.com/rest/secure/angelbroking/historical/v1/getCandleData"

                  #thirty_days_ago = datetime.now() - timedelta(days=30)
                  #from_date = thirty_days_ago.strftime("%Y-%m-%d %H:%M")
                  #to_date = datetime.now().strftime("%Y-%m-%d %H:%M")

                  from_date = "2021-07-01 09:41"
                  to_date = "2021-07-29 10:41"

                  print(from_date)
                  print(to_date)

                  payload = { "exchange": "NSE",
                  "symboltoken": "3045",
                  "interval": "ONE_HOUR",
                  "fromdate": from_date,
                  "todate": to_date
                  }

                  encoded_data = json.dumps(payload).encode('utf-8')

                  r = http.request('POST', API_ENDPOINT,
                  headers=headers,

                          body=encoded_data)
                  

                  print(r.status)
                  print('DRAW:',r.data)

                  resp_body = r.data.decode('utf-8')
                  print(f'DATA:{resp_body}')

                  1 Reply Last reply Reply Quote 0
                  • S
                    SKExplorer @Moderator_2 last edited by

                    @Moderator_2 I have tried smartApi.getCandleData, I get the same http 400 error....http response has no error message either to debug!!!!

                    Is there something additional to be added to the HEADER data for Historical API ? I am successfully sing the same header to retrieve quote data.

                    can you try my code and see whats wrong ?

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