Insight Structure
An insight stores the trading intent and the execution state needed to inspect that intent later.
Core fields include:
- symbol
- side
- confidence
- timeframe
- parent/child lineage
- quantity
- contracts
- entry structure
- take-profit and stop-loss levels
- trailing stop gap
- fill and close prices
- broker realized PnL, commission, and swap
- execution legs
- state history
pub struct Insight { pub insight_id: Uuid, pub parent_id: Option<Uuid>, pub state: InsightState, pub children: Vec<Insight>,
// Order information pub order_id: Option<String>, pub side: OrderSide, pub symbol: String, pub quantity: Option<f64>, pub contracts: Option<f64>,
// Order execution details pub order_type: OrderType, pub order_class: OrderClass, pub limit_price: Option<f64>, pub stop_price: Option<f64>, pub take_profit_levels: Option<Vec<f64>>, pub stop_loss_levels: Option<Vec<f64>>, pub trailing_stop_price: Option<f64>,
// Strategy information pub strategy_type: StrategyType, pub confidence: u8, pub timeframe: TimeFrame, pub period_unfilled: Option<u32>, pub period_till_tp: Option<u32>, pub execution_depends: Vec<StrategyDependentConfirmation>,
// Closing information pub filled_price: Option<f64>, pub close_order_id: Option<String>, pub close_price: Option<f64>, pub broker_realized_pnl: Option<f64>, pub commission: Option<f64>, pub swap: Option<f64>, pub partial_closes: Vec<PartialCloseResult>, pub created_at: DateTime<Utc>, pub updated_at: DateTime<Utc>, pub filled_at: Option<DateTime<Utc>>, pub closed_at: Option<DateTime<Utc>>, pub legs: OrderLegs,
// Market conditions pub market_changed: bool,
// Internal flags pub submitted: bool, pub cancelling: bool, pub closing: bool, pub first_on_fill: bool, pub partial_filled_quantity: Option<f64>,
// State tracking pub state_history: Vec<(DateTime<Utc>, InsightState, Option<String>)>, pub context: Option<InsightStrategyContext>,}Creating An Insight
Section titled “Creating An Insight”The most common user-facing pattern is:
let mut insight = Insight::new( OrderSide::Buy, "AAPL".to_string(), StrategyType::Testing, ctx.timeframe().clone(), 80, None,);
insight .set_limit_price(Some(200.0)) .set_take_profit_levels(Some(vec![206.0])) .set_stop_loss(Some(197.5)) .set_period_unfilled(Some(5)) .set_period_till_tp(Some(12));
ctx.add_insight(insight);From there, the insight pipeline can add sizing, validations, or submission behaviour.
Essential cookies and storage
We use essential cookies and storage for sign-in, account security, colour theme preferences, this notice, and required PostHog internal usage, session quality, and reliability metrics. We do not use advertising cookies.
