deribit_base/error/
conversions.rs

1/******************************************************************************
2   Author: Joaquín Béjar García
3   Email: jb@taunais.com
4   Date: 22/7/25
5******************************************************************************/
6
7use crate::error::codes::DeribitErrorCode;
8
9// Conversion from i32 to DeribitErrorCode
10impl From<i32> for DeribitErrorCode {
11    fn from(code: i32) -> Self {
12        match code {
13            0 => Self::Success,
14            10000 => Self::AuthorizationRequired,
15            10001 => Self::Error,
16            10002 => Self::QtyTooLow,
17            10003 => Self::OrderOverlap,
18            10004 => Self::OrderNotFound,
19            10005 => Self::PriceTooLow,
20            10006 => Self::PriceTooLow4Idx,
21            10007 => Self::PriceTooHigh,
22            10009 => Self::NotEnoughFunds,
23            10010 => Self::AlreadyClosed,
24            10011 => Self::PriceNotAllowed,
25            10012 => Self::BookClosed,
26            10013 => Self::PmeMaxTotalOpenOrders,
27            10014 => Self::PmeMaxFutureOpenOrders,
28            10015 => Self::PmeMaxOptionOpenOrders,
29            10016 => Self::PmeMaxFutureOpenOrdersSize,
30            10017 => Self::PmeMaxOptionOpenOrdersSize,
31            10018 => Self::NonPmeMaxFuturePositionSize,
32            10019 => Self::LockedByAdmin,
33            10020 => Self::InvalidOrUnsupportedInstrument,
34            10021 => Self::InvalidAmount,
35            10022 => Self::InvalidQuantity,
36            10023 => Self::InvalidPrice,
37            10024 => Self::InvalidMaxShow,
38            10025 => Self::InvalidOrderId,
39            10026 => Self::PricePrecisionExceeded,
40            10027 => Self::NonIntegerContractAmount,
41            10028 => Self::TooManyRequests,
42            10029 => Self::NotOwnerOfOrder,
43            10030 => Self::MustBeWebsocketRequest,
44            10031 => Self::InvalidArgsForInstrument,
45            10032 => Self::WholeCostTooLow,
46            10033 => Self::NotImplemented,
47            10034 => Self::TriggerPriceTooHigh,
48            10035 => Self::TriggerPriceTooLow,
49            10036 => Self::InvalidMaxShowAmount,
50            10037 => Self::NonPmeTotalShortOptionsPositionsSize,
51            10038 => Self::PmeMaxRiskReducingOrders,
52            10039 => Self::NotEnoughFundsInCurrency,
53            10040 => Self::Retry,
54            10041 => Self::SettlementInProgress,
55            10043 => Self::PriceWrongTick,
56            10044 => Self::TriggerPriceWrongTick,
57            10045 => Self::CanNotCancelLiquidationOrder,
58            10046 => Self::CanNotEditLiquidationOrder,
59            10047 => Self::MatchingEngineQueueFull,
60            10048 => Self::NotOnThisServer,
61            10049 => Self::CancelOnDisconnectFailed,
62            10066 => Self::TooManyConcurrentRequests,
63            10072 => Self::DisabledWhilePositionLock,
64            11008 => Self::AlreadyFilled,
65            11013 => Self::MaxSpotOpenOrders,
66            11021 => Self::PostOnlyPriceModificationNotPossible,
67            11022 => Self::MaxSpotOrderQuantity,
68            11029 => Self::InvalidArguments,
69            11030 => Self::OtherReject,
70            11031 => Self::OtherError,
71            11035 => Self::NoMoreTriggers,
72            11036 => Self::InvalidTriggerPrice,
73            11037 => Self::OutdatedInstrumentForIvOrder,
74            11038 => Self::NoAdvForFutures,
75            11039 => Self::NoAdvPostonly,
76            11041 => Self::NotAdvOrder,
77            11042 => Self::PermissionDenied,
78            11043 => Self::BadArgument,
79            11044 => Self::NotOpenOrder,
80            11045 => Self::InvalidEvent,
81            11046 => Self::OutdatedInstrument,
82            11047 => Self::UnsupportedArgCombination,
83            11048 => Self::WrongMaxShowForOption,
84            11049 => Self::BadArguments,
85            11050 => Self::BadRequest,
86            11051 => Self::SystemMaintenance,
87            11052 => Self::SubscribeErrorUnsubscribed,
88            11053 => Self::TransferNotFound,
89            11054 => Self::PostOnlyReject,
90            11055 => Self::PostOnlyNotAllowed,
91            11056 => Self::UnauthenticatedPublicRequestsTemporarilyDisabled,
92            11090 => Self::InvalidAddr,
93            11091 => Self::InvalidTransferAddress,
94            11092 => Self::AddressAlreadyExist,
95            11093 => Self::MaxAddrCountExceeded,
96            11094 => Self::InternalServerError,
97            11095 => Self::DisabledDepositAddressCreation,
98            11096 => Self::AddressBelongsToUser,
99            11097 => Self::NoDepositAddress,
100            11098 => Self::AccountLocked,
101            12001 => Self::TooManySubaccounts,
102            12002 => Self::WrongSubaccountName,
103            12003 => Self::LoginOverLimit,
104            12004 => Self::RegistrationOverLimit,
105            12005 => Self::CountryIsBanned,
106            12100 => Self::TransferNotAllowed,
107            12998 => Self::SecurityKeyAuthorizationOverLimit,
108            13004 => Self::InvalidCredentials,
109            13005 => Self::PwdMatchError,
110            13006 => Self::SecurityError,
111            13007 => Self::UserNotFound,
112            13008 => Self::RequestFailed,
113            13009 => Self::Unauthorized,
114            13010 => Self::ValueRequired,
115            13011 => Self::ValueTooShort,
116            13012 => Self::UnavailableInSubaccount,
117            13013 => Self::InvalidPhoneNumber,
118            13014 => Self::CannotSendSms,
119            13015 => Self::InvalidSmsCode,
120            13016 => Self::InvalidInput,
121            13018 => Self::InvalidContentType,
122            13019 => Self::OrderbookClosed,
123            13020 => Self::NotFound,
124            13021 => Self::Forbidden,
125            13025 => Self::MethodSwitchedOffByAdmin,
126            13028 => Self::TemporarilyUnavailable,
127            13030 => Self::MmpTrigger,
128            13031 => Self::VerificationRequired,
129            13032 => Self::NonUniqueOrderLabel,
130            13034 => Self::NoMoreSecurityKeysAllowed,
131            13035 => Self::ActiveComboLimitReached,
132            13036 => Self::UnavailableForComboBooks,
133            13037 => Self::IncompleteKycData,
134            13040 => Self::MmpRequired,
135            13042 => Self::CodNotEnabled,
136            13043 => Self::QuotesFrozen,
137            13403 => Self::ScopeExceeded,
138            13503 => Self::Unavailable,
139            13666 => Self::RequestCancelledByUser,
140            13777 => Self::Replaced,
141            13778 => Self::RawSubscriptionsNotAvailableForUnauthorized,
142            13780 => Self::MovePositionsOverLimit,
143            13781 => Self::CouponAlreadyUsed,
144            13791 => Self::KycTransferAlreadyInitiated,
145            _ => Self::Unknown(code),
146        }
147    }
148}