|
BetaTrader
A HFT Eco-System
|
The exchange_fix component is a standalone server responsible for handling client connections over the Financial Information eXchange (FIX) protocol. It acts as the primary gateway for clients to submit orders to the BetaTrader trading engine.
This component implements a fully asynchronous, multi-client FIX server using the Asio networking library. It listens for incoming TCP connections, manages client sessions, and translates FIX messages into commands for the exchange_app.
FixSessionManager, including authentication and sequence number validation.OutboundMessageBuilder for consistent, protocol-compliant binary FIX serialization (BodyLength, Checksum).exchange_app.The system is designed with a clear separation of concerns between the transport layer (exchange_fix) and the business logic layer (exchange_app / exchange_matching). Communication is achieved via an asynchronous publisher-subscriber pattern.
FixServer**: Top-level server class that owns the Asio acceptor and session map.FixSession**: Represents a single connected client, managing the async read/write loop.FixSessionManager**: Thread-safe manager of session state, keyed by SenderCompID (not connection ID). Maintains a two-map indirection (connectionId → compId → SessionState) so that sequence numbers persist across client reconnections. All public methods are mutex-protected for safe cross-thread access.OutboundMessageBuilder**: Centralized utility for constructing binary FIX strings including Checksum and BodyLength.FixUtils**: Shared parsing and formatting helpers.FixSession is created.FixSessionManager authenticates the SenderCompID against the database and links the connection ID to the CompID.SequenceRepository. Existing state survives across reconnections.MsgSeqNum (34). Gaps trigger a ResendRequest. Outbound sequences are incremented and persisted atomically via useNextOutboundSequence().The FIX Gateway translates client messages into internal commands and routes them to the exchange_app:
trading_core::NewOrdertrading_core::CancelOrdertrading_core::ModifyOrderThe FIX server is built as a separate executable target named fix_server.
bash cmake --build . --target fix_server bash ./build/exchange/exchange_fix/fix SequenceRepository and survive server restarts.MarketDataRequest handlers to the actual engine snapshots.