barter_execution/
error.rs1use barter_instrument::{
2 asset::{AssetIndex, name::AssetNameExchange},
3 exchange::ExchangeId,
4 instrument::{InstrumentIndex, name::InstrumentNameExchange},
5};
6use barter_integration::error::SocketError;
7use serde::{Deserialize, Serialize};
8use thiserror::Error;
9
10pub type UnindexedClientError = ClientError<AssetNameExchange, InstrumentNameExchange>;
13
14pub type UnindexedApiError = ApiError<AssetNameExchange, InstrumentNameExchange>;
17
18pub type UnindexedOrderError = OrderError<AssetNameExchange, InstrumentNameExchange>;
21
22#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize, Error)]
24pub enum ClientError<AssetKey = AssetIndex, InstrumentKey = InstrumentIndex> {
25 #[error("Connectivity: {0}")]
29 Connectivity(#[from] ConnectivityError),
30
31 #[error("API: {0}")]
35 Api(#[from] ApiError<AssetKey, InstrumentKey>),
36
37 #[error("failed to fetch AccountSnapshot: {0}")]
39 AccountSnapshot(String),
40
41 #[error("failed to init AccountStream: {0}")]
43 AccountStream(String),
44}
45
46#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize, Error)]
50pub enum ConnectivityError {
51 #[error("Exchange offline: {0}")]
53 ExchangeOffline(ExchangeId),
54
55 #[error("ExecutionRequest timed out")]
57 Timeout,
58
59 #[error("{0}")]
61 Socket(String),
62}
63
64impl From<SocketError> for ConnectivityError {
65 fn from(value: SocketError) -> Self {
66 Self::Socket(value.to_string())
67 }
68}
69
70#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize, Error)]
74pub enum ApiError<AssetKey = AssetIndex, InstrumentKey = InstrumentIndex> {
75 #[error("asset {0} invalid: {1}")]
80 AssetInvalid(AssetKey, String),
81
82 #[error("instrument {0} invalid: {1}")]
88 InstrumentInvalid(InstrumentKey, String),
89
90 #[error("rate limit exceeded")]
91 RateLimit,
92 #[error("asset {0} balance insufficient: {1}")]
93 BalanceInsufficient(AssetKey, String),
94 #[error("order rejected: {0}")]
95 OrderRejected(String),
96 #[error("order already cancelled")]
97 OrderAlreadyCancelled,
98 #[error("order already fully filled")]
99 OrderAlreadyFullyFilled,
100}
101
102#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize, Error)]
104pub enum OrderError<AssetKey = AssetIndex, InstrumentKey = InstrumentIndex> {
105 #[error("connectivity: {0}")]
109 Connectivity(#[from] ConnectivityError),
110
111 #[error("order rejected: {0}")]
115 Rejected(#[from] ApiError<AssetKey, InstrumentKey>),
116}
117
118#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize, Error)]
120pub enum KeyError {
121 #[error("ExchangeId: {0}")]
124 ExchangeId(String),
125
126 #[error("AssetKey: {0}")]
129 AssetKey(String),
130
131 #[error("InstrumentKey: {0}")]
134 InstrumentKey(String),
135}