schwab_api/endpoints/
accounts.rs1use crate::client::SchwabClient;
2use crate::error::Result;
3use crate::models::account::Account;
4use crate::models::AccountNumberHash;
5
6pub struct AccountsApi<'a> {
7 client: &'a SchwabClient,
8}
9
10impl<'a> AccountsApi<'a> {
11 pub fn new(client: &'a SchwabClient) -> Self {
12 Self { client }
13 }
14
15 pub async fn account_numbers(&self) -> Result<Vec<AccountNumberHash>> {
17 self.client.get_json("/accounts/accountNumbers", &[]).await
18 }
19
20 pub async fn list(&self, fields: Option<&str>) -> Result<Vec<Account>> {
22 let query = super::opt_query("fields", fields);
23 self.client.get_json("/accounts", &query).await
24 }
25
26 pub async fn get(&self, account_number: &str, fields: Option<&str>) -> Result<Account> {
28 let path = format!("/accounts/{account_number}");
29 let query = super::opt_query("fields", fields);
30 self.client.get_json(&path, &query).await
31 }
32}