#[non_exhaustive]pub enum Timeframe {
Show 24 variants
Ms100,
Ms250,
Ms500,
Sec1,
Sec2,
Sec5,
Sec10,
Sec30,
Min1,
Min5,
Min15,
Min30,
Hour1,
Hour4,
Day1,
Week1,
Month1,
Custom(NonZeroU64),
Ticks(NonZeroU64),
Volume(NonZeroU64),
Range(NonZeroU64),
Delta(NonZeroU64),
Weeks(NonZeroU32),
Months(NonZeroU32),
}Expand description
Timeframe for bar aggregation.
Time variants represent a fixed or calendar interval over which OHLCV data is aggregated
into a single Bar. The default timeframe is Min1.
Timeframes are divided into tiers:
| Tier | Variants |
|---|---|
| Tick count | Ticks(count) – a nonzero number of executions |
| Volume | Volume(units) – exact traded volume |
| Range | Range(ticks) – price range in instrument ticks |
| Delta | Delta(units) – absolute buy minus sell volume |
| Millisecond | Ms100, Ms250, Ms500 |
| Second | Sec1 .. Sec30 |
| Minute | Min1, Min5, Min15, Min30 |
| Hourly | Hour1, Hour4 |
| Daily+ | Day1, Week1, Month1, Weeks(count), Months(count) |
| Custom | Custom(seconds) – any user-defined interval |
§Example
use egui_charts::model::Timeframe;
let tf = Timeframe::Hour4;
assert_eq!(tf.duration_ms(), 14_400_000);
assert_eq!(tf.to_string(), "4h");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Ms100
100-millisecond bars (HFT).
Ms250
250-millisecond bars (HFT).
Ms500
500-millisecond bars (HFT).
Sec1
1-second bars.
Sec2
2-second bars.
Sec5
5-second bars.
Sec10
10-second bars.
Sec30
30-second bars.
Min1
1-minute bars (default).
Min5
5-minute bars.
Min15
15-minute bars.
Min30
30-minute bars.
Hour1
1-hour bars.
Hour4
4-hour bars.
Day1
Daily bars.
Week1
Weekly bars.
Month1
Monthly bars (approximated as 30 days for duration calculations).
Custom(NonZeroU64)
Custom timeframe defined in seconds. Allows user-defined intervals (e.g., 45s, 3min, 2h). The interval is never zero.
Ticks(NonZeroU64)
One bar per nonzero number of accepted trades, starting at subscription or replay start.
Volume(NonZeroU64)
Exact traded volume per bar, in whole units. A fill spanning bars is split by size.
Range(NonZeroU64)
Price range in instrument ticks. Closes on the first real fill reaching the range; skipped prices can overshoot it. No synthetic executions are inserted.
Delta(NonZeroU64)
Absolute buy minus sell volume per bar, in whole units. Fills split at the threshold; unknown sides contribute volume but no delta.
Weeks(NonZeroU32)
Calendar weeks, aligned to Monday 1970-01-05 in the clock’s timezone.
Months(NonZeroU32)
Calendar months, aligned to January 1970 in the clock’s timezone. Three, six and twelve months start on calendar quarters, half-years and years.
Implementations§
Source§impl Timeframe
impl Timeframe
Sourcepub fn as_str(&self) -> Cow<'static, str>
pub fn as_str(&self) -> Cow<'static, str>
Returns the canonical string label for this timeframe (e.g. "1min", "4h", "1D").
Sourcepub fn is_trade_based(self) -> bool
pub fn is_trade_based(self) -> bool
Whether bars close on executions rather than a time boundary.
Sourcepub fn all() -> Vec<Timeframe>
pub fn all() -> Vec<Timeframe>
Returns the preset time intervals in ascending duration order. Trade-based intervals are excluded.
Sourcepub fn duration_ms(&self) -> i64
pub fn duration_ms(&self) -> i64
Duration in milliseconds, saturating at i64::MAX for huge custom timeframes.
Calendar months use an approximate 30 days each; use super::BarClock for boundaries.
Trade-based intervals have no time duration and return zero; do not use them to step time.
Sourcepub fn from_resolution(resolution: &str) -> Option<Self>
pub fn from_resolution(resolution: &str) -> Option<Self>
Convert a resolution string to Timeframe
Trait Implementations§
impl Copy for Timeframe
Source§impl<'de> Deserialize<'de> for Timeframe
impl<'de> Deserialize<'de> for Timeframe
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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§
impl<T> AsId for T
impl<T> AsIdSalt for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
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