{"record":{"id":"d92256c274416170","repo":"nautechsystems/nautilus_trader","slug":"timedelta-not-supported-for-aggregation-type","errorCode":null,"errorMessage":"Timedelta not supported for aggregation type: {:?}","messagePattern":"Timedelta not supported for aggregation type: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/data/bar.rs","lineNumber":587,"sourceCode":"\n        match self.aggregation {\n            BarAggregation::Millisecond => SignedDuration::from_millis(step),\n            BarAggregation::Second => SignedDuration::from_secs(step),\n            BarAggregation::Minute => SignedDuration::from_mins(step),\n            BarAggregation::Hour => SignedDuration::from_hours(step),\n            BarAggregation::Day => duration_days(step),\n            BarAggregation::Week => {\n                duration_days(step.checked_mul(7).expect(\"`step` overflows i64 days\"))\n            }\n            BarAggregation::Month => {\n                // Proxy for comparing bar lengths\n                duration_days(step.checked_mul(30).expect(\"`step` overflows i64 days\"))\n            }\n            BarAggregation::Year => {\n                // Proxy for comparing bar lengths\n                duration_days(step.checked_mul(365).expect(\"`step` overflows i64 days\"))\n            }\n            _ => panic!(\n                \"Timedelta not supported for aggregation type: {:?}\",\n                self.aggregation\n            ),\n        }\n    }\n\n    /// Return a value indicating whether the aggregation method is time-driven:\n    ///  - [`BarAggregation::Millisecond`]\n    ///  - [`BarAggregation::Second`]\n    ///  - [`BarAggregation::Minute`]\n    ///  - [`BarAggregation::Hour`]\n    ///  - [`BarAggregation::Day`]\n    ///  - [`BarAggregation::Week`]\n    ///  - [`BarAggregation::Month`]\n    ///  - [`BarAggregation::Year`]\n    #[must_use]\n    pub fn is_time_aggregated(&self) -> bool {\n        matches!(","sourceCodeStart":569,"sourceCodeEnd":605,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/data/bar.rs#L569-L605","documentation":"`BarType::timedelta` (and its Python wrapper) returns the bar interval as a timedelta duration. Like `get_bar_interval`, it only supports the time-based aggregations; the `_ => panic!(\"Timedelta not supported for aggregation type: {:?}\", self.aggregation)` arm fires for non-time aggregations such as Tick or Value. Called via `bar_close_from_open`, `py_timedelta`, and `py_get_interval_ns`.","triggerScenarios":"Calling `bar_type.timedelta()` (or `py_get_interval_ns` from Python) on a BarType whose aggregation is TICK or VALUE; computing bar close times generically over a list of bar types that includes tick/value bars.","commonSituations":"Python strategy code calling `.timedelta` on tick bars to compute close times; mixed bar-type dashboards; instrument configs where the aggregation was changed from SECOND to TICK but downstream code still asks for a timedelta.","solutions":["Check the aggregation is time based before calling `timedelta()`.","Handle tick/value bar types separately (they close on events, not on a time interval).","Fix the BarType aggregation in your config/spec so it matches the time-interval expectation."],"exampleFix":"# before\ninterval = bar_type.timedelta()  # panics for TICK bars\n\n# after\nfrom nautilus_trader.model.enums import BarAggregation\nTIME_BASED = {BarAggregation.MILLISECOND, BarAggregation.SECOND, BarAggregation.MINUTE,\n              BarAggregation.HOUR, BarAggregation.DAY, BarAggregation.WEEK,\n              BarAggregation.MONTH, BarAggregation.YEAR}\nif bar_type.spec().aggregation not in TIME_BASED:\n    raise ValueError(f\"no timedelta for {bar_type.spec().aggregation}\")\ninterval = bar_type.timedelta()","handlingStrategy":"validation","validationCode":"# Python\nif bar_type.spec().aggregation in (BarAggregation.TICK, BarAggregation.VALUE):\n    raise ValueError(\"timedelta only defined for time-based bar aggregations\")\ninterval = bar_type.timedelta()","typeGuard":"def has_timedelta(bar_type) -> bool:\n    a = bar_type.spec().aggregation\n    from nautilus_trader.model.enums import BarAggregation\n    return a not in (BarAggregation.TICK, BarAggregation.VALUE)","tryCatchPattern":null,"preventionTips":["Check the aggregation enum before any timedelta/interval call","Handle tick and value bars via event counts rather than durations","Audit strategy configs for aggregations changed to TICK/VALUE after code was written"],"tags":["rust","python","bars","aggregation","panic"],"backgroundTag":"unsupported-enum-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}