Add futures expiration settlement
This commit is contained in:
@@ -161,3 +161,30 @@ fn futures_open_order_rejects_when_margin_is_insufficient() {
|
||||
assert!(account.position("IF2501", FuturesDirection::Long).is_none());
|
||||
assert!((account.total_cash() - 10_000.0).abs() < 1e-6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn futures_expiration_settlement_closes_all_contract_directions() {
|
||||
let spec = FuturesContractSpec::new(300.0, 0.12, 0.14);
|
||||
let mut account = FuturesAccountState::new(1_000_000.0);
|
||||
|
||||
account.open("IF2501", FuturesDirection::Long, spec, 2, 4000.0, 0.0);
|
||||
account.open("IF2501", FuturesDirection::Short, spec, 1, 4000.0, 0.0);
|
||||
|
||||
let report = account.expire_contract(d(2025, 1, 17), "IF2501", 4010.0, "contract expired");
|
||||
|
||||
assert_eq!(report.order_events.len(), 2);
|
||||
assert_eq!(report.fill_events.len(), 2);
|
||||
assert!(
|
||||
report
|
||||
.order_events
|
||||
.iter()
|
||||
.all(|event| event.status == OrderStatus::Filled)
|
||||
);
|
||||
assert!(account.position("IF2501", FuturesDirection::Long).is_none());
|
||||
assert!(
|
||||
account
|
||||
.position("IF2501", FuturesDirection::Short)
|
||||
.is_none()
|
||||
);
|
||||
assert!((account.total_cash() - 1_003_000.0).abs() < 1e-6);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user