Navigation

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

    getCandleData() missing 1 required positional argument: 'historicDataParams'

    Python SDK
    2
    7
    85
    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.
    • H
      hisameer last edited by

      I have been trying to use the historical data but I am encountering this issue every time.
      Please tell me what mistake I am making below:

      import smartapi
      
      hist = {
          "exchange": "NSE",
          "symboltoken": "3045",
          "interval": "ONE_MINUTE",
          "fromdate": "2021-02-08 09:00", 
          "todate": "2021-02-08 09:16"
      }
      
      try:
          smartapi.SmartConnect.getCandleData(hist)
      except Exception as e:
          print("Historical API failed: {}".format(e))
      

      And this is the error I am encountering:

      Historical API failed: getCandleData() missing 1 required positional argument: 'historicDataParams'
      
      P 1 Reply Last reply Reply Quote 0
      • P
        pavank @hisameer last edited by

        @Boofy you need to login before requesting historical data.

        H 3 Replies Last reply Reply Quote 0
        • H
          hisameer @pavank last edited by hisameer

          Hello @pavank,
          I tried logging in and then executing the same code but still the result is same.

          See here below:

          527f875b-dc78-4ed0-accb-647c202437a7-image.png

          But when I do this:

          try:
              smartapi.SmartConnect.getCandleData(hist, hist)
          except Exception as e:
              print("Historical API failed: {}".format(e))
          
          

          Somehow previous error gets resolved, though that should not happen.
          But after doing this I get new kind of error:

          6132836c-9e5b-4ca1-be23-5e484c5ab934-image.png

          1 Reply Last reply Reply Quote 0
          • H
            hisameer @pavank last edited by

            @pavank Are you using same snippet from GitHub?
            If not can you share yours?

            1 Reply Last reply Reply Quote 0
            • H
              hisameer last edited by

              EDIT:

              I also tried this:

              try:
                  smartapi.SmartConnect.getCandleData(historicDataParams=hist)
              except Exception as e:
                  print("Historical API failed: {}".format(e))
              
              

              But after doing that I get this error:

              e8abd532-6c2a-444b-bc21-bdb7d081a677-image.png

              1 Reply Last reply Reply Quote 0
              • H
                hisameer last edited by hisameer

                THE ISSUE IS SOLVED
                I needed to use the initiated object of SmartApi class.

                import secrets
                import smartapi
                
                #create object of call
                obj = smartapi.SmartConnect(api_key=secrets.datafeed_key)
                
                #login api call
                loginData = obj.generateSession(secrets.client_id,secrets.pswd)
                refreshToken= loginData['data']['refreshToken']
                
                #fetch the feedtoken
                feedToken = obj.getfeedToken()
                
                #fetch User Profile
                userProfile = obj.getProfile(refreshToken)
                
                hist = {
                    "exchange": "NSE",
                    "symboltoken": "3045",
                    "interval": "ONE_MINUTE",
                    "fromdate": "2021-02-08 09:00", 
                    "todate": "2021-02-08 09:16"
                }
                
                try:
                    hist_data = obj.getCandleData(hist)
                    print(hist_data)
                except Exception as e:
                    print("Historical API failed: {}".format(e))
                
                

                This is the code in case someone else also encountered something like this.

                1 Reply Last reply Reply Quote 0
                • H
                  hisameer @pavank last edited by

                  Thank you @pavank
                  I realized it later.

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