ig_client/presentation/
order.rs

1/******************************************************************************
2   Author: Joaquín Béjar García
3   Email: jb@taunais.com
4   Date: 13/5/25
5******************************************************************************/
6use pretty_simple_display::DisplaySimple;
7use serde::{Deserialize, Serialize};
8
9/// Order direction (buy or sell)
10#[derive(Debug, Clone, DisplaySimple, Serialize, Deserialize, PartialEq, Default)]
11#[serde(rename_all = "UPPERCASE")]
12pub enum Direction {
13    /// Buy direction (long position)
14    #[default]
15    Buy,
16    /// Sell direction (short position)
17    Sell,
18}
19
20/// Order type
21#[derive(Debug, Clone, DisplaySimple, Serialize, Deserialize, PartialEq, Default)]
22#[serde(rename_all = "UPPERCASE")]
23pub enum OrderType {
24    /// Limit order - executed when price reaches specified level
25    #[default]
26    Limit,
27    /// Market order - executed immediately at current market price
28    Market,
29    /// Quote order - executed at quoted price
30    Quote,
31    /// Stop order - becomes market order when price reaches specified level
32    Stop,
33    /// Stop limit order - becomes limit order when price reaches specified level
34    StopLimit,
35}
36
37/// Represents the status of an order or transaction in the system.
38///
39/// This enum covers various states an order can be in throughout its lifecycle,
40/// from creation to completion or cancellation.
41#[derive(Debug, Clone, DisplaySimple, Serialize, Deserialize, PartialEq, Default)]
42#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
43pub enum Status {
44    /// Order has been amended or modified after initial creation
45    Amended,
46    /// Order has been deleted from the system
47    Deleted,
48    /// Order has been completely closed with all positions resolved
49    FullyClosed,
50    /// Order has been opened and is active in the market
51    Opened,
52    /// Order has been partially closed with some positions still open
53    PartiallyClosed,
54    /// Order has been closed but may differ from FullyClosed in context
55    Closed,
56    /// Default state - order is open and active in the market
57    #[default]
58    Open,
59    /// Order has been updated with new parameters
60    Updated,
61    /// Order has been accepted by the system or exchange
62    Accepted,
63    /// Order has been rejected by the system or exchange
64    Rejected,
65    /// Order is currently working (waiting to be filled)
66    Working,
67    /// Order has been filled (executed)
68    Filled,
69    /// Order has been cancelled
70    Cancelled,
71    /// Order has expired (time in force elapsed)
72    Expired,
73}
74
75/// Order duration (time in force)
76#[derive(Debug, Clone, DisplaySimple, Serialize, Deserialize, PartialEq, Default)]
77#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
78pub enum TimeInForce {
79    /// Order remains valid until cancelled by the client
80    #[default]
81    GoodTillCancelled,
82    /// Order remains valid until a specified date
83    GoodTillDate,
84    /// Order is executed immediately (partially or completely) or cancelled
85    ImmediateOrCancel,
86    /// Order must be filled completely immediately or cancelled
87    FillOrKill,
88}