Skip to main content

ig_client/application/interfaces/
watchlist.rs

1/******************************************************************************
2   Author: Joaquín Béjar García
3   Email: jb@taunais.com
4   Date: 8/3/26
5******************************************************************************/
6
7//! Watchlist service interface for IG Markets API
8//!
9//! This module defines the interface for managing watchlists, including
10//! creating, retrieving, updating, and deleting watchlists and their contents.
11
12use crate::error::AppError;
13use crate::model::responses::{
14    CreateWatchlistResponse, StatusResponse, WatchlistMarketsResponse, WatchlistsResponse,
15};
16use async_trait::async_trait;
17
18/// Service for managing watchlists in the IG Markets API
19///
20/// Watchlists allow users to organize and track groups of instruments.
21/// This trait provides methods for full CRUD operations on watchlists.
22#[async_trait]
23pub trait WatchlistService: Send + Sync {
24    /// Returns all watchlists belonging to the active account
25    ///
26    /// # Returns
27    /// * `Ok(WatchlistsResponse)` - List of all watchlists
28    /// * `Err(AppError)` - If the request fails
29    async fn get_watchlists(&self) -> Result<WatchlistsResponse, AppError>;
30
31    /// Creates a new watchlist with the given name and optional initial instruments
32    ///
33    /// # Arguments
34    /// * `name` - The name for the new watchlist
35    /// * `epics` - Optional list of EPICs to add to the watchlist
36    ///
37    /// # Returns
38    /// * `Ok(CreateWatchlistResponse)` - The created watchlist ID and status
39    /// * `Err(AppError)` - If the request fails
40    async fn create_watchlist(
41        &self,
42        name: &str,
43        epics: Option<&[String]>,
44    ) -> Result<CreateWatchlistResponse, AppError>;
45
46    /// Returns the markets in a specific watchlist
47    ///
48    /// # Arguments
49    /// * `watchlist_id` - The ID of the watchlist to retrieve
50    ///
51    /// # Returns
52    /// * `Ok(WatchlistMarketsResponse)` - The watchlist's markets
53    /// * `Err(AppError)` - If the request fails
54    async fn get_watchlist(&self, watchlist_id: &str)
55    -> Result<WatchlistMarketsResponse, AppError>;
56
57    /// Deletes a watchlist
58    ///
59    /// # Arguments
60    /// * `watchlist_id` - The ID of the watchlist to delete
61    ///
62    /// # Returns
63    /// * `Ok(StatusResponse)` - The deletion status
64    /// * `Err(AppError)` - If the request fails
65    async fn delete_watchlist(&self, watchlist_id: &str) -> Result<StatusResponse, AppError>;
66
67    /// Adds an instrument to a watchlist
68    ///
69    /// # Arguments
70    /// * `watchlist_id` - The ID of the watchlist
71    /// * `epic` - The EPIC of the instrument to add
72    ///
73    /// # Returns
74    /// * `Ok(StatusResponse)` - The operation status
75    /// * `Err(AppError)` - If the request fails
76    async fn add_to_watchlist(
77        &self,
78        watchlist_id: &str,
79        epic: &str,
80    ) -> Result<StatusResponse, AppError>;
81
82    /// Removes an instrument from a watchlist
83    ///
84    /// # Arguments
85    /// * `watchlist_id` - The ID of the watchlist
86    /// * `epic` - The EPIC of the instrument to remove
87    ///
88    /// # Returns
89    /// * `Ok(StatusResponse)` - The operation status
90    /// * `Err(AppError)` - If the request fails
91    async fn remove_from_watchlist(
92        &self,
93        watchlist_id: &str,
94        epic: &str,
95    ) -> Result<StatusResponse, AppError>;
96}