deribit_http/model/
user_lock.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9pub struct UserLock {
10 #[serde(rename = "type")]
12 pub lock_type: String,
13 #[serde(skip_serializing_if = "Option::is_none")]
15 pub currency: Option<String>,
16 #[serde(skip_serializing_if = "Option::is_none")]
18 pub reason: Option<String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
21 pub timestamp: Option<u64>,
22 #[serde(skip_serializing_if = "Option::is_none")]
24 pub expiration_timestamp: Option<u64>,
25 #[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}