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
23        order: &CreateOrderRequest,
24    ) -> Result<CreateOrderResponse, AppError>;
25
26    /// Gets the confirmation of an order
27    async fn get_order_confirmation(
28        &self,
29
30        deal_reference: &str,
31    ) -> Result<OrderConfirmationResponse, AppError>;
32
33    /// Updates an existing position
34    async fn update_position(
35        &self,
36
37        deal_id: &str,
38        update: &UpdatePositionRequest,
39    ) -> Result<UpdatePositionResponse, AppError>;
40
41    /// Closes an existing position
42    async fn close_position(
43        &self,
44
45        close_request: &ClosePositionRequest,
46    ) -> Result<ClosePositionResponse, AppError>;
47
48    /// Creates a new working order
49    async fn create_working_order(
50        &self,
51
52        order: &CreateWorkingOrderRequest,
53    ) -> Result<CreateWorkingOrderResponse, AppError>;
54}