bybit/models/return_codes/
asset.rs1use crate::prelude::*;
2
3#[derive(Clone, Copy, PartialEq, Eq, Hash, Display, derive_more::Debug, derive_more::From)]
7#[repr(i32)]
8#[display("{} - {}", *self as i32, self.message())]
9pub enum AssetCode {
10 InsufficientBalance = 140001,
12
13 InvalidCoin = 140002,
15
16 InvalidAmount = 140003,
18
19 TransferFailed = 140004,
21
22 WithdrawalFailed = 140005,
24
25 DepositFailed = 140006,
27
28 CoinNotExist = 140007,
30
31 InvalidWithdrawalAddress = 140008,
33
34 WithdrawalDisabled = 140009,
36
37 DepositDisabled = 140010,
39
40 TransferDisabled = 140011,
42
43 WithdrawalAmountTooSmall = 140012,
45
46 WithdrawalAmountTooLarge = 140013,
48
49 WithdrawalFeeTooHigh = 140014,
51
52 WithdrawalAddressNotWhitelisted = 140015,
54
55 WithdrawalAddressNotSupported = 140016,
57
58 InternalTransferNotAllowed = 140017,
60
61 WithdrawalNotAllowed = 140018,
63
64 DepositNotAllowed = 140019,
66
67 SubAccountTransferDisabled = 140020,
69
70 MasterAccountTransferDisabled = 140021,
72
73 InvalidChainType = 140022,
75
76 WithdrawalAddressWrongChain = 140023,
78
79 WithdrawalNotSupported = 140024,
81
82 DepositNotSupported = 140025,
84
85 TransferAmountTooSmall = 140026,
87
88 TransferAmountTooLarge = 140027,
90}
91
92impl AssetCode {
93 pub fn from_code<T>(code: T) -> Option<Self>
96 where
97 T: Into<i32> + Copy,
98 {
99 let code = code.into();
100 match code {
101 140001 => Some(Self::InsufficientBalance),
102 140002 => Some(Self::InvalidCoin),
103 140003 => Some(Self::InvalidAmount),
104 140004 => Some(Self::TransferFailed),
105 140005 => Some(Self::WithdrawalFailed),
106 140006 => Some(Self::DepositFailed),
107 140007 => Some(Self::CoinNotExist),
108 140008 => Some(Self::InvalidWithdrawalAddress),
109 140009 => Some(Self::WithdrawalDisabled),
110 140010 => Some(Self::DepositDisabled),
111 140011 => Some(Self::TransferDisabled),
112 140012 => Some(Self::WithdrawalAmountTooSmall),
113 140013 => Some(Self::WithdrawalAmountTooLarge),
114 140014 => Some(Self::WithdrawalFeeTooHigh),
115 140015 => Some(Self::WithdrawalAddressNotWhitelisted),
116 140016 => Some(Self::WithdrawalAddressNotSupported),
117 140017 => Some(Self::InternalTransferNotAllowed),
118 140018 => Some(Self::WithdrawalNotAllowed),
119 140019 => Some(Self::DepositNotAllowed),
120 140020 => Some(Self::SubAccountTransferDisabled),
121 140021 => Some(Self::MasterAccountTransferDisabled),
122 140022 => Some(Self::InvalidChainType),
123 140023 => Some(Self::WithdrawalAddressWrongChain),
124 140024 => Some(Self::WithdrawalNotSupported),
125 140025 => Some(Self::DepositNotSupported),
126 140026 => Some(Self::TransferAmountTooSmall),
127 140027 => Some(Self::TransferAmountTooLarge),
128 _ => None,
129 }
130 }
131
132 pub fn message(&self) -> &'static str {
134 match self {
135 Self::InsufficientBalance => "Insufficient balance in account.",
136 Self::InvalidCoin => "Invalid coin.",
137 Self::InvalidAmount => "Invalid amount.",
138 Self::TransferFailed => "Transfer failed.",
139 Self::WithdrawalFailed => "Withdrawal failed.",
140 Self::DepositFailed => "Deposit failed.",
141 Self::CoinNotExist => "Coin does not exist.",
142 Self::InvalidWithdrawalAddress => "Withdrawal address is invalid.",
143 Self::WithdrawalDisabled => "Withdrawal is disabled.",
144 Self::DepositDisabled => "Deposit is disabled.",
145 Self::TransferDisabled => "Transfer is disabled.",
146 Self::WithdrawalAmountTooSmall => "Withdrawal amount is too small.",
147 Self::WithdrawalAmountTooLarge => "Withdrawal amount is too large.",
148 Self::WithdrawalFeeTooHigh => "Withdrawal fee is too high.",
149 Self::WithdrawalAddressNotWhitelisted => "Withdrawal address is not in whitelist.",
150 Self::WithdrawalAddressNotSupported => "Withdrawal address is not supported.",
151 Self::InternalTransferNotAllowed => "Internal transfer is not allowed for this coin.",
152 Self::WithdrawalNotAllowed => "Withdrawal is not allowed for this account.",
153 Self::DepositNotAllowed => "Deposit is not allowed for this account.",
154 Self::SubAccountTransferDisabled => "Sub-account transfer is disabled.",
155 Self::MasterAccountTransferDisabled => "Master account transfer is disabled.",
156 Self::InvalidChainType => "Invalid chain type.",
157 Self::WithdrawalAddressWrongChain => "Withdrawal address is not on the selected chain.",
158 Self::WithdrawalNotSupported => "Withdrawal is not supported for this coin.",
159 Self::DepositNotSupported => "Deposit is not supported for this coin.",
160 Self::TransferAmountTooSmall => "Transfer amount is too small.",
161 Self::TransferAmountTooLarge => "Transfer amount is too large.",
162 }
163 }
164}
165
166#[cfg(test)]
167mod tests {
168 use super::*;
169 type Sut = AssetCode;
170 #[test]
171 fn test_from_code_i32() {
172 assert_eq!(Sut::from_code(140001), Some(Sut::InsufficientBalance));
173 assert_eq!(Sut::from_code(140027), Some(Sut::TransferAmountTooLarge));
174 assert_eq!(Sut::from_code(99999), None);
175 }
176
177 #[test]
178 fn test_display() {
179 let error = Sut::InsufficientBalance;
180 assert_eq!(
181 error.to_string(),
182 "140001 - Insufficient balance in account."
183 );
184 let error = Sut::TransferAmountTooLarge;
185 assert_eq!(error.to_string(), "140027 - Transfer amount is too large.");
186 }
187}