Session

Struct Session 

pub struct Session { /* private fields */ }
Expand description

Wrapper for Engine::Session

Provides a safe Rust interface to FIX sessions, including application registration for receiving callbacks.

Implementations§

§

impl Session

pub unsafe fn from_ptr(ptr: usize) -> Self

Create a Session wrapper from a raw pointer

§Safety

The pointer must be valid and point to a live Engine::Session object. The Session object must outlive this wrapper.

pub fn as_ptr(&self) -> usize

Get the raw pointer to the C++ Session object

pub fn register_application( &self, app: ApplicationHandle, delay: u32, max_tries: i32, ) -> Result<(), String>

Register an application to receive callbacks for this session

§Arguments
  • app - The ApplicationHandle to register
  • delay - Delay in milliseconds between registration attempts (default: 300)
  • max_tries - Maximum number of registration attempts, -1 for infinite (default: -1)
§Returns
  • Ok(()) if registration succeeds
  • Err(String) if registration fails
§Example
use fixantenna_bindings::{Session, ApplicationHandle};

// Assuming we have a valid session pointer
let session = unsafe { Session::from_ptr(0x12345678) };
let app = ApplicationHandle::new();
session.register_application(app, 300, -1).expect("Failed to register");

pub fn unregister_application(&self) -> Result<(), String>

Unregister the current application from this session

This should be called before releasing the session to ensure proper cleanup.

§Returns
  • Ok(()) if unregistration succeeds
  • Err(String) if unregistration fails

pub fn connect(&self) -> Result<(), String>

Connect session (acceptor mode - listen for incoming connections)

For acceptor sessions, this makes the session ready to accept incoming connections.

§Returns
  • Ok(()) if connection succeeds
  • Err(String) if connection fails

pub fn connect_initiator( &self, hbi: i32, host: &str, port: i32, ) -> Result<(), String>

Connect session (initiator mode - connect to remote host)

For initiator sessions, this establishes a connection to the specified remote host.

§Arguments
  • hbi - Heartbeat interval in seconds
  • host - Remote host address (e.g., “127.0.0.1” or “example.com”)
  • port - Remote port number
§Returns
  • Ok(()) if connection succeeds
  • Err(String) if connection fails
§Example
use fixantenna_bindings::{FixEngine, SessionIdWrapper, Session};

let engine = FixEngine::new("engine.properties").unwrap();
let session_id = SessionIdWrapper::new(
    "SENDER".to_string(),
    "TARGET".to_string(),
    "".to_string()
);
let session = engine.create_session(&session_id, "FIX44", None).unwrap();

// Connect as initiator to remote host
session.connect_initiator(30, "localhost", 9876).unwrap();

pub fn disconnect(&self) -> Result<(), String>

Disconnect session gracefully

Sends a logout message and closes the connection.

§Returns
  • Ok(()) if disconnection succeeds
  • Err(String) if disconnection fails

pub fn put(&self, message: &FixMessage) -> Result<(), String>

Send FIX message to counterparty

§Arguments
  • message - The FIX message to send
§Returns
  • Ok(()) if message is queued successfully
  • Err(String) if sending fails

pub fn put_fast(&self, message: &FixMessage) -> bool

Send a FIX message without error handling overhead

This is a faster version of put() that returns a boolean instead of Result. Use this in latency-critical code paths where you handle errors differently.

§Arguments
  • message - The FIX message to send
§Returns
  • true if message was queued successfully
  • false if sending failed

pub fn get_session_id(&self) -> SessionIdWrapper

Get session identifier

§Returns

SessionIdWrapper containing sender/target comp IDs

pub fn get_in_seq_num(&self) -> Result<i32, String>

Get incoming sequence number

Returns the next expected incoming sequence number (the expected MsgSeqNum of the next incoming message).

§Returns
  • Ok(i32) - The incoming sequence number
  • Err(String) - Error if operation fails
§Example
use fixantenna_bindings::{FixEngine, SessionIdWrapper};

