pub struct FixClient { /* private fields */ }Expand description
Cloneable client of one FIX session.
Implementations§
Source§impl FixClient
impl FixClient
Sourcepub async fn cancel(
&self,
cl_ord_id: &str,
) -> Result<OrderReport, ConnectorError>
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.
Sourcepub async fn replace(
&self,
cl_ord_id: &str,
terms: Replacement,
) -> Result<OrderReport, ConnectorError>
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
impl FixClient
Sourcepub async fn connect(
configuration: ConfigurationFix,
kind: SessionKind,
) -> Result<Self, ConnectorError>
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.
Sourcepub async fn connect_with<C: Connect>(
configuration: ConfigurationFix,
kind: SessionKind,
connector: C,
) -> Result<Self, ConnectorError>
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.
Sourcepub const fn kind(&self) -> SessionKind
pub const fn kind(&self) -> SessionKind
Returns which session the client serves.
Sourcepub fn events(&self) -> Receiver<Event>
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.
Sourcepub async fn send(&self, message: Message) -> Result<u64, ConnectorError>
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.
Sourcepub async fn logout(&self) -> Result<(), ConnectorError>
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.
Sourcepub async fn force_reconnect(&self) -> Result<(), ConnectorError>
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.
Sourcepub async fn request<T>(
&self,
message: Message,
reference: &str,
pick: impl FnMut(&Message) -> Option<Result<T, ConnectorError>>,
) -> Result<T, ConnectorError>
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.
Sourcepub async fn request_once<T>(
&self,
message: Message,
reference: &str,
pick: impl FnMut(&Message) -> Option<Result<T, ConnectorError>>,
) -> Result<T, ConnectorError>
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§impl FixClient
impl FixClient
Sourcepub async fn subscribe_spot(
&self,
symbol: SymbolId,
) -> Result<SpotStream, ConnectorError>
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.
Sourcepub async fn subscribe_depth(
&self,
symbol: SymbolId,
) -> Result<DepthStream, ConnectorError>
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
impl FixClient
Sourcepub async fn order_status(
&self,
cl_ord_id: &str,
) -> Result<OrderReport, ConnectorError>
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.
Sourcepub async fn open_orders(&self) -> Result<Vec<OrderReport>, ConnectorError>
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.
Sourcepub async fn positions(&self) -> Result<Vec<Position>, ConnectorError>
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
impl FixClient
Sourcepub async fn securities(&self) -> Result<Vec<Security>, ConnectorError>
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
impl FixClient
Sourcepub async fn place(
&self,
order: NewOrder,
) -> Result<OrderReport, ConnectorError>
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.