Skip to main content

Timeframe

Struct Timeframe 

Source
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

Source

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.

Source

pub fn millis(ms: i64) -> Result<Self>

Convenience: build a millisecond timeframe.

Source

pub fn seconds(s: i64) -> Result<Self>

Convenience: build a seconds-resolution timeframe.

Source

pub fn one_minute_ms() -> Self

One-minute timeframe in milliseconds (60_000).

Source

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);
Source

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);
Source

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);
Source

pub const fn bucket(self) -> i64

Bucket size.

Source

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§

Source§

impl Clone for Timeframe

Source§

fn clone(&self) -> Timeframe

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Timeframe

Source§

impl Debug for Timeframe

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Timeframe

Source§

impl PartialEq for Timeframe

Source§

fn eq(&self, other: &Timeframe) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Timeframe

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V