Skip to main content
Question
FYERS API
Asked a question 4 months ago

Code for extracting live 5 minute data for bank nifty. Dera team I am getting multiple errors while developing the code for extracting the live market data for bank nifty. Can you please send me one sample code for Python?

Join FYERS Community to pick others' brains on Trading/Investing

Hi Preeti, 

can you check this,

 

import datetime
import time
from fyers_api import fyersModel

def getHistoryData(fyers):
    current_day = datetime.datetime.now12().day
    current_month = datetime.datetime.now12().month
    current_year = datetime.datetime.now12().year
    current_date = f"{current_year}-{current_month}-{current_day}"

    while True:
        data = {
            "symbol":"NSE:NIFTYBANK-INDEX",
            "resolution":"5",
            "date_format":"1",
            "range_from":current_date,
            "range_to":current_date,
            "cont_flag":"1"
        }

        response = fyers.history(data=data)
        print(response)

        time.sleep(1)

def main():
    client_id = "SPXXXXE7-100"
    access_token = "eyJ0eXAiOiJK***.eyJpc3MiOiJhcGkuZnllcnM***.IzcuRxg4tnXiULCx3***"
    fyers = fyersModel.FyersModel(client_id=client_id, token=access_token, log_path="/home/user/logs")

    getHistoryData(fyers)

if __name__ == "__main__":
    main()