Skip to main content

deribit_http/model/
custody.rs

1//! Custody account models for Deribit API
2//!
3//! This module contains types for custody accounts.
4
5use serde::{Deserialize, Serialize};
6
7/// Custody account information
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9pub struct CustodyAccount {
10    /// Custody account ID
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub id: Option<String>,
13    /// Currency of the custody account
14    pub currency: String,
15    /// Current balance
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub balance: Option<f64>,
18    /// Custody provider name
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub provider: Option<String>,
21    /// Account status
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub status: Option<String>,
24    /// Account creation timestamp in milliseconds
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub creation_timestamp: Option<u64>,
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32
33    #[test]
34    fn test_custody_account_deserialization() {
35        let json = r#"{
36            "id": "custody_123",
37            "currency": "BTC",
38            "balance": 1.5,
39            "provider": "fireblocks",
40            "status": "active"
41        }"#;
42
43        let account: CustodyAccount = serde_json::from_str(json).expect("Failed to parse");
44        assert_eq!(account.currency, "BTC");
45        assert_eq!(account.balance, Some(1.5));
46        assert_eq!(account.provider, Some("fireblocks".to_string()));
47    }
48
49    #[test]
50    fn test_custody_account_minimal() {
51        let json = r#"{
52            "currency": "ETH"
53        }"#;
54
55        let account: CustodyAccount = serde_json::from_str(json).expect("Failed to parse");
56        assert_eq!(account.currency, "ETH");
57        assert!(account.id.is_none());
58    }
59}