ig_client/application/interfaces/sentiment.rs
1/******************************************************************************
2 Author: Joaquín Béjar García
3 Email: jb@taunais.com
4 Date: 8/3/26
5******************************************************************************/
6
7//! Client sentiment service interface for IG Markets API
8//!
9//! This module defines the interface for retrieving client sentiment data,
10//! which shows the percentage of IG clients who are long vs short on instruments.
11
12use crate::error::AppError;
13use crate::model::responses::{ClientSentimentResponse, MarketSentiment};
14use async_trait::async_trait;
15
16/// Service for retrieving client sentiment data from the IG Markets API
17///
18/// Client sentiment shows the percentage of IG clients holding long versus
19/// short positions on a given instrument, providing insight into market positioning.
20#[async_trait]
21pub trait SentimentService: Send + Sync {
22 /// Returns client sentiment for multiple markets
23 ///
24 /// # Arguments
25 /// * `market_ids` - List of market IDs to get sentiment for
26 ///
27 /// # Returns
28 /// * `Ok(ClientSentimentResponse)` - Sentiment data for the requested markets
29 /// * `Err(AppError)` - If the request fails
30 async fn get_client_sentiment(
31 &self,
32 market_ids: &[String],
33 ) -> Result<ClientSentimentResponse, AppError>;
34
35 /// Returns client sentiment for a single market
36 ///
37 /// # Arguments
38 /// * `market_id` - The market ID to get sentiment for
39 ///
40 /// # Returns
41 /// * `Ok(MarketSentiment)` - Sentiment data for the market
42 /// * `Err(AppError)` - If the request fails
43 async fn get_client_sentiment_by_market(
44 &self,
45 market_id: &str,
46 ) -> Result<MarketSentiment, AppError>;
47
48 /// Returns client sentiment for related markets
49 ///
50 /// Returns a list of related (also traded) client sentiment for
51 /// the given instrument's market.
52 ///
53 /// # Arguments
54 /// * `market_id` - The market ID to get related sentiments for
55 ///
56 /// # Returns
57 /// * `Ok(ClientSentimentResponse)` - Sentiment data for related markets
58 /// * `Err(AppError)` - If the request fails
59 async fn get_related_sentiment(
60 &self,
61 market_id: &str,
62 ) -> Result<ClientSentimentResponse, AppError>;
63}