Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    How convert data feed's (live) timezone?

    General Code/Help
    data feed live data timezone trading session
    2
    3
    326
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • SPECULARI FUND
      SPECULARI FUND last edited by

      My data feed time in UNIX time 1588157340000 in milliseconds.
      Using this site - https://www.epochconverter.com/ I see that this is GMT timezone. How convert to US/Eastern? It's possible?

      timezone = pytz.timezone("US/Eastern")
      cerebro.run()
      

      This code change timezone for logs, but not for data feed.

      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        "The Unix epoch is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT)". So in this regard it is timezone agnostic - or one may think about it being always UTC.

        Internally Backtrader maintains the data feed times in UTC as well - so if your data feed uses datetime in non-UTC timezone - it will be converted internally ( for CSV based feeds you may specify the feed timezone by specifying the tzinput parameter. Some other data feeds - mostly live feeds - can automatically determine the timezone )

        More here: https://www.backtrader.com/docu/timemgmt/#datetime-input

        If the question was just how to convert the UNIX timestamp datetime to another timezone in python - this is simple:

        from datetime import datetime, timezone
        import pytz
        
        dt_utc = datetime.fromtimestamp(1588762182, timezone.utc)
        dt_eastern = dt_utc.astimezone(pytz.timezone("US/Eastern"))
        
        print(dt_utc.isoformat())
        print(dt_eastern.isoformat())
        

        This will print:

        2020-05-06T10:49:42+00:00
        2020-05-06T06:49:42-04:00
        
        SPECULARI FUND 1 Reply Last reply Reply Quote 1
        • SPECULARI FUND
          SPECULARI FUND @vladisld last edited by

          @vladisld thank you for reply. Yes, I was asking about internal timezone for live data feed. So, you need add "tz" argument to Datafactory(tz=timezone). But if you want show in logs same timezone, need add to cerebro.run():

          timezone = pytz.timezone("US/Eastern")
          cerebro.run(tz=timezone)
          

          With last param I was confused because in logs I saw right timezone, but data feed has different (UTC).

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
          $(document).ready(function () { app.coldLoad(); }); }