跳转到内容

交易信号结构

交易信号记录交易意图及其执行状态,供后续检查和分析。

核心字段包括:

  • 品种代码
  • 买卖方向
  • 置信度
  • 周期
  • 父子关联关系
  • 数量
  • 合约数
  • 入场结构
  • 止盈和止损价位
  • 移动止损间距
  • 成交价和平仓价
  • 经纪商已实现盈亏、佣金和隔夜利息
  • 执行订单分支
  • 状态历史
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>,
}

最常见的使用模式如下:

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

随后可由信号处理流水线完成仓位计算、验证或提交。