binance_api/error/
response.rs

1//! The response from a binance server indicating some error.
2//!
3//! For more information refer to either [spot specific][`crate::spot::error`]
4//! or [futures specific][`crate::futures::error`] error codes.
5use std::collections::HashMap;
6
7use serde::Deserialize;
8use serde_json::Value;
9use thiserror::Error;
10
11#[derive(Debug, Deserialize, Error)]
12#[error("[{code}]: {msg}")]
13/// The error returned as a JSON from the Binance server.
14/// Errors consist of two parts: an error code and a message.
15/// Codes are universal, but messages can vary.
16pub struct Error {
17    /// The numeric code identifying the kind of an error.
18    pub code: i32,
19    /// The helper message for the particular case of an error.
20    pub msg: String,
21
22    /// Rarely used but still exists in the following cases:
23    /// - with the 'data' key when
24    ///   [cancelling an existing order along with sending a new order]
25    ///
26    ///   There is a reserved HTTP code (409) for such case and specific error codes (-2021 and -2022).
27    ///
28    ///   See more information at
29    ///   <https://binance-docs.github.io/apidocs/spot/en/#errors-regarding-post-api-v3-order-cancelreplace>
30    ///
31    /// [cancelling an existing order along with sending a new order]: https://binance-docs.github.io/apidocs/spot/en/#cancel-an-existing-order-and-send-a-new-order-trade
32    #[serde(flatten)]
33    extra: HashMap<String, Value>,
34}
35
36/// 10xx - General Server or Network issues
37/// <https://binance-docs.github.io/apidocs/spot/en/#10xx-general-server-or-network-issues>
38impl Error {
39    /// An unknown error occurred while processing the request.
40    pub const UNKNOWN: i32 = -1000;
41
42    /// Internal error; unable to process your request. Please try again.
43    pub const DISCONNECTED: i32 = -1001;
44
45    /// You are not authorized to execute this request.
46    pub const UNAUTHORIZED: i32 = -1002;
47
48    /// Either of the following was happened:
49    /// - Too many requests queued.
50    /// - Too much request weight used; please use the websocket for live updates to avoid polling the API.
51    /// - Way too much request weight used; IP banned. Please use the websocket for live updates to avoid bans.
52    pub const TOO_MANY_REQUESTS: i32 = -1003;
53
54    /// An unexpected response was received from the message bus. Execution status unknown.
55    pub const UNEXPECTED_RESP: i32 = -1006;
56
57    /// Timeout waiting for response from backend server. Send status unknown; execution status unknown.
58    pub const TIMEOUT: i32 = -1007;
59
60    /// Unsupported order combination.
61    ///
62    /// The most probable case is:
63    /// - The orderType, timeInForce, stopPrice, and/or icebergQty combination isn't allowed.
64    pub const UNKNOWN_ORDER_COMPOSITION: i32 = -1014;
65
66    /// Too many new orders.
67    pub const TOO_MANY_ORDERS: i32 = -1015;
68
69    /// This service is no longer available.
70    pub const SERVICE_SHUTTING_DOWN: i32 = -1016;
71
72    /// This operation is not supported.
73    pub const UNSUPPORTED_OPERATION: i32 = -1020;
74
75    /// Either of the following was happened:
76    /// - Timestamp for this request is outside of the recvWindow.
77    /// - Timestamp for this request was 1000ms ahead of the server's time.
78    pub const INVALID_TIMESTAMP: i32 = -1021;
79
80    /// Signature for this request is not valid.
81    pub const INVALID_SIGNATURE: i32 = -1022;
82}
83
84/// 11xx - Request issues
85/// <https://binance-docs.github.io/apidocs/spot/en/#11xx-2xxx-request-issues>
86impl Error {
87    /// Illegal characters found in a parameter.
88    pub const ILLEGAL_CHARS: i32 = -1100;
89
90    /// Either of the following was happened:
91    /// - Too many parameters sent for this endpoint.
92    /// - Duplicate values for a parameter detected.
93    pub const TOO_MANY_PARAMETERS: i32 = -1101;
94
95    /// Either of the following was happened:
96    /// - A mandatory parameter was not sent, was empty/null, or malformed.
97    /// - Either of the two parameters must be sent, but both were empty/null.
98    pub const MANDATORY_PARAM_EMPTY_OR_MALFORMED: i32 = -1102;
99
100    /// An unknown parameter was sent.
101    pub const UNKNOWN_PARAM: i32 = -1103;
102
103    /// Not all sent parameters were read.
104    pub const UNREAD_PARAMETERS: i32 = -1104;
105
106    /// A parameter was empty.
107    pub const PARAM_EMPTY: i32 = -1105;
108
109    /// A parameter was sent when not required.
110    pub const PARAM_NOT_REQUIRED: i32 = -1106;
111
112    /// Precision is over the maximum defined for this asset.
113    pub const BAD_PRECISION: i32 = -1111;
114
115    /// No orders on book for symbol.
116    pub const NO_DEPTH: i32 = -1112;
117
118    /// TimeInForce parameter sent when not required.
119    pub const TIF_NOT_REQUIRED: i32 = -1114;
120
121    /// Invalid timeInForce.
122    pub const INVALID_TIF: i32 = -1115;
123
124    /// Invalid orderType.
125    pub const INVALID_ORDER_TYPE: i32 = -1116;
126
127    /// Invalid side.
128    pub const INVALID_SIDE: i32 = -1117;
129
130    /// New client order ID was empty.
131    pub const EMPTY_NEW_CL_ORD_ID: i32 = -1118;
132
133    /// Original client order ID was empty.
134    pub const EMPTY_ORG_CL_ORD_ID: i32 = -1119;
135
136    /// Invalid interval.
137    pub const BAD_INTERVAL: i32 = -1120;
138
139    /// Invalid symbol.
140    pub const BAD_SYMBOL: i32 = -1121;
141
142    /// This listenKey does not exist.
143    pub const INVALID_LISTEN_KEY: i32 = -1125;
144
145    /// Lookup interval is too big (more than allowed hours between startTime and endTime).
146    pub const MORE_THAN_XX_HOURS: i32 = -1127;
147
148    /// Combination of optional parameters invalid.
149    pub const OPTIONAL_PARAMS_BAD_COMBO: i32 = -1128;
150
151    /// Invalid data sent for a parameter.
152    pub const INVALID_PARAMETER: i32 = -1130;
153}
154
155/// 20xx - Processing issues
156/// <https://binance-docs.github.io/apidocs/spot/en/#11xx-2xxx-request-issues>
157impl Error {
158    /// New order was rejected.
159    pub const NEW_ORDER_REJECTED: i32 = -2010;
160
161    /// Cancellation of an order was rejected.
162    pub const CANCEL_REJECTED: i32 = -2011;
163
164    /// Order does not exist.
165    pub const NO_SUCH_ORDER: i32 = -2013;
166
167    /// API-key format invalid.
168    pub const BAD_API_KEY_FMT: i32 = -2014;
169
170    /// Invalid API-key, IP, or permissions for action.
171    pub const REJECTED_MBX_KEY: i32 = -2015;
172
173    /// No trading window could be found for the symbol. Try ticker/24hrs instead.
174    pub const NO_TRADING_WINDOW: i32 = -2016;
175}
176
177// TODO:
178/// 3xxx-5xxx - SAPI-specific issues
179/// <https://binance-docs.github.io/apidocs/spot/en/#3xxx-5xxx-sapi-specific-issues>
180impl Error {}
181
182/// 6xxx - Savings issues
183/// <https://binance-docs.github.io/apidocs/spot/en/#6xxx-savings-issues>
184impl Error {}
185
186/// 70xx - Futures issues
187/// <https://binance-docs.github.io/apidocs/spot/en/#70xx-futures>
188impl Error {}
189
190/// 9xxx - Filter failures
191/// <https://binance-docs.github.io/apidocs/spot/en/#9xxx-filter-failures>
192impl Error {}
193
194/// 10xxx - Futures Cross Collateral
195/// <https://binance-docs.github.io/apidocs/spot/en/#10xxx-futures-cross-collateral>
196impl Error {}
197
198/// 12xxx - Liquid Swap
199/// <https://binance-docs.github.io/apidocs/spot/en/#12xxx-liquid-swap>
200impl Error {}
201
202/// 13xxx - BLVT
203/// <https://binance-docs.github.io/apidocs/spot/en/#13xxx-blvt>
204impl Error {}
205
206/// 18xxx - Binance Code
207/// <https://binance-docs.github.io/apidocs/spot/en/#18xxx-binance-code>
208impl Error {}
209
210/// 20xxx - Futures Algo
211/// <https://binance-docs.github.io/apidocs/spot/en/#20xxx-futures-algo>
212impl Error {}
213
214/// 21xxx - Portfolio Margin Account
215/// <https://binance-docs.github.io/apidocs/spot/en/#21xxx-portfolio-margin-account>
216impl Error {}