deribit_base/model/
transaction.rs

1/****************************************************************************
2   Author: Joaquín Béjar García
3   Email: jb@taunais.com
4   Date: 21/7/25
5******************************************************************************/
6use pretty_simple_display::{DebugPretty, DisplaySimple};
7use serde::{Deserialize, Serialize};
8
9/// Transaction type enumeration
10#[derive(Debug, Clone, Serialize, Deserialize, Default)]
11pub enum TransactionType {
12    /// Deposit transaction
13    Deposit,
14    /// Withdrawal transaction
15    Withdrawal,
16    /// Trade transaction (default)
17    #[default]
18    Trade,
19    /// Transfer transaction
20    Transfer,
21    /// Fee transaction
22    Fee,
23    /// Funding transaction
24    Funding,
25    /// Bonus transaction
26    Bonus,
27    /// Dividend transaction
28    Dividend,
29    /// Liquidation transaction
30    Liquidation,
31    /// Insurance transaction
32    Insurance,
33}
34
35/// Generic transaction log entry
36#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
37pub struct TransactionLogEntry {
38    /// Unique transaction identifier
39    pub id: u64,
40    /// Currency of the transaction
41    pub currency: String,
42    /// Transaction amount
43    pub amount: f64,
44    /// Account balance after transaction
45    pub balance: f64,
46    /// Transaction timestamp
47    pub timestamp: u64,
48    /// Type of transaction
49    pub transaction_type: TransactionType,
50    /// Additional transaction information
51    pub info: Option<String>,
52}
53
54impl Default for TransactionLogEntry {
55    fn default() -> Self {
56        Self {
57            id: 0,
58            currency: String::new(),
59            amount: 0.0,
60            balance: 0.0,
61            timestamp: 0,
62            transaction_type: TransactionType::default(),
63            info: None,
64        }
65    }
66}
67
68/// Paginated transaction log response
69#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize, Default)]
70pub struct TransactionLog {
71    /// Continuation token for pagination
72    pub continuation: Option<String>,
73    /// List of transaction log entries
74    pub logs: Vec<TransactionLogEntry>,
75}
76
77/// Deposit information
78#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
79pub struct Deposit {
80    /// Deposit address
81    pub address: String,
82    /// Deposit amount
83    pub amount: f64,
84    /// Currency of the deposit
85    pub currency: String,
86    /// Current state of the deposit
87    pub state: String,
88    /// Timestamp when deposit was received
89    pub received_timestamp: u64,
90    /// Transaction ID on the blockchain
91    pub transaction_id: Option<String>,
92    /// Timestamp when deposit was last updated
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub updated_timestamp: Option<u64>,
95}
96
97/// Deposits response wrapper
98#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
99pub struct DepositsResponse {
100    /// Total count of deposits
101    pub count: u32,
102    /// List of deposit entries
103    pub data: Vec<Deposit>,
104}
105
106/// Withdrawal information
107#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
108pub struct Withdrawal {
109    /// Withdrawal address
110    pub address: String,
111    /// Withdrawal amount
112    pub amount: f64,
113    /// Currency of the withdrawal
114    pub currency: String,
115    /// Withdrawal fee
116    pub fee: f64,
117    /// Unique withdrawal identifier
118    pub id: u64,
119    /// Withdrawal priority level
120    pub priority: String,
121    /// Current state of the withdrawal
122    pub state: String,
123    /// Timestamp when withdrawal was created
124    pub created_timestamp: u64,
125    /// Timestamp when withdrawal was last updated
126    pub updated_timestamp: Option<u64>,
127    /// Transaction ID on the blockchain
128    pub transaction_id: Option<String>,
129}
130
131/// Withdrawals response wrapper
132#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
133pub struct WithdrawalsResponse {
134    /// Total count of withdrawals
135    pub count: u32,
136    /// List of withdrawal entries
137    pub data: Vec<Withdrawal>,
138}
139
140#[cfg(test)]
141mod tests {
142    use super::*;
143
144    #[test]
145    fn test_default_transaction_log_entry() {
146        let tx = TransactionLogEntry::default();
147        assert_eq!(tx.id, 0);
148        assert_eq!(tx.amount, 0.0);
149    }
150}