ticks[0]['last_trade_time'] it giving the local of the country i am in. While traveling to abroad.

Sbag edited November 2023 in Market data (WebSockets)
How one would get the Indian time in ticker data
  • sujith
    You will have to convert to UTC time and then add +5:30 or convert date to IST timezone.
  • Sbag
    Sbag edited November 2023
    Thanks for the response. I know that.

    I am using following function. I suppose if i do that for every tick it will be expensive right? there should be some flag for the data in the market location time..

    from csv import DictWriter
    field_names = ["time","LTP"]

    def feed_data(ticks):

    with open('event.csv', 'a') as f_object:
    dictwriter_object = DictWriter(f_object, fieldnames=field_names)

    # Pass the dictionary as an argument to the Writerow()
    dict = {"time":ticks[0]['last_trade_time'],"LTP":ticks[0]['last_price']}
    #print("i am from -> feed_data function")

    def on_ticks(ws, ticks):
    #It will print the ticker
    # Callback to receive ticks.
    #logging.debug("Ticks: {}".format(ticks))

    def on_connect(ws, response):
    # Callback on successful connect.
    # Subscribe to a list of instrument_tokens (RELIANCE and ACC here).

    # Set RELIANCE to tick in `full` mode.
    #ws.set_mode(ws.MODE_FULL, [81153])
    ws.set_mode(ws.MODE_FULL, [65859335])

    def on_close(ws, code, reason):
    # On connection close stop the main loop
    # Reconnection will not happen after executing `ws.stop()`
  • MAG
    MAG edited November 2023
    A few questions that may enable folks to help you better -
    1. What is your OS
    2. What programming language are you using? In this case it obviously seems to be python.
    3. What is the timezone on your computer?

    Simplest check - first what is the timezone on the computer you are running your code on?
    Most operating systems nowadays sync up time using NTP and automatically switch timezones based on geolocation.

    Try setting the timezone manually to Asia/calcutta. That might solve your issue without needing to do anything in code. If not you may need to turn off network time sync and set time manually.

    You may also want to look at how python handles timezone in datetime. However from previous experiences I know that this is not a zerodha tick feed / python / app layer issue. Its more to do with timezone settings on the OS layer. I know because I have been there and done that.
  • MAG
    MAG edited November 2023
    If you are using linux,
    You can do the following
    #switch to root user
    > sudo su -

    #edit roots crontab using crontab -e and add the following lines
    @reboot /usr/bin/timedatectl set-timezone Asia/Kolkata
    @reboot cat Asia/Kolkata > /etc/timezone
Sign In or Register to comment.