Skip to main content

resample_with_session

Function resample_with_session 

Source
pub fn resample_with_session(
    bars: &[Bar],
    from: impl Into<BarClock>,
    to: impl Into<BarClock>,
    instrument: &Instrument,
    extended_hours: bool,
) -> Option<Vec<Bar>>
Expand description

Builds a coarser interval using the instrument’s exchange trading hours and dates.

Intraday inputs must be stamped at their actual open, including a shortened final bar. Intraday target slots start at the first selected session window of each trading date; daily, weekly and monthly targets use that trading date, including overnight sessions. Bars outside the selected hours and holidays are omitted. No bars are invented across gaps, and the last output includes all available inputs even while its period is forming. Daily and longer inputs already carry their trading date as a calendar label. Pass timeframes for UTC labels, or matching source and target BarClock values to retain another calendar. Exchange time determines the trading date; the target clock determines its output label.

As with resample, returns None if an input straddles target slots or folded volume overflows. The host retains the base history and calls again after live updates or corrections. Native source intervals can be reported through Instrument::native_timeframes.