From c85116c59db4c921fee97394a9f2c40609b22a62 Mon Sep 17 00:00:00 2001 From: boris Date: Wed, 22 Apr 2026 23:23:51 -0700 Subject: [PATCH] Add open auction strategy hook --- crates/fidc-core/src/engine.rs | 1 + crates/fidc-core/src/strategy.rs | 3 +++ crates/fidc-core/tests/engine_hooks.rs | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/crates/fidc-core/src/engine.rs b/crates/fidc-core/src/engine.rs index e7048df..a3e752b 100644 --- a/crates/fidc-core/src/engine.rs +++ b/crates/fidc-core/src/engine.rs @@ -203,6 +203,7 @@ where portfolio: &portfolio, }; self.strategy.before_trading(&daily_context)?; + self.strategy.open_auction(&daily_context)?; let decision = decision_slot .map(|(decision_idx, decision_date)| { diff --git a/crates/fidc-core/src/strategy.rs b/crates/fidc-core/src/strategy.rs index d381439..af1236a 100644 --- a/crates/fidc-core/src/strategy.rs +++ b/crates/fidc-core/src/strategy.rs @@ -18,6 +18,9 @@ pub trait Strategy { fn before_trading(&mut self, _ctx: &StrategyContext<'_>) -> Result<(), BacktestError> { Ok(()) } + fn open_auction(&mut self, _ctx: &StrategyContext<'_>) -> Result<(), BacktestError> { + Ok(()) + } fn on_day(&mut self, ctx: &StrategyContext<'_>) -> Result; fn after_trading(&mut self, _ctx: &StrategyContext<'_>) -> Result<(), BacktestError> { Ok(()) diff --git a/crates/fidc-core/tests/engine_hooks.rs b/crates/fidc-core/tests/engine_hooks.rs index e2088bb..a50f321 100644 --- a/crates/fidc-core/tests/engine_hooks.rs +++ b/crates/fidc-core/tests/engine_hooks.rs @@ -29,6 +29,16 @@ impl Strategy for HookProbeStrategy { Ok(()) } + fn open_auction( + &mut self, + ctx: &StrategyContext<'_>, + ) -> Result<(), fidc_core::BacktestError> { + self.log + .borrow_mut() + .push(format!("auction:{}", ctx.execution_date)); + Ok(()) + } + fn on_day( &mut self, ctx: &StrategyContext<'_>, @@ -217,10 +227,12 @@ fn engine_runs_strategy_hooks_in_daily_order() { log.borrow().as_slice(), [ "before:2025-01-02", + "auction:2025-01-02", "on_day:2025-01-02", "after:2025-01-02", "settlement:2025-01-02", "before:2025-01-03", + "auction:2025-01-03", "on_day:2025-01-03", "after:2025-01-03", "settlement:2025-01-03",