Skip to content

Advanced Insight Management

AQE supports child insights directly on the core insight model. A parent insight can attach one or more child insights and preserve that relationship through the runtime and the snapshot data model.

aq-engine/src/core/insight/insight.rs
pub fn add_child_insight(
&mut self,
mut child_insight: Insight,
_ctx: &mut dyn StrategyContext,
) -> &mut Self {
child_insight.strategy_type =
StrategyType::Custom(format!("{}-CHILD", self.strategy_type.to_string()));
child_insight.parent_id = Some(self.insight_id);
if child_insight.quantity.is_none() {
child_insight.quantity = self.quantity;
}
let child_id = child_insight.insight_id;
self.children.push(child_insight);
self.update_state(
self.state.clone(),
Some(format!("Added child insight: {:?}", child_id)),
);
self
}

That gives you two important capabilities:

  • lineage: child insights remain connected to the original parent through parent_id
  • deferred submission: AQE can queue child insights and submit them at the right time in the runtime loop

Typical use cases include staged entries, follow-up signals derived from a parent fill, and multi-step trade plans that need a linked inspection trail.

The insight stores the configuration you define, but the broker owns the actual execution legs:

  • take-profit legs
  • stop-loss legs
  • trailing-stop legs

For example, a trailing stop is defined on the insight as a float gap, while the broker creates and manages the actual trailing stop leg during execution.

Insights can record partial close results over time. That matters for:

  • scale-out strategies
  • multi-target exits
  • accurate inspection in AQS and backtest review

If a strategy uses more than one take-profit level, AQE can close part of the quantity while leaving the remaining position open.

Child insights and partial closes solve different problems:

  • partial closes keep one insight open while reducing size over time
  • child insights create separate linked insights with their own lifecycle