Skip to main content

FixSession

Struct FixSession 

Source
pub struct FixSession { /* private fields */ }
Expand description

The driver. Holds the FSM state, config, and the sequence store.

Implementations§

Source§

impl FixSession

Source

pub fn new(config: FixSessionConfig, store: Arc<dyn FixSeqStore>) -> Self

Construct a session from config and a sequence store.

Source

pub fn state(&self) -> SessionState

Source

pub fn config(&self) -> &FixSessionConfig

Source

pub fn store(&self) -> &Arc<dyn FixSeqStore>

Source

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.

Source

pub async fn build_logout(&mut self, reason: Option<&str>) -> FixMessage

Build and “send” a Logout with optional reason text. Transitions to SessionState::LogoutSent.

Source

pub async fn build_heartbeat(&mut self, test_req_id: Option<&str>) -> FixMessage

Build a Heartbeat, optionally echoing a TestReqID.

Source

pub async fn heartbeat(&mut self) -> FixMessage

Periodic heartbeat (alias for build_heartbeat(None)), to be driven by a timer on the heartbeat interval.

Source

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).

Source

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).

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Extension for T
where T: Any + Send + Sync,