nifty 50 index historical data of every 5 minutes for selected period to excel

Yedukondalu
Hi everybody.
I want to get the nifty 50 index historical data of every 5 minutes for the selected period or on a selected date and I need to copy them into excel/csv file in my PC.
Is there any process available to do this? Please provide.
I want to get Open, High, Low, Close values of each time frame.
  • tonystark
    Heres a sample code to achieve this,
    import pandas as pd
    from kiteconnect import KiteConnect

    api_key = "your_api_key"
    access_token = "your_access_token"

    kite = KiteConnect(api_key=api_key)
    kite.set_access_token(access_token)

    # Set instrument token for Nifty 50 index
    instrument_token = "256265" # Change this with the appropriate instrument token for Nifty 50 index

    # Set start and end dates for historical data
    start_date = "2023-05-01"
    end_date = "2023-05-16"

    # Fetch historical data
    data = kite.historical_data(
    instrument_token,
    start_date,
    end_date,
    interval="5minute"
    )

    # Convert data to a pandas DataFrame
    df = pd.DataFrame(data)

    # Save data to a CSV file
    csv_file_path = "nifty50_historical_data.csv"
    df.to_csv(csv_file_path, index=False)

    print("Historical data saved successfully to:", csv_file_path)
Sign In or Register to comment.