Skip to content

fix: take liquidity when an L3 order is modified to a marketable price - #1

Merged
23f3001135 merged 1 commit into
masterfrom
fix/l3-modify-marketable-takes
Jul 23, 2026
Merged

fix: take liquidity when an L3 order is modified to a marketable price#1
23f3001135 merged 1 commit into
masterfrom
fix/l3-modify-marketable-takes

Conversation

@23f3001135

Copy link
Copy Markdown
Owner

Summary

When a resting L3 order is modified to a price that crosses the book (buy >= best ask, sell <= best bid), it must take liquidity rather than reposition in the queue at a crossed price.

L3NoPartialFillExchange::ack_modify now detects a marketable modify and cancels + re-submits the order (re-normalizing leaves_qty to the new qty), mirroring the L2 NoPartialFillExchange, which modifies via cancel + new. If the order is already gone (filled/expired/unknown id), the modify is rejected, matching the existing OrderNotFound path.

Tests

Added unit tests covering:

  • buy modified to/through the best ask takes and fills
  • sell modified to/through the best bid takes and fills
  • non-marketable modify still rests and repositions via the queue model

cargo test -p hftbacktest --no-default-features --features backtest passes (25 tests).

@23f3001135
23f3001135 requested a review from Copilot July 23, 2026 08:50
@23f3001135
23f3001135 merged commit d56cbc5 into master Jul 23, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes L3 backtest behavior when a resting order is modified to a marketable (book-crossing) price: instead of allowing the order to “rest” at a crossed price, the exchange now cancels and re-submits the order so it properly takes liquidity (leveraging existing ack_new marketable-fill behavior). This aligns L3 behavior with the existing L2 NoPartialFillExchange approach.

Changes:

  • Detect marketable (book-crossing) modifies in L3NoPartialFillExchange::ack_modify and handle them via cancel + re-submit (then fill via ack_new).
  • Preserve existing rejection behavior when the order being modified is not found (already gone).
  • Add unit tests covering marketable buy/sell modifies and a non-marketable modify that continues to rest/reposition via the queue model.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants