Skip to content

Execution.time off by host UTC offset - zone-less timestamp resolved against host local zone #230

Description

@ivannp

Version: ib_async 2.1.0

TWS sends execution times zone-less (YYYYMMDD-HH:MM:SS, UTC), but on a non-UTC host they decode to the wrong instant.

In Decoder.execDetails, when TimezoneTWS is unset the parsed time stays naive, then time.astimezone(defaultTimezone) is called and naive.astimezone() presumes system local time, so the UTC time string gets read in the host's zone.

Repro (host = America/Chicago):

from ib_async.util import parseIBDatetime
from zoneinfo import ZoneInfo
t = parseIBDatetime("20260824-20:00:12")            # naive
print(t.astimezone(ZoneInfo("America/New_York")))
# -> 2026-08-24 21:00:12-04:00  (wrong; expected 16:00, i.e. 20:00 UTC)

Result silently depends on host timezone. Suggested fix - default the source zone to UTC when there is no timezone information in the string.

TWS seems to send most timestamps with timezone attached to it. Log inspection suggests that timestamps without a timezone are indeed in UTC, but there is no documentation confirming this except here, but it's about their web api.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions