Journal resting orders in the matching engine

C++ · C++ · intermediate · modification

Compliance wants the audit journal to show every order that rests in the book, not only the fills. This PR adds `rest_line` next to the existing `fill_line` in `src/engine/journal_lines.hpp` and `src/engine/journal_lines.cpp`, formatting `REST <order id> <client id> <B|S> <quantity>@<price>`. `src/engine/matching_engine.cpp` writes that line at the end of `submit`, in the branch that rests the remaining quantity in the book, so it follows the order's FILL lines. `tests/journal_lines_test.cpp` (new) covers the REST line format, and `tests/matching_engine_test.cpp` gains an engine case.

C++20, standard library only, built with CMake (unchanged: it builds `src/engine/*.cpp` into the engine library and every `tests/*_test.cpp` together with `tests/check_main.cpp` into the test runner) by Apple clang 17 locally and GCC 13 in CI, with `-Wall -Wextra -Wconversion -Werror`. Threading: there is one `MatchingEngine`, one `OrderBook` and one `Journal` per instrument, all used only on that instrument's engine thread. Existing and unchanged: `engine::Order` (`src/engine/order.hpp`) is a plain struct with `std::uint64_t id` (unique per instrument), `std::string client_id` (1 to 20 characters, `A-Z` and `0-9`), `Side side` (`Buy` or `Sell`), and `std::int64_t price` (ticks, 1 to 1'000'000'000) and `quantity` (1 to 1'000'000'000 on submit); the gateway validates every order against these ranges before calling `submit`. `OrderBook` (`src/engine/order_book.hpp`) keeps resting orders per side in price levels (`std::map` of `std::deque<Order>`): `void add(Order order)` takes the order by value and moves it to the back of its price level, `best(side)` returns a reference to the order matched next and `pop_best(side)` removes it (both require a non-empty side), plus `empty(side)` and `size(side)`. `MatchingEngine` (`src/engine/matching_engine.hpp`) holds references to the instrument's book and journal; `Journal` (`src/engine/journal.hpp`) is an interface with `virtual void write(std::string_view line)`, which appends one line in call order and does not throw (I/O failures are handled inside the journal). Self-trade prevention is out of scope, and allocation failure is fatal to the process. `tests/check.hpp` is the repo's tiny test helper: `TEST(name) { ... }` registers a test, `CHECK(expr)` and `CHECK_EQ(a, b)` record a failure with file and line, and the `main` in `tests/check_main.cpp` runs every registered test and exits non-zero if any check failed. `tests/memory_journal.hpp` (existing) provides `MemoryJournal`, which keeps every written line in `lines`.

Requirements

Files touched

Review this PR

C++ practice