Skip to main content

coinbase_advanced/models/
perpetuals.rs

1//! Perpetuals/INTX API types.
2
3use serde::{Deserialize, Serialize};
4
5/// Amount with value and currency.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct IntxAmount {
8    /// The amount value.
9    #[serde(default)]
10    pub value: Option<String>,
11    /// The currency.
12    #[serde(default)]
13    pub currency: Option<String>,
14}
15
16/// INTX (perpetuals) position.
17#[derive(Debug, Clone, Deserialize)]
18pub struct IntxPosition {
19    /// Product ID.
20    pub product_id: String,
21    /// Product UUID.
22    #[serde(default)]
23    pub product_uuid: Option<String>,
24    /// Portfolio UUID.
25    #[serde(default)]
26    pub portfolio_uuid: Option<String>,
27    /// Symbol (e.g., BTC-PERP).
28    #[serde(default)]
29    pub symbol: Option<String>,
30    /// Volume-weighted average price.
31    #[serde(default)]
32    pub vwap: Option<IntxAmount>,
33    /// Position side (LONG, SHORT).
34    #[serde(default)]
35    pub position_side: Option<String>,
36    /// Net size.
37    #[serde(default)]
38    pub net_size: Option<String>,
39    /// Buy order size.
40    #[serde(default)]
41    pub buy_order_size: Option<String>,
42    /// Sell order size.
43    #[serde(default)]
44    pub sell_order_size: Option<String>,
45    /// Initial margin contribution.
46    #[serde(default)]
47    pub im_contribution: Option<String>,
48    /// Unrealized PnL.
49    #[serde(default)]
50    pub unrealized_pnl: Option<IntxAmount>,
51    /// Mark price.
52    #[serde(default)]
53    pub mark_price: Option<IntxAmount>,
54    /// Liquidation price.
55    #[serde(default)]
56    pub liquidation_price: Option<IntxAmount>,
57    /// Leverage.
58    #[serde(default)]
59    pub leverage: Option<String>,
60    /// IM notional.
61    #[serde(default)]
62    pub im_notional: Option<IntxAmount>,
63    /// MM notional.
64    #[serde(default)]
65    pub mm_notional: Option<IntxAmount>,
66    /// Position notional.
67    #[serde(default)]
68    pub position_notional: Option<String>,
69}
70
71/// INTX position summary.
72#[derive(Debug, Clone, Deserialize)]
73pub struct IntxSummary {
74    /// Aggregated PnL.
75    #[serde(default)]
76    pub aggregated_pnl: Option<IntxAmount>,
77}
78
79/// Response for listing perpetuals positions.
80#[derive(Debug, Clone, Deserialize)]
81pub struct ListPerpetualsPositionsResponse {
82    /// Positions.
83    #[serde(default)]
84    pub positions: Vec<IntxPosition>,
85    /// Summary.
86    #[serde(default)]
87    pub summary: Option<IntxSummary>,
88}
89
90/// Response for getting a single perpetuals position.
91#[derive(Debug, Clone, Deserialize)]
92pub struct GetPerpetualsPositionResponse {
93    /// The position.
94    pub position: IntxPosition,
95}
96
97/// INTX portfolio balance.
98#[derive(Debug, Clone, Deserialize)]
99pub struct IntxPortfolioBalance {
100    /// Asset.
101    #[serde(default)]
102    pub asset: Option<String>,
103    /// Quantity.
104    #[serde(default)]
105    pub quantity: Option<String>,
106    /// Hold.
107    #[serde(default)]
108    pub hold: Option<String>,
109    /// Transfer hold.
110    #[serde(default)]
111    pub transfer_hold: Option<String>,
112    /// Collateral value.
113    #[serde(default)]
114    pub collateral_value: Option<String>,
115    /// Max withdraw amount.
116    #[serde(default)]
117    pub max_withdraw_amount: Option<String>,
118}
119
120/// Response for getting portfolio balances.
121#[derive(Debug, Clone, Deserialize)]
122pub struct GetPortfolioBalancesResponse {
123    /// Portfolio balances.
124    #[serde(default)]
125    pub portfolio_balances: Vec<IntxPortfolioBalance>,
126}
127
128/// INTX portfolio summary.
129#[derive(Debug, Clone, Deserialize)]
130pub struct IntxPortfolioSummary {
131    /// Unrealized PnL.
132    #[serde(default)]
133    pub unrealized_pnl: Option<IntxAmount>,
134    /// Buying power.
135    #[serde(default)]
136    pub buying_power: Option<IntxAmount>,
137    /// Total balance.
138    #[serde(default)]
139    pub total_balance: Option<IntxAmount>,
140    /// Max withdrawal amount.
141    #[serde(default)]
142    pub max_withdrawal_amount: Option<IntxAmount>,
143}
144
145/// Response for getting portfolio summary.
146#[derive(Debug, Clone, Deserialize)]
147pub struct GetPerpetualsPortfolioSummaryResponse {
148    /// Summary.
149    pub summary: IntxPortfolioSummary,
150}
151
152/// Request to allocate funds to a portfolio.
153#[derive(Debug, Clone, Serialize)]
154pub struct AllocatePortfolioRequest {
155    /// Portfolio UUID.
156    pub portfolio_uuid: String,
157    /// Symbol.
158    pub symbol: String,
159    /// Amount to allocate.
160    pub amount: String,
161    /// Currency.
162    pub currency: String,
163}
164
165impl AllocatePortfolioRequest {
166    /// Create a new allocate portfolio request.
167    pub fn new(
168        portfolio_uuid: impl Into<String>,
169        symbol: impl Into<String>,
170        amount: impl Into<String>,
171        currency: impl Into<String>,
172    ) -> Self {
173        Self {
174            portfolio_uuid: portfolio_uuid.into(),
175            symbol: symbol.into(),
176            amount: amount.into(),
177            currency: currency.into(),
178        }
179    }
180}
181
182/// Request to set multi-asset collateral.
183#[derive(Debug, Clone, Serialize)]
184pub struct SetMultiAssetCollateralRequest {
185    /// Whether multi-asset collateral is enabled.
186    pub multi_asset_collateral_enabled: bool,
187}
188
189impl SetMultiAssetCollateralRequest {
190    /// Create a new set multi-asset collateral request.
191    pub fn new(enabled: bool) -> Self {
192        Self {
193            multi_asset_collateral_enabled: enabled,
194        }
195    }
196}