{"record":{"id":"88812eed79a2699c","repo":"nautechsystems/nautilus_trader","slug":"invalid-step-in-bar-type-spec-step-step-for-agg-88812e","errorCode":null,"errorMessage":"Invalid step in bar_type.spec.step: {step} for aggregation={aggregation}. step must evenly divide {subunits} (so it is periodic).","messagePattern":"Invalid step in bar_type\\.spec\\.step: (.+?) for aggregation=(.+?)\\. step must evenly divide (.+?) \\(so it is periodic\\)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/data/bar.rs","lineNumber":526,"sourceCode":"            BarAggregation::Hour => Self::validate_periodic_step(step, aggregation, 24, false)?,\n            // 12-MONTH is allowed (unlike other full-subunit steps) because the shipped\n            // BAR_SPEC_12_MONTH_LAST constant and OKX yearly candles depend on it\n            BarAggregation::Month => Self::validate_periodic_step(step, aggregation, 12, true)?,\n            BarAggregation::Day | BarAggregation::Week | BarAggregation::Year => {}\n            _ => return Ok(()),\n        }\n\n        try_time_interval(step, aggregation).map(|_| ())\n    }\n\n    fn validate_periodic_step(\n        step: usize,\n        aggregation: BarAggregation,\n        subunits: usize,\n        allow_equal: bool,\n    ) -> anyhow::Result<()> {\n        if !subunits.is_multiple_of(step) {\n            anyhow::bail!(\n                \"Invalid step in bar_type.spec.step: {step} for aggregation={aggregation}. \\\n                 step must evenly divide {subunits} (so it is periodic).\",\n            );\n        }\n\n        if !allow_equal && subunits == step {\n            anyhow::bail!(\n                \"Invalid step in bar_type.spec.step: {step} for aggregation={aggregation}. \\\n                 step must not be {subunits}. Use higher aggregation unit instead.\",\n            );\n        }\n\n        Ok(())\n    }\n\n    /// Creates a new [`BarSpecification`] instance.\n    ///\n    /// # Panics","sourceCodeStart":508,"sourceCodeEnd":544,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/data/bar.rs#L508-L544","documentation":"validate_periodic_step requires the step to evenly divide the unit's subunits (e.g. seconds in a minute) so bars occur at fixed periodic offsets within the unit. A step that does not divide evenly would produce irregular boundaries and is rejected.","triggerScenarios":"Constructing/validating a BarTypeSpec whose step (e.g. 7 seconds in a 60-subunit minute) does not evenly divide the parent unit's subunit count.","commonSituations":"Config mistakes like step=45 for second-based bars within a minute when the divisor check fails, hand-written bar specs, or programmatically generated steps from arbitrary durations.","solutions":["Choose a step that evenly divides the subunits (e.g. 1, 2, 5, 10, 15, 30 for minutes)","Let validate_step compute a valid step instead of hardcoding one","Reject/repair the bar spec in config validation before creating the BarType"],"exampleFix":"// before: 7-second step in 60-second minute (not periodic)\nlet step = 7;\n// after\nlet step = 10; // divides 60 evenly\nbar_type_spec.validate_step()?;","handlingStrategy":"validation","validationCode":"if subunits % step != 0 {\n    return Err(anyhow!(\"step {step} must evenly divide {subunits}\"));\n}\nvalidate_periodic_step(step, aggregation, subunits, allow_equal)?;","typeGuard":null,"tryCatchPattern":"if let Err(e) = validate_periodic_step(step, aggregation, subunits, allow_equal) {\n    // fall back to a standard step (e.g. largest divisor <= requested)\n}","preventionTips":["Prefer canonical steps (1, 2, 5, 10, 15, 30) within each unit","Validate bar specs at config load time","Compute steps from durations rather than hardcoding arbitrary values"],"tags":["rust","bars","aggregation","step","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}