From 22856574ca1d877594ecd8fb0f5ef33e1e702cbb Mon Sep 17 00:00:00 2001 From: Vedant Jawandhia Date: Sun, 2 Aug 2026 01:38:27 +0530 Subject: [PATCH] Fix PartialFillExchange exact-qty fills and local partial-fill accounting Treat filled_qty == leaves_qty as a complete fill (>=) so InvalidOrderStatus is not raised when the queue model reports an exact fill (#312). Apply PartiallyFilled responses on the local side so position/balance track incremental exec_qty (#316). Co-authored-by: Cursor --- hftbacktest/src/backtest/proc/l3_local.rs | 4 ++-- hftbacktest/src/backtest/proc/local.rs | 4 ++-- hftbacktest/src/backtest/proc/partialfillexchange.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hftbacktest/src/backtest/proc/l3_local.rs b/hftbacktest/src/backtest/proc/l3_local.rs index c9afcac6c..460acdd6b 100644 --- a/hftbacktest/src/backtest/proc/l3_local.rs +++ b/hftbacktest/src/backtest/proc/l3_local.rs @@ -278,8 +278,8 @@ where wait_resp_order_received = true; } - // Processes receiving order response. - if order.status == Status::Filled { + // Processes receiving order response (full and partial fills). + if order.status == Status::Filled || order.status == Status::PartiallyFilled { self.state.apply_fill(&order); } // Applies the received order response to the local orders. diff --git a/hftbacktest/src/backtest/proc/local.rs b/hftbacktest/src/backtest/proc/local.rs index adc48e25e..2c6436859 100644 --- a/hftbacktest/src/backtest/proc/local.rs +++ b/hftbacktest/src/backtest/proc/local.rs @@ -98,8 +98,8 @@ where wait_resp_order_received = true; } - // Processes receiving order response. - if order.status == Status::Filled { + // Processes receiving order response (full and partial fills). + if order.status == Status::Filled || order.status == Status::PartiallyFilled { self.state.apply_fill(&order); } // Applies the received order response to the local orders. diff --git a/hftbacktest/src/backtest/proc/partialfillexchange.rs b/hftbacktest/src/backtest/proc/partialfillexchange.rs index 53bca76ca..f8b18c6b6 100644 --- a/hftbacktest/src/backtest/proc/partialfillexchange.rs +++ b/hftbacktest/src/backtest/proc/partialfillexchange.rs @@ -152,7 +152,7 @@ where // q_ahead is negative since is_filled is true and its value represents the // executable quantity of this order after execution in the queue ahead of this // order. - let exec_qty = if filled_qty > order.leaves_qty { + let exec_qty = if filled_qty >= order.leaves_qty { self.filled_orders.push(order.order_id); order.leaves_qty } else { @@ -192,7 +192,7 @@ where // q_ahead is negative since is_filled is true and its value represents the // executable quantity of this order after execution in the queue ahead of this // order. - let exec_qty = if filled_qty > order.leaves_qty { + let exec_qty = if filled_qty >= order.leaves_qty { self.filled_orders.push(order.order_id); order.leaves_qty } else {