#[test]
fn multiple_full_executions() {
use clob_sync::prelude::*;
let mut book =
InMemoryOrderBookFactory::create_order_book(Symbol::from("AAPL"));
let sell1 = Order::new(
OrderType::Limit(Price::from(100)),
Quantity::from(10u64),
OrderSide::Sell,
Symbol::from("AAPL"),
)
.with_id();
let sell2 = Order::new(
OrderType::Limit(Price::from(101)),
Quantity::from(10u64),
OrderSide::Sell,
Symbol::from("AAPL"),
)
.with_id();
let sell3 = Order::new(
OrderType::Limit(Price::from(102)),
Quantity::from(10u64),
OrderSide::Sell,
Symbol::from("AAPL"),
)
.with_id();
let sell4 = Order::new(
OrderType::Limit(Price::from(103)),
Quantity::from(10u64),
OrderSide::Sell,
Symbol::from("AAPL"),
)
.with_id();
book.execute(&sell1).unwrap();
book.execute(&sell2).unwrap();
book.execute(&sell3).unwrap();
book.execute(&sell4).unwrap();
let market_buy = Order::new(
OrderType::Market,
Quantity::from(50u64),
OrderSide::Buy,
Symbol::from("AAPL"),
)
.with_id();
let result = book.execute(&market_buy).unwrap();
match result {
Executions::Executed(executions) => {
assert_eq!(executions.len(), 8);
let mut full_execution_ids: Vec<OrderId> = Vec::new();
let mut partial_execution_ids: Vec<OrderId> = Vec::new();
for exec in executions.iter() {
match exec {
Execution::FullExecution(id) => {
full_execution_ids.push(*id);
}
Execution::PartialExecution(id, qty) => {
partial_execution_ids.push(*id);
assert!(!qty.is_zero());
}
_ => panic!("unexpected execution type"),
}
}
assert_eq!(full_execution_ids.len(), 4);
assert_eq!(partial_execution_ids.len(), 4);
let unique_partial_ids: Vec<_> = partial_execution_ids.to_vec();
assert!(
unique_partial_ids
.iter()
.all(|id| *id == unique_partial_ids[0]),
"All partial executions should reference the same incoming order UUID"
);
}
Executions::AllocatedNoExecutions => {
panic!("expected executions, got none");
}
}
}