Skip to main content

BcsApiError

Enum BcsApiError 

Source
pub enum BcsApiError {
    HttpError {
        status: Option<u16>,
        message: String,
        trace_id: Option<String>,
    },
    WsError {
        code: Option<String>,
        message: String,
    },
    AuthError {
        message: String,
    },
    ValidationError {
        trace_id: Option<String>,
        errors: Vec<ValidationFieldError>,
    },
    NotFound {
        trace_id: Option<String>,
    },
    ParseError(String),
    RateLimitExceeded,
    SubscriptionError {
        message: String,
    },
}
Expand description

The error of every REST call and of the subscription calls of a WebSocket session.

Read the variant to decide what to do:

  • BcsApiError::ValidationError and BcsApiError::NotFound are answers of the broker. The request reached it and was refused. Retrying the same request gives the same answer.
  • BcsApiError::RateLimitExceeded means “slow down”. The broker limits REST calls per account, about 10 per second for most services and 3 per second for non-trade operations (broker docs).
  • BcsApiError::AuthError means the refresh token was refused. A new token is needed.
  • BcsApiError::HttpError with no status is a transport failure (connection, timeout). For a command that creates an order this is an unknown outcome: the order may exist. Never repeat such a command blindly, ask for the order by its client order id first.

§Examples

use brokapi_bcs_protocol::error::BcsApiError;

let err = BcsApiError::NotFound { trace_id: Some("abc".into()) };
assert!(matches!(err, BcsApiError::NotFound { .. }));
// The messages are for logs, not for parsing.
assert!(!err.to_string().is_empty());

Variants§

§

HttpError

An HTTP-level failure.

Three sources: a transport failure (status is None, message is the transport text), a non-success status with the broker’s JSON error body (message is the broker’s error type such as UNAUTHORIZED, FORBIDDEN or RESOURCE_EXHAUSTED, and trace_id is set), and a non-success status with a body that is not that JSON (message is the raw body).

Fields

§status: Option<u16>

HTTP status code, if the broker answered at all.

§message: String

The broker’s error type, the raw body, or the transport error text.

§trace_id: Option<String>

The broker’s trace id, to quote to the broker support. None for transport failures.

§

WsError

A WebSocket-level failure.

The session raises it when it cannot open a connection. The session logs it and retries by itself, so you rarely see it as a return value.

Fields

§code: Option<String>

Error code, if the broker gave one.

§message: String

Description of the failure.

§

AuthError

The token endpoint refused the refresh token (expired, deleted or of a wrong kind).

message is the error_description of the token service, or its error if there is no description. Fix the token. Repeating the call does not help.

Fields

§message: String

The text from the token service.

§

ValidationError

The broker refused the request body or parameters (type = VALIDATION_ERROR).

For an order this is a refusal: nothing was placed. errors names the fields. A price outside the exchange band is a typical cause (not verified against the live API which field is named).

Fields

§trace_id: Option<String>

The broker’s trace id.

§errors: Vec<ValidationFieldError>

The refused fields, possibly empty.

§

NotFound

The broker has no such object (type = NOT_FOUND), for example an unknown order.

Fields

§trace_id: Option<String>

The broker’s trace id.

§

ParseError(String)

A reply or a URL could not be parsed.

The text holds the parser’s message. For a reply, it also holds the first 200 bytes of the body. The request itself did go through: for an order command this is an unknown outcome of the order, look it up before you repeat it.

§

RateLimitExceeded

HTTP 429 without the broker’s JSON error body.

A 429 that comes with the JSON body is BcsApiError::HttpError with status = Some(429) and message = "RESOURCE_EXHAUSTED". Handle both, or use the rate limiter in crate::utils::rate_limiter to stay below the limit.

§

SubscriptionError

A subscription command was refused locally, before anything was sent.

Causes: the session is not a market data session, the limit of 100 subscriptions per session is reached, or the session task has ended.

Fields

§message: String

Why the command was refused.

Trait Implementations§

Source§

impl Debug for BcsApiError

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for BcsApiError

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Error for BcsApiError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for BcsApiError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for BcsApiError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for BcsApiError

Source§

fn from(err: ParseError) -> Self

Converts to this type from the input type.

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more