Time Modeling

Time Zones


LEAN is an international trading engine, so it can operate across time zones. The exchange, your algorithm, and the data in your algorithm can all have different time zones.

Exchange Time Zone

Exchanges are located in different areas, so they can have different time zones. To get the time zone of the exchange that a Security trades on, use its Exchange.Hours.TimeZoneexchange.hours.time_zone property.

var timeZone = Securities[_symbol].Exchange.Hours.TimeZone;
time_zone = self.securities[self._symbol].exchange.hours.time_zone

Algorithm Time Zone

LEAN supports international trading across multiple time zones and markets, so it needs a reference time zone for the algorithm to set the Timetime. The default time zone is Eastern Time (ET), which is UTC-4 in summer and UTC-5 in winter. To set a different time zone, call the SetTimeZoneset_time_zone method. This method accepts either a string following the IANA Time Zone database convention or a NodaTime.DateTimeZone object. If you pass a string, the method converts it to a NodaTime.DateTimeZone object. The TimeZones class provides the following helper attributes to create NodaTime.DateTimeZone objects:


To get the time zone of your algorithm, use theTimeZonetime_zone property.

time_zone = self.time_zone
var timeZone = TimeZone;

To get the algorithm time in Coordinated Universal Time (UTC), use the UtcTimeutc_time property.

utc_time = self.utc_time
var utcTime = UtcTime;

The Timetime and UtcTimeutc_time objects have no time zone. LEAN maintains their state to be consistent.

Data Time Zone

Datasets can have different time zones because the time zone is up to the data provider, where they are located, and where they collect the data. LEAN tracks the time zone of each dataset so that you receive the correct data at the right point in time in your algorithm. If you have multiple datasets in your algorithm from different time zones, LEAN synchronizes them to your algorithm time. Furthermore, if you set up time period consolidators, LEAN consolidates the data based on the data time zone.

To get the time zone of a dataset, view the listing page in the Dataset Market or call the GetDataTimeZone method.

time_zone = self.market_hours_database.get_data_time_zone(Market.USA, self.symbol, SecurityType.EQUITY)
var timeZone = MarketHoursDatabase.GetDataTimeZone(Market.USA, _symbol, SecurityType.Equity);

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: