TimeBucket#
API documentation for 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__(*args, **kwds)#
Methods
to_hours
()The length of this bucket as hours.
Get delta object for a TimeBucket definition.
Get pandas delta object for a TimeBucket definition.
Get frequency input for Pandas fuctions.
floor
(timestamp)Floor the time bucket to the nearest value.
Map Pandas timedelta to a well-known time bucket enum.
Attributes
One minute candles
Five minute candles
Quarter candles
Hourly candles
Four hour candles
Eight hour candles
Daily candles
Weekly candles
Monthly candles
We do not have "yearly" candles, but some trade statistics are calculated for 360 days, thus we need a corresponding time bucket for them.
Some statistics like "all time high", for example, only make sense if a "bucket" spans across the entire timeline.
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
- h8 = '8h'#
Eight 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:
- to_pandas_timedelta()[source]#
Get pandas delta object for a TimeBucket definition.
You can use this to construct aregime-filter.ipynbrbitrary timespans or iterate candle data, or to compare with two timebuckets.
- 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:
- floor(timestamp)[source]#
Floor the time bucket to the nearest value.
Handle business week as d7
- Parameters:
timestamp (Timestamp) –
- Return type:
Timestamp