ig_client/application/interfaces/order.rs
1use crate::error::AppError;
2use crate::model::requests::{
3 ClosePositionRequest, CreateOrderRequest, CreateWorkingOrderRequest, UpdatePositionRequest,
4};
5use crate::model::responses::{
6 ClosePositionResponse, CreateOrderResponse, CreateWorkingOrderResponse,
7 OrderConfirmationResponse, UpdatePositionResponse,
8};
9
10use async_trait::async_trait;
11
12#[async_trait]
13/// Service for creating, updating, and managing trading orders with the IG Markets API
14///
15/// This trait defines the interface for interacting with the IG Markets order endpoints,
16/// allowing clients to create new orders, get order confirmations, update existing positions,
17/// and close positions.
18pub trait OrderService: Send + Sync {
19 /// Creates a new order
20 async fn create_order(
21 &self,
22 order: &CreateOrderRequest,
23 ) -> Result<CreateOrderResponse, AppError>;
24
25 /// Gets the confirmation of an order
26 async fn get_order_confirmation(
27 &self,
28 deal_reference: &str,
29 ) -> Result<OrderConfirmationResponse, AppError>;
30
31 /// Updates an existing position
32 async fn update_position(
33 &self,
34 deal_id: &str,
35 update: &UpdatePositionRequest,
36 ) -> Result<UpdatePositionResponse, AppError>;
37
38 /// Closes an existing position
39 async fn close_position(
40 &self,
41 close_request: &ClosePositionRequest,
42 ) -> Result<ClosePositionResponse, AppError>;
43
44 /// Creates a new working order
45 async fn create_working_order(
46 &self,
47 order: &CreateWorkingOrderRequest,
48 ) -> Result<CreateWorkingOrderResponse, AppError>;
49
50 /// Deletes a working order based on the provided deal ID.
51 ///
52 /// # Parameters
53 /// - `deal_id`: A `String` representing the deal ID of the working order that needs to be deleted.
54 ///
55 /// # Returns
56 /// - `Result<(), AppError>`:
57 /// - On success, the function returns `Ok(())` indicating that the working order was successfully deleted.
58 /// - On failure, it returns `Err(AppError)` containing the error details that occurred during the deletion process.
59 ///
60 /// # Errors
61 /// This function will return an `AppError` in the following scenarios:
62 /// - If the deletion operation fails due to invalid deal ID.
63 /// - If there are connectivity issues with the database or external services.
64 /// - If the calling user does not have permission to delete the specified working order.
65 ///
66 async fn delete_working_order(&self, deal_id: &str) -> Result<(), AppError>;
67}