DateTime

DataTime functions are made so that you can get the current date and time that your strategy thinks it is, regardless of whether you are backtesting or trading live. These can be especially useful when you’re backtesting so that you can see what date/time it is according to the backtest (eg. if you’re backtesting in the 1990s it can tell you that the strategy thinks it is Jan 10, 1991 rather than today’s date). You can see a list of them below:

get_datetime([adjust_for_delay])

Returns the current datetime according to the data source.

get_timestamp()

Returns the current timestamp according to the data source.

get_round_minute([timeshift])

Returns the current minute rounded to the nearest minute.

get_last_minute()

Returns the last minute of the current day.

get_round_day([timeshift])

Returns the current day rounded to the nearest day.

get_last_day()

Returns the last day of the current month.

get_datetime_range(length[, timestep, timeshift])

Returns a list of datetimes for the given length and timestep.

localize_datetime(dt)

Returns a datetime localized to the data source's timezone.

to_default_timezone(dt)

Returns a datetime localized to the data source's default timezone.