支持策略决策前批量加载执行价
This commit is contained in:
@@ -622,6 +622,35 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ensure_execution_quotes_for_symbols_at_times(
|
||||
&mut self,
|
||||
execution_date: NaiveDate,
|
||||
symbols: &BTreeSet<String>,
|
||||
quote_times: &[NaiveTime],
|
||||
) -> Result<(), BacktestError> {
|
||||
if self.execution_quote_loader.is_none() || quote_times.is_empty() || symbols.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let base_symbols = symbols
|
||||
.iter()
|
||||
.filter(|symbol| !symbol.trim().is_empty())
|
||||
.cloned()
|
||||
.collect::<BTreeSet<_>>();
|
||||
if base_symbols.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
for quote_time in quote_times {
|
||||
let mut symbols = base_symbols.clone();
|
||||
self.load_missing_execution_quotes(
|
||||
execution_date,
|
||||
Some(*quote_time),
|
||||
None,
|
||||
&mut symbols,
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply_strategy_directives(
|
||||
&mut self,
|
||||
execution_date: NaiveDate,
|
||||
@@ -1951,6 +1980,33 @@ where
|
||||
)?;
|
||||
let on_day_open_orders = self.open_order_views();
|
||||
let decision_quote_times = self.strategy.decision_quote_times();
|
||||
if !decision_quote_times.is_empty() {
|
||||
let decision_quote_symbols =
|
||||
self.strategy.decision_quote_symbols(&StrategyContext {
|
||||
execution_date,
|
||||
decision_date,
|
||||
decision_index,
|
||||
data: &self.data,
|
||||
portfolio: &portfolio,
|
||||
futures_account: self.futures_account.as_ref(),
|
||||
open_orders: &on_day_open_orders,
|
||||
dynamic_universe: self.dynamic_universe.as_ref(),
|
||||
subscriptions: &self.subscriptions,
|
||||
process_events: &process_events,
|
||||
active_process_event: None,
|
||||
active_datetime: stage_datetime(
|
||||
execution_date,
|
||||
default_stage_time(ScheduleStage::OnDay),
|
||||
),
|
||||
order_events: result.order_events.as_slice(),
|
||||
fills: result.fills.as_slice(),
|
||||
})?;
|
||||
self.ensure_execution_quotes_for_symbols_at_times(
|
||||
execution_date,
|
||||
&decision_quote_symbols,
|
||||
&decision_quote_times,
|
||||
)?;
|
||||
}
|
||||
self.ensure_execution_quotes_for_portfolio_times(
|
||||
execution_date,
|
||||
&portfolio,
|
||||
|
||||
Reference in New Issue
Block a user