1use crate::{impl_json_debug_pretty, impl_json_display};
8use serde::{Deserialize, Serialize};
9
10#[derive(Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
15#[serde(from = "i32", into = "i32")]
16pub enum DeribitErrorCode {
17 Success,
19 AuthorizationRequired,
21 Error,
23 QtyTooLow,
25 OrderOverlap,
27 OrderNotFound,
29 PriceTooLow,
31 PriceTooLow4Idx,
33 PriceTooHigh,
35 NotEnoughFunds,
37 AlreadyClosed,
39 PriceNotAllowed,
41 BookClosed,
43 PmeMaxTotalOpenOrders,
45 PmeMaxFutureOpenOrders,
47 PmeMaxOptionOpenOrders,
49 PmeMaxFutureOpenOrdersSize,
51 PmeMaxOptionOpenOrdersSize,
53 NonPmeMaxFuturePositionSize,
55 LockedByAdmin,
57 InvalidOrUnsupportedInstrument,
59 InvalidAmount,
61 InvalidQuantity,
63 InvalidPrice,
65 InvalidMaxShow,
67 InvalidOrderId,
69 PricePrecisionExceeded,
71 NonIntegerContractAmount,
73 TooManyRequests,
75 NotOwnerOfOrder,
77 MustBeWebsocketRequest,
79 InvalidArgsForInstrument,
81 WholeCostTooLow,
83 NotImplemented,
85 TriggerPriceTooHigh,
87 TriggerPriceTooLow,
89 InvalidMaxShowAmount,
91 NonPmeTotalShortOptionsPositionsSize,
93 PmeMaxRiskReducingOrders,
95 NotEnoughFundsInCurrency,
97 Retry,
99 SettlementInProgress,
101 PriceWrongTick,
103 TriggerPriceWrongTick,
105 CanNotCancelLiquidationOrder,
107 CanNotEditLiquidationOrder,
109 MatchingEngineQueueFull,
111 NotOnThisServer,
113 CancelOnDisconnectFailed,
115 TooManyConcurrentRequests,
117 DisabledWhilePositionLock,
119 AlreadyFilled,
121 MaxSpotOpenOrders,
123 PostOnlyPriceModificationNotPossible,
125 MaxSpotOrderQuantity,
127 InvalidArguments,
129 OtherReject,
131 OtherError,
133 NoMoreTriggers,
135 InvalidTriggerPrice,
137 OutdatedInstrumentForIvOrder,
139 NoAdvForFutures,
141 NoAdvPostonly,
143 NotAdvOrder,
145 PermissionDenied,
147 BadArgument,
149 NotOpenOrder,
151 InvalidEvent,
153 OutdatedInstrument,
155 UnsupportedArgCombination,
157 WrongMaxShowForOption,
159 BadArguments,
161 BadRequest,
163 SystemMaintenance,
165 SubscribeErrorUnsubscribed,
167 TransferNotFound,
169 PostOnlyReject,
171 PostOnlyNotAllowed,
173 UnauthenticatedPublicRequestsTemporarilyDisabled,
175 InvalidAddr,
177 InvalidTransferAddress,
179 AddressAlreadyExist,
181 MaxAddrCountExceeded,
183 InternalServerError,
185 DisabledDepositAddressCreation,
187 AddressBelongsToUser,
189 NoDepositAddress,
191 AccountLocked,
193 TooManySubaccounts,
195 WrongSubaccountName,
197 LoginOverLimit,
199 RegistrationOverLimit,
201 CountryIsBanned,
203 TransferNotAllowed,
205 SecurityKeyAuthorizationOverLimit,
207 InvalidCredentials,
209 PwdMatchError,
211 SecurityError,
213 UserNotFound,
215 RequestFailed,
217 Unauthorized,
219 ValueRequired,
221 ValueTooShort,
223 UnavailableInSubaccount,
225 InvalidPhoneNumber,
227 CannotSendSms,
229 InvalidSmsCode,
231 InvalidInput,
233 InvalidContentType,
235 OrderbookClosed,
237 NotFound,
239 Forbidden,
241 MethodSwitchedOffByAdmin,
243 TemporarilyUnavailable,
245 MmpTrigger,
247 VerificationRequired,
249 NonUniqueOrderLabel,
251 NoMoreSecurityKeysAllowed,
253 ActiveComboLimitReached,
255 UnavailableForComboBooks,
257 IncompleteKycData,
259 MmpRequired,
261 CodNotEnabled,
263 QuotesFrozen,
265 ScopeExceeded,
267 Unavailable,
269 RequestCancelledByUser,
271 Replaced,
273 RawSubscriptionsNotAvailableForUnauthorized,
275 MovePositionsOverLimit,
277 CouponAlreadyUsed,
279 KycTransferAlreadyInitiated,
281 Unknown(i32),
283}
284
285impl DeribitErrorCode {
286 pub fn code(&self) -> i32 {
288 self.clone().into()
289 }
290
291 pub fn message(&self) -> &'static str {
293 match self {
294 Self::Success => "success",
295 Self::AuthorizationRequired => "authorization_required",
296 Self::Error => "error",
297 Self::QtyTooLow => "qty_too_low",
298 Self::OrderOverlap => "order_overlap",
299 Self::OrderNotFound => "order_not_found",
300 Self::PriceTooLow => "price_too_low",
301 Self::PriceTooLow4Idx => "price_too_low4idx",
302 Self::PriceTooHigh => "price_too_high",
303 Self::NotEnoughFunds => "not_enough_funds",
304 Self::AlreadyClosed => "already_closed",
305 Self::PriceNotAllowed => "price_not_allowed",
306 Self::BookClosed => "book_closed",
307 Self::PmeMaxTotalOpenOrders => "pme_max_total_open_orders",
308 Self::PmeMaxFutureOpenOrders => "pme_max_future_open_orders",
309 Self::PmeMaxOptionOpenOrders => "pme_max_option_open_orders",
310 Self::PmeMaxFutureOpenOrdersSize => "pme_max_future_open_orders_size",
311 Self::PmeMaxOptionOpenOrdersSize => "pme_max_option_open_orders_size",
312 Self::NonPmeMaxFuturePositionSize => "non_pme_max_future_position_size",
313 Self::LockedByAdmin => "locked_by_admin",
314 Self::InvalidOrUnsupportedInstrument => "invalid_or_unsupported_instrument",
315 Self::InvalidAmount => "invalid_amount",
316 Self::InvalidQuantity => "invalid_quantity",
317 Self::InvalidPrice => "invalid_price",
318 Self::InvalidMaxShow => "invalid_max_show",
319 Self::InvalidOrderId => "invalid_order_id",
320 Self::PricePrecisionExceeded => "price_precision_exceeded",
321 Self::NonIntegerContractAmount => "non_integer_contract_amount",
322 Self::TooManyRequests => "too_many_requests",
323 Self::NotOwnerOfOrder => "not_owner_of_order",
324 Self::MustBeWebsocketRequest => "must_be_websocket_request",
325 Self::InvalidArgsForInstrument => "invalid_args_for_instrument",
326 Self::WholeCostTooLow => "whole_cost_too_low",
327 Self::NotImplemented => "not_implemented",
328 Self::TriggerPriceTooHigh => "trigger_price_too_high",
329 Self::TriggerPriceTooLow => "trigger_price_too_low",
330 Self::InvalidMaxShowAmount => "invalid_max_show_amount",
331 Self::NonPmeTotalShortOptionsPositionsSize => {
332 "non_pme_total_short_options_positions_size"
333 }
334 Self::PmeMaxRiskReducingOrders => "pme_max_risk_reducing_orders",
335 Self::NotEnoughFundsInCurrency => "not_enough_funds_in_currency",
336 Self::Retry => "retry",
337 Self::SettlementInProgress => "settlement_in_progress",
338 Self::PriceWrongTick => "price_wrong_tick",
339 Self::TriggerPriceWrongTick => "trigger_price_wrong_tick",
340 Self::CanNotCancelLiquidationOrder => "can_not_cancel_liquidation_order",
341 Self::CanNotEditLiquidationOrder => "can_not_edit_liquidation_order",
342 Self::MatchingEngineQueueFull => "matching_engine_queue_full",
343 Self::NotOnThisServer => "not_on_this_server",
344 Self::CancelOnDisconnectFailed => "cancel_on_disconnect_failed",
345 Self::TooManyConcurrentRequests => "too_many_concurrent_requests",
346 Self::DisabledWhilePositionLock => "disabled_while_position_lock",
347 Self::AlreadyFilled => "already_filled",
348 Self::MaxSpotOpenOrders => "max_spot_open_orders",
349 Self::PostOnlyPriceModificationNotPossible => {
350 "post_only_price_modification_not_possible"
351 }
352 Self::MaxSpotOrderQuantity => "max_spot_order_quantity",
353 Self::InvalidArguments => "invalid_arguments",
354 Self::OtherReject => "other_reject",
355 Self::OtherError => "other_error",
356 Self::NoMoreTriggers => "no_more_triggers",
357 Self::InvalidTriggerPrice => "invalid_trigger_price",
358 Self::OutdatedInstrumentForIvOrder => "outdated_instrument_for_IV_order",
359 Self::NoAdvForFutures => "no_adv_for_futures",
360 Self::NoAdvPostonly => "no_adv_postonly",
361 Self::NotAdvOrder => "not_adv_order",
362 Self::PermissionDenied => "permission_denied",
363 Self::BadArgument => "bad_argument",
364 Self::NotOpenOrder => "not_open_order",
365 Self::InvalidEvent => "invalid_event",
366 Self::OutdatedInstrument => "outdated_instrument",
367 Self::UnsupportedArgCombination => "unsupported_arg_combination",
368 Self::WrongMaxShowForOption => "wrong_max_show_for_option",
369 Self::BadArguments => "bad_arguments",
370 Self::BadRequest => "bad_request",
371 Self::SystemMaintenance => "system_maintenance",
372 Self::SubscribeErrorUnsubscribed => "subscribe_error_unsubscribed",
373 Self::TransferNotFound => "transfer_not_found",
374 Self::PostOnlyReject => "post_only_reject",
375 Self::PostOnlyNotAllowed => "post_only_not_allowed",
376 Self::UnauthenticatedPublicRequestsTemporarilyDisabled => {
377 "unauthenticated_public_requests_temporarily_disabled"
378 }
379 Self::InvalidAddr => "invalid_addr",
380 Self::InvalidTransferAddress => "invalid_transfer_address",
381 Self::AddressAlreadyExist => "address_already_exist",
382 Self::MaxAddrCountExceeded => "max_addr_count_exceeded",
383 Self::InternalServerError => "internal_server_error",
384 Self::DisabledDepositAddressCreation => "disabled_deposit_address_creation",
385 Self::AddressBelongsToUser => "address_belongs_to_user",
386 Self::NoDepositAddress => "no_deposit_address",
387 Self::AccountLocked => "account_locked",
388 Self::TooManySubaccounts => "too_many_subaccounts",
389 Self::WrongSubaccountName => "wrong_subaccount_name",
390 Self::LoginOverLimit => "login_over_limit",
391 Self::RegistrationOverLimit => "registration_over_limit",
392 Self::CountryIsBanned => "country_is_banned",
393 Self::TransferNotAllowed => "transfer_not_allowed",
394 Self::SecurityKeyAuthorizationOverLimit => "security_key_authorization_over_limit",
395 Self::InvalidCredentials => "invalid_credentials",
396 Self::PwdMatchError => "pwd_match_error",
397 Self::SecurityError => "security_error",
398 Self::UserNotFound => "user_not_found",
399 Self::RequestFailed => "request_failed",
400 Self::Unauthorized => "unauthorized",
401 Self::ValueRequired => "value_required",
402 Self::ValueTooShort => "value_too_short",
403 Self::UnavailableInSubaccount => "unavailable_in_subaccount",
404 Self::InvalidPhoneNumber => "invalid_phone_number",
405 Self::CannotSendSms => "cannot_send_sms",
406 Self::InvalidSmsCode => "invalid_sms_code",
407 Self::InvalidInput => "invalid_input",
408 Self::InvalidContentType => "invalid_content_type",
409 Self::OrderbookClosed => "orderbook_closed",
410 Self::NotFound => "not_found",
411 Self::Forbidden => "forbidden",
412 Self::MethodSwitchedOffByAdmin => "method_switched_off_by_admin",
413 Self::TemporarilyUnavailable => "temporarily_unavailable",
414 Self::MmpTrigger => "mmp_trigger",
415 Self::VerificationRequired => "verification_required",
416 Self::NonUniqueOrderLabel => "non_unique_order_label",
417 Self::NoMoreSecurityKeysAllowed => "no_more_security_keys_allowed",
418 Self::ActiveComboLimitReached => "active_combo_limit_reached",
419 Self::UnavailableForComboBooks => "unavailable_for_combo_books",
420 Self::IncompleteKycData => "incomplete_KYC_data",
421 Self::MmpRequired => "mmp_required",
422 Self::CodNotEnabled => "cod_not_enabled",
423 Self::QuotesFrozen => "quotes_frozen",
424 Self::ScopeExceeded => "scope_exceeded",
425 Self::Unavailable => "unavailable",
426 Self::RequestCancelledByUser => "request_cancelled_by_user",
427 Self::Replaced => "replaced",
428 Self::RawSubscriptionsNotAvailableForUnauthorized => {
429 "raw_subscriptions_not_available_for_unauthorized"
430 }
431 Self::MovePositionsOverLimit => "move_positions_over_limit",
432 Self::CouponAlreadyUsed => "coupon_already_used",
433 Self::KycTransferAlreadyInitiated => "KYC_transfer_already_initiated",
434 Self::Unknown(_) => "unknown_error",
435 }
436 }
437
438 pub fn is_success(&self) -> bool {
440 matches!(self, Self::Success)
441 }
442
443 pub fn is_authorization_error(&self) -> bool {
445 matches!(self, Self::AuthorizationRequired | Self::Unauthorized)
446 }
447
448 pub fn is_rate_limit_error(&self) -> bool {
450 matches!(
451 self,
452 Self::TooManyRequests | Self::TooManyConcurrentRequests
453 )
454 }
455
456 pub fn is_validation_error(&self) -> bool {
458 matches!(
459 self,
460 Self::InvalidAmount
461 | Self::InvalidPrice
462 | Self::InvalidQuantity
463 | Self::InvalidOrderId
464 | Self::InvalidArguments
465 | Self::BadArgument
466 | Self::BadArguments
467 | Self::InvalidInput
468 )
469 }
470
471 pub fn is_trading_error(&self) -> bool {
473 matches!(
474 self,
475 Self::QtyTooLow
476 | Self::OrderOverlap
477 | Self::OrderNotFound
478 | Self::PriceTooLow
479 | Self::PriceTooHigh
480 | Self::NotEnoughFunds
481 | Self::AlreadyClosed
482 | Self::PriceNotAllowed
483 | Self::BookClosed
484 )
485 }
486}
487
488impl std::error::Error for DeribitErrorCode {}
490
491impl_json_display!(DeribitErrorCode);
493impl_json_debug_pretty!(DeribitErrorCode);
494
495impl From<DeribitErrorCode> for i32 {
497 fn from(error: DeribitErrorCode) -> Self {
498 match error {
499 DeribitErrorCode::Success => 0,
500 DeribitErrorCode::AuthorizationRequired => 10000,
501 DeribitErrorCode::Error => 10001,
502 DeribitErrorCode::QtyTooLow => 10002,
503 DeribitErrorCode::OrderOverlap => 10003,
504 DeribitErrorCode::OrderNotFound => 10004,
505 DeribitErrorCode::PriceTooLow => 10005,
506 DeribitErrorCode::PriceTooLow4Idx => 10006,
507 DeribitErrorCode::PriceTooHigh => 10007,
508 DeribitErrorCode::NotEnoughFunds => 10009,
509 DeribitErrorCode::AlreadyClosed => 10010,
510 DeribitErrorCode::PriceNotAllowed => 10011,
511 DeribitErrorCode::BookClosed => 10012,
512 DeribitErrorCode::PmeMaxTotalOpenOrders => 10013,
513 DeribitErrorCode::PmeMaxFutureOpenOrders => 10014,
514 DeribitErrorCode::PmeMaxOptionOpenOrders => 10015,
515 DeribitErrorCode::PmeMaxFutureOpenOrdersSize => 10016,
516 DeribitErrorCode::PmeMaxOptionOpenOrdersSize => 10017,
517 DeribitErrorCode::NonPmeMaxFuturePositionSize => 10018,
518 DeribitErrorCode::LockedByAdmin => 10019,
519 DeribitErrorCode::InvalidOrUnsupportedInstrument => 10020,
520 DeribitErrorCode::InvalidAmount => 10021,
521 DeribitErrorCode::InvalidQuantity => 10022,
522 DeribitErrorCode::InvalidPrice => 10023,
523 DeribitErrorCode::InvalidMaxShow => 10024,
524 DeribitErrorCode::InvalidOrderId => 10025,
525 DeribitErrorCode::PricePrecisionExceeded => 10026,
526 DeribitErrorCode::NonIntegerContractAmount => 10027,
527 DeribitErrorCode::TooManyRequests => 10028,
528 DeribitErrorCode::NotOwnerOfOrder => 10029,
529 DeribitErrorCode::MustBeWebsocketRequest => 10030,
530 DeribitErrorCode::InvalidArgsForInstrument => 10031,
531 DeribitErrorCode::WholeCostTooLow => 10032,
532 DeribitErrorCode::NotImplemented => 10033,
533 DeribitErrorCode::TriggerPriceTooHigh => 10034,
534 DeribitErrorCode::TriggerPriceTooLow => 10035,
535 DeribitErrorCode::InvalidMaxShowAmount => 10036,
536 DeribitErrorCode::NonPmeTotalShortOptionsPositionsSize => 10037,
537 DeribitErrorCode::PmeMaxRiskReducingOrders => 10038,
538 DeribitErrorCode::NotEnoughFundsInCurrency => 10039,
539 DeribitErrorCode::Retry => 10040,
540 DeribitErrorCode::SettlementInProgress => 10041,
541 DeribitErrorCode::PriceWrongTick => 10043,
542 DeribitErrorCode::TriggerPriceWrongTick => 10044,
543 DeribitErrorCode::CanNotCancelLiquidationOrder => 10045,
544 DeribitErrorCode::CanNotEditLiquidationOrder => 10046,
545 DeribitErrorCode::MatchingEngineQueueFull => 10047,
546 DeribitErrorCode::NotOnThisServer => 10048,
547 DeribitErrorCode::CancelOnDisconnectFailed => 10049,
548 DeribitErrorCode::TooManyConcurrentRequests => 10066,
549 DeribitErrorCode::DisabledWhilePositionLock => 10072,
550 DeribitErrorCode::AlreadyFilled => 11008,
551 DeribitErrorCode::MaxSpotOpenOrders => 11013,
552 DeribitErrorCode::PostOnlyPriceModificationNotPossible => 11021,
553 DeribitErrorCode::MaxSpotOrderQuantity => 11022,
554 DeribitErrorCode::InvalidArguments => 11029,
555 DeribitErrorCode::OtherReject => 11030,
556 DeribitErrorCode::OtherError => 11031,
557 DeribitErrorCode::NoMoreTriggers => 11035,
558 DeribitErrorCode::InvalidTriggerPrice => 11036,
559 DeribitErrorCode::OutdatedInstrumentForIvOrder => 11037,
560 DeribitErrorCode::NoAdvForFutures => 11038,
561 DeribitErrorCode::NoAdvPostonly => 11039,
562 DeribitErrorCode::NotAdvOrder => 11041,
563 DeribitErrorCode::PermissionDenied => 11042,
564 DeribitErrorCode::BadArgument => 11043,
565 DeribitErrorCode::NotOpenOrder => 11044,
566 DeribitErrorCode::InvalidEvent => 11045,
567 DeribitErrorCode::OutdatedInstrument => 11046,
568 DeribitErrorCode::UnsupportedArgCombination => 11047,
569 DeribitErrorCode::WrongMaxShowForOption => 11048,
570 DeribitErrorCode::BadArguments => 11049,
571 DeribitErrorCode::BadRequest => 11050,
572 DeribitErrorCode::SystemMaintenance => 11051,
573 DeribitErrorCode::SubscribeErrorUnsubscribed => 11052,
574 DeribitErrorCode::TransferNotFound => 11053,
575 DeribitErrorCode::PostOnlyReject => 11054,
576 DeribitErrorCode::PostOnlyNotAllowed => 11055,
577 DeribitErrorCode::UnauthenticatedPublicRequestsTemporarilyDisabled => 11056,
578 DeribitErrorCode::InvalidAddr => 11090,
579 DeribitErrorCode::InvalidTransferAddress => 11091,
580 DeribitErrorCode::AddressAlreadyExist => 11092,
581 DeribitErrorCode::MaxAddrCountExceeded => 11093,
582 DeribitErrorCode::InternalServerError => 11094,
583 DeribitErrorCode::DisabledDepositAddressCreation => 11095,
584 DeribitErrorCode::AddressBelongsToUser => 11096,
585 DeribitErrorCode::NoDepositAddress => 11097,
586 DeribitErrorCode::AccountLocked => 11098,
587 DeribitErrorCode::TooManySubaccounts => 12001,
588 DeribitErrorCode::WrongSubaccountName => 12002,
589 DeribitErrorCode::LoginOverLimit => 12003,
590 DeribitErrorCode::RegistrationOverLimit => 12004,
591 DeribitErrorCode::CountryIsBanned => 12005,
592 DeribitErrorCode::TransferNotAllowed => 12100,
593 DeribitErrorCode::SecurityKeyAuthorizationOverLimit => 12998,
594 DeribitErrorCode::InvalidCredentials => 13004,
595 DeribitErrorCode::PwdMatchError => 13005,
596 DeribitErrorCode::SecurityError => 13006,
597 DeribitErrorCode::UserNotFound => 13007,
598 DeribitErrorCode::RequestFailed => 13008,
599 DeribitErrorCode::Unauthorized => 13009,
600 DeribitErrorCode::ValueRequired => 13010,
601 DeribitErrorCode::ValueTooShort => 13011,
602 DeribitErrorCode::UnavailableInSubaccount => 13012,
603 DeribitErrorCode::InvalidPhoneNumber => 13013,
604 DeribitErrorCode::CannotSendSms => 13014,
605 DeribitErrorCode::InvalidSmsCode => 13015,
606 DeribitErrorCode::InvalidInput => 13016,
607 DeribitErrorCode::InvalidContentType => 13018,
608 DeribitErrorCode::OrderbookClosed => 13019,
609 DeribitErrorCode::NotFound => 13020,
610 DeribitErrorCode::Forbidden => 13021,
611 DeribitErrorCode::MethodSwitchedOffByAdmin => 13025,
612 DeribitErrorCode::TemporarilyUnavailable => 13028,
613 DeribitErrorCode::MmpTrigger => 13030,
614 DeribitErrorCode::VerificationRequired => 13031,
615 DeribitErrorCode::NonUniqueOrderLabel => 13032,
616 DeribitErrorCode::NoMoreSecurityKeysAllowed => 13034,
617 DeribitErrorCode::ActiveComboLimitReached => 13035,
618 DeribitErrorCode::UnavailableForComboBooks => 13036,
619 DeribitErrorCode::IncompleteKycData => 13037,
620 DeribitErrorCode::MmpRequired => 13040,
621 DeribitErrorCode::CodNotEnabled => 13042,
622 DeribitErrorCode::QuotesFrozen => 13043,
623 DeribitErrorCode::ScopeExceeded => 13403,
624 DeribitErrorCode::Unavailable => 13503,
625 DeribitErrorCode::RequestCancelledByUser => 13666,
626 DeribitErrorCode::Replaced => 13777,
627 DeribitErrorCode::RawSubscriptionsNotAvailableForUnauthorized => 13778,
628 DeribitErrorCode::MovePositionsOverLimit => 13780,
629 DeribitErrorCode::CouponAlreadyUsed => 13781,
630 DeribitErrorCode::KycTransferAlreadyInitiated => 13791,
631 DeribitErrorCode::Unknown(code) => code,
632 }
633 }
634}
635
636#[cfg(test)]
637mod tests {
638 use super::*;
639
640 #[test]
641 fn test_error_code_conversion() {
642 let error = DeribitErrorCode::from(10000);
643 assert_eq!(error, DeribitErrorCode::AuthorizationRequired);
644 assert_eq!(error.code(), 10000);
645 assert_eq!(error.message(), "authorization_required");
646 }
647
648 #[test]
649 fn test_unknown_error_code() {
650 let error = DeribitErrorCode::from(99999);
651 assert_eq!(error, DeribitErrorCode::Unknown(99999));
652 assert_eq!(error.code(), 99999);
653 assert_eq!(error.message(), "unknown_error");
654 }
655
656 #[test]
657 fn test_success_code() {
658 let error = DeribitErrorCode::from(0);
659 assert_eq!(error, DeribitErrorCode::Success);
660 assert!(error.is_success());
661 assert!(!error.is_authorization_error());
662 }
663
664 #[test]
665 fn test_error_categorization() {
666 let auth_error = DeribitErrorCode::AuthorizationRequired;
667 assert!(auth_error.is_authorization_error());
668 assert!(!auth_error.is_trading_error());
669
670 let trading_error = DeribitErrorCode::QtyTooLow;
671 assert!(trading_error.is_trading_error());
672 assert!(!trading_error.is_authorization_error());
673
674 let rate_limit_error = DeribitErrorCode::TooManyRequests;
675 assert!(rate_limit_error.is_rate_limit_error());
676 assert!(!rate_limit_error.is_validation_error());
677
678 let validation_error = DeribitErrorCode::InvalidAmount;
679 assert!(validation_error.is_validation_error());
680 assert!(!validation_error.is_rate_limit_error());
681 }
682
683 #[test]
684 fn test_serde_serialization() {
685 let error = DeribitErrorCode::AuthorizationRequired;
686 let json = serde_json::to_string(&error).unwrap();
687 assert_eq!(json, "10000");
688
689 let deserialized: DeribitErrorCode = serde_json::from_str(&json).unwrap();
690 assert_eq!(deserialized, error);
691 }
692
693 #[test]
694 fn test_specific_error_codes() {
695 assert_eq!(DeribitErrorCode::from(0), DeribitErrorCode::Success);
697 assert_eq!(DeribitErrorCode::from(10001), DeribitErrorCode::Error);
698 assert_eq!(DeribitErrorCode::from(10002), DeribitErrorCode::QtyTooLow);
699 assert_eq!(
700 DeribitErrorCode::from(13009),
701 DeribitErrorCode::Unauthorized
702 );
703 assert_eq!(DeribitErrorCode::from(13020), DeribitErrorCode::NotFound);
704
705 assert_eq!(DeribitErrorCode::Success.code(), 0);
707 assert_eq!(DeribitErrorCode::AuthorizationRequired.code(), 10000);
708 assert_eq!(DeribitErrorCode::TooManyRequests.code(), 10028);
709 }
710}