OrderService

Trait OrderService 

Source
pub trait OrderService: Send + Sync {
    // Required methods
    fn create_order<'life0, 'life1, 'async_trait>(
        &'life0 self,
        order: &'life1 CreateOrderRequest,
    ) -> Pin<Box<dyn Future<Output = Result<CreateOrderResponse, AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_order_confirmation<'life0, 'life1, 'async_trait>(
        &'life0 self,
        deal_reference: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<OrderConfirmationResponse, AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_order_confirmation_w_retry<'life0, 'life1, 'async_trait>(
        &'life0 self,
        deal_reference: &'life1 str,
        retries: u64,
        delay_ms: u64,
    ) -> Pin<Box<dyn Future<Output = Result<OrderConfirmationResponse, AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn update_position<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        deal_id: &'life1 str,
        update: &'life2 UpdatePositionRequest,
    ) -> Pin<Box<dyn Future<Output = Result<UpdatePositionResponse, AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn update_level_in_position<'life0, 'life1, 'async_trait>(
        &'life0 self,
        deal_id: &'life1 str,
        limit_level: Option<f64>,
    ) -> Pin<Box<dyn Future<Output = Result<UpdatePositionResponse, AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn close_position<'life0, 'life1, 'async_trait>(
        &'life0 self,
        close_request: &'life1 ClosePositionRequest,
    ) -> Pin<Box<dyn Future<Output = Result<ClosePositionResponse, AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn create_working_order<'life0, 'life1, 'async_trait>(
        &'life0 self,
        order: &'life1 CreateWorkingOrderRequest,
    ) -> Pin<Box<dyn Future<Output = Result<CreateWorkingOrderResponse, AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn delete_working_order<'life0, 'life1, 'async_trait>(
        &'life0 self,
        deal_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Service for creating, updating, and managing trading orders with the IG Markets API

This trait defines the interface for interacting with the IG Markets order endpoints, allowing clients to create new orders, get order confirmations, update existing positions, and close positions.

Required Methods§

Source

fn create_order<'life0, 'life1, 'async_trait>( &'life0 self, order: &'life1 CreateOrderRequest, ) -> Pin<Box<dyn Future<Output = Result<CreateOrderResponse, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Creates a new order

Source

fn get_order_confirmation<'life0, 'life1, 'async_trait>( &'life0 self, deal_reference: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<OrderConfirmationResponse, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Gets the confirmation of an order

Source

fn get_order_confirmation_w_retry<'life0, 'life1, 'async_trait>( &'life0 self, deal_reference: &'life1 str, retries: u64, delay_ms: u64, ) -> Pin<Box<dyn Future<Output = Result<OrderConfirmationResponse, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Gets the confirmation of an order with retry logic

Source

fn update_position<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, deal_id: &'life1 str, update: &'life2 UpdatePositionRequest, ) -> Pin<Box<dyn Future<Output = Result<UpdatePositionResponse, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Updates an existing position

Source

fn update_level_in_position<'life0, 'life1, 'async_trait>( &'life0 self, deal_id: &'life1 str, limit_level: Option<f64>, ) -> Pin<Box<dyn Future<Output = Result<UpdatePositionResponse, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Asynchronously updates the limit level of a position in a specified deal.

§Parameters
  • deal_id: A reference to a string slice representing the unique identifier of the deal whose position is to be updated.
  • limit_level: An optional f64 value specifying the new limit level for the position. If None, the limit level will not be updated.
§Returns
  • Result<UpdatePositionResponse, AppError>:
    • On success, returns an UpdatePositionResponse containing details of the updated position.
    • On failure, returns an AppError indicating the error encountered during the operation.
§Errors

This function returns an AppError in case of:

  • Invalid deal_id (e.g., deal doesn’t exist).
  • Backend service issues or database failures.
  • Input validation errors for the limit_level.
§Notes

Ensure that the passed deal_id exists, and the limit_level (if provided) adheres to any required constraints specific to the application’s domain logic.

Source

fn close_position<'life0, 'life1, 'async_trait>( &'life0 self, close_request: &'life1 ClosePositionRequest, ) -> Pin<Box<dyn Future<Output = Result<ClosePositionResponse, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Closes an existing position

Source

fn create_working_order<'life0, 'life1, 'async_trait>( &'life0 self, order: &'life1 CreateWorkingOrderRequest, ) -> Pin<Box<dyn Future<Output = Result<CreateWorkingOrderResponse, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Creates a new working order

Source

fn delete_working_order<'life0, 'life1, 'async_trait>( &'life0 self, deal_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Deletes a working order based on the provided deal ID.

§Parameters
  • deal_id: A String representing the deal ID of the working order that needs to be deleted.
§Returns
  • Result<(), AppError>:
    • On success, the function returns Ok(()) indicating that the working order was successfully deleted.
    • On failure, it returns Err(AppError) containing the error details that occurred during the deletion process.
§Errors

This function will return an AppError in the following scenarios:

  • If the deletion operation fails due to invalid deal ID.
  • If there are connectivity issues with the database or external services.
  • If the calling user does not have permission to delete the specified working order.

Implementors§