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


  • 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'
    

  • Thank you @pavank
    I realized it later.


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


  • 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


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


  • 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


  • @Boofy you need to login before requesting historical data.