I can not get data by using api, please help me out. Below is my code


  • Re: [List of all Smartapi functions in Python](/topic/3625/list-of-all-smartapi-functions-in-pyth```
    from SmartApi import SmartConnect #or from SmartApi.smartConnect import SmartConnect
    import pyotp
    from logzero import logger
    import pandas as pd

    api_key = 'X14DuTIU'
    username = 'AAAE460930'
    pwd = '2469'
    smartApi = SmartConnect(api_key)

    token = '5545AXMLBA7O2H5P3Z3DDH35FU'
    totp = pyotp.TOTP(token).now()

    correlation_id = "abcde"
    data = smartApi.generateSession(username, pwd, totp)

    if data['status'] == False:
    logger.error(data)

    else:
    # login api call
    # logger.info(f"You Credentials: {data}")
    authToken = data['data']['jwtToken']
    refreshToken = data['data']['refreshToken']
    # fetch the feedtoken
    feedToken = smartApi.getfeedToken()
    # fetch User Profile
    res = smartApi.getProfile(refreshToken)
    smartApi.generateToken(refreshToken)
    res=res['data']['exchanges']

    historicParam={
    "exchange": "NSE",
    "symboltoken": "99926009",
    "interval": "ONE_MINUTE",
    "fromdate": "2024-07-11 09:00",
    "todate": "2024-07-12 09:16"
    }

    df=smartApi.getCandleData(historicParam)
    print(xdata)
    df=pd.DataFrame(df)

    df.to_excel("BankNiftyData.xlsx")
    df = pd.read_excel("BankNiftyData.xlsx")

    Convert the 'datetime' column to datetime objects

    df['datetime'] = pd.to_datetime(df['datetime'], format='%d-%m-%Y %H:%M')

    Create new columns for 'date' and 'time'

    df['date'] = df['datetime'].dt.date
    df['time'] = df['datetime'].dt.time

    Reorder columns (optional)

    cols = ['date', 'time'] + [col for col in df.columns if col not in ['datetime', 'date', 'time']]
    df = df[cols]

    Assuming the column with four numbers is the third column (index 2)

    values = df.iloc[:, 2].str.split(expand=True)

    Assign column names

    values.columns = ['open', 'high', 'low', 'close']

    Concatenate with the original DataFrame

    df = pd.concat([df.iloc[:, :2], values], axis=1)

    Save the modified DataFrame to a new Excel file

    df.to_excel("BankNiftyData.xlsx", index=False)


  • @AAAE460930 what is the exact problem that you are facing?