R1-04: Messages, events, and reason codes - #4
Merged
Conversation
Defines the exchange's inbound message and outbound event vocabulary from EXCHANGE_RULES.md and the MATCHING_ENGINE_SPEC I/O lists: - messages.hpp: OrderType enum; NewOrder (R-3.2), CancelOrder (R-6.1), ModifyOrder (R-7.1), SessionEnd (R-12) structs; Inbound variant. - events.hpp: complete RejectReason (17) and CancelReason (5) enumerations (R-14) and LiquidityFlag; EventHeader (R-10.2, kept separate so payloads stay small); OrderAccepted/OrderRejected/ OrderCanceled/OrderModified/Fill/Trade payloads; Outbound variant. The FILLED-terminal state is implicit per R-4.3, so no OrderFilled event. Public market-data messages are excluded (belong to md, R2). - enums.cpp: to_cstr string tables (switch with no default so -Wswitch enforces exhaustiveness) and from_cstr round-trip parsers. Every payload is trivially copyable and <= 64 bytes (static_assert); kAll* arrays are pinned to the enum counts. Tests cover field wiring, variant dispatch, unique/canonical reason-code names matching the spec strings, and name round-trips. Verified: 39/39 tests pass under debug and asan-ubsan; -Werror clean; clang-format clean.
Build-time gtest_discover_tests intermittently fails on CI runners with 'Missing expected JSON file with test list'. PRE_TEST enumerates at ctest time instead, avoiding running executables during the build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
R1-04: Messages, events, and reason codes — Completion Report
Status: complete
Branch/PR:
task/R1-04-eventsWhat was built
The exchange's message and event vocabulary, translated from EXCHANGE_RULES.md and the MATCHING_ENGINE_SPEC I/O lists.
core/messages.hpp:OrderTypeenum;NewOrder(R-3.2),CancelOrder(R-6.1),ModifyOrder(R-7.1),SessionEnd(R-12) structs;Inboundvariant.core/events.hpp: completeRejectReason(17) andCancelReason(5) enumerations (R-14) plusLiquidityFlag;EventHeader(R-10.2, kept separate so payloads stay ≤64 B);OrderAccepted/OrderRejected/OrderCanceled/OrderModified/Fill/Tradepayloads;Outboundvariant.core/src/enums.cpp:to_cstrtables (switch, no default →-Wswitchenforces exhaustiveness) andfrom_cstrround-trip parsers.Acceptance criteria
RejectReason/CancelReasoncomplete enumerations — 17 + 5,static_assertpins array size to enum countsizeof ≤ 64static_asserts — on every payload struct + variantsto_cstr+from_cstr, round-trip testedVerification output
Tests added
static_assert(headers +test_events.cpp)NewOrder.*,Inbound.*,Outbound.*RejectReason.*,CancelReason.*OrderTypeAndLiquidity.NamesDeviations / Questions
EventHeader(seq_out/seq_in/ts_event) is a separate struct, not embedded in each event payload. R-10.2 says every event "carries" the header; embedding its 24 bytes would pushTrade(49 B of ids) past the 64-byte payload budget from MEMORY_MODEL.md. Keeping payloads header-free preserves ≤64 B and trivial-copyability; the sequencer (R1-11) pairs header+payload. Flagging as a conscious structural choice consistent with both docs.OrderFilledevent — the FILLED-terminal state is implicit per R-4.3 (the fill that brings remaining to zero), matching the spec's state machine. Noted so it's clearly intentional.Notes for reviewer
Fill.feeis a signedCash(taker fee > 0 cost, maker rebate < 0 cost) so accounting (R2) can apply it uniformly; the auditTradecarries full identities while the anonymized publicTradeMDis deferred tomd(R2).