diff --git a/crates/fidc-core/src/broker.rs b/crates/fidc-core/src/broker.rs index bc2e2f4..e217d6d 100644 --- a/crates/fidc-core/src/broker.rs +++ b/crates/fidc-core/src/broker.rs @@ -1004,7 +1004,8 @@ where quantity = quantity.saturating_sub(lot); continue; } - if gross <= cash + 1e-6 { + let cost = self.cost_model.calculate(OrderSide::Buy, gross); + if gross + cost.total() <= cash + 1e-6 { return quantity; } quantity = quantity.saturating_sub(lot); diff --git a/crates/fidc-core/src/strategy.rs b/crates/fidc-core/src/strategy.rs index c7945b8..56ec39d 100644 --- a/crates/fidc-core/src/strategy.rs +++ b/crates/fidc-core/src/strategy.rs @@ -580,7 +580,7 @@ impl JqMicroCapStrategy { let mut quantity = self.round_lot_quantity((cash / sizing_price).floor() as u32, 100); while quantity > 0 { let gross_amount = execution_price * quantity as f64; - if gross_amount <= cash + 1e-6 { + if gross_amount + self.buy_commission(gross_amount) <= cash + 1e-6 { return quantity; } quantity = quantity.saturating_sub(100); @@ -825,7 +825,8 @@ impl JqMicroCapStrategy { take_qty = take_qty.saturating_sub(round_lot.max(1)); continue; } - if candidate_gross <= cash + 1e-6 { + let candidate_cash = candidate_gross + self.buy_commission(candidate_gross); + if candidate_cash <= cash + 1e-6 { break; } take_qty = take_qty.saturating_sub(round_lot.max(1)); @@ -904,7 +905,7 @@ impl JqMicroCapStrategy { take_qty = take_qty.saturating_sub(lot); continue; } - if candidate_gross <= cash + 1e-6 { + if candidate_gross + self.buy_commission(candidate_gross) <= cash + 1e-6 { break; } take_qty = take_qty.saturating_sub(lot);