ig_client/application/services/interfaces/market.rs
1use crate::application::models::market::{
2 HistoricalPricesResponse, MarketDetails, MarketNavigationResponse, MarketSearchResult,
3};
4use crate::error::AppError;
5use crate::session::interface::IgSession;
6use async_trait::async_trait;
7
8/// Interface for the market service
9#[async_trait]
10pub trait MarketService: Send + Sync {
11 /// Searches markets by search term
12 async fn search_markets(
13 &self,
14 session: &IgSession,
15 search_term: &str,
16 ) -> Result<MarketSearchResult, AppError>;
17
18 /// Gets details of a specific market by its EPIC
19 async fn get_market_details(
20 &self,
21 session: &IgSession,
22 epic: &str,
23 ) -> Result<MarketDetails, AppError>;
24
25 /// Gets details of multiple markets by their EPICs in a single request
26 ///
27 /// This method accepts a vector of EPICs and returns a vector of market details.
28 /// The EPICs are sent as a comma-separated list in a single API request.
29 ///
30 /// # Arguments
31 /// * `session` - The active IG session
32 /// * `epics` - A slice of EPICs to get details for
33 ///
34 /// # Returns
35 /// A vector of market details in the same order as the input EPICs
36 async fn get_multiple_market_details(
37 &self,
38 session: &IgSession,
39 epics: &[String],
40 ) -> Result<Vec<MarketDetails>, AppError>;
41
42 /// Gets historical prices for a market
43 async fn get_historical_prices(
44 &self,
45 session: &IgSession,
46 epic: &str,
47 resolution: &str,
48 from: &str,
49 to: &str,
50 ) -> Result<HistoricalPricesResponse, AppError>;
51
52 /// Gets the top-level market navigation nodes
53 ///
54 /// This method returns the root nodes of the market hierarchy, which can be used
55 /// to navigate through the available markets.
56 async fn get_market_navigation(
57 &self,
58 session: &IgSession,
59 ) -> Result<MarketNavigationResponse, AppError>;
60
61 /// Gets the market navigation node with the specified ID
62 ///
63 /// This method returns the child nodes and markets under the specified node ID.
64 ///
65 /// # Arguments
66 /// * `node_id` - The ID of the navigation node to retrieve
67 async fn get_market_navigation_node(
68 &self,
69 session: &IgSession,
70 node_id: &str,
71 ) -> Result<MarketNavigationResponse, AppError>;
72}