ig_client/application/services/interfaces/
market.rs

1use crate::application::models::market::{
2    HistoricalPricesResponse, MarketDetails, MarketNavigationResponse, MarketSearchResult,
3};
4use crate::application::services::types::DBEntry;
5use crate::error::AppError;
6use crate::session::interface::IgSession;
7use async_trait::async_trait;
8
9/// Interface for the market service
10#[async_trait]
11pub trait MarketService: Send + Sync {
12    /// Searches markets by search term
13    async fn search_markets(
14        &self,
15        session: &IgSession,
16        search_term: &str,
17    ) -> Result<MarketSearchResult, AppError>;
18
19    /// Gets details of a specific market by its EPIC
20    async fn get_market_details(
21        &self,
22        session: &IgSession,
23        epic: &str,
24    ) -> Result<MarketDetails, AppError>;
25
26    /// Gets details of multiple markets by their EPICs in a single request
27    ///
28    /// This method accepts a vector of EPICs and returns a vector of market details.
29    /// The EPICs are sent as a comma-separated list in a single API request.
30    ///
31    /// # Arguments
32    /// * `session` - The active IG session
33    /// * `epics` - A slice of EPICs to get details for
34    ///
35    /// # Returns
36    /// A vector of market details in the same order as the input EPICs
37    async fn get_multiple_market_details(
38        &self,
39        session: &IgSession,
40        epics: &[String],
41    ) -> Result<Vec<MarketDetails>, AppError>;
42
43    /// Gets historical prices for a market
44    async fn get_historical_prices(
45        &self,
46        session: &IgSession,
47        epic: &str,
48        resolution: &str,
49        from: &str,
50        to: &str,
51    ) -> Result<HistoricalPricesResponse, AppError>;
52
53    /// Gets the top-level market navigation nodes
54    ///
55    /// This method returns the root nodes of the market hierarchy, which can be used
56    /// to navigate through the available markets.
57    async fn get_market_navigation(
58        &self,
59        session: &IgSession,
60    ) -> Result<MarketNavigationResponse, AppError>;
61
62    /// Gets the market navigation node with the specified ID
63    ///
64    /// This method returns the child nodes and markets under the specified node ID.
65    ///
66    /// # Arguments
67    /// * `node_id` - The ID of the navigation node to retrieve
68    async fn get_market_navigation_node(
69        &self,
70        session: &IgSession,
71        node_id: &str,
72    ) -> Result<MarketNavigationResponse, AppError>;
73
74    /// Navigates through all levels of the market hierarchy and collects all MarketData
75    ///
76    /// This method performs a comprehensive traversal of the IG Markets hierarchy,
77    /// starting from the root navigation and going through multiple levels to collect
78    /// all available market instruments.
79    ///
80    /// # Arguments
81    /// * `session` - The authenticated IG session
82    /// * `max_levels` - Maximum depth to traverse (default: 5 levels)
83    ///
84    /// # Returns
85    /// * `Result<Vec<MarketData>, AppError>` - Vector containing all found market instruments
86    async fn get_all_markets(
87        &self,
88        session: &IgSession,
89    ) -> Result<Vec<crate::application::models::market::MarketData>, AppError>;
90
91    /// Gets all markets converted to database entries format
92    ///
93    /// This method retrieves all available markets and converts them to a standardized
94    /// database entry format for storage or further processing.
95    ///
96    /// # Arguments
97    /// * `session` - The authenticated IG session
98    ///
99    /// # Returns
100    /// * `Result<Vec<DBEntry>, AppError>` - Vector of database entries representing all markets
101    async fn get_vec_db_entries(&self, session: &IgSession) -> Result<Vec<DBEntry>, AppError>;
102}