pub struct FixSession { /* private fields */ }Expand description
The driver. Holds the FSM state, config, and the sequence store.
Implementations§
Source§impl FixSession
impl FixSession
Sourcepub fn new(config: FixSessionConfig, store: Arc<dyn FixSeqStore>) -> Self
pub fn new(config: FixSessionConfig, store: Arc<dyn FixSeqStore>) -> Self
Construct a session from config and a sequence store.
pub fn state(&self) -> SessionState
pub fn config(&self) -> &FixSessionConfig
pub fn store(&self) -> &Arc<dyn FixSeqStore>
Sourcepub async fn build_logon(&mut self) -> FixMessage
pub async fn build_logon(&mut self) -> FixMessage
Build and “send” a Logon. Transitions to SessionState::LogonSent.
When reset_on_logon is set, the
store is reset first and ResetSeqNumFlag(141)=Y is included.
Sourcepub async fn build_logout(&mut self, reason: Option<&str>) -> FixMessage
pub async fn build_logout(&mut self, reason: Option<&str>) -> FixMessage
Build and “send” a Logout with optional reason text. Transitions to
SessionState::LogoutSent.
Sourcepub async fn build_heartbeat(&mut self, test_req_id: Option<&str>) -> FixMessage
pub async fn build_heartbeat(&mut self, test_req_id: Option<&str>) -> FixMessage
Build a Heartbeat, optionally echoing a TestReqID.
Sourcepub async fn heartbeat(&mut self) -> FixMessage
pub async fn heartbeat(&mut self) -> FixMessage
Periodic heartbeat (alias for build_heartbeat(None)), to be driven by
a timer on the heartbeat interval.
Sourcepub async fn build_resend_request(&mut self, begin: u64, end: u64) -> FixMessage
pub async fn build_resend_request(&mut self, begin: u64, end: u64) -> FixMessage
Build a ResendRequest(2) for [begin, end]. end == 0 means
“infinity” per the FIX spec (all messages from begin onward).
Sourcepub async fn build_gap_fill(
&self,
begin_seq: u64,
new_seq_no: u64,
) -> FixMessage
pub async fn build_gap_fill( &self, begin_seq: u64, new_seq_no: u64, ) -> FixMessage
Build a SequenceReset(4) with GapFillFlag(123)=Y advancing the
counterparty’s expected inbound sequence to new_seq_no. The message is
stamped with MsgSeqNum = begin_seq rather than consuming a fresh
outbound number (gap-fill must occupy the slot of the first skipped
message).
Sourcepub async fn build_app_message(&self, msg: FixMessage) -> FixMessage
pub async fn build_app_message(&self, msg: FixMessage) -> FixMessage
Build an outbound application message of msg_type, stamping the header
and consuming an outbound sequence number. The caller sets the
application fields before/after as needed; this is the entry point the
application uses to send (e.g.) a NewOrderSingle.
Sourcepub async fn handle_inbound(&mut self, msg: FixMessage) -> InboundOutcome
pub async fn handle_inbound(&mut self, msg: FixMessage) -> InboundOutcome
Process one inbound message and return the FSM’s reaction: the administrative replies to send and, if it is an application message that should be surfaced, that message.
This is the single, fully-testable entry point for the inbound side of the protocol.
Sourcepub async fn run(
self,
inbound: Source<Result<Bytes, FramingError>>,
writer: UnboundedSender<Bytes>,
app_tx: UnboundedSender<FixMessage>,
app_rx: UnboundedReceiver<FixMessage>,
)
pub async fn run( self, inbound: Source<Result<Bytes, FramingError>>, writer: UnboundedSender<Bytes>, app_tx: UnboundedSender<FixMessage>, app_rx: UnboundedReceiver<FixMessage>, )
Drive this FSM over a live atomr-streams TCP connection.
Reads SOH-delimited frames from inbound (already framed Bytes),
parses them, runs handle_inbound, and writes
every produced outbound message to writer. Application messages are
forwarded to app_tx. Outbound application messages submitted on
app_rx are stamped and written. The loop ends when the inbound stream
closes or the session reaches SessionState::Disconnected after a
logout.
This helper exists for real deployments; the protocol logic itself is
fully testable through handle_inbound without
any socket.