pub struct Candle {
pub open: f64,
pub high: f64,
pub low: f64,
pub close: f64,
pub volume: f64,
pub timestamp: i64,
}Expand description
A single OHLCV bar.
Timestamps are unitless i64 values so callers can use whatever epoch resolution
they prefer (milliseconds, microseconds, seconds…). Wickra never inspects them
numerically beyond passing them through.
Fields§
§open: f64Bar open price.
high: f64Bar high price.
low: f64Bar low price.
close: f64Bar close price.
volume: f64Bar volume.
timestamp: i64Bar timestamp (caller-defined epoch / resolution).
Implementations§
Source§impl Candle
impl Candle
Sourcepub fn new(
open: f64,
high: f64,
low: f64,
close: f64,
volume: f64,
timestamp: i64,
) -> Result<Self>
pub fn new( open: f64, high: f64, low: f64, close: f64, volume: f64, timestamp: i64, ) -> Result<Self>
Construct a new candle, validating the OHLC relationships and finiteness.
§Errors
Returns Error::InvalidCandle if any of these invariants are violated:
high >= max(open, close, low)low <= min(open, close, high)- all of
open,high,low,close,volumeare finite volume >= 0
Sourcepub const fn new_unchecked(
open: f64,
high: f64,
low: f64,
close: f64,
volume: f64,
timestamp: i64,
) -> Self
pub const fn new_unchecked( open: f64, high: f64, low: f64, close: f64, volume: f64, timestamp: i64, ) -> Self
Construct a candle without validation. The caller asserts that all OHLC invariants hold and that no field is NaN or infinite.
Sourcepub fn typical_price(&self) -> f64
pub fn typical_price(&self) -> f64
The typical price (high + low + close) / 3. Used by CCI, MFI, VWAP, etc.
Sourcepub fn median_price(&self) -> f64
pub fn median_price(&self) -> f64
The mid price (high + low) / 2.
Sourcepub fn weighted_close(&self) -> f64
pub fn weighted_close(&self) -> f64
The weighted close (high + low + 2*close) / 4.
Sourcepub fn true_range(&self, prev_close: Option<f64>) -> f64
pub fn true_range(&self, prev_close: Option<f64>) -> f64
True range of this candle relative to a previous close: max(H-L, |H-prev|, |L-prev|).
If no previous close is supplied, falls back to high - low.
Trait Implementations§
impl Copy for Candle
impl StructuralPartialEq for Candle
Auto Trait Implementations§
impl Freeze for Candle
impl RefUnwindSafe for Candle
impl Send for Candle
impl Sync for Candle
impl Unpin for Candle
impl UnsafeUnpin for Candle
impl UnwindSafe for Candle
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