Skip to content

Preserve FIFO time priority after order cancellation - #4

Open
Hei-MaoM wants to merge 1 commit into
SLMolenaar:masterfrom
Hei-MaoM:codex/orderbook-preserve-fifo
Open

Preserve FIFO time priority after order cancellation#4
Hei-MaoM wants to merge 1 commit into
SLMolenaar:masterfrom
Hei-MaoM:codex/orderbook-preserve-fifo

Conversation

@Hei-MaoM

Copy link
Copy Markdown

Fixes #3

CancelOrder used swap-and-pop for non-tail cancellations. That keeps the
index map consistent but moves the newest order ahead of older orders at the
same price, violating the documented price-time (FIFO) priority.

This change:

  • erases the cancelled order in place so surviving orders keep arrival order;
  • re-indexes the shifted suffix in the order lookup map;
  • adds a regression test that cancels the head order and verifies the next
    resting order matches first.

The order-preserving erase changes cancellation from O(1) to O(n) in the
number of orders after the cancelled slot, which is required to keep FIFO in
the existing contiguous-vector representation.

Validation:

  • g++ -std=c++20 -O2 -Wall -Wextra -pedantic tests.cpp
  • OrderBookTests: all 22 functionality tests passed
  • Performance benchmarks and high-frequency simulation completed successfully

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.

[Bug Report] CancelOrder uses swap-and-pop, which breaks FIFO time priority for the survivors at that price level

1 participant