Add open auction strategy hook

This commit is contained in:
boris
2026-04-22 23:23:51 -07:00
parent 2b5241c2e6
commit c85116c59d
3 changed files with 16 additions and 0 deletions

View File

@@ -203,6 +203,7 @@ where
portfolio: &portfolio, portfolio: &portfolio,
}; };
self.strategy.before_trading(&daily_context)?; self.strategy.before_trading(&daily_context)?;
self.strategy.open_auction(&daily_context)?;
let decision = decision_slot let decision = decision_slot
.map(|(decision_idx, decision_date)| { .map(|(decision_idx, decision_date)| {

View File

@@ -18,6 +18,9 @@ pub trait Strategy {
fn before_trading(&mut self, _ctx: &StrategyContext<'_>) -> Result<(), BacktestError> { fn before_trading(&mut self, _ctx: &StrategyContext<'_>) -> Result<(), BacktestError> {
Ok(()) Ok(())
} }
fn open_auction(&mut self, _ctx: &StrategyContext<'_>) -> Result<(), BacktestError> {
Ok(())
}
fn on_day(&mut self, ctx: &StrategyContext<'_>) -> Result<StrategyDecision, BacktestError>; fn on_day(&mut self, ctx: &StrategyContext<'_>) -> Result<StrategyDecision, BacktestError>;
fn after_trading(&mut self, _ctx: &StrategyContext<'_>) -> Result<(), BacktestError> { fn after_trading(&mut self, _ctx: &StrategyContext<'_>) -> Result<(), BacktestError> {
Ok(()) Ok(())

View File

@@ -29,6 +29,16 @@ impl Strategy for HookProbeStrategy {
Ok(()) 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( fn on_day(
&mut self, &mut self,
ctx: &StrategyContext<'_>, ctx: &StrategyContext<'_>,
@@ -217,10 +227,12 @@ fn engine_runs_strategy_hooks_in_daily_order() {
log.borrow().as_slice(), log.borrow().as_slice(),
[ [
"before:2025-01-02", "before:2025-01-02",
"auction:2025-01-02",
"on_day:2025-01-02", "on_day:2025-01-02",
"after:2025-01-02", "after:2025-01-02",
"settlement:2025-01-02", "settlement:2025-01-02",
"before:2025-01-03", "before:2025-01-03",
"auction:2025-01-03",
"on_day:2025-01-03", "on_day:2025-01-03",
"after:2025-01-03", "after:2025-01-03",
"settlement:2025-01-03", "settlement:2025-01-03",