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 = "UPPERCASE")]
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    #[serde(rename = "FULLY_CLOSED")]
50    FullyClosed,
51    /// Order has been opened and is active in the market
52    Opened,
53    /// Order has been partially closed with some positions still open
54    #[serde(rename = "PARTIALLY_CLOSED")]
55    PartiallyClosed,
56    /// Order has been closed but may differ from FullyClosed in context
57    Closed,
58    /// Default state - order is open and active in the market
59    #[default]
60    Open,
61    /// Order has been updated with new parameters
62    Updated,
63    /// Order has been accepted by the system or exchange
64    Accepted,
65    /// Order has been rejected by the system or exchange
66    Rejected,
67    /// Order is currently working (waiting to be filled)
68    Working,
69    /// Order has been filled (executed)
70    Filled,
71    /// Order has been cancelled
72    Cancelled,
73    /// Order has expired (time in force elapsed)
74    Expired,
75}
76
77/// Order duration (time in force)
78#[derive(Debug, Clone, DisplaySimple, Serialize, Deserialize, PartialEq, Default)]
79pub enum TimeInForce {
80    /// Order remains valid until cancelled by the client
81    #[serde(rename = "GOOD_TILL_CANCELLED")]
82    #[default]
83    GoodTillCancelled,
84    /// Order remains valid until a specified date
85    #[serde(rename = "GOOD_TILL_DATE")]
86    GoodTillDate,
87    /// Order is executed immediately (partially or completely) or cancelled
88    #[serde(rename = "IMMEDIATE_OR_CANCEL")]
89    ImmediateOrCancel,
90    /// Order must be filled completely immediately or cancelled
91    #[serde(rename = "FILL_OR_KILL")]
92    FillOrKill,
93}