deribit_http/model/response/
other.rs

1/******************************************************************************
2   Author: Joaquín Béjar García
3   Email: jb@taunais.com
4   Date: 15/9/25
5******************************************************************************/
6use crate::prelude::*;
7use pretty_simple_display::{DebugPretty, DisplaySimple};
8use serde::{Deserialize, Serialize};
9use serde_with::skip_serializing_none;
10
11/// Trading limit structure
12#[skip_serializing_none]
13#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
14pub struct TradingLimit {
15    /// Total rate limit for trading operations
16    pub total: RateLimit,
17}
18
19/// Account limits structure
20#[skip_serializing_none]
21#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
22pub struct AccountLimits {
23    /// Whether limits are applied per currency
24    pub limits_per_currency: bool,
25    /// Rate limits for non-matching engine operations
26    pub non_matching_engine: RateLimit,
27    /// Rate limits for matching engine operations
28    pub matching_engine: MatchingEngineLimit,
29}
30
31/// Rate limit structure
32#[skip_serializing_none]
33#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
34pub struct RateLimit {
35    /// Maximum burst capacity for rate limiting
36    pub burst: u32,
37    /// Rate limit per time unit
38    pub rate: u32,
39}
40
41/// Matching engine limits
42#[skip_serializing_none]
43#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
44pub struct MatchingEngineLimit {
45    /// Trading limits configuration
46    pub trading: TradingLimit,
47    /// Spot trading rate limits
48    pub spot: RateLimit,
49    /// Quote request rate limits
50    pub quotes: RateLimit,
51    /// Maximum quotes rate limits
52    pub max_quotes: RateLimit,
53    /// Guaranteed quotes rate limits
54    pub guaranteed_quotes: RateLimit,
55    /// Cancel all orders rate limits
56    pub cancel_all: RateLimit,
57}
58
59/// Response type for user trades, containing a vector of user trade data
60pub type UserTradeResponse = Vec<UserTrade>;
61
62/// Response type for user trades with pagination info (used by instrument-specific endpoints)
63#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
64pub struct UserTradeWithPaginationResponse {
65    /// List of user trades
66    pub trades: Vec<UserTrade>,
67    /// Whether there are more trades available
68    pub has_more: bool,
69}
70
71/// Contract size response
72#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
73pub struct ContractSizeResponse {
74    /// Contract size value
75    pub contract_size: f64,
76}
77
78/// Test response for connectivity checks
79#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
80pub struct TestResponse {
81    /// Version information
82    pub version: String,
83}
84
85/// Status response
86#[skip_serializing_none]
87#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
88pub struct StatusResponse {
89    /// Whether the system is locked (optional)
90    pub locked: Option<bool>,
91    /// Status message (optional)
92    pub message: Option<String>,
93    /// List of locked indices (optional)
94    pub locked_indices: Option<Vec<String>>,
95    /// Additional fields that might be present in the API response
96    #[serde(flatten)]
97    pub additional_fields: std::collections::HashMap<String, serde_json::Value>,
98}
99
100/// APR history response
101#[skip_serializing_none]
102#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
103pub struct AprHistoryResponse {
104    /// List of APR data points
105    pub data: Vec<AprDataPoint>,
106    /// Continuation token for pagination
107    pub continuation: Option<String>,
108}
109
110/// Hello response
111#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
112pub struct HelloResponse {
113    /// Version string
114    pub version: String,
115}
116
117/// Delivery prices response
118#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
119pub struct DeliveryPricesResponse {
120    /// List of delivery price data
121    pub data: Vec<DeliveryPriceData>,
122    /// Total number of records
123    pub records_total: u32,
124}
125
126/// APR data point
127#[skip_serializing_none]
128#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
129pub struct AprDataPoint {
130    /// Annual percentage rate
131    pub apr: f64,
132    /// Timestamp of the data point (optional)
133    pub timestamp: Option<u64>,
134    /// Day of the data point
135    pub day: i32,
136}
137
138/// Expirations response
139#[skip_serializing_none]
140#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
141pub struct ExpirationsResponse {
142    /// Direct future expirations (when currency="any")
143    pub future: Option<Vec<String>>,
144    /// Direct option expirations (when currency="any")
145    pub option: Option<Vec<String>>,
146    /// Map of currency to their expirations (when specific currency)
147    #[serde(flatten)]
148    pub currencies: std::collections::HashMap<String, CurrencyExpirations>,
149}
150
151/// Last trades response
152#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
153pub struct LastTradesResponse {
154    /// Whether there are more trades available
155    pub has_more: bool,
156    /// List of recent trades
157    pub trades: Vec<LastTrade>,
158}
159
160/// Settlements response structure
161#[skip_serializing_none]
162#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
163pub struct SettlementsResponse {
164    /// Continuation token for pagination
165    pub continuation: Option<String>,
166    /// List of settlement events
167    pub settlements: Vec<Settlement>,
168}
169
170impl SettlementsResponse {
171    /// Create a new settlements response
172    pub fn new(settlements: Vec<Settlement>) -> Self {
173        Self {
174            continuation: None,
175            settlements,
176        }
177    }
178
179    /// Create settlements response with continuation token
180    pub fn with_continuation(
181        settlements: Vec<crate::model::settlement::Settlement>,
182        continuation: String,
183    ) -> Self {
184        Self {
185            continuation: Some(continuation),
186            settlements,
187        }
188    }
189
190    /// Check if there are more results
191    pub fn has_more(&self) -> bool {
192        self.continuation.is_some()
193    }
194}
195
196/// Paginated transaction log response
197#[skip_serializing_none]
198#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize, Default)]
199pub struct TransactionLogResponse {
200    /// Continuation token for pagination. NULL when no continuation.
201    pub continuation: Option<u64>,
202    /// List of transaction log entries
203    pub logs: Vec<TransactionLogEntry>,
204}
205
206/// Transfer result for order-related transfers (e.g., fee rebates)
207#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
208pub struct TransferResultResponse {
209    /// Transfer identifier
210    pub id: String,
211    /// Transfer status
212    pub status: String,
213}
214
215/// Account summary response containing user account information
216#[skip_serializing_none]
217#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
218pub struct AccountSummaryResponse {
219    /// Account id
220    pub id: u64,
221    /// User email
222    pub email: String,
223    /// System generated user nickname
224    pub system_name: String,
225    /// Account name (given by user)
226    pub username: String,
227    /// When Block RFQ Self Match Prevention is enabled
228    pub block_rfq_self_match_prevention: bool,
229    /// Time at which the account was created (milliseconds since the Unix epoch)
230    pub creation_timestamp: u64,
231    /// Account type
232    #[serde(rename = "type")]
233    pub account_type: String,
234    /// Optional identifier of the referrer
235    pub referrer_id: Option<String>,
236    /// Whether account is loginable using email and password
237    pub login_enabled: bool,
238    /// Whether Security Key authentication is enabled
239    pub security_keys_enabled: bool,
240    /// Whether MMP is enabled
241    pub mmp_enabled: bool,
242    /// true when the inter-user transfers are enabled for user
243    pub interuser_transfers_enabled: bool,
244    /// Self trading rejection behavior - reject_taker or cancel_maker
245    pub self_trading_reject_mode: String,
246    /// true if self trading rejection behavior is applied to trades between subaccounts
247    pub self_trading_extended_to_subaccounts: bool,
248    /// Aggregated list of per-currency account summaries
249    pub summaries: Vec<AccountResult>,
250}
251
252/// Account summary information
253#[skip_serializing_none]
254#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
255pub struct AccountResult {
256    /// Currency of the summary
257    pub currency: String,
258    /// The account's balance
259    pub balance: f64,
260    /// The account's current equity
261    pub equity: f64,
262    /// The account's available funds
263    pub available_funds: f64,
264    /// The account's margin balance
265    pub margin_balance: f64,
266    /// Profit and loss
267    pub total_pl: Option<f64>,
268    /// Session realized profit and loss
269    pub session_rpl: Option<f64>,
270    /// Session unrealized profit and loss
271    pub session_upl: Option<f64>,
272    /// The maintenance margin
273    pub maintenance_margin: f64,
274    /// The account's initial margin
275    pub initial_margin: f64,
276    /// The account's available to withdrawal funds
277    pub available_withdrawal_funds: Option<f64>,
278    /// When true cross collateral is enabled for user
279    pub cross_collateral_enabled: Option<bool>,
280    /// The sum of position deltas
281    pub delta_total: Option<f64>,
282    /// Futures profit and Loss
283    pub futures_pl: Option<f64>,
284    /// Futures session realized profit and Loss
285    pub futures_session_rpl: Option<f64>,
286    /// Futures session unrealized profit and Loss
287    pub futures_session_upl: Option<f64>,
288    /// Options summary delta
289    pub options_delta: Option<f64>,
290    /// Options summary gamma
291    pub options_gamma: Option<f64>,
292    /// Options profit and Loss
293    pub options_pl: Option<f64>,
294    /// Options session realized profit and Loss
295    pub options_session_rpl: Option<f64>,
296    /// Options session unrealized profit and Loss
297    pub options_session_upl: Option<f64>,
298    /// Options summary theta
299    pub options_theta: Option<f64>,
300    /// Options summary vega
301    pub options_vega: Option<f64>,
302    /// true when portfolio margining is enabled for user
303    pub portfolio_margining_enabled: Option<bool>,
304    /// The sum of position deltas without positions that will expire during closest expiration
305    pub projected_delta_total: Option<f64>,
306    /// Projected initial margin
307    pub projected_initial_margin: Option<f64>,
308    /// Projected maintenance margin
309    pub projected_maintenance_margin: Option<f64>,
310    /// Delta total map (currency -> delta)
311    pub delta_total_map: Option<std::collections::HashMap<String, f64>>,
312    /// The deposit address for the account (if available)
313    pub deposit_address: Option<String>,
314    /// List of fee objects for all currency pairs and instrument types
315    pub fees: Option<Vec<FeeStructure>>,
316    /// Account limits structure
317    pub limits: Option<AccountLimits>,
318    /// Name of user's currently enabled margin model
319    pub margin_model: Option<String>,
320    /// Map of options' gammas per index
321    pub options_gamma_map: Option<std::collections::HashMap<String, f64>>,
322    /// Map of options' thetas per index
323    pub options_theta_map: Option<std::collections::HashMap<String, f64>>,
324    /// Map of options' vegas per index
325    pub options_vega_map: Option<std::collections::HashMap<String, f64>>,
326    /// Options value
327    pub options_value: Option<f64>,
328    /// The account's balance reserved in active spot orders
329    pub spot_reserve: Option<f64>,
330    /// Estimated Liquidation Ratio
331    pub estimated_liquidation_ratio: Option<f64>,
332    /// Estimated liquidation ratio map
333    pub estimated_liquidation_ratio_map: Option<std::collections::HashMap<String, f64>>,
334    /// The account's fee balance (it can be used to pay for fees)
335    pub fee_balance: Option<f64>,
336    /// The account's balance reserved in other orders
337    pub additional_reserve: Option<f64>,
338
339    // Additional fields for cross-collateral users
340    /// Optional field returned with value true when user has non block chain equity
341    pub has_non_block_chain_equity: Option<bool>,
342    /// The account's total margin balance in all cross collateral currencies, expressed in USD
343    pub total_margin_balance_usd: Option<f64>,
344    /// The account's total delta total in all cross collateral currencies, expressed in USD
345    pub total_delta_total_usd: Option<f64>,
346    /// The account's total initial margin in all cross collateral currencies, expressed in USD
347    pub total_initial_margin_usd: Option<f64>,
348    /// The account's total maintenance margin in all cross collateral currencies, expressed in USD
349    pub total_maintenance_margin_usd: Option<f64>,
350    /// The account's total equity in all cross collateral currencies, expressed in USD
351    pub total_equity_usd: Option<f64>,
352    /// System name for the account
353    pub system_name: Option<String>,
354    /// Account type
355    pub account_type: Option<String>,
356}