Timeframes Module

The Timeframe class represents a range of kline candles with start/end timestamps, timezone, and iteration support.

Timeframe class: represents a discrete time range of klines.

Uses KlineTimestamp from kline-timestamp library for candle boundary calculations.

Classes:

Timeframe(start, end[, timezone_IANA, ...])

class Timeframe(start: str | int | datetime | KlineTimestamp | None, end: str | int | datetime | KlineTimestamp | None, timezone_IANA: str | None = 'UTC', tick_interval: str | None = '1m', hours: int = None, limit: int = None, closed: bool = True)[source]

Bases: object

Methods:

to_string()

Converts the Timeframe to a formatted string.

adjust_to_open([inplace])

Adjusts the start and end to the beginning of their respective tick intervals.

get_ms()

Returns the total milliseconds from start to end.

update_tick_interval(tick_interval[, inplace])

Updates the tick interval.

get_hours()

Returns the number of hours in the Timeframe.

get_limit()

Returns the number of candles (len).

get_pandas_index([name])

Returns a pandas DatetimeIndex for the Timeframe.

to_string() str[source]

Converts the Timeframe to a formatted string.

adjust_to_open(inplace: bool = False) Timeframe[source]

Adjusts the start and end to the beginning of their respective tick intervals.

get_ms() int[source]

Returns the total milliseconds from start to end.

update_tick_interval(tick_interval: str | None, inplace: bool = False)[source]

Updates the tick interval.

Parameters:
  • tick_interval – The new tick interval.

  • inplace – If True, modifies in place. If False, returns new Timeframe.

get_hours() float[source]

Returns the number of hours in the Timeframe.

get_limit() int[source]

Returns the number of candles (len).

get_pandas_index(name: str = '') DatetimeIndex[source]

Returns a pandas DatetimeIndex for the Timeframe.

Parameters:

name – The name of the index.