let engine = FixEngine::new("engine.properties").unwrap();
let session_id = SessionIdWrapper::new(
    "SENDER".to_string(),
    "TARGET".to_string(),
    "".to_string()
);
let session = engine.create_session(&session_id, "FIX44", None).unwrap();

let in_seq = session.get_in_seq_num().unwrap();
println!("Incoming sequence number: {}", in_seq);

pub fn get_out_seq_num(&self) -> Result<i32, String>

Get outgoing sequence number

Returns the outgoing sequence number (MsgSeqNum of the next outgoing message).

§Returns
  • Ok(i32) - The outgoing sequence number
  • Err(String) - Error if operation fails
§Example
use fixantenna_bindings::{FixEngine, SessionIdWrapper};

let engine = FixEngine::new("engine.properties").unwrap();
let session_id = SessionIdWrapper::new(
    "SENDER".to_string(),
    "TARGET".to_string(),
    "".to_string()
);
let session = engine.create_session(&session_id, "FIX44", None).unwrap();

let out_seq = session.get_out_seq_num().unwrap();
println!("Outgoing sequence number: {}", out_seq);

pub fn set_in_seq_num(&self, seq_num: i32) -> Result<(), String>

Set incoming sequence number

Forcedly sets the value of the incoming sequence number (the expected MsgSeqNum of the next incoming message).

§Arguments
  • seq_num - The new incoming sequence number
§Returns
  • Ok(()) - Success
  • Err(String) - Error if operation fails
§Example
use fixantenna_bindings::{FixEngine, SessionIdWrapper};

let engine = FixEngine::new("engine.properties").unwrap();
let session_id = SessionIdWrapper::new(
    "SENDER".to_string(),
    "TARGET".to_string(),
    "".to_string()
);
let session = engine.create_session(&session_id, "FIX44", None).unwrap();

session.set_in_seq_num(100).unwrap();

pub fn set_out_seq_num(&self, seq_num: i32) -> Result<(), String>

Set outgoing sequence number

Forcedly sets the value of the outgoing sequence number (MsgSeqNum of the next outgoing message).

§Arguments
  • seq_num - The new outgoing sequence number
§Returns
  • Ok(()) - Success
  • Err(String) - Error if operation fails
§Example
use fixantenna_bindings::{FixEngine, SessionIdWrapper};

let engine = FixEngine::new("engine.properties").unwrap();
let session_id = SessionIdWrapper::new(
    "SENDER".to_string(),
    "TARGET".to_string(),
    "".to_string()
);
let session = engine.create_session(&session_id, "FIX44", None).unwrap();

session.set_out_seq_num(100).unwrap();

pub fn reset_seq_num_and_send_logon(&self) -> Result<(), String>

Reset sequence numbers and send logon

Resets both incoming and outgoing sequence numbers to 1 and sends a Logon message. This is typically used when resetting a session.

§Returns
  • Ok(()) - Success
  • Err(String) - Error if operation fails
§Example
use fixantenna_bindings::{FixEngine, SessionIdWrapper};

let engine = FixEngine::new("engine.properties").unwrap();
let session_id = SessionIdWrapper::new(
    "SENDER".to_string(),
    "TARGET".to_string(),
    "".to_string()
);
let session = engine.create_session(&session_id, "FIX44", None).unwrap();

// Reset sequence numbers and send logon
session.reset_seq_num_and_send_logon().unwrap();

pub fn reset_seq_num_local(&self) -> Result<(), String>

Reset sequence numbers locally

Resets both incoming and outgoing sequence numbers to 1 locally without sending a Logon message. This is used for local sequence number reset.

§Returns
  • Ok(()) - Success
  • Err(String) - Error if operation fails
§Example
use fixantenna_bindings::{FixEngine, SessionIdWrapper};

let engine = FixEngine::new("engine.properties").unwrap();
let session_id = SessionIdWrapper::new(
    "SENDER".to_string(),
    "TARGET".to_string(),
    "".to_string()
);
let session = engine.create_session(&session_id, "FIX44", None).unwrap();

// Reset sequence numbers locally without sending logon
session.reset_seq_num_local().unwrap();

pub fn get_state(&self) -> Result<SessionState, String>

Get current session state

