Skip to main content

coinbase_advanced/models/
account.rs

1//! Account-related types.
2
3use serde::{Deserialize, Serialize};
4
5use super::Balance;
6
7/// A Coinbase trading account.
8#[derive(Debug, Clone, Deserialize)]
9pub struct Account {
10    /// Unique identifier for the account.
11    pub uuid: String,
12    /// Display name of the account.
13    pub name: String,
14    /// Currency held in this account.
15    pub currency: String,
16    /// Available balance for trading.
17    pub available_balance: Balance,
18    /// Whether this is the default account for the currency.
19    pub default: bool,
20    /// Whether the account is active.
21    pub active: bool,
22    /// When the account was created.
23    pub created_at: String,
24    /// When the account was last updated.
25    pub updated_at: String,
26    /// When the account was deleted (if applicable).
27    pub deleted_at: Option<String>,
28    /// Account type (e.g., "ACCOUNT_TYPE_CRYPTO").
29    #[serde(rename = "type")]
30    pub account_type: String,
31    /// Whether the account is ready for use.
32    pub ready: bool,
33    /// Amount on hold (in orders, etc.).
34    pub hold: Balance,
35    /// The retail portfolio this account belongs to.
36    pub retail_portfolio_id: Option<String>,
37}
38
39/// Request parameters for listing accounts.
40#[derive(Debug, Clone, Default, Serialize)]
41pub struct ListAccountsParams {
42    /// Maximum number of accounts to return.
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub limit: Option<u32>,
45    /// Cursor for pagination.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub cursor: Option<String>,
48    /// Filter by retail portfolio ID.
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub retail_portfolio_id: Option<String>,
51}
52
53impl ListAccountsParams {
54    /// Create new list accounts parameters.
55    pub fn new() -> Self {
56        Self::default()
57    }
58
59    /// Set the limit.
60    pub fn limit(mut self, limit: u32) -> Self {
61        self.limit = Some(limit);
62        self
63    }
64
65    /// Set the cursor.
66    pub fn cursor(mut self, cursor: impl Into<String>) -> Self {
67        self.cursor = Some(cursor.into());
68        self
69    }
70
71    /// Filter by portfolio ID.
72    pub fn portfolio(mut self, portfolio_id: impl Into<String>) -> Self {
73        self.retail_portfolio_id = Some(portfolio_id.into());
74        self
75    }
76}
77
78/// Response from listing accounts.
79#[derive(Debug, Clone, Deserialize)]
80pub struct ListAccountsResponse {
81    /// The list of accounts.
82    pub accounts: Vec<Account>,
83    /// Whether there are more accounts.
84    pub has_next: bool,
85    /// Cursor for the next page.
86    pub cursor: Option<String>,
87    /// Total size (if available).
88    pub size: Option<u32>,
89}
90
91/// Response from getting a single account.
92#[derive(Debug, Clone, Deserialize)]
93pub struct GetAccountResponse {
94    /// The account details.
95    pub account: Account,
96}