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::ValidationErrorandBcsApiError::NotFoundare answers of the broker. The request reached it and was refused. Retrying the same request gives the same answer.BcsApiError::RateLimitExceededmeans “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::AuthErrormeans the refresh token was refused. A new token is needed.BcsApiError::HttpErrorwith 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
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
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.
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
errors: Vec<ValidationFieldError>The refused fields, possibly empty.
NotFound
The broker has no such object (type = NOT_FOUND), for example an unknown order.
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.
Trait Implementations§
Source§impl Debug for BcsApiError
impl Debug for BcsApiError
Source§impl Display for BcsApiError
impl Display for BcsApiError
Source§impl Error for BcsApiError
impl Error for BcsApiError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()