For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

How convert data feed's (live) timezone?

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

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

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

  • "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:

    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"))

    This will print:


  • @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

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

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