FixApplicationHandle

Struct FixApplicationHandle 

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

A handle on a FIX engine instance.

The FixApplicationHandle allows for requesting the basic operations of starting the FIX connection, sending a message to the peer, and ending the connection.

The handle offers asynchronous and synchronous APIs for these operations. As well as functions that return immedietly with a oneshot::Receiver that will eventually return the result of the operation.

The underlying engine could stop running at any moment for a variety of reasons. Only until you attempt an operation, will you learn the engine has stopped by receiving an ApplicationError::SessionEnded.

FixApplicationHandle impl’s Clone, Send and Sync and therefore multiple copies of the handle can be made and passed to different threads that can all request messages to be sent. Only one thread has to call end for the engine to terminate the connection.

§Example - Multiple Threads

 use forgefix::{
     SessionSettings, FixApplicationInitiator, ApplicationError
 };
 use forgefix::fix::{encode::MessageBuilder, generated::MsgType};

 let (handle, mut receiver) = FixApplicationInitiator::build(settings)?
     .initiate()
     .await?;
 receiver.close();

 // FixApplicationHandle can be cloned
 let handle1 = handle.clone();
 let handle2 = handle.clone();

 // FixApplicationHandle clones can be sent across threads and tasks
 let h1 = tokio::spawn(async move {

     // thread logic here...

     let builder = MessageBuilder::new(
         &handle1.begin_string(),
         MsgType::ORDER_SINGLE.into()
     );
     handle1.send_message_async(builder).await

     // ...
 });

 // send to multiple tasks...
 let h2 = tokio::spawn(async move {
     let builder = MessageBuilder::new(
         &handle2.begin_string(),
         MsgType::ORDER_SINGLE.into()
     );
     handle2.send_message_async(builder).await
 });

 // wait for all threads to finish...
 let (res1, res2) = tokio::join!(h1, h2);
 res1??;
 res2??;
     
 // end the FIX connection
 handle.end_async().await?;

Implementations§

Source§

impl FixApplicationHandle

Source

pub fn start(&self) -> Result<Receiver<bool>, ApplicationError>

Send a request to the engine to start the connection and return immediately.

The receiver will eventually yield true if a connection was successfully established, or false othersize.

Source

pub async fn start_async(&self) -> Result<(), ApplicationError>

Send a request to the engine to start the connection and await asynchronously.

Source

pub fn start_sync(&self) -> Result<(), ApplicationError>

Send a request to the engine to start a connection, and block until a result is returned.

Source

pub fn send_message( &self, builder: MessageBuilder, ) -> Result<Receiver<bool>, ApplicationError>

Send a request to the engine to send the message in the MessageBuilder to the peer, and return immediately.

If the request was successfully sent to the engine, a oneshot::Receiver will be returned.

The receiver will yield true once the message has successfully sent over the TCP connection. It will yeild false if a message cannot be sent.

Source

pub async fn send_message_async( &self, builder: MessageBuilder, ) -> Result<(), ApplicationError>

Send a request to the engine to send the message in builder and await asynchronously.

Source

pub fn send_message_sync( &self, builder: MessageBuilder, ) -> Result<(), ApplicationError>

Send a request to the engine to send the message in builder and block until a result is returned.

Source

pub fn end(&self) -> Result<Receiver<bool>, ApplicationError>

Send a request to the engine to end the FIX connection, and return immediately.

If the request was successfully send to the engine, a oneshot::Receiver will be returned.

The receiver will yield true is the FIX connection is over, and ended without any issues. Otherwise it will be false.

Source

pub async fn end_async(&self) -> Result<(), ApplicationError>

Send a request to the engine to end the FIX connection, and await asynchronously.

Source

pub fn end_sync(&self) -> Result<(), ApplicationError>

Send a request to the engine to end the FIX connection, and block until a result is returned.

Source

pub fn begin_string(&self) -> Arc<String>

Get the BeginString(8) of this FIX Session. Should generally be "FIX.4.2".

Trait Implementations§

Source§

impl Clone for FixApplicationHandle

Source§

fn clone(&self) -> FixApplicationHandle

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.