pub struct OpenApiClient { /* private fields */ }Expand description
Cloneable client of the Open API.
Implementations§
Source§impl OpenApiClient
impl OpenApiClient
Sourcepub async fn trader(&self, account: AccountId) -> Result<Trader, ConnectorError>
pub async fn trader(&self, account: AccountId) -> Result<Trader, ConnectorError>
Reads the details of an authorised account: its balance, deposit currency, leverage and kind.
Two requests are made: one for the account and one for the assets of the account, among which the name of the deposit asset is looked up.
§Errors
Returns ConnectorError::Server when the server refuses a request,
ConnectorError::Value when the account carries a value out of range or a deposit
asset the server does not list, and the errors of
Connection::request otherwise.
Source§impl OpenApiClient
impl OpenApiClient
Sourcepub async fn connect(
configuration: ConfigurationOpenApi,
) -> Result<Self, ConnectorError>
pub async fn connect( configuration: ConfigurationOpenApi, ) -> Result<Self, ConnectorError>
Connects over TLS to the host named by the configuration.
§Errors
Returns ConnectorError::Transport when the connection cannot be established.
Sourcepub async fn connect_with<C: Connect>(
configuration: ConfigurationOpenApi,
connector: C,
options: ConnectionOptions,
) -> Result<Self, ConnectorError>
pub async fn connect_with<C: Connect>( configuration: ConfigurationOpenApi, connector: C, options: ConnectionOptions, ) -> Result<Self, ConnectorError>
Connects through the given connector with the given connection options.
§Errors
Returns ConnectorError::Transport when the connection cannot be established.
Sourcepub const fn connection(&self) -> &Connection
pub const fn connection(&self) -> &Connection
Returns the connection the client sends its requests over.
Sourcepub fn configuration(&self) -> &ConfigurationOpenApi
pub fn configuration(&self) -> &ConfigurationOpenApi
Returns the configuration the client was built from.
Authorises the application with its client id and secret.
This must succeed before any other request is sent.
§Errors
Returns ConnectorError::Server when the credentials are refused, and the errors of
Connection::request otherwise.
Sourcepub async fn accounts(&self) -> Result<Vec<Account>, ConnectorError>
pub async fn accounts(&self) -> Result<Vec<Account>, ConnectorError>
Lists the trading accounts the access token grants access to.
§Errors
Returns ConnectorError::Server when the token is refused,
ConnectorError::Value when the server reports an account id out of range, and the
errors of Connection::request otherwise.
Authorises a trading account with the access token.
This also starts a new session for an account whose authorisation the server ended.
§Errors
Returns ConnectorError::Server when the token or the account is refused, and the
errors of Connection::request otherwise.
Sourcepub fn access_token(&self) -> AccessToken
pub fn access_token(&self) -> AccessToken
Returns the access token in use, which differs from the configured one after a refresh.
Sourcepub async fn set_tokens(&self, pair: &TokenPair)
pub async fn set_tokens(&self, pair: &TokenPair)
Replaces the token pair the client uses for its next requests.
The accounts authorised so far are authorised with the new access token after a reconnection.
Sourcepub async fn refresh_token(&self) -> Result<TokenPair, ConnectorError>
pub async fn refresh_token(&self) -> Result<TokenPair, ConnectorError>
Exchanges the refresh token for a new pair over the connection.
The old pair stops working once the server has answered and the client uses the new one from then on. Accounts authorised earlier stay authorised on this connection. Store the returned pair before doing anything else: it is the only copy.
§Errors
Returns TokenError::NoRefreshToken when no refresh token is known,
ConnectorError::Server when the server refuses the refresh,
TokenError::Malformed when the response lacks a token, and the errors of
Connection::request otherwise.
Sourcepub async fn refresh_token_over_http(&self) -> Result<TokenPair, ConnectorError>
pub async fn refresh_token_over_http(&self) -> Result<TokenPair, ConnectorError>
Exchanges the refresh token for a new pair at the token endpoint, over TLS.
Behaves like OpenApiClient::refresh_token but does not use the connection.
§Errors
Fails like OpenApiClient::refresh_token_over_http_with.
Sourcepub async fn refresh_token_over_http_with<C: Connect>(
&self,
connector: &C,
) -> Result<TokenPair, ConnectorError>
pub async fn refresh_token_over_http_with<C: Connect>( &self, connector: &C, ) -> Result<TokenPair, ConnectorError>
Exchanges the refresh token for a new pair at the token endpoint through connector.
§Errors
Returns TokenError::NoRefreshToken when no refresh token is known and the errors of
refresh_over_http otherwise.
Sourcepub async fn subscribe_spots(
&self,
account: AccountId,
symbols: &[SymbolId],
) -> Result<(), ConnectorError>
pub async fn subscribe_spots( &self, account: AccountId, symbols: &[SymbolId], ) -> Result<(), ConnectorError>
Subscribes to the spot prices of the given symbols on an authorised account.
The prices arrive as events carrying a
ProtoOaSpotEvent. The subscription is
restored after a reconnection.
§Errors
Returns ConnectorError::Server when the server refuses the subscription, and the
errors of Connection::request otherwise.
Sourcepub async fn unsubscribe_spots(
&self,
account: AccountId,
symbols: &[SymbolId],
) -> Result<(), ConnectorError>
pub async fn unsubscribe_spots( &self, account: AccountId, symbols: &[SymbolId], ) -> Result<(), ConnectorError>
Ends the subscription to the spot prices of the given symbols.
§Errors
Returns ConnectorError::Server when the server refuses the request, and the errors
of Connection::request otherwise.
Sourcepub async fn version(&self) -> Result<String, ConnectorError>
pub async fn version(&self) -> Result<String, ConnectorError>
Sourcepub async fn shutdown(&self)
pub async fn shutdown(&self)
Stops the connection task; see Connection::shutdown.
Source§impl OpenApiClient
impl OpenApiClient
Sourcepub async fn subscribe_depth(
&self,
account: AccountId,
symbols: &[SymbolId],
) -> Result<DepthStream, ConnectorError>
pub async fn subscribe_depth( &self, account: AccountId, symbols: &[SymbolId], ) -> Result<DepthStream, ConnectorError>
Subscribes to the market depth of the given symbols on an authorised account and returns its changes as a stream.
The stream starts to listen before the subscription is requested, so the first entries the server sends are not missed. The subscription is restored after a reconnection.
§Errors
Returns ConnectorError::Server when the server refuses the subscription, and the
errors of Connection::request
otherwise.
Sourcepub async fn unsubscribe_depth(
&self,
account: AccountId,
symbols: &[SymbolId],
) -> Result<(), ConnectorError>
pub async fn unsubscribe_depth( &self, account: AccountId, symbols: &[SymbolId], ) -> Result<(), ConnectorError>
Ends the subscription to the market depth of the given symbols.
§Errors
Returns ConnectorError::Server when the server refuses the request, and the errors
of Connection::request otherwise.
Source§impl OpenApiClient
impl OpenApiClient
Sourcepub fn executions(&self, account: AccountId) -> ExecutionStream
pub fn executions(&self, account: AccountId) -> ExecutionStream
Starts to read the execution events and order error events of an authorised account.
Nothing is sent: the server delivers these events for every account authorised on the connection. Create the stream before the request whose events are to be read.
Source§impl OpenApiClient
impl OpenApiClient
Sourcepub async fn deal_history(
&self,
account: AccountId,
range: TimeRange,
) -> Result<Vec<Deal>, ConnectorError>
pub async fn deal_history( &self, account: AccountId, range: TimeRange, ) -> Result<Vec<Deal>, ConnectorError>
Fetches the deals of an authorised account inside a range of time, oldest first.
The server selects a deal by the moment it was last updated, which for a deal is the moment it was created, and includes both ends of the range. The server refuses a request whose ends are the same, so a single millisecond is asked for together with the one before it, and what belongs to that other millisecond is left out.
A range longer than MAX_HISTORY_RANGE is fetched with several requests, each of
which counts against the limit for historical data. The server sends a limited number
of deals per request; a part of the range it reports to hold more is halved and asked
for again, until every part is answered whole. Every deal of the range is thus
returned, and returned once.
§Errors
Returns ConnectorError::Server when the server refuses a request,
ConnectorError::Value when a deal carries a value out of range,
ConnectorError::Incomplete when the server reports more deals than it sends for a
part too short to be halved, in which case no part of the range is returned, and the
errors of Connection::request
otherwise.
Sourcepub async fn order_history(
&self,
account: AccountId,
range: TimeRange,
) -> Result<Vec<Order>, ConnectorError>
pub async fn order_history( &self, account: AccountId, range: TimeRange, ) -> Result<Vec<Order>, ConnectorError>
Fetches the orders of an authorised account that were last updated inside a range of time, in the order of their last update, oldest first.
The orders are the ones in force and the ones that are filled, cancelled, expired or
refused. Both ends of the range are included, and the range is cut into requests and
answered whole as described for OpenApiClient::deal_history.
§Errors
Fails like OpenApiClient::deal_history.
Sourcepub async fn cash_flow_history(
&self,
account: AccountId,
range: TimeRange,
) -> Result<Vec<CashFlow>, ConnectorError>
pub async fn cash_flow_history( &self, account: AccountId, range: TimeRange, ) -> Result<Vec<CashFlow>, ConnectorError>
Fetches the deposits, withdrawals and other changes of the balance of an authorised account outside of trading that were made inside a range of time, oldest first.
A range longer than MAX_HISTORY_RANGE is fetched with several requests, each of
which counts against the limit for historical data. A single millisecond is asked for
together with the one before it, and what belongs to that other millisecond is left
out.
§Errors
Returns ConnectorError::Server when the server refuses a request,
ConnectorError::Value when a change carries a value out of range, in which case no
part of the range is returned, and the errors of
Connection::request otherwise.
Source§impl OpenApiClient
impl OpenApiClient
Sourcepub fn margin_events(&self, account: AccountId) -> MarginStream
pub fn margin_events(&self, account: AccountId) -> MarginStream
Starts to read the margin events of an authorised account.
Nothing is sent: the server delivers these events for every account authorised on the connection. Create the stream before the request whose events are to be read.
Sourcepub async fn margin_calls(
&self,
account: AccountId,
) -> Result<Vec<MarginCall>, ConnectorError>
pub async fn margin_calls( &self, account: AccountId, ) -> Result<Vec<MarginCall>, ConnectorError>
Lists the margin calls of an authorised account.
§Errors
Returns ConnectorError::Server when the server refuses the request,
ConnectorError::Value when a margin call carries a value out of range, and the
errors of Connection::request
otherwise.
Sourcepub async fn update_margin_call(
&self,
account: AccountId,
call: MarginCall,
) -> Result<(), ConnectorError>
pub async fn update_margin_call( &self, account: AccountId, call: MarginCall, ) -> Result<(), ConnectorError>
Sets the threshold of a margin call of an authorised account.
The request states the whole margin call and has the same outcome however often it arrives, so it is sent again after a reconnection like a request that reads.
§Errors
Returns ConnectorError::Value when the threshold is negative, in which case nothing
is sent, ConnectorError::Server when the server refuses the request, and the errors
of Connection::request otherwise.
Source§impl OpenApiClient
impl OpenApiClient
Sourcepub async fn subscribe_quotes(
&self,
account: AccountId,
symbols: &[SymbolId],
) -> Result<QuoteStream, ConnectorError>
pub async fn subscribe_quotes( &self, account: AccountId, symbols: &[SymbolId], ) -> Result<QuoteStream, ConnectorError>
Subscribes to the spot prices of the given symbols on an authorised account and returns their quotes as a stream.
The stream starts to listen before the subscription is requested, so the first prices the server sends are not missed. The subscription is restored after a reconnection.
§Errors
Fails like OpenApiClient::subscribe_spots.
Sourcepub fn quotes(&self, account: AccountId, symbols: &[SymbolId]) -> QuoteStream
pub fn quotes(&self, account: AccountId, symbols: &[SymbolId]) -> QuoteStream
Returns the quotes of symbols that are subscribed already, without subscribing.
The stream delivers quotes that arrive after this call and stays silent for symbols without a subscription.
Source§impl OpenApiClient
impl OpenApiClient
Sourcepub async fn assets(
&self,
account: AccountId,
) -> Result<Vec<Asset>, ConnectorError>
pub async fn assets( &self, account: AccountId, ) -> Result<Vec<Asset>, ConnectorError>
Lists the assets known to an authorised account.
§Errors
Returns ConnectorError::Server when the server refuses the request,
ConnectorError::Value when an asset carries a value out of range, and the errors of
Connection::request otherwise.
Sourcepub async fn symbols(
&self,
params: SymbolsParams,
) -> Result<SymbolList, ConnectorError>
pub async fn symbols( &self, params: SymbolsParams, ) -> Result<SymbolList, ConnectorError>
Lists the symbols of an authorised account, without their trading details.
§Errors
Returns ConnectorError::Server when the server refuses the request,
ConnectorError::Value when a symbol carries a value out of range, and the errors of
Connection::request otherwise.
Sourcepub async fn symbol_details(
&self,
account: AccountId,
symbols: &[SymbolId],
) -> Result<Vec<Symbol>, ConnectorError>
pub async fn symbol_details( &self, account: AccountId, symbols: &[SymbolId], ) -> Result<Vec<Symbol>, ConnectorError>
Fetches the trading details of the given symbols of an authorised account.
Symbols the server does not know are left out of the answer.
§Errors
Returns ConnectorError::Server when the server refuses the request,
ConnectorError::Value when a symbol carries a value out of range, and the errors of
Connection::request otherwise.
Source§impl OpenApiClient
impl OpenApiClient
Sourcepub async fn tick_data(
&self,
params: &TickDataParams,
) -> Result<Vec<Tick>, ConnectorError>
pub async fn tick_data( &self, params: &TickDataParams, ) -> Result<Vec<Tick>, ConnectorError>
Fetches the ticks of one side of a symbol inside a range of time, oldest first.
Both ends of the range are included. On the wire a request covers the milliseconds from
fromTimestamp up to, but not including, toTimestamp, so every request ends one
millisecond after the last one it asks for.
The server answers with a limited number of ticks per request, latest first, and accepts
at most TickDataParams::MAX_RANGE per request. A longer or busier range is fetched
with several requests, latest part first, each of which counts against the limit for
historical data. An answer that announces more ticks may have cut its oldest
millisecond short, so the ticks it brought of that millisecond are set aside and the
next request ends with that millisecond, which is then taken whole from the answer to
it. Every tick of the range is thus returned, and returned once. With a limit the
latest ticks are returned; which of several ticks sharing the oldest millisecond
returned are left out is not defined.
§Errors
Returns ConnectorError::Server when the server refuses a request,
ConnectorError::Value when a tick carries a value out of range or the range ends at
the last moment a timestamp can name, ConnectorError::Incomplete when the server
announces more ticks than it sends and the rest cannot be asked for, either because the
answer is empty or because all of it lies inside the millisecond the request ends with,
in which case no part of the range is returned, and the errors of
Connection::request otherwise.
Source§impl OpenApiClient
impl OpenApiClient
Sourcepub async fn place_order(
&self,
order: &NewOrder,
symbol: &Symbol,
) -> Result<Execution, ConnectorError>
pub async fn place_order( &self, order: &NewOrder, symbol: &Symbol, ) -> Result<Execution, ConnectorError>
Places an order on an authorised account and returns the first execution event the server answers with.
symbol holds the trading details of the symbol of the order, as
OpenApiClient::symbol_details returns them. The order is checked against them and
nothing is sent when its volume lies outside the smallest and largest volume of the
symbol or off its step, when a price or a distance is finer than the digits of the
symbol, or when the order has terms its kind does not take.
The first event of an order the server takes is its acceptance, with
ExecutionType::Accepted. An order at market is executed right after: the fill
arrives as a further event, which is read from the events of the connection. A pending
order stays in force and is listed among the orders of the account.
The request is written at most once and never sent again by this library.
§Errors
Returns ConnectorError::Value when the order does not fit the symbol or the answer
carries a value out of range, ConnectorError::Server with the code the server gives
when it refuses the order, be it with an error, an order error event or an execution
event that reports the refusal, ConnectorError::OutcomeUnknown when the request was
written and no answer arrived, in which case the order may or may not be in force, and
the errors of
Connection::request_once
otherwise.
Sourcepub async fn amend_order(
&self,
amendment: &OrderAmendment,
symbol: &Symbol,
) -> Result<Execution, ConnectorError>
pub async fn amend_order( &self, amendment: &OrderAmendment, symbol: &Symbol, ) -> Result<Execution, ConnectorError>
Amends a pending order and returns the first execution event the server answers with,
which for an amendment the server takes has ExecutionType::Replaced and carries
the order as it is afterwards.
symbol holds the trading details of the symbol of the order; the amendment is checked
against them as an order is before it is placed. Only limit, stop and stop-limit orders
can be amended.
The request is written at most once and never sent again by this library.
§Errors
Returns the errors of OpenApiClient::place_order.
Sourcepub async fn amend_position(
&self,
amendment: &PositionAmendment,
symbol: &Symbol,
) -> Result<Execution, ConnectorError>
pub async fn amend_position( &self, amendment: &PositionAmendment, symbol: &Symbol, ) -> Result<Execution, ConnectorError>
Amends the stop loss and take profit of a position and returns the first execution
event the server answers with, which carries the position as it is afterwards. For an
amendment the server takes the event has ExecutionType::Accepted when the position
had neither a stop loss nor a take profit before, since the order that holds them is
new then, and ExecutionType::Replaced otherwise.
symbol holds the trading details of the symbol of the position; the prices are
checked against its digits before anything is sent.
The request is written at most once and never sent again by this library.
§Errors
Returns the errors of OpenApiClient::place_order.
Sourcepub async fn cancel_order(
&self,
account: AccountId,
order: OrderId,
) -> Result<Execution, ConnectorError>
pub async fn cancel_order( &self, account: AccountId, order: OrderId, ) -> Result<Execution, ConnectorError>
Cancels a pending order of an authorised account and returns the first execution event
the server answers with, which for an order the server takes out of force has
ExecutionType::Cancelled and carries the order as it was last.
The request is written at most once and never sent again by this library.
§Errors
Returns ConnectorError::Value when the answer carries a value out of range,
ConnectorError::Server with the code the server gives when it refuses to cancel,
be it with an error, an order error event or an execution event that reports the
refusal, ConnectorError::OutcomeUnknown when the request was written and no answer
arrived, in which case the order may or may not be in force, and the errors of
Connection::request_once
otherwise.
Sourcepub async fn reconcile(
&self,
account: AccountId,
) -> Result<Reconciliation, ConnectorError>
pub async fn reconcile( &self, account: AccountId, ) -> Result<Reconciliation, ConnectorError>
Reads the open positions and the orders in force of an authorised account.
The orders include the ones that hold the stop loss and take profit of a position. The answer is returned whole or not at all: one position or order that does not parse fails the call.
§Errors
Returns ConnectorError::Value when the answer carries a value out of range and the
errors of Connection::request
otherwise.
Sourcepub async fn close_position(
&self,
account: AccountId,
position: &Position,
volume: Volume,
symbol: &Symbol,
) -> Result<Execution, ConnectorError>
pub async fn close_position( &self, account: AccountId, position: &Position, volume: Volume, symbol: &Symbol, ) -> Result<Execution, ConnectorError>
Closes a position of an authorised account, in whole or in part, and returns the first execution event the server answers with.
position is the position as it was last read, volume the part of it to close, in
units of the symbol, and symbol holds the trading details of the symbol of the
position. Nothing is sent when the volume is zero or larger than the position, or when
a part of the position lies off the step of the symbol.
The server closes with an order of its own: the first event is the acceptance of that
order, with ExecutionType::Accepted, and the fill arrives as a further event, which
is read from the events of the connection and carries the deal with its
Deal::closing detail and the position as it is afterwards.
The request is written at most once and never sent again by this library.
§Errors
Returns the errors of OpenApiClient::place_order; with
ConnectorError::OutcomeUnknown the position may or may not be closed.
Source§impl OpenApiClient
impl OpenApiClient
Sourcepub async fn trendbars(
&self,
params: &TrendbarsParams,
) -> Result<Vec<Trendbar>, ConnectorError>
pub async fn trendbars( &self, params: &TrendbarsParams, ) -> Result<Vec<Trendbar>, ConnectorError>
Fetches the bars of a symbol and period that overlap a range of time, oldest first.
The server answers one request with a limited number of bars and accepts a limited span
of time per period, see Period::max_range. A longer range is fetched with several
requests, latest part first, each of which counts against the limit for historical data.
The bar that is still forming is not part of the answer.
§Errors
Returns ConnectorError::Server when the server refuses a request,
ConnectorError::Value when a bar lacks a field or carries a value out of range, and
the errors of Connection::request
otherwise.
Sourcepub async fn subscribe_live_trendbars(
&self,
account: AccountId,
symbol: SymbolId,
period: Period,
) -> Result<TrendbarStream, ConnectorError>
pub async fn subscribe_live_trendbars( &self, account: AccountId, symbol: SymbolId, period: Period, ) -> Result<TrendbarStream, ConnectorError>
Subscribes to the forming bar of a symbol and period on an authorised account.
The server sends live bars only for symbols whose spot prices are subscribed, so the spot subscription is requested first unless this client holds it already. Both subscriptions are restored after a reconnection, in that order.
§Errors
Returns ConnectorError::Server when the server refuses a subscription, and the
errors of Connection::request
otherwise.
Sourcepub async fn unsubscribe_live_trendbars(
&self,
account: AccountId,
symbol: SymbolId,
period: Period,
) -> Result<(), ConnectorError>
pub async fn unsubscribe_live_trendbars( &self, account: AccountId, symbol: SymbolId, period: Period, ) -> Result<(), ConnectorError>
Ends the subscription to the forming bar of a symbol and period.
§Errors
Returns ConnectorError::Server when the server refuses the request, and the errors
of Connection::request otherwise.