nautilus_binance/futures/websocket/trading/error.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Binance Futures WebSocket Trading API error types.
17
18use std::fmt::Display;
19
20/// Binance Futures WebSocket Trading API error type.
21#[derive(Debug)]
22pub enum BinanceFuturesWsApiError {
23 /// General client error.
24 ClientError(String),
25 /// Handler not available (channel closed).
26 HandlerUnavailable(String),
27 /// Connection error.
28 ConnectionError(String),
29 /// Request rejected by venue.
30 RequestRejected {
31 /// Error code from venue.
32 code: i32,
33 /// Error message from venue.
34 msg: String,
35 },
36 /// JSON parsing or serialization error.
37 JsonError(String),
38 /// Request ID not found in pending requests.
39 UnknownRequestId(String),
40}
41
42impl Display for BinanceFuturesWsApiError {
43 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 match self {
45 Self::ClientError(msg) => write!(f, "Client error: {msg}"),
46 Self::HandlerUnavailable(msg) => write!(f, "Handler unavailable: {msg}"),
47 Self::ConnectionError(msg) => write!(f, "Connection error: {msg}"),
48 Self::RequestRejected { code, msg } => {
49 write!(f, "Request rejected [{code}]: {msg}")
50 }
51 Self::JsonError(msg) => write!(f, "JSON error: {msg}"),
52 Self::UnknownRequestId(id) => write!(f, "Unknown request ID: {id}"),
53 }
54 }
55}
56
57impl std::error::Error for BinanceFuturesWsApiError {}
58
59/// Result type for Binance Futures WebSocket Trading API operations.
60pub type BinanceFuturesWsApiResult<T> = Result<T, BinanceFuturesWsApiError>;