Expand limit order intent coverage

This commit is contained in:
boris
2026-04-23 03:28:14 -07:00
parent a7bb29ce2a
commit 8906490a40
3 changed files with 454 additions and 1 deletions

View File

@@ -2805,7 +2805,7 @@ fn broker_keeps_limit_buy_open_until_price_becomes_marketable() {
#[test]
fn broker_uses_limit_price_slippage_for_limit_orders() {
let date = NaiveDate::from_ymd_opt(2024, 1, 10).unwrap();
let data = two_day_limit_order_data(10.0, 10.0);
let data = two_day_limit_order_data(10.0, 10.2);
let broker = BrokerSimulator::new_with_execution_price(
ChinaAShareCostModel::default(),
ChinaEquityRuleHooks::default(),
@@ -2839,6 +2839,65 @@ fn broker_uses_limit_price_slippage_for_limit_orders() {
assert!((report.fill_events[0].price - 10.1).abs() < 1e-9);
}
#[test]
fn broker_executes_limit_value_and_limit_percent_intents() {
let date = NaiveDate::from_ymd_opt(2024, 1, 10).unwrap();
let data = two_day_limit_order_data(10.0, 10.0);
let broker = BrokerSimulator::new_with_execution_price(
ChinaAShareCostModel::default(),
ChinaEquityRuleHooks::default(),
PriceField::Open,
);
let mut value_portfolio = PortfolioState::new(1_000_000.0);
let value_report = broker
.execute(
date,
&mut value_portfolio,
&data,
&StrategyDecision {
rebalance: false,
target_weights: BTreeMap::new(),
exit_symbols: BTreeSet::new(),
order_intents: vec![OrderIntent::LimitValue {
symbol: "000002.SZ".to_string(),
value: 20_000.0,
limit_price: 10.1,
reason: "limit_value".to_string(),
}],
notes: Vec::new(),
diagnostics: Vec::new(),
},
)
.expect("broker execution");
assert_eq!(value_report.fill_events.len(), 1);
assert!(value_portfolio.position("000002.SZ").is_some());
let mut percent_portfolio = PortfolioState::new(1_000_000.0);
let percent_report = broker
.execute(
date,
&mut percent_portfolio,
&data,
&StrategyDecision {
rebalance: false,
target_weights: BTreeMap::new(),
exit_symbols: BTreeSet::new(),
order_intents: vec![OrderIntent::LimitPercent {
symbol: "000002.SZ".to_string(),
percent: 0.02,
limit_price: 10.1,
reason: "limit_percent".to_string(),
}],
notes: Vec::new(),
diagnostics: Vec::new(),
},
)
.expect("broker execution");
assert_eq!(percent_report.fill_events.len(), 1);
assert!(percent_portfolio.position("000002.SZ").is_some());
}
#[test]
fn broker_cancels_open_order_by_order_id() {
let day1 = NaiveDate::from_ymd_opt(2024, 1, 10).unwrap();