Add rqalpha-style order reject lifecycle events
This commit is contained in:
@@ -648,7 +648,7 @@ fn broker_cancels_buy_when_open_hits_upper_limit() {
|
||||
.contains("open at or above upper limit")
|
||||
);
|
||||
assert!(report.process_events.iter().any(|event| {
|
||||
event.kind == ProcessEventKind::OrderUnsolicitedUpdate
|
||||
event.kind == ProcessEventKind::OrderCreationReject
|
||||
&& event.symbol.as_deref() == Some("000002.SZ")
|
||||
&& event.side == Some(fidc_core::OrderSide::Buy)
|
||||
}));
|
||||
@@ -2974,6 +2974,43 @@ fn broker_cancels_open_order_by_order_id() {
|
||||
assert!(portfolio.position("000002.SZ").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn broker_emits_cancellation_reject_for_unknown_order() {
|
||||
let day1 = NaiveDate::from_ymd_opt(2024, 1, 10).unwrap();
|
||||
let data = two_day_limit_order_data(10.0, 10.1);
|
||||
let broker = BrokerSimulator::new_with_execution_price(
|
||||
ChinaAShareCostModel::default(),
|
||||
ChinaEquityRuleHooks::default(),
|
||||
PriceField::Open,
|
||||
);
|
||||
let mut portfolio = PortfolioState::new(1_000_000.0);
|
||||
|
||||
let report = broker
|
||||
.execute(
|
||||
day1,
|
||||
&mut portfolio,
|
||||
&data,
|
||||
&StrategyDecision {
|
||||
rebalance: false,
|
||||
target_weights: BTreeMap::new(),
|
||||
exit_symbols: BTreeSet::new(),
|
||||
order_intents: vec![OrderIntent::CancelOrder {
|
||||
order_id: 999_999,
|
||||
reason: "user_cancel".to_string(),
|
||||
}],
|
||||
notes: Vec::new(),
|
||||
diagnostics: Vec::new(),
|
||||
},
|
||||
)
|
||||
.expect("cancel reject execution");
|
||||
|
||||
assert!(report.order_events.is_empty());
|
||||
assert!(report.fill_events.is_empty());
|
||||
assert!(report.process_events.iter().any(|event| {
|
||||
event.kind == ProcessEventKind::OrderCancellationReject && event.order_id == Some(999_999)
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn broker_reserves_sellable_quantity_for_open_limit_sells() {
|
||||
let date = NaiveDate::from_ymd_opt(2024, 1, 10).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user