Unable to get historical nifty50 data from api


  • As per one of the posts F&O was a feature to be published in the api. Has it been done yet or is my code not working properly. Thanks

    from smartapi import SmartConnect
    
    from constants import *
    
    obj = SmartConnect(api_key=historicalApiKey)
    data = obj.generateSession(userName, password)
    print(data)
    
    try:
        historicParam = {
            "exchange": "NSE",
            "symboltoken": "constants.niftyToken",
            "interval": "ONE_MINUTE",
            "fromdate": "2022-05-31 09:00",
            "todate": "2022-05-31 15:30"
        }
        resp = obj.getCandleData(historicParam)
    except Exception as e:
        print("Historic Api failed: {}".format(e.message))
    
    print(resp)
    
    # logout
    try:
        logout = obj.terminateSession('Your Client Id')
        print("Logout Successfull")
    except Exception as e:
        print("Logout failed: {}".format(e.message))
    

    Response:

    {'status': True, 'message': 'SUCCESS', 'errorcode': '', 'data': None}
    Logout Successfull
    

    Any help would be much appreciated. @admin


  • @ankitkathait28 said in Unable to get historical nifty50 data from api:

    As per one of the posts F&O was a feature to be published in the api.

    We do provide NSE futures data at free of cost for intraday and daily time frames. Intraday is available since 2016-10-03 and daily since 2000-01-01 respectively.

    NSE options data is not available.

    User only needs to change the exchange segement from NSE to NFO and update the required fututes contract token number from scrip master to fetch the data.

    aa1c9fbf-d539-43ca-8d56-6307b62e0ae1-image.png


  • @ankitkathait28
    symboltoken is not correct other wise you should get historical data for nifty