Add scheduled process hooks to strategy engine
This commit is contained in:
@@ -118,6 +118,7 @@ impl Strategy for AuctionOrderStrategy {
|
||||
|
||||
struct ScheduledProbeStrategy {
|
||||
log: Rc<RefCell<Vec<String>>>,
|
||||
process_log: Rc<RefCell<Vec<String>>>,
|
||||
}
|
||||
|
||||
struct LimitCarryStrategy {
|
||||
@@ -129,6 +130,17 @@ impl Strategy for ScheduledProbeStrategy {
|
||||
"scheduled-probe"
|
||||
}
|
||||
|
||||
fn on_process_event(
|
||||
&mut self,
|
||||
_ctx: &StrategyContext<'_>,
|
||||
event: &fidc_core::ProcessEvent,
|
||||
) -> Result<(), fidc_core::BacktestError> {
|
||||
self.process_log
|
||||
.borrow_mut()
|
||||
.push(format!("{:?}:{}", event.kind, event.detail));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn schedule_rules(&self) -> Vec<ScheduleRule> {
|
||||
vec![
|
||||
ScheduleRule::daily("daily_auction", ScheduleStage::OpenAuction),
|
||||
@@ -826,7 +838,11 @@ fn engine_runs_scheduled_rules_for_daily_weekly_and_monthly_triggers() {
|
||||
.expect("dataset");
|
||||
|
||||
let log = Rc::new(RefCell::new(Vec::new()));
|
||||
let strategy = ScheduledProbeStrategy { log: log.clone() };
|
||||
let process_log = Rc::new(RefCell::new(Vec::new()));
|
||||
let strategy = ScheduledProbeStrategy {
|
||||
log: log.clone(),
|
||||
process_log: process_log.clone(),
|
||||
};
|
||||
let broker = BrokerSimulator::new_with_execution_price(
|
||||
ChinaAShareCostModel::default(),
|
||||
ChinaEquityRuleHooks::default(),
|
||||
@@ -859,4 +875,25 @@ fn engine_runs_scheduled_rules_for_daily_weekly_and_monthly_triggers() {
|
||||
"scheduled:first_trading_day_on_day:2025-02-03",
|
||||
]
|
||||
);
|
||||
let process_log = process_log.borrow();
|
||||
assert!(
|
||||
process_log
|
||||
.iter()
|
||||
.any(|item| { item == "PreScheduled:scheduled:daily_auction:open_auction:pre" })
|
||||
);
|
||||
assert!(
|
||||
process_log
|
||||
.iter()
|
||||
.any(|item| { item == "PostScheduled:scheduled:daily_auction:open_auction:post" })
|
||||
);
|
||||
assert!(
|
||||
process_log
|
||||
.iter()
|
||||
.any(|item| { item == "PreScheduled:scheduled:friday_on_day:on_day:pre" })
|
||||
);
|
||||
assert!(
|
||||
process_log
|
||||
.iter()
|
||||
.any(|item| { item == "PostScheduled:scheduled:first_trading_day_on_day:on_day:post" })
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user