Returns the current state of the session (established, waiting for logon, etc.).

§Returns
  • Ok(SessionState) - The current session state
  • Err(String) - Error if operation fails
§Example
use fixantenna_bindings::{FixEngine, SessionIdWrapper, SessionState};

let engine = FixEngine::new("engine.properties").unwrap();
let session_id = SessionIdWrapper::new(
    "SENDER".to_string(),
    "TARGET".to_string(),
    "".to_string()
);
let session = engine.create_session(&session_id, "FIX44", None).unwrap();

let state = session.get_state().unwrap();
println!("Session state: {:?}", state);

pub fn get_outgoing_queue_size(&self) -> usize

Get outgoing queue size

Returns the number of messages currently in the outgoing queue. A large number indicates the remote side is a slow consumer.

§Returns

Number of messages in the outgoing queue

§Example
use fixantenna_bindings::{FixEngine, SessionIdWrapper};

let engine = FixEngine::new("engine.properties").unwrap();
let session_id = SessionIdWrapper::new(
    "SENDER".to_string(),
    "TARGET".to_string(),
    "".to_string()
);
let session = engine.create_session(&session_id, "FIX44", None).unwrap();

let queue_size = session.get_outgoing_queue_size();
println!("Outgoing queue size: {}", queue_size);

pub fn get_parser(&self) -> Result<String, String>

Get parser name

Returns the name of the FIX parser being used (e.g., “FIX44”, “FIX50”).

§Returns
  • Ok(String) - Parser name
  • Err(String) - Error if operation fails
§Example
use fixantenna_bindings::{FixEngine, SessionIdWrapper};

let engine = FixEngine::new("engine.properties").unwrap();
let session_id = SessionIdWrapper::new(
    "SENDER".to_string(),
    "TARGET".to_string(),
    "".to_string()
);
let session = engine.create_session(&session_id, "FIX44", None).unwrap();

let parser = session.get_parser().unwrap();
println!("Parser: {}", parser);

pub fn get_remote_host_ip(&self) -> Result<String, String>

Get remote host IP address

Returns the IP address of the remote connection.

§Returns
  • Ok(String) - Remote IP address
  • Err(String) - Error if operation fails
§Example
use fixantenna_bindings::{FixEngine, SessionIdWrapper};

let engine = FixEngine::new("engine.properties").unwrap();
let session_id = SessionIdWrapper::new(
    "SENDER".to_string(),
    "TARGET".to_string(),
    "".to_string()
);
let session = engine.create_session(&session_id, "FIX44", None).unwrap();

// After connection is established
let ip = session.get_remote_host_ip().unwrap();
println!("Remote IP: {}", ip);

pub fn get_remote_port(&self) -> Result<i32, String>

Get remote port

Returns the port number of the remote connection.

§Returns
  • Ok(i32) - Remote port number
  • Err(String) - Error if operation fails
§Example
use fixantenna_bindings::{FixEngine, SessionIdWrapper};

let engine = FixEngine::new("engine.properties").unwrap();
let session_id = SessionIdWrapper::new(
    "SENDER".to_string(),
    "TARGET".to_string(),
    "".to_string()
);
let session = engine.create_session(&session_id, "FIX44", None).unwrap();

// After connection is established
let port = session.get_remote_port().unwrap();
println!("Remote port: {}", port);

pub fn get_storage_creation_time(&self) -> f64

Get storage creation time

Returns the timestamp when the session storage was created, in seconds since epoch (with millisecond precision).

§Returns

Timestamp in seconds since epoch (1970-01-01)

§Example
use fixantenna_bindings::{FixEngine, SessionIdWrapper};

let engine = FixEngine::new("engine.properties").unwrap();
let session_id = SessionIdWrapper::new(
    "SENDER".to_string(),
    "TARGET".to_string(),
    "".to_string()
);
let session = engine.create_session(&session_id, "FIX44", None).unwrap();

let creation_time = session.get_storage_creation_time();
println!("Storage created at: {} seconds since epoch", creation_time);

Trait Implementations§

§

impl Drop for Session

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl Send for Session

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