deribit_http/model/
transaction.rs

1/******************************************************************************
2   Author: Joaquín Béjar García
3   Email: jb@taunais.com
4   Date: 15/9/25
5******************************************************************************/
6use pretty_simple_display::{DebugPretty, DisplaySimple};
7use serde::{Deserialize, Serialize};
8use serde_with::skip_serializing_none;
9
10/// Transaction type enumeration
11#[derive(Debug, Clone, Serialize, Deserialize, Default)]
12pub enum TransactionType {
13    /// Deposit transaction
14    Deposit,
15    /// Withdrawal transaction
16    Withdrawal,
17    /// Trade transaction (default)
18    #[default]
19    Trade,
20    /// Transfer transaction
21    Transfer,
22    /// Fee transaction
23    Fee,
24    /// Funding transaction
25    Funding,
26    /// Bonus transaction
27    Bonus,
28    /// Dividend transaction
29    Dividend,
30    /// Liquidation transaction
31    Liquidation,
32    /// Insurance transaction
33    Insurance,
34}
35
36/// Generic transaction log entry
37#[skip_serializing_none]
38#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
39pub struct TransactionLogEntry {
40    /// Unique identifier
41    pub id: u64,
42    /// Currency, i.e "BTC", "ETH", "USDC"
43    pub currency: String,
44    /// It represents the requested order size. For perpetual and inverse futures the amount is in USD units.
45    /// For options and linear futures it is the underlying base currency coin.
46    pub amount: Option<f64>,
47    /// Cash balance after the transaction
48    pub balance: f64,
49    /// The timestamp (milliseconds since the Unix epoch)
50    pub timestamp: u64,
51    /// Transaction category/type. Common types: trade, deposit, withdrawal, settlement, delivery, transfer, swap, correction
52    #[serde(rename = "type")]
53    pub transaction_type: String,
54    /// Additional information regarding transaction. Strongly dependent on the log entry type
55    pub info: Option<serde_json::Value>,
56    /// Change in cash balance. For trades: fees and options premium paid/received.
57    /// For settlement: Futures session PNL and perpetual session funding.
58    pub change: f64,
59    /// For futures and perpetual contracts: Realized session PNL (since last settlement).
60    /// For options: the amount paid or received for the options traded.
61    pub cashflow: f64,
62    /// Unique user identifier
63    pub user_id: u64,
64    /// Unique (per currency) trade identifier
65    pub trade_id: Option<String>,
66    /// Unique order identifier
67    pub order_id: Option<String>,
68    /// Updated position size after the transaction
69    pub position: Option<f64>,
70    /// One of: short or long in case of settlements, close sell or close buy in case of deliveries,
71    /// open sell, open buy, close sell, close buy in case of trades
72    pub side: Option<TransactionSide>,
73    /// It represents the order size in contract units. (Optional, may be absent in historical data).
74    pub contracts: Option<f64>,
75    /// Actual funding rate of trades and settlements on perpetual instruments
76    pub interest_pl: Option<f64>,
77    /// Trade role of the user: maker or taker
78    pub user_role: Option<UserRole>,
79    /// Fee role of the user: maker or taker. Can be different from trade role when iceberg order was involved.
80    pub fee_role: Option<String>,
81    /// The index price for the instrument during the delivery
82    pub index_price: Option<f64>,
83    /// Settlement/delivery price or the price level of the traded contracts
84    pub price: Option<f64>,
85    /// Sequential identifier of user transaction
86    pub user_seq: u64,
87    /// The settlement price for the instrument during the delivery
88    pub settlement_price: Option<f64>,
89    /// Currency symbol associated with the price field value
90    pub price_currency: Option<String>,
91    /// Updated equity value after the transaction
92    pub equity: f64,
93    /// Total session funding rate
94    pub total_interest_pl: Option<f64>,
95    /// Session unrealized profit and loss
96    pub session_upl: Option<f64>,
97    /// Indicator informing whether the cashflow is waiting for settlement or not
98    pub profit_as_cashflow: Option<bool>,
99    /// Commission paid so far (in base currency)
100    pub commission: Option<f64>,
101    /// Session realized profit and loss
102    pub session_rpl: Option<f64>,
103    /// Market price during the trade
104    pub mark_price: Option<f64>,
105    /// ID of the Block RFQ - when trade was part of the Block RFQ
106    pub block_rfq_id: Option<u64>,
107    /// The IP address from which the trade was initiated
108    pub ip: Option<String>,
109    /// System name or user defined subaccount alias
110    pub username: String,
111    /// Unique instrument identifier
112    pub instrument_name: Option<String>,
113}
114
115/// Transaction side enumeration indicating the direction or type of trade
116#[derive(Debug, Clone, Serialize, Deserialize)]
117pub enum TransactionSide {
118    /// Long position
119    #[serde(rename = "long")]
120    Long,
121    /// Short position
122    #[serde(rename = "short")]
123    Short,
124    /// Opening buy position
125    #[serde(rename = "open buy")]
126    OpenBuy,
127    /// Opening sell position
128    #[serde(rename = "open sell")]
129    OpenSell,
130    /// Closing buy position
131    #[serde(rename = "close buy")]
132    CloseBuy,
133    /// Closing sell position
134    #[serde(rename = "close sell")]
135    CloseSell,
136    /// No specific side
137    #[serde(rename = "-")]
138    None,
139}
140
141/// User role in a trade transaction
142#[derive(Debug, Clone, Serialize, Deserialize)]
143#[serde(rename_all = "lowercase")]
144pub enum UserRole {
145    /// User who provides liquidity (maker)
146    Maker,
147    /// User who takes liquidity (taker)
148    Taker,
149}
150
151/// Request parameters for retrieving transaction log entries
152#[skip_serializing_none]
153#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize, Default)]
154pub struct TransactionLogRequest {
155    /// Currency code (e.g., "BTC", "ETH", "USDC")
156    pub currency: String,
157    /// Start timestamp in milliseconds since Unix epoch
158    pub start_timestamp: u64,
159    /// End timestamp in milliseconds since Unix epoch
160    pub end_timestamp: u64,
161    /// Optional search query string
162    pub query: Option<String>,
163    /// Maximum number of entries to return
164    pub count: Option<u64>,
165    /// Optional subaccount identifier
166    pub subaccount_id: Option<u64>,
167    /// Continuation token for pagination
168    pub continuation: Option<u64>,
169}