ig_client/application/interfaces/account.rs
1use crate::error::AppError;
2use crate::model::responses::AccountPreferencesResponse;
3use crate::prelude::{
4 AccountActivityResponse, AccountsResponse, PositionsResponse, TransactionHistoryResponse,
5 WorkingOrdersResponse,
6};
7use async_trait::async_trait;
8
9/// Interface for the account service
10#[async_trait]
11pub trait AccountService: Send + Sync {
12 /// Gets information about all user accounts
13 async fn get_accounts(&self) -> Result<AccountsResponse, AppError>;
14
15 /// Gets open positions
16 async fn get_positions(&self) -> Result<PositionsResponse, AppError>;
17
18 /// Gets open positions base in filter
19 async fn get_positions_w_filter(&self, filter: &str) -> Result<PositionsResponse, AppError>;
20
21 /// Gets working orders
22 async fn get_working_orders(&self) -> Result<WorkingOrdersResponse, AppError>;
23
24 /// Gets account activity
25 ///
26 /// # Arguments
27 /// * `session` - The current session
28 /// * `from` - Start date in ISO format (e.g. "2023-01-01T00:00:00Z")
29 /// * `to` - End date in ISO format (e.g. "2023-02-01T00:00:00Z")
30 ///
31 /// # Returns
32 /// * Account activity for the specified period
33 async fn get_activity(&self, from: &str, to: &str)
34 -> Result<AccountActivityResponse, AppError>;
35
36 /// Gets detailed account activity
37 ///
38 /// This method includes additional details for each activity item by using
39 /// the detailed=true parameter in the API request.
40 ///
41 /// # Arguments
42 /// * `session` - The current session
43 /// * `from` - Start date in ISO format (e.g. "2023-01-01T00:00:00Z")
44 /// * `to` - End date in ISO format (e.g. "2023-02-01T00:00:00Z")
45 ///
46 /// # Returns
47 /// * Detailed account activity for the specified period
48 async fn get_activity_with_details(
49 &self,
50
51 from: &str,
52 to: &str,
53 ) -> Result<AccountActivityResponse, AppError>;
54
55 /// Gets transaction history for a given period, handling pagination automatically.
56 async fn get_transactions(
57 &self,
58 from: &str,
59 to: &str,
60 ) -> Result<TransactionHistoryResponse, AppError>;
61
62 /// Gets account preferences
63 ///
64 /// # Returns
65 /// * `Ok(AccountPreferencesResponse)` - The account preferences
66 /// * `Err(AppError)` - If the request fails
67 async fn get_preferences(&self) -> Result<AccountPreferencesResponse, AppError>;
68
69 /// Updates account preferences
70 ///
71 /// # Arguments
72 /// * `trailing_stops_enabled` - Whether trailing stops should be enabled
73 ///
74 /// # Returns
75 /// * `Ok(())` - If the update was successful
76 /// * `Err(AppError)` - If the request fails
77 async fn update_preferences(&self, trailing_stops_enabled: bool) -> Result<(), AppError>;
78
79 /// Gets account activity for a specified period
80 ///
81 /// # Arguments
82 /// * `period` - Period in milliseconds (e.g., 600000 for 10 minutes)
83 ///
84 /// # Returns
85 /// * `Ok(AccountActivityResponse)` - Account activity for the period
86 /// * `Err(AppError)` - If the request fails
87 async fn get_activity_by_period(
88 &self,
89 period_ms: u64,
90 ) -> Result<AccountActivityResponse, AppError>;
91}