pub struct Candle {
pub close_time: DateTime<Utc>,
pub open: Decimal,
pub high: Decimal,
pub low: Decimal,
pub close: Decimal,
pub volume: Decimal,
pub trade_count: u64,
}Expand description
Normalised Barter OHLCV Candle model.
§close_time contract
close_time is the exclusive end-of-period boundary of the candle:
close_time == open_time + intervalA candle aggregates the trades that fall in the half-open interval
[close_time − interval, close_time) — i.e. trades with
open_time ≤ ts < close_time. A trade landing exactly on close_time
belongs to the next candle, so close_time equals the next candle’s
open instant.
Two distinct caveats apply to the boundary — do not conflate them:
- Not session-aligned (daily/weekly/monthly): the boundary is the UTC
period grid (
day → next 00:00 UTC, etc.), not an exchange session close. The library has no session calendar. - Variable-length calendar arithmetic (month/quarter/year only): these
are nominal boundaries computed with calendar months (chrono
Months), not fixedDurations. Daily and weekly are exact fixed durations in UTC (no DST), exact to the millisecond. Theopen_time + N monthsequality holds only whenopen_timeis calendar-grid-aligned (e.g. a1Mcandle opens on the 1st at 00:00 UTC); a non-aligned open day-clamps (Jan 31 + 1 month → Feb 28/29). Venue-supplied open times are always aligned, so clamping never arises in practice, but it is part of the contract for callers computing boundaries from arbitrary instants.
Candle deliberately carries neither open_time nor interval — recover
them from the originating fetch request / subscription resolution
(open_time ≡ close_time − interval). Range-computing producers derive
close_time through close_time_from_open so the boundary is defined in
exactly one place (the Massive WS path uses the venue-supplied boundary
directly — see close_time_from_open for the full producer list).
§Using a Candle with the engine
When wrapping a Candle into a MarketEvent for
a consuming engine (live or backtest), set
time_exchange to this
close_time — it is the period-END instant, the only choice that avoids
lookahead (see that field’s contract). The library’s own candle producers
already do this.
Fields§
§close_time: DateTime<Utc>§open: Decimal§high: Decimal§low: Decimal§close: Decimal§volume: Decimal§trade_count: u64Trait Implementations§
impl Copy for Candle
Source§impl<'de> Deserialize<'de> for Candle
impl<'de> Deserialize<'de> for Candle
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>,
Source§impl PartialOrd for Candle
impl PartialOrd 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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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