Skip to main content

ig_client/application/interfaces/
account.rs

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