Skip to main content

FixClient

Struct FixClient 

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

Cloneable client of one FIX session.

Implementations§

Source§

impl FixClient

Source

pub async fn cancel( &self, cl_ord_id: &str, ) -> Result<OrderReport, ConnectorError>

Cancels the waiting order the client gave the identifier cl_ord_id and returns the report of the cancellation.

§Errors

Returns ConnectorError::Fix with FixError::CancelRejected when the server refuses, among others because it knows no such order, and otherwise the errors of FixClient::request. A cancellation may be repeated after a ConnectorError::Timeout.

Source

pub async fn replace( &self, cl_ord_id: &str, terms: Replacement, ) -> Result<OrderReport, ConnectorError>

Replaces the terms of the waiting order the client gave the identifier cl_ord_id and returns the report of the order as replaced. The report carries the identifier of the request; the order goes on answering to the identifier it was placed under.

§Errors

Returns ConnectorError::Fix with FixError::CancelRejected when the server refuses, among others because it knows no such order, ConnectorError::OutcomeUnknown when the answer does not arrive in time or the session is lost first, and otherwise the errors of FixClient::request_once.

Source§

impl FixClient

Source

pub async fn connect( configuration: ConfigurationFix, kind: SessionKind, ) -> Result<Self, ConnectorError>

Connects to the host named by the configuration and logs on to the session.

The connection runs over TLS unless the configuration asks for none.

§Errors

Returns ConnectorError::Transport when the connection cannot be established, ConnectorError::Fix with FixError::LogonRefused when the server answers the logon with a logout, and ConnectorError::Timeout when it does not answer in time.

Source

pub async fn connect_with<C: Connect>( configuration: ConfigurationFix, kind: SessionKind, connector: C, ) -> Result<Self, ConnectorError>

Connects through the given connector and logs on to the session.

§Errors

Returns the errors of FixClient::connect.

Source

pub const fn kind(&self) -> SessionKind

Returns which session the client serves.

Source

pub const fn timeout(&self) -> Duration

Returns the longest wait for an answer of the server.

Source

pub fn events(&self) -> Receiver<Event>

Subscribes to the events of the session from this moment on.

A reader that falls behind loses the oldest events and is told how many.

Source

pub async fn send(&self, message: Message) -> Result<u64, ConnectorError>

Sends a message and returns the sequence number it was given.

The message goes out as it is, with one exception: a business message reject (j) is never sent. It is refused here, before anything is written and without a sequence number, because the server refuses one with a reject and closes the connection. Every message of the application passes through this method, those of FixClient::request and FixClient::request_once included.

§Errors

Returns ConnectorError::Fix with FixError::Unsendable for a business message reject and with another FixError when the message cannot be encoded, ConnectorError::Transport when the write fails, and ConnectorError::Closed when the session has ended or is between two connections; the message was not sent then.

Source

pub async fn logout(&self) -> Result<(), ConnectorError>

Logs out and closes the connection; the session ends for every clone of the client.

§Errors

Returns ConnectorError::Timeout when the server does not confirm the logout in time, ConnectorError::Transport when the connection fails first, and ConnectorError::Closed when the session has ended already. The connection is closed in every case. A logout between two connections ends the session without an exchange and returns Ok.

Source

pub async fn force_reconnect(&self) -> Result<(), ConnectorError>

Drops the connection on this side, which starts a reconnection as a loss would.

§Errors

Returns ConnectorError::Closed when the session has ended.

Source

pub async fn closed(&self)

Waits until the session has ended.

Source

pub async fn request<T>( &self, message: Message, reference: &str, pick: impl FnMut(&Message) -> Option<Result<T, ConnectorError>>, ) -> Result<T, ConnectorError>

Sends a request and waits for the message pick accepts as its answer.

pick sees every message that arrives after the request was sent and returns the outcome once it recognises the answer. reference is the identifier the request carries, by which a refusal of the server names it; it may be empty.

§Errors

Returns ConnectorError::Fix with FixError::Rejected or FixError::BusinessRejected when the server refuses the request, ConnectorError::Timeout when no answer arrives in time, ConnectorError::OutcomeUnknown when the server asks for the request again, which the library never sends twice, ConnectorError::Transport when the connection is lost first, ConnectorError::Lagged when the reader fell behind and the answer may have been skipped, and ConnectorError::Closed when the session has ended already or has no connection at the moment, between Event::Disconnected and Event::Reconnected.

Source

pub async fn request_once<T>( &self, message: Message, reference: &str, pick: impl FnMut(&Message) -> Option<Result<T, ConnectorError>>, ) -> Result<T, ConnectorError>

Sends a request that must not be sent twice, such as an order, and waits for its answer.

§Errors

Returns the errors of FixClient::request, except that a wait cut short by the deadline or by the loss of the session is reported as ConnectorError::OutcomeUnknown: the server may have acted on the request.

Source

pub fn next_id(&self, prefix: &str) -> String

Returns an identifier no other request of this client carries.

Source§

impl FixClient

Source

pub async fn subscribe_spot( &self, symbol: SymbolId, ) -> Result<SpotStream, ConnectorError>

Subscribes to the best prices of a symbol and waits for the first report.

§Errors

Returns ConnectorError::Fix when the server refuses the subscription, ConnectorError::Timeout when no price arrives in time, and ConnectorError::Transport or ConnectorError::Closed when the session ends.

Source

pub async fn subscribe_depth( &self, symbol: SymbolId, ) -> Result<DepthStream, ConnectorError>

Subscribes to the depth of the market of a symbol and waits for the first book, which the server sends empty; the entries follow as changes.

§Errors

Returns the errors of FixClient::subscribe_spot.

Source§

impl FixClient

Source

pub async fn order_status( &self, cl_ord_id: &str, ) -> Result<OrderReport, ConnectorError>

Asks for the state of the order the client gave the identifier cl_ord_id.

§Errors

Returns ConnectorError::Fix with FixError::BusinessRejected when the server knows no such order, and otherwise the errors of FixClient::request.

Source

pub async fn open_orders(&self) -> Result<Vec<OrderReport>, ConnectorError>

Lists the waiting orders of the account.

§Errors

Returns the errors of FixClient::request; when a report cannot be read or the list stays incomplete no order is returned.

Source

pub async fn positions(&self) -> Result<Vec<Position>, ConnectorError>

Lists the open positions of the account.

§Errors

Returns ConnectorError::Fix with FixError::BusinessRejected when the server reports the request as invalid, and otherwise the errors of FixClient::request; when a report cannot be read or the list stays incomplete no position is returned.

Source§

impl FixClient

Source

pub async fn securities(&self) -> Result<Vec<Security>, ConnectorError>

Lists the symbols of the account.

§Errors

Returns ConnectorError::Fix when the server refuses the request or lists a symbol without its name or its digits, in which case no symbol is returned, and otherwise the errors of FixClient::request.

Source§

impl FixClient

Source

pub async fn place( &self, order: NewOrder, ) -> Result<OrderReport, ConnectorError>

Places an order and returns the report that settles the request: the fill of a market order, the acceptance of a limit or stop order.

The order is sent once and never again by the library.

§Errors

Returns ConnectorError::Fix with FixError::OrderRejected when the server accepts the message and then refuses, cancels or expires the order, with FixError::BusinessRejected or FixError::Rejected when it refuses the message, and with FixError::MissingField when its report lacks a field every report of an order carries. Returns ConnectorError::OutcomeUnknown when the answer does not arrive in time or the session is lost first: the order may or may not exist. Returns otherwise the errors of FixClient::request_once.

Trait Implementations§

Source§

impl Clone for FixClient

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FixClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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