Aller au contenu

Structure d’un insight

Un insight stocke l’intention de trading et l’état d’exécution nécessaire pour l’inspecter ensuite.

Les champs principaux incluent :

  • symbole
  • side
  • confiance
  • timeframe
  • lignée parent/enfant
  • quantité
  • contrats
  • structure d’entrée
  • niveaux de take-profit et stop-loss
  • écart de trailing stop
  • prix de fill et de clôture
  • PnL réalisé courtier, commission et swap
  • jambes d’exécution
  • historique d’état
aq-engine/src/core/insight/insight.rs
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>,
}

Le pattern utilisateur le plus courant est :

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);

À partir de là, le pipeline d’insights peut ajouter le sizing, les validations ou le comportement de soumission.