修复涨跌停最终执行价约束

This commit is contained in:
boris
2026-06-15 20:04:42 +08:00
parent e0949a0eaa
commit 725f1845d9
2 changed files with 160 additions and 43 deletions
@@ -4237,6 +4237,50 @@ fn broker_uses_limit_price_slippage_for_limit_orders() {
assert!((report.fill_events[0].price - 10.1).abs() < 1e-9);
}
#[test]
fn broker_rejects_limit_buy_when_final_execution_price_reaches_upper_limit() {
let date = NaiveDate::from_ymd_opt(2024, 1, 10).unwrap();
let data = two_day_limit_order_data(10.0, 10.2);
let broker = BrokerSimulator::new_with_execution_price(
ChinaAShareCostModel::default(),
ChinaEquityRuleHooks::default(),
PriceField::Open,
)
.with_slippage_model(SlippageModel::LimitPrice);
let mut portfolio = PortfolioState::new(1_000_000.0);
let report = broker
.execute(
date,
&mut portfolio,
&data,
&StrategyDecision {
rebalance: false,
target_weights: BTreeMap::new(),
exit_symbols: BTreeSet::new(),
order_intents: vec![OrderIntent::LimitShares {
symbol: "000002.SZ".to_string(),
quantity: 200,
limit_price: 11.0,
reason: "limit_entry_at_upper_limit".to_string(),
}],
notes: Vec::new(),
diagnostics: Vec::new(),
},
)
.expect("broker execution");
assert!(report.fill_events.is_empty());
assert_eq!(report.order_events.len(), 1);
assert_eq!(report.order_events[0].status, OrderStatus::Canceled);
assert!(
report.order_events[0]
.reason
.contains("open at or above upper limit")
);
assert!(portfolio.position("000002.SZ").is_none());
}
#[test]
fn broker_executes_limit_value_and_limit_percent_intents() {
let date = NaiveDate::from_ymd_opt(2024, 1, 10).unwrap();