TimeBucket#

tradingstrategy.timebucket.TimeBucket Python class in Trading Strategy framework.

class TimeBucket[source]#

Bases: Enum

Supported time windows for candle and liquidity data.

We use term “bucket”, from the TimescaleDB slang to symbol the time window of a candle data we are querying.

The raw blockchain data is assembled to 1 minute time buckets. Then the 1 minute timebuckets are resampled to other windows.

All time windows are in UTC. Daily time buckets have their hour, minute and second set to the zero in the outputted data. Hourly time buckets have minute and hour set to zero, etc.

Python labels are reserved from the actual values, because Python symbol cannot start with a number.

__init__()#

Methods

to_timedelta()

Get delta object for a TimeBucket definition.

to_pandas_timedelta()

Get pandas delta object for a TimeBucket definition.

to_frequency()

Get frequency input for Pandas fuctions.

Attributes

m1

One minute candles

m5

Five minute candles

m15

Quarter candles

h1

Hourly candles

h4

Four hour candles

d1

Daily candles

d7

Weekly candles

d30

Monthly candles

d360

We do not have "yearly" candles, but some trade statistics are calculated for 360 days, thus we need a corresponding time bucket for them.

infinite

Some statistics like "all time high", for example, only make sense if a "bucket" spans across the entire timeline.

not_applicable

A placeholder value representing a "NULL value" for cases where Python's None is not a favorable choice for some reason.

m1 = '1m'#

One minute candles

m5 = '5m'#

Five minute candles

m15 = '15m'#

Quarter candles

h1 = '1h'#

Hourly candles

h4 = '4h'#

Four hour candles

d1 = '1d'#

Daily candles

d7 = '7d'#

Weekly candles

d30 = '30d'#

Monthly candles

d360 = '360d'#

We do not have “yearly” candles, but some trade statistics are calculated for 360 days, thus we need a corresponding time bucket for them.

infinite = 'infinite'#

Some statistics like “all time high”, for example, only make sense if a “bucket” spans across the entire timeline.

not_applicable = 'not_applicable'#

A placeholder value representing a “NULL value” for cases where Python’s None is not a favorable choice for some reason.

to_timedelta()[source]#

Get delta object for a TimeBucket definition.

You can use this to construct arbitrary timespans or iterate candle data.

Return type:

timedelta

to_pandas_timedelta()[source]#

Get pandas delta object for a TimeBucket definition.

You can use this to construct arbitrary timespans or iterate candle data.

Return type:

Timedelta

to_frequency()[source]#

Get frequency input for Pandas fuctions.

You can use this to construct arbitrary timespans or iterate candle data.

Return type:

DateOffset