pub struct Timeframe { /* private fields */ }Expand description
A candle bucket size measured in the same unit as the tick timestamps.
Wickra is unit-agnostic about timestamps: choose whichever makes sense for your source (milliseconds for Binance trade events, microseconds for IB, seconds for daily bars).
Implementations§
Source§impl Timeframe
impl Timeframe
Sourcepub fn new(bucket: i64) -> Result<Self>
pub fn new(bucket: i64) -> Result<Self>
Construct a timeframe with the given bucket size in the chosen unit.
§Errors
Returns Error::InvalidTimeframe if bucket <= 0.
Sourcepub fn one_minute_ms() -> Self
pub fn one_minute_ms() -> Self
One-minute timeframe in milliseconds (60_000).
Sourcepub fn minutes(n: i64) -> Result<Self>
pub fn minutes(n: i64) -> Result<Self>
Convenience: build a timeframe of n whole minutes, measured in
seconds — consistent with Timeframe::seconds.
minutes(5) yields a bucket of 300, for use with second-resolution
timestamps. For millisecond timestamps (Binance) multiply yourself or
use Timeframe::millis.
§Errors
Returns Error::InvalidTimeframe if n is not positive or if
n * 60 overflows i64.
use wickra_data::aggregator::Timeframe;
assert_eq!(Timeframe::minutes(5)?.bucket(), 300);Sourcepub fn hours(n: i64) -> Result<Self>
pub fn hours(n: i64) -> Result<Self>
Convenience: build a timeframe of n whole hours, measured in seconds
(hours(2) → a bucket of 7_200).
§Errors
Returns Error::InvalidTimeframe if n is not positive or if
n * 3_600 overflows i64.
use wickra_data::aggregator::Timeframe;
assert_eq!(Timeframe::hours(2)?.bucket(), 7_200);Sourcepub fn days(n: i64) -> Result<Self>
pub fn days(n: i64) -> Result<Self>
Convenience: build a timeframe of n whole days, measured in seconds
(days(1) → a bucket of 86_400).
§Errors
Returns Error::InvalidTimeframe if n is not positive or if
n * 86_400 overflows i64.
use wickra_data::aggregator::Timeframe;
assert_eq!(Timeframe::days(1)?.bucket(), 86_400);Sourcepub fn floor(self, ts: i64) -> i64
pub fn floor(self, ts: i64) -> i64
Floor a raw timestamp to this timeframe’s bucket boundary.
For a timestamp within one bucket of i64::MIN the mathematically
exact boundary lies below i64::MIN and cannot be represented; in that
(practically unreachable) case the result saturates at i64::MIN
rather than overflowing and panicking in debug builds. bucket is
always positive, so rem_euclid itself cannot panic.