pub struct TimeFrame {
pub quantity: NonZeroU32,
pub unit: TimeUnit,
}Expand description
Represents a timeframe with a quantity and a unit.
Timeframes specify the bar duration for chart data (e.g. 1 day, 5 minutes).
They can be created with convenience constructors, the general
new() method, or by parsing a string.
§Examples
use openpine_vm::{TimeFrame, TimeUnit};
// Convenience constructors
let daily = TimeFrame::days(1);
let five_min = TimeFrame::minutes(5);
let weekly = TimeFrame::weeks(1);
// General constructor
let monthly = TimeFrame::new(3, TimeUnit::Month);
// Parse from TradingView-style strings
let tf: TimeFrame = "D".parse().unwrap(); // 1 day
assert_eq!(tf, TimeFrame::days(1));
let tf: TimeFrame = "60".parse().unwrap(); // 60 minutes
assert_eq!(tf, TimeFrame::minutes(60));
let tf: TimeFrame = "4W".parse().unwrap(); // 4 weeks
assert_eq!(tf, TimeFrame::weeks(4));
// Display back to string
assert_eq!(TimeFrame::days(1).to_string(), "D");
assert_eq!(TimeFrame::minutes(5).to_string(), "5");
assert_eq!(TimeFrame::months(3).to_string(), "3M");Fields§
§quantity: NonZeroU32Number of units in the timeframe.
unit: TimeUnitBase unit for the timeframe.
Implementations§
Source§impl TimeFrame
impl TimeFrame
Sourcepub fn new(quantity: u32, unit: TimeUnit) -> Self
pub fn new(quantity: u32, unit: TimeUnit) -> Self
Creates a new TimeFrame with the given quantity and unit.
Sourcepub fn seconds(quantity: u32) -> Self
pub fn seconds(quantity: u32) -> Self
Creates a TimeFrame representing the given number of seconds.
Sourcepub fn minutes(quantity: u32) -> Self
pub fn minutes(quantity: u32) -> Self
Creates a TimeFrame representing the given number of minutes.
Sourcepub fn weeks(quantity: u32) -> Self
pub fn weeks(quantity: u32) -> Self
Creates a TimeFrame representing the given number of weeks.
Sourcepub fn months(quantity: u32) -> Self
pub fn months(quantity: u32) -> Self
Creates a TimeFrame representing the given number of months.
Sourcepub fn ticks(quantity: u32) -> Self
pub fn ticks(quantity: u32) -> Self
Creates a TimeFrame representing the given number of ticks.
Sourcepub fn multiplier(&self) -> u32
pub fn multiplier(&self) -> u32
Returns the multiplier (quantity) of the timeframe.
For example, ‘60’ - 60, ‘D’ - 1, ‘5W’ - 5.
Sourcepub fn in_seconds(&self) -> Option<u64>
pub fn in_seconds(&self) -> Option<u64>
Returns the timeframe duration in seconds, if representable.
Sourcepub fn from_seconds(seconds: i64) -> Self
pub fn from_seconds(seconds: i64) -> Self
Chooses a coarse TimeFrame that best fits seconds.
Trait Implementations§
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 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 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,
§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
key and return true if they are equal.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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.