1use crate::prelude::*;
7use pretty_simple_display::{DebugPretty, DisplaySimple};
8use serde::{Deserialize, Serialize};
9use serde_with::skip_serializing_none;
10
11#[skip_serializing_none]
13#[derive(DebugPretty, DisplaySimple, Clone, Default, Serialize, Deserialize)]
14pub struct TradingLimit {
15 #[serde(default)]
17 pub total: RateLimit,
18}
19
20#[skip_serializing_none]
22#[derive(DebugPretty, DisplaySimple, Clone, Default, Serialize, Deserialize)]
23pub struct AccountLimits {
24 #[serde(default)]
26 pub limits_per_currency: bool,
27 #[serde(default)]
29 pub non_matching_engine: RateLimit,
30 #[serde(default)]
32 pub matching_engine: MatchingEngineLimit,
33}
34
35#[skip_serializing_none]
37#[derive(DebugPretty, DisplaySimple, Clone, Default, Serialize, Deserialize)]
38pub struct RateLimit {
39 #[serde(default)]
41 pub burst: u32,
42 #[serde(default)]
44 pub rate: u32,
45}
46
47#[skip_serializing_none]
49#[derive(DebugPretty, DisplaySimple, Clone, Default, Serialize, Deserialize)]
50pub struct MatchingEngineLimit {
51 #[serde(default)]
53 pub trading: TradingLimit,
54 #[serde(default)]
56 pub spot: RateLimit,
57 #[serde(default)]
59 pub quotes: RateLimit,
60 #[serde(default)]
62 pub max_quotes: RateLimit,
63 #[serde(default)]
65 pub guaranteed_quotes: RateLimit,
66 #[serde(default)]
68 pub cancel_all: RateLimit,
69}
70
71pub type UserTradeResponse = Vec<UserTrade>;
73
74#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
76pub struct UserTradeWithPaginationResponse {
77 pub trades: Vec<UserTrade>,
79 pub has_more: bool,
81}
82
83#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
85pub struct ContractSizeResponse {
86 pub contract_size: f64,
88}
89
90#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
92pub struct TestResponse {
93 pub version: String,
95}
96
97#[skip_serializing_none]
99#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
100pub struct StatusResponse {
101 pub locked: Option<bool>,
103 pub message: Option<String>,
105 pub locked_indices: Option<Vec<String>>,
107 #[serde(flatten)]
109 pub additional_fields: std::collections::HashMap<String, serde_json::Value>,
110}
111
112#[skip_serializing_none]
114#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
115pub struct AprHistoryResponse {
116 pub data: Vec<AprDataPoint>,
118 pub continuation: Option<String>,
120}
121
122#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
124pub struct HelloResponse {
125 pub version: String,
127}
128
129#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
131pub struct DeliveryPricesResponse {
132 pub data: Vec<DeliveryPriceData>,
134 pub records_total: u32,
136}
137
138#[skip_serializing_none]
140#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
141pub struct AprDataPoint {
142 pub apr: f64,
144 pub timestamp: Option<u64>,
146 pub day: i32,
148}
149
150#[skip_serializing_none]
152#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
153pub struct ExpirationsResponse {
154 pub future: Option<Vec<String>>,
156 pub option: Option<Vec<String>>,
158 #[serde(flatten)]
160 pub currencies: std::collections::HashMap<String, CurrencyExpirations>,
161}
162
163#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
165pub struct LastTradesResponse {
166 pub has_more: bool,
168 pub trades: Vec<LastTrade>,
170}
171
172#[skip_serializing_none]
174#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
175pub struct SettlementsResponse {
176 pub continuation: Option<String>,
178 pub settlements: Vec<Settlement>,
180}
181
182impl SettlementsResponse {
183 pub fn new(settlements: Vec<Settlement>) -> Self {
185 Self {
186 continuation: None,
187 settlements,
188 }
189 }
190
191 pub fn with_continuation(
193 settlements: Vec<crate::model::settlement::Settlement>,
194 continuation: String,
195 ) -> Self {
196 Self {
197 continuation: Some(continuation),
198 settlements,
199 }
200 }
201
202 pub fn has_more(&self) -> bool {
204 self.continuation.is_some()
205 }
206}
207
208#[skip_serializing_none]
210#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize, Default)]
211pub struct TransactionLogResponse {
212 pub continuation: Option<u64>,
214 pub logs: Vec<TransactionLogEntry>,
216}
217
218#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
220pub struct TransferResultResponse {
221 pub id: String,
223 pub status: String,
225}
226
227#[skip_serializing_none]
229#[derive(Debug, Clone, Serialize, Deserialize)]
230pub struct AccountInfo {
231 pub id: u64,
233 pub email: String,
235 pub system_name: Option<String>,
237 pub username: Option<String>,
239 pub block_rfq_self_match_prevention: Option<bool>,
241 pub creation_timestamp: Option<u64>,
243 #[serde(rename = "type")]
245 pub account_type: Option<String>,
246 pub referrer_id: Option<String>,
248 pub login_enabled: Option<bool>,
250 pub security_keys_enabled: Option<bool>,
252 pub mmp_enabled: Option<bool>,
254 pub interuser_transfers_enabled: Option<bool>,
256 pub self_trading_reject_mode: Option<String>,
258 pub self_trading_extended_to_subaccounts: Option<bool>,
260}
261
262#[skip_serializing_none]
264#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
265pub struct AccountSummaryResponse {
266 #[serde(default)]
268 pub id: u64,
269 #[serde(default)]
271 pub email: String,
272 #[serde(default)]
274 pub system_name: String,
275 #[serde(default)]
277 pub username: String,
278 #[serde(default)]
280 pub block_rfq_self_match_prevention: bool,
281 #[serde(default)]
283 pub creation_timestamp: u64,
284 #[serde(rename = "type", default)]
286 pub account_type: String,
287 pub referrer_id: Option<String>,
289 #[serde(default)]
291 pub login_enabled: bool,
292 #[serde(default)]
294 pub security_keys_enabled: bool,
295 #[serde(default)]
297 pub mmp_enabled: bool,
298 #[serde(default)]
300 pub interuser_transfers_enabled: bool,
301 #[serde(default)]
303 pub self_trading_reject_mode: String,
304 #[serde(default)]
306 pub self_trading_extended_to_subaccounts: bool,
307 #[serde(default)]
309 pub summaries: Vec<AccountResult>,
310}
311
312#[skip_serializing_none]
317#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
318pub struct AccountSummariesResponse {
319 #[serde(flatten)]
321 pub account: AccountInfo,
322 pub summaries: Vec<AccountResult>,
324}
325
326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
331#[serde(from = "(u64, f64)", into = "(u64, f64)")]
332pub struct MarkPriceHistoryPoint {
333 pub timestamp: u64,
335 pub mark_price: f64,
337}
338
339impl From<(u64, f64)> for MarkPriceHistoryPoint {
340 fn from((timestamp, mark_price): (u64, f64)) -> Self {
341 Self {
342 timestamp,
343 mark_price,
344 }
345 }
346}
347
348impl From<MarkPriceHistoryPoint> for (u64, f64) {
349 fn from(point: MarkPriceHistoryPoint) -> Self {
350 (point.timestamp, point.mark_price)
351 }
352}
353
354#[skip_serializing_none]
359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
360pub struct IndexNameInfo {
361 pub name: String,
363 pub future_combo_enabled: Option<bool>,
365 pub option_combo_enabled: Option<bool>,
367}
368
369#[skip_serializing_none]
374#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
375pub struct TradeVolume {
376 pub currency: String,
378 pub calls_volume: f64,
380 pub puts_volume: f64,
382 pub futures_volume: f64,
384 pub spot_volume: f64,
386 pub calls_volume_7d: Option<f64>,
388 pub puts_volume_7d: Option<f64>,
390 pub futures_volume_7d: Option<f64>,
392 pub spot_volume_7d: Option<f64>,
394 pub calls_volume_30d: Option<f64>,
396 pub puts_volume_30d: Option<f64>,
398 pub futures_volume_30d: Option<f64>,
400 pub spot_volume_30d: Option<f64>,
402}
403
404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
408pub struct VolatilityIndexCandle {
409 pub timestamp: u64,
411 pub open: f64,
413 pub high: f64,
415 pub low: f64,
417 pub close: f64,
419}
420
421#[skip_serializing_none]
425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
426pub struct VolatilityIndexData {
427 #[serde(deserialize_with = "deserialize_candles")]
429 pub data: Vec<VolatilityIndexCandle>,
430 pub continuation: Option<u64>,
432}
433
434fn deserialize_candles<'de, D>(deserializer: D) -> Result<Vec<VolatilityIndexCandle>, D::Error>
436where
437 D: serde::Deserializer<'de>,
438{
439 use serde::de::Error;
440 let raw: Vec<Vec<serde_json::Value>> = Vec::deserialize(deserializer)?;
441 let mut candles = Vec::with_capacity(raw.len());
442
443 for arr in raw {
444 if arr.len() != 5 {
445 return Err(D::Error::custom(format!(
446 "expected 5 elements in candle array, got {}",
447 arr.len()
448 )));
449 }
450 let timestamp = arr[0]
451 .as_u64()
452 .ok_or_else(|| D::Error::custom("invalid timestamp"))?;
453 let open = arr[1]
454 .as_f64()
455 .ok_or_else(|| D::Error::custom("invalid open"))?;
456 let high = arr[2]
457 .as_f64()
458 .ok_or_else(|| D::Error::custom("invalid high"))?;
459 let low = arr[3]
460 .as_f64()
461 .ok_or_else(|| D::Error::custom("invalid low"))?;
462 let close = arr[4]
463 .as_f64()
464 .ok_or_else(|| D::Error::custom("invalid close"))?;
465
466 candles.push(VolatilityIndexCandle {
467 timestamp,
468 open,
469 high,
470 low,
471 close,
472 });
473 }
474
475 Ok(candles)
476}
477
478#[skip_serializing_none]
480#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
481pub struct AccountResult {
482 #[serde(default)]
484 pub currency: String,
485 pub balance: f64,
487 pub equity: f64,
489 pub available_funds: f64,
491 pub margin_balance: f64,
493 pub total_pl: Option<f64>,
495 pub session_rpl: Option<f64>,
497 pub session_upl: Option<f64>,
499 pub maintenance_margin: f64,
501 pub initial_margin: f64,
503 pub available_withdrawal_funds: Option<f64>,
505 pub cross_collateral_enabled: Option<bool>,
507 pub delta_total: Option<f64>,
509 pub futures_pl: Option<f64>,
511 pub futures_session_rpl: Option<f64>,
513 pub futures_session_upl: Option<f64>,
515 pub options_delta: Option<f64>,
517 pub options_gamma: Option<f64>,
519 pub options_pl: Option<f64>,
521 pub options_session_rpl: Option<f64>,
523 pub options_session_upl: Option<f64>,
525 pub options_theta: Option<f64>,
527 pub options_vega: Option<f64>,
529 pub portfolio_margining_enabled: Option<bool>,
531 pub projected_delta_total: Option<f64>,
533 pub projected_initial_margin: Option<f64>,
535 pub projected_maintenance_margin: Option<f64>,
537 pub delta_total_map: Option<std::collections::HashMap<String, f64>>,
539 pub deposit_address: Option<String>,
541 pub fees: Option<Vec<FeeStructure>>,
543 pub limits: Option<AccountLimits>,
545 pub margin_model: Option<String>,
547 pub options_gamma_map: Option<std::collections::HashMap<String, f64>>,
549 pub options_theta_map: Option<std::collections::HashMap<String, f64>>,
551 pub options_vega_map: Option<std::collections::HashMap<String, f64>>,
553 pub options_value: Option<f64>,
555 pub spot_reserve: Option<f64>,
557 pub estimated_liquidation_ratio: Option<f64>,
559 pub estimated_liquidation_ratio_map: Option<std::collections::HashMap<String, f64>>,
561 pub fee_balance: Option<f64>,
563 pub additional_reserve: Option<f64>,
565
566 pub has_non_block_chain_equity: Option<bool>,
569 pub total_margin_balance_usd: Option<f64>,
571 pub total_delta_total_usd: Option<f64>,
573 pub total_initial_margin_usd: Option<f64>,
575 pub total_maintenance_margin_usd: Option<f64>,
577 pub total_equity_usd: Option<f64>,
579 pub system_name: Option<String>,
581 pub account_type: Option<String>,
583}