ig_client/application/services/interfaces/
order.rs

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