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.
Trait Implementations§
impl Copy for Timeframe
impl Eq for Timeframe
impl StructuralPartialEq for Timeframe
Auto Trait Implementations§
impl Freeze for Timeframe
impl RefUnwindSafe for Timeframe
impl Send for Timeframe
impl Sync for Timeframe
impl Unpin for Timeframe
impl UnsafeUnpin for Timeframe
impl UnwindSafe for Timeframe
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more