Skip to content

Insight Lifecycle

AQE tracks insights through a state machine that includes:

  • New
  • Executed
  • Filled
  • Closed
  • Cancelled
  • Rejected

Typical paths look like:

  • New -> Executed -> Filled -> Closed
  • New -> Rejected
  • Executed -> Cancelled
  • Filled -> Closed

Expiry, pipe failures, broker rejections, and trade updates all feed into those transitions.

AQE supports two important lifecycle controls:

  • period_unfilled applies while the insight is still New or Executed. Expired insights are rejected or cancellation is requested, depending on state.
  • period_till_tp applies once the insight is Filled. Expiry can trigger a close request.

Those checks are enforced by the runtime, not by the UI.

Every significant change can be recorded into state_history, including:

  • state transitions
  • submission
  • broker acceptance
  • fills
  • partial closes
  • cancellation requests
  • rejections
  • expiry handling

That history is what makes the shared inspector in AQS and Backtest Results useful for review.

Use state_log(...) when you want to attach a review note to an insight without changing its lifecycle state. The strategy hook receives insights by shared reference, so add these messages from a pipe or another runtime path that has &mut Insight.

use aq_engine::core::insight::{types::InsightState, Insight};
use aq_engine::core::pipeline::{InsightPipe, InsightPipeBuilder, InsightPipeResult};
use aq_engine::core::strategy::StrategyContext;
pub struct ReviewNotePipe;
impl InsightPipe for ReviewNotePipe {
fn version(&self) -> &str {
"1.0"
}
fn run(&mut self, _ctx: &mut dyn StrategyContext, insight: &mut Insight) -> InsightPipeResult {
insight.state_log(Some("Risk check passed".to_string()));
InsightPipeResult::new(
true,
true,
Some("Review note added to insight history".to_string()),
self.name().to_string(),
)
}
}

Register the pipe on the state where you want the note to be added:

ctx.add_pipe(
InsightPipeBuilder::new(Box::new(ReviewNotePipe))
.target_state(InsightState::Filled)
.build(),
);

state_log(...) keeps the current state, updates updated_at, and appends the supplied message to state_history. If you pass None, AQE records "State log entry".

Insight snapshots include execution fields such as filled_price, close_price, broker_realized_pnl, commission, and swap. Live runs sync those snapshots to AQS Cloud, and backtests persist them to the local result database.