ig_client/application/services/interfaces/
order.rs

1use crate::application::models::account::WorkingOrders;
2use crate::application::models::order::{
3    ClosePositionRequest, ClosePositionResponse, CreateOrderRequest, CreateOrderResponse,
4    OrderConfirmation, UpdatePositionRequest, UpdatePositionResponse,
5};
6use crate::application::models::working_order::{
7    CreateWorkingOrderRequest, CreateWorkingOrderResponse,
8};
9use crate::error::AppError;
10use crate::session::interface::IgSession;
11use async_trait::async_trait;
12
13#[async_trait]
14/// Service for creating, updating, and managing trading orders with the IG Markets API
15///
16/// This trait defines the interface for interacting with the IG Markets order endpoints,
17/// allowing clients to create new orders, get order confirmations, update existing positions,
18/// and close positions.
19pub trait OrderService: Send + Sync {
20    /// Creates a new order
21    async fn create_order(
22        &self,
23        session: &IgSession,
24        order: &CreateOrderRequest,
25    ) -> Result<CreateOrderResponse, AppError>;
26
27    /// Gets the confirmation of an order
28    async fn get_order_confirmation(
29        &self,
30        session: &IgSession,
31        deal_reference: &str,
32    ) -> Result<OrderConfirmation, AppError>;
33
34    /// Updates an existing position
35    async fn update_position(
36        &self,
37        session: &IgSession,
38        deal_id: &str,
39        update: &UpdatePositionRequest,
40    ) -> Result<UpdatePositionResponse, AppError>;
41
42    /// Closes an existing position
43    async fn close_position(
44        &self,
45        session: &IgSession,
46        close_request: &ClosePositionRequest,
47    ) -> Result<ClosePositionResponse, AppError>;
48
49    /// Gets all working orders
50    async fn get_working_orders(&self, session: &IgSession) -> Result<WorkingOrders, AppError>;
51
52    /// Creates a new working order
53    async fn create_working_order(
54        &self,
55        session: &IgSession,
56        order: &CreateWorkingOrderRequest,
57    ) -> Result<CreateWorkingOrderResponse, AppError>;
58}