use std::fmt::{Display, Formatter};
use crate::futures::GetAuthHeaderMapError;
use crate::futures::response::ErrorApiResponse;
#[derive(Debug, thiserror::Error)]
pub enum ApiError {
#[error("Reqwest error: {0:?}")]
ReqwestError(#[from] reqwest::Error),
#[error("Error response: {0:?}")]
ErrorResponse(#[from] ErrorApiResponse),
#[error("Get auth header map error: {0:?}")]
GetAuthHeaderMapError(#[from] GetAuthHeaderMapError),
}
#[derive(Debug, PartialEq, Eq, Hash, serde_repr::Deserialize_repr, strum_macros::IntoStaticStr)]
#[repr(i32)]
pub enum ErrorCode {
OperationSucceed = 0,
PublicAbnormal = 9999,
InternalError = 500,
SystemBusy = 501,
Unauthorized = 401,
ApiKeyExpired = 402,
AccessedIpNotInWhitelist = 406,
UnknownSourceOfRequest = 506,
ExcessiveFrequencyOfRequests = 510,
EndpointInaccessible = 511,
InvalidRequest = 513,
ParameterError = 600,
DataDecodingError = 601,
VerifyFailed = 602,
RepeatedRequests = 603,
AccountReadPermissionRequired = 701,
AccountModifyPermissionRequired = 702,
TradeInformationReadPermissionRequired = 703,
TransactionInformationModifyPermissionRequired = 704,
AccountDoesNotExist = 1000,
ContractDoesNotExist = 1001,
ContractNotActivated = 1002,
ErrorInRiskLimitLevel = 1003,
AmountError = 1004,
WrongOrderDirection = 2001,
WrongOpeningType = 2002,
OverpricedToPay = 2003,
LowPriceForSelling = 2004,
BalanceInsufficient = 2005,
LeverageRatioError = 2006,
OrderPriceError = 2007,
QuantityInsufficient = 2008,
PositionsDoNotExistOrHaveBeenClosed = 2009,
UnknownOrderSent = 2011,
OrderQuantityError = 2012,
CancelOrdersOverMaximumLimit = 2013,
QuantityOfBatchOrderExceedsLimit = 2014,
PriceOrQuantityAccuracyError = 2015,
TriggerVolumeOverMaximum = 2016,
ExceedingMaximumAvailableMargin = 2018,
ThereIsActiveOpenPosition = 2019,
SingleLeverageIsNotConsistentWithExistingPositionLeverage = 2021,
WrongPositionType = 2022,
PositionsOverMaximumLeverage = 2023,
OrdersWithLeverageOverMaximum = 2024,
HoldingPositionsOverMaximumAllowablePositions = 2025,
ModificationOfLeverageIsNotSupportedForCross = 2026,
ThereIsOnlyOneCrossOrIsolatedInTheSameDirection = 2027,
MaximumOrderQuantityExceeded = 2028,
ErrorOrderType = 2029,
ExternalOrderIdIsTooLong = 2030,
AllowableHoldingPositionExceedCurrentRiskLimit = 2031,
OrderPriceIsLessThanLongPositionForceLiquidatePrice = 2032,
OrderPriceIsMoreThanShortPositionForceLiquidatePrice = 2033,
BatchQueryQuantityLimitExceeded = 2034,
UnsupportedMarketPriceTier = 2035,
TriggerPriceTypeError = 3001,
TriggerTypeError = 3002,
ExecutiveCycleError = 3003,
TriggerPriceError = 3004,
UnsupportedCurrency = 4001,
OrdersMoreThanLimit = 2036,
FrequentTransactions = 2037,
MaximumAllowablePositionQuantityExceeded = 2038,
TakePriceAndStopLossPriceCannotBeNoneAtTheSameTime = 5001,
StopLimitOrderDoesNotExistOrHasClosed = 5002,
TakeProfitAndStopLossPriceSettingIsWrong = 5003,
TakeProfitAndStopLossOrderVolumeIsMoreThanHoldingPositionsCanBeLiquidated = 5004,
TradingForbidden = 6001,
OpenForbidden = 6002,
TimeRangeError = 6003,
TradingPairAndStatusShouldBeFillIn = 6004,
TradingPairIsNotAvailable = 6005,
}
impl Display for ErrorCode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let s: &'static str = self.into();
write!(f, "{}", s)
}
}
impl std::error::Error for ErrorCode {}