修正执行价quote多时间加载

This commit is contained in:
boris
2026-06-16 00:05:34 +08:00
parent c2de9d8e83
commit ff145300b4
3 changed files with 259 additions and 7 deletions
+19
View File
@@ -341,6 +341,8 @@ pub struct BacktestEngine<S, C, R> {
futures_cost_model: FuturesTransactionCostModel,
futures_validation_config: FuturesValidationConfig,
execution_quote_loader: Option<ExecutionQuoteLoader>,
execution_quote_request_cache:
BTreeSet<(NaiveDate, String, Option<NaiveTime>, Option<NaiveTime>)>,
}
impl<S, C, R> BacktestEngine<S, C, R> {
@@ -369,6 +371,7 @@ impl<S, C, R> BacktestEngine<S, C, R> {
futures_cost_model: FuturesTransactionCostModel::default(),
futures_validation_config: FuturesValidationConfig::default(),
execution_quote_loader: None,
execution_quote_request_cache: BTreeSet::new(),
}
}
@@ -553,12 +556,20 @@ where
symbols: &mut BTreeSet<String>,
) -> Result<(), BacktestError> {
symbols.retain(|symbol| {
let request_key = (execution_date, symbol.clone(), start_time, end_time);
if self.execution_quote_request_cache.contains(&request_key) {
return false;
}
if start_time.is_some() && end_time.is_none() {
return true;
}
!has_execution_quote_in_window(&self.data, execution_date, symbol, start_time, end_time)
});
if symbols.is_empty() {
return Ok(());
}
let requested_symbols = symbols.iter().cloned().collect::<Vec<_>>();
let request = ExecutionQuoteRequest {
date: execution_date,
start_time,
@@ -571,6 +582,14 @@ where
.expect("checked execution quote loader")
.as_mut()(request)?;
self.data.add_execution_quotes(quotes);
for symbol in requested_symbols {
self.execution_quote_request_cache.insert((
execution_date,
symbol,
start_time,
end_time,
));
}
Ok(())
}