Skip to main content

ig_client/application/interfaces/
costs.rs

1/******************************************************************************
2   Author: Joaquín Béjar García
3   Email: jb@taunais.com
4   Date: 8/3/26
5******************************************************************************/
6
7//! Indicative costs and charges service interface for IG Markets API
8//!
9//! This module defines the interface for retrieving indicative costs and charges
10//! information for opening, closing, and editing positions. This is required
11//! for regulatory compliance in certain jurisdictions.
12
13use crate::error::AppError;
14use crate::model::requests::{CloseCostsRequest, EditCostsRequest, OpenCostsRequest};
15use crate::model::responses::{
16    CostsHistoryResponse, DurableMediumResponse, IndicativeCostsResponse,
17};
18use async_trait::async_trait;
19
20/// Service for retrieving indicative costs and charges from the IG Markets API
21///
22/// This service provides regulatory cost information for trading activities,
23/// including costs for opening, closing, and editing positions.
24#[async_trait]
25pub trait CostsService: Send + Sync {
26    /// Returns indicative costs and charges for opening a position
27    ///
28    /// # Arguments
29    /// * `request` - The request containing position details
30    ///
31    /// # Returns
32    /// * `Ok(IndicativeCostsResponse)` - The indicative costs and charges
33    /// * `Err(AppError)` - If the request fails
34    async fn get_indicative_costs_open(
35        &self,
36        request: &OpenCostsRequest,
37    ) -> Result<IndicativeCostsResponse, AppError>;
38
39    /// Returns indicative costs and charges for closing a position
40    ///
41    /// # Arguments
42    /// * `request` - The request containing position details
43    ///
44    /// # Returns
45    /// * `Ok(IndicativeCostsResponse)` - The indicative costs and charges
46    /// * `Err(AppError)` - If the request fails
47    async fn get_indicative_costs_close(
48        &self,
49        request: &CloseCostsRequest,
50    ) -> Result<IndicativeCostsResponse, AppError>;
51
52    /// Returns indicative costs and charges for editing a position
53    ///
54    /// # Arguments
55    /// * `request` - The request containing position edit details
56    ///
57    /// # Returns
58    /// * `Ok(IndicativeCostsResponse)` - The indicative costs and charges
59    /// * `Err(AppError)` - If the request fails
60    async fn get_indicative_costs_edit(
61        &self,
62        request: &EditCostsRequest,
63    ) -> Result<IndicativeCostsResponse, AppError>;
64
65    /// Returns historical costs and charges for a date range
66    ///
67    /// # Arguments
68    /// * `from` - Start date in ISO format (e.g., "2023-01-01")
69    /// * `to` - End date in ISO format (e.g., "2023-12-31")
70    ///
71    /// # Returns
72    /// * `Ok(CostsHistoryResponse)` - Historical costs data
73    /// * `Err(AppError)` - If the request fails
74    async fn get_costs_history(
75        &self,
76        from: &str,
77        to: &str,
78    ) -> Result<CostsHistoryResponse, AppError>;
79
80    /// Returns a durable medium document for a quote reference
81    ///
82    /// # Arguments
83    /// * `quote_reference` - The indicative quote reference
84    ///
85    /// # Returns
86    /// * `Ok(DurableMediumResponse)` - The durable medium document
87    /// * `Err(AppError)` - If the request fails
88    async fn get_durable_medium(
89        &self,
90        quote_reference: &str,
91    ) -> Result<DurableMediumResponse, AppError>;
92}