{"record":{"id":"f7eb4ba96d381789","repo":"nautechsystems/nautilus_trader","slug":"cannot-request-aggregated-bars-bar-type-must-be","errorCode":null,"errorMessage":"Cannot request aggregated bars: {bar_type} must be internally aggregated","messagePattern":"Cannot request aggregated bars: (.+?) must be internally aggregated","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/data/src/engine/requests.rs","lineNumber":296,"sourceCode":"        .context(\"`bar_types` request parameter must be an array\")?;\n    let mut bar_types = Vec::with_capacity(values.len());\n    for value in values {\n        let raw = value\n            .as_str()\n            .context(\"`bar_types` request parameter must contain strings\")?;\n        bar_types\n            .push(BarType::from_str(raw).context(\"failed to parse `bar_types` request parameter\")?);\n    }\n\n    if bar_types.is_empty() {\n        return Ok(None);\n    }\n\n    if let Some(bar_type) = bar_types\n        .iter()\n        .find(|bar_type| !bar_type.is_internally_aggregated())\n    {\n        anyhow::bail!(\"Cannot request aggregated bars: {bar_type} must be internally aggregated\");\n    }\n\n    let mut unique_bar_types = Vec::with_capacity(bar_types.len());\n    for bar_type in bar_types {\n        if !unique_bar_types.contains(&bar_type) {\n            unique_bar_types.push(bar_type);\n        }\n    }\n\n    let update_subscriptions = params.get_bool(\"update_subscriptions\").unwrap_or(false);\n    let skip_first_non_full_bar = params.get_bool(\"skip_first_non_full_bar\");\n\n    Ok(Some(RequestBarAggregation {\n        bar_types: unique_bar_types,\n        update_subscriptions,\n        disable_build_with_no_updates: false,\n        skip_first_non_full_bar,\n    }))","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/data/src/engine/requests.rs#L278-L314","documentation":"Requesting historical/aggregated bars through the request path requires every requested BarType to be internally aggregated, because the engine aggregates them with its own aggregators during the request. A bar type sourced from an external provider cannot be aggregated by the request pipeline, so the request is rejected.","triggerScenarios":"Calling prepare_request_bar_aggregators / request_bar_aggregation_from_params (e.g. RequestBars via strategy.request_bars) where at least one BarType in the bar_types param has AggregationSource::External.","commonSituations":"Building bar type strings with ':external' suffix in a historical data request; reusing live-subscription bar types (externally fed by an adapter) in a backtest/history request; config templates that specify external aggregation.","solutions":["Drop the external aggregation source from the requested bar types so they default to internal aggregation.","If the data is only available externally, use a direct historical request to the data client instead of the internal aggregation request path.","Validate all bar types with bar_type.is_internally_aggregated() before issuing the request."],"exampleFix":"// before\nclient.request_bars(BarType::from_str(\"AAPL.XNAS-5-MINUTE-LAST:external\")?)?;\n// after\nclient.request_bars(BarType::from_str(\"AAPL.XNAS-5-MINUTE-LAST\")?)?;","handlingStrategy":"validation","validationCode":"if bar_types.iter().any(|bt| !bt.is_internally_aggregated()) {\n    anyhow::bail!(\"all requested bar types must be internally aggregated\");\n}","typeGuard":"fn all_internally_aggregated(bts: &[BarType]) -> bool {\n    bts.iter().all(|bt| bt.is_internally_aggregated())\n}","tryCatchPattern":"match client.request_bars(bar_types, ...) {\n    Err(e) if e.to_string().contains(\"must be internally aggregated\") => {\n        let fixed: Vec<BarType> = bar_types.into_iter().map(|bt| bt.to_internal_aggregation()).collect();\n        client.request_bars(fixed, ...)?;\n    }\n    r => r?,\n}","preventionTips":["Strip external-aggregation suffixes from bar type strings used in history requests","Use direct data-client historical requests for externally sourced bars","Sanitize bar types parsed from config before requesting"],"tags":["rust","data-engine","bars","historical-request"],"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"}