mexc_rs/futures/error.rs
1// https://mxcdevelop.github.io/apidocs/contract_v1_en/#error-code-example
2
3use crate::futures::response::ErrorApiResponse;
4use crate::futures::GetAuthHeaderMapError;
5use std::fmt::{Display, Formatter};
6
7#[derive(Debug, thiserror::Error)]
8pub enum ApiError {
9 #[error("Reqwest error: {0:?}")]
10 ReqwestError(#[from] reqwest::Error),
11 #[error("Error response: {0:?}")]
12 ErrorResponse(#[from] ErrorApiResponse),
13 #[error("Get auth header map error: {0:?}")]
14 GetAuthHeaderMapError(#[from] GetAuthHeaderMapError),
15}
16
17// 0 Operate succeed
18// 9999 Public abnormal
19// 500 Internal error
20// 501 System busy
21// 401 Unauthorized
22// 402 Api_key expired
23// 406 Accessed IP is not in the whitelist
24// 506 Unknown source of request
25// 510 Excessive frequency of requests
26// 511 Endpoint inaccessible
27// 513 Invalid request(for open api serves time more or less than 10s)
28// 600 Parameter error
29// 601 Data decoding error
30// 602 Verify failed
31// 603 Repeated requests
32// 701 Account read permission is required
33// 702 Account modify permission is required
34// 703 Trade information read permission is required
35// 704 Transaction information modify permission is required
36// 1000 Account does not exist
37// 1001 Contract does not exist
38// 1002 Contract not activated
39// 1003 Error in risk limit level
40// 1004 Amount error
41// 2001 Wrong order direction
42// 2002 Wrong opening type
43// 2003 Overpriced to pay
44// 2004 Low-price for selling
45// 2005 Balance insufficient
46// 2006 Leverage ratio error
47// 2007 Order price error
48// 2008 The quantity is insufficient
49// 2009 Positions do not exist or have been closed
50// 2011 Order quantity error
51// 2013 Cancel orders over maximum limit
52// 2014 The quantity of batch order exceeds the limit
53// 2015 Price or quantity accuracy error
54// 2016 Trigger volume over the maximum
55// 2018 Exceeding the maximum available margin
56// 2019 There is an active open position
57// 2021 The single leverage is not consistent with the existing position leverage
58// 2022 Wrong position type
59// 2023 There are positions over the maximum leverage
60// 2024 There are orders with leverage over the maximum
61// 2025 The holding positions is over the maximum allowable positions
62// 2026 Modification of leverage is not supported for cross
63// 2027 There is only one cross or isolated in the same direction
64// 2028 The maximum order quantity is exceeded
65// 2029 Error order type
66// 2030 External order ID is too long (Max. 32 bits )
67// 2031 The allowable holding position exceed the current risk limit
68// 2032 Order price is less than long position force liquidate price
69// 2033 Order price is more than short position force liquidate price
70// 2034 The batch query quantity limit is exceeded
71// 2035 Unsupported market price tier
72// 3001 Trigger price type error
73// 3002 Trigger type error
74// 3003 Executive cycle error
75// 3004 Trigger price error
76// 4001 Unsupported currency
77// 2036 The orders more than the limit, please contact customer service
78// 2037 Frequent transactions, please try it later
79// 2038 The maximum allowable position quantity is exceeded, please contact customer service!
80// 5001 The take-price and the stop-loss price cannot be none at the same time
81// 5002 The Stop-Limit order does not exist or has closed
82// 5003 Take-profit and stop-loss price setting is wrong
83// 5004 The take-profit and stop-loss order volume is more than the holding positions can be liquidated
84// 6001 Trading forbidden
85// 6002 Open forbidden
86// 6003 Time range error
87// 6004 The trading pair and status should be fill in
88// 6005 The trading pair is not available
89
90#[derive(Debug, PartialEq, Eq, Hash, serde_repr::Deserialize_repr, strum_macros::IntoStaticStr)]
91#[repr(i32)]
92pub enum ErrorCode {
93 OperationSucceed = 0,
94 PublicAbnormal = 9999,
95 InternalError = 500,
96 SystemBusy = 501,
97 Unauthorized = 401,
98 ApiKeyExpired = 402,
99 NotFound = 404,
100 AccessedIpNotInWhitelist = 406,
101 UnknownSourceOfRequest = 506,
102 ExcessiveFrequencyOfRequests = 510,
103 EndpointInaccessible = 511,
104 InvalidRequest = 513,
105 ParameterError = 600,
106 DataDecodingError = 601,
107 VerifyFailed = 602,
108 RepeatedRequests = 603,
109 AccountReadPermissionRequired = 701,
110 AccountModifyPermissionRequired = 702,
111 TradeInformationReadPermissionRequired = 703,
112 TransactionInformationModifyPermissionRequired = 704,
113 AccountDoesNotExist = 1000,
114 ContractDoesNotExist = 1001,
115 ContractNotActivated = 1002,
116 ErrorInRiskLimitLevel = 1003,
117 AmountError = 1004,
118 WrongOrderDirection = 2001,
119 WrongOpeningType = 2002,
120 OverpricedToPay = 2003,
121 LowPriceForSelling = 2004,
122 BalanceInsufficient = 2005,
123 LeverageRatioError = 2006,
124 OrderPriceError = 2007,
125 QuantityInsufficient = 2008,
126 PositionsDoNotExistOrHaveBeenClosed = 2009,
127 UnknownOrderSent = 2011,
128 OrderQuantityError = 2012,
129 CancelOrdersOverMaximumLimit = 2013,
130 QuantityOfBatchOrderExceedsLimit = 2014,
131 PriceOrQuantityAccuracyError = 2015,
132 TriggerVolumeOverMaximum = 2016,
133 ExceedingMaximumAvailableMargin = 2018,
134 ThereIsActiveOpenPosition = 2019,
135 SingleLeverageIsNotConsistentWithExistingPositionLeverage = 2021,
136 WrongPositionType = 2022,
137 PositionsOverMaximumLeverage = 2023,
138 OrdersWithLeverageOverMaximum = 2024,
139 HoldingPositionsOverMaximumAllowablePositions = 2025,
140 ModificationOfLeverageIsNotSupportedForCross = 2026,
141 ThereIsOnlyOneCrossOrIsolatedInTheSameDirection = 2027,
142 MaximumOrderQuantityExceeded = 2028,
143 ErrorOrderType = 2029,
144 ExternalOrderIdIsTooLong = 2030,
145 AllowableHoldingPositionExceedCurrentRiskLimit = 2031,
146 OrderPriceIsLessThanLongPositionForceLiquidatePrice = 2032,
147 OrderPriceIsMoreThanShortPositionForceLiquidatePrice = 2033,
148 BatchQueryQuantityLimitExceeded = 2034,
149 UnsupportedMarketPriceTier = 2035,
150 TriggerPriceTypeError = 3001,
151 TriggerTypeError = 3002,
152 ExecutiveCycleError = 3003,
153 TriggerPriceError = 3004,
154 UnsupportedCurrency = 4001,
155 OrdersMoreThanLimit = 2036,
156 FrequentTransactions = 2037,
157 MaximumAllowablePositionQuantityExceeded = 2038,
158 TakePriceAndStopLossPriceCannotBeNoneAtTheSameTime = 5001,
159 StopLimitOrderDoesNotExistOrHasClosed = 5002,
160 TakeProfitAndStopLossPriceSettingIsWrong = 5003,
161 TakeProfitAndStopLossOrderVolumeIsMoreThanHoldingPositionsCanBeLiquidated = 5004,
162 TradingForbidden = 6001,
163 OpenForbidden = 6002,
164 TimeRangeError = 6003,
165 TradingPairAndStatusShouldBeFillIn = 6004,
166 TradingPairIsNotAvailable = 6005,
167}
168
169impl Display for ErrorCode {
170 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
171 let s: &'static str = self.into();
172 write!(f, "{}", s)
173 }
174}
175
176impl std::error::Error for ErrorCode {}