Skip to main content

deribit_http/model/
user_lock.rs

1//! User lock models for Deribit API
2//!
3//! This module contains types for user account locks.
4
5use serde::{Deserialize, Serialize};
6
7/// User account lock information
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9pub struct UserLock {
10    /// Type of lock (e.g., "withdrawal", "trading")
11    #[serde(rename = "type")]
12    pub lock_type: String,
13    /// Currency affected by the lock, if applicable
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub currency: Option<String>,
16    /// Reason for the lock
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub reason: Option<String>,
19    /// Timestamp when the lock was applied in milliseconds
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub timestamp: Option<u64>,
22    /// When the lock expires in milliseconds, if applicable
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub expiration_timestamp: Option<u64>,
25    /// Whether the lock is currently active
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub locked: Option<bool>,
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn test_user_lock_deserialization() {
36        let json = r#"{
37            "type": "withdrawal",
38            "currency": "BTC",
39            "reason": "security_review",
40            "timestamp": 1550058362000,
41            "locked": true
42        }"#;
43
44        let lock: UserLock = serde_json::from_str(json).expect("Failed to parse");
45        assert_eq!(lock.lock_type, "withdrawal");
46        assert_eq!(lock.currency, Some("BTC".to_string()));
47        assert_eq!(lock.locked, Some(true));
48    }
49
50    #[test]
51    fn test_user_lock_minimal() {
52        let json = r#"{
53            "type": "trading"
54        }"#;
55
56        let lock: UserLock = serde_json::from_str(json).expect("Failed to parse");
57        assert_eq!(lock.lock_type, "trading");
58        assert!(lock.currency.is_none());
59    }
60}