Skip to main content

coinbase_advanced/models/
futures.rs

1//! Futures/CFM API types.
2
3use serde::{Deserialize, Serialize};
4
5/// CFM futures position.
6#[derive(Debug, Clone, Deserialize)]
7pub struct FuturesPosition {
8    /// Product ID.
9    pub product_id: String,
10    /// Expiration time.
11    #[serde(default)]
12    pub expiration_time: Option<String>,
13    /// Position side (LONG, SHORT).
14    #[serde(default)]
15    pub side: Option<String>,
16    /// Number of contracts.
17    #[serde(default)]
18    pub number_of_contracts: Option<String>,
19    /// Current price.
20    #[serde(default)]
21    pub current_price: Option<String>,
22    /// Average entry price.
23    #[serde(default)]
24    pub avg_entry_price: Option<String>,
25    /// Unrealized PnL.
26    #[serde(default)]
27    pub unrealized_pnl: Option<String>,
28    /// Daily realized PnL.
29    #[serde(default)]
30    pub daily_realized_pnl: Option<String>,
31}
32
33/// Response for listing futures positions.
34#[derive(Debug, Clone, Deserialize)]
35pub struct ListFuturesPositionsResponse {
36    /// Positions.
37    #[serde(default)]
38    pub positions: Vec<FuturesPosition>,
39}
40
41/// Response for getting a single futures position.
42#[derive(Debug, Clone, Deserialize)]
43pub struct GetFuturesPositionResponse {
44    /// The position.
45    pub position: FuturesPosition,
46}
47
48/// Futures balance summary.
49#[derive(Debug, Clone, Deserialize)]
50pub struct FuturesBalanceSummary {
51    /// Futures buying power.
52    #[serde(default)]
53    pub futures_buying_power: Option<String>,
54    /// Total USD balance.
55    #[serde(default)]
56    pub total_usd_balance: Option<String>,
57    /// CFTC unrealized PnL.
58    #[serde(default)]
59    pub cbi_usd_balance: Option<String>,
60    /// CFM USD balance.
61    #[serde(default)]
62    pub cfm_usd_balance: Option<String>,
63    /// Total open orders hold amount.
64    #[serde(default)]
65    pub total_open_orders_hold_amount: Option<String>,
66    /// Unrealized PnL.
67    #[serde(default)]
68    pub unrealized_pnl: Option<String>,
69    /// Daily realized PnL.
70    #[serde(default)]
71    pub daily_realized_pnl: Option<String>,
72    /// Initial margin.
73    #[serde(default)]
74    pub initial_margin: Option<String>,
75    /// Available margin.
76    #[serde(default)]
77    pub available_margin: Option<String>,
78    /// Liquidation threshold.
79    #[serde(default)]
80    pub liquidation_threshold: Option<String>,
81    /// Liquidation buffer amount.
82    #[serde(default)]
83    pub liquidation_buffer_amount: Option<String>,
84    /// Liquidation buffer percentage.
85    #[serde(default)]
86    pub liquidation_buffer_percentage: Option<String>,
87}
88
89/// Response for getting balance summary.
90#[derive(Debug, Clone, Deserialize)]
91pub struct GetFuturesBalanceSummaryResponse {
92    /// Balance summary.
93    pub balance_summary: FuturesBalanceSummary,
94}
95
96/// Intraday margin setting.
97#[derive(Debug, Clone, Deserialize, Serialize)]
98pub struct IntradayMarginSetting {
99    /// The margin setting value.
100    #[serde(default)]
101    pub setting: Option<String>,
102}
103
104/// Response for getting intraday margin setting.
105#[derive(Debug, Clone, Deserialize)]
106pub struct GetIntradayMarginSettingResponse {
107    /// The setting.
108    #[serde(default)]
109    pub setting: Option<String>,
110}
111
112/// Current margin window.
113#[derive(Debug, Clone, Deserialize)]
114pub struct MarginWindow {
115    /// Margin window type.
116    #[serde(default)]
117    pub margin_window_type: Option<String>,
118    /// End time.
119    #[serde(default)]
120    pub end_time: Option<String>,
121    /// Is intraday margin killswitch enabled.
122    #[serde(default)]
123    pub is_intraday_margin_killswitch_enabled: Option<bool>,
124    /// Is intraday margin enabled.
125    #[serde(default)]
126    pub is_intraday_margin_enrollment_killswitch_enabled: Option<bool>,
127}
128
129/// Response for getting current margin window.
130#[derive(Debug, Clone, Deserialize)]
131pub struct GetCurrentMarginWindowResponse {
132    /// The margin window.
133    pub margin_window: MarginWindow,
134}
135
136/// Parameters for getting current margin window.
137#[derive(Debug, Clone, Default, Serialize)]
138pub struct GetCurrentMarginWindowParams {
139    /// Margin profile type.
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub margin_profile_type: Option<String>,
142}
143
144impl GetCurrentMarginWindowParams {
145    /// Create new parameters.
146    pub fn new() -> Self {
147        Self::default()
148    }
149
150    /// Set the margin profile type.
151    pub fn margin_profile_type(mut self, margin_profile_type: impl Into<String>) -> Self {
152        self.margin_profile_type = Some(margin_profile_type.into());
153        self
154    }
155}
156
157/// A futures sweep.
158#[derive(Debug, Clone, Deserialize)]
159pub struct FuturesSweep {
160    /// Sweep ID.
161    #[serde(default)]
162    pub id: Option<String>,
163    /// Requested amount.
164    #[serde(default)]
165    pub requested_amount: Option<String>,
166    /// Should sweep all.
167    #[serde(default)]
168    pub should_sweep_all: Option<bool>,
169    /// Status.
170    #[serde(default)]
171    pub status: Option<String>,
172    /// Scheduled time.
173    #[serde(default)]
174    pub scheduled_time: Option<String>,
175}
176
177/// Response for listing futures sweeps.
178#[derive(Debug, Clone, Deserialize)]
179pub struct ListFuturesSweepsResponse {
180    /// Sweeps.
181    #[serde(default)]
182    pub sweeps: Vec<FuturesSweep>,
183}
184
185/// Request to schedule a futures sweep.
186#[derive(Debug, Clone, Serialize)]
187pub struct ScheduleFuturesSweepRequest {
188    /// USD amount to sweep.
189    pub usd_amount: String,
190}
191
192impl ScheduleFuturesSweepRequest {
193    /// Create a new schedule futures sweep request.
194    pub fn new(usd_amount: impl Into<String>) -> Self {
195        Self {
196            usd_amount: usd_amount.into(),
197        }
198    }
199}
200
201/// Response from scheduling a futures sweep.
202#[derive(Debug, Clone, Deserialize)]
203pub struct ScheduleFuturesSweepResponse {
204    /// Success status.
205    #[serde(default)]
206    pub success: bool,
207}
208
209/// Request to set intraday margin setting.
210#[derive(Debug, Clone, Serialize)]
211pub struct SetIntradayMarginSettingRequest {
212    /// The setting value.
213    pub setting: String,
214}
215
216impl SetIntradayMarginSettingRequest {
217    /// Create a new set intraday margin setting request.
218    pub fn new(setting: impl Into<String>) -> Self {
219        Self {
220            setting: setting.into(),
221        }
222    }
